aa
This commit is contained in:
@@ -3,6 +3,7 @@ package weixinmsg
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/platformapi/weixinapi"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -76,7 +77,7 @@ const (
|
||||
|
||||
WX_STORE_ALERT_TEMPLATE_ID = "0AjzVl1wPl6iO4nFOS4IEsJYSzBymlT37DciIvcCOxE"
|
||||
|
||||
WX_KNOWLEDGE_BASE_TEMPLATE_ID = "0qAvaN7g8oveRgNw127Q7NdnCmmcN0H1a-uaBVjJWzk" //知识库模板
|
||||
WX_KNOWLEDGE_BASE_TEMPLATE_ID = "1Fc703r13L3KQ6r_jdql2em_YhQ9CyOXTnqtDx-6Hx8" //知识库模板
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -956,6 +957,96 @@ func NotifyAdjustOrder(order *model.GoodsOrder) (err error) {
|
||||
return SendMsgToStore(storeID, WX_ADJUSTORDER_TEMPLATE_ID, globals.WxBackstageHost+fmt.Sprintf("%s%d", WX_TO_ORDER_PAGE_URL, storeID), WX_MINI_TO_ORDER_PAGE_URL, data)
|
||||
}
|
||||
|
||||
func SendStoreMessageKnowledge(ctx *jxcontext.Context, title string, knowIDs, storeIDs []int) (hint string, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
content string
|
||||
)
|
||||
knows, err := dao.GetKnowledgeDepotNoPage(db, knowIDs)
|
||||
for k, v := range knows {
|
||||
if k != 0 {
|
||||
content += weixinapi.SNSCutLine
|
||||
}
|
||||
content += v.Content
|
||||
}
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
msg := &model.Message{
|
||||
Title: title,
|
||||
Content: content,
|
||||
Type: 4,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(msg, ctx.GetUserName())
|
||||
if err = dao.CreateEntity(db, msg); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return "", err
|
||||
}
|
||||
msgStatusList := make([]*model.MessageStatus, len(storeIDs))
|
||||
for k, storeID := range storeIDs {
|
||||
msgStatus := &model.MessageStatus{
|
||||
MessageID: msg.ID,
|
||||
StoreID: storeID,
|
||||
Status: model.MessageStatusNew,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(msgStatus, ctx.GetUserName())
|
||||
if err = dao.CreateEntity(db, msgStatus); err != nil {
|
||||
dao.Rollback(db, txDB)
|
||||
return "", err
|
||||
}
|
||||
msgStatusList[k] = msgStatus
|
||||
}
|
||||
dao.Commit(db, txDB)
|
||||
|
||||
rootTask := tasksch.NewParallelTask("SendStoreMessageKnowledge", nil, ctx, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
db := dao.GetDB()
|
||||
msgStatus := batchItemList[0].(*model.MessageStatus)
|
||||
if err = NotifyKnowledge(msgStatus.StoreID, title); err == nil {
|
||||
msgStatus.Status = model.MessageStatusSendAllSuccess
|
||||
} else {
|
||||
msgStatus.Status = model.MessageStatusSendAllFailed
|
||||
}
|
||||
dao.WrapUpdateULEntity(msgStatus, ctx.GetUserName())
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(msgStatus, false))
|
||||
_, err = dao.UpdateEntity(db, msgStatus)
|
||||
return nil, err
|
||||
}, msgStatusList)
|
||||
tasksch.HandleTask(rootTask, nil, true).Run()
|
||||
//if !isAsync {
|
||||
// _, err = rootTask.GetResult(0)
|
||||
//} else {
|
||||
hint = rootTask.ID
|
||||
//}
|
||||
return "", err
|
||||
}
|
||||
|
||||
func NotifyKnowledge(storeID int, title string) (err error) {
|
||||
globals.SugarLogger.Debugf("NotifyKnowledge storeID:%d, title:%s", storeID, title)
|
||||
templateID := WX_KNOWLEDGE_BASE_TEMPLATE_ID
|
||||
data := map[string]interface{}{
|
||||
"first": map[string]interface{}{
|
||||
"value": "今日每日一词已更新!",
|
||||
"color": "#333333",
|
||||
},
|
||||
"keyword1": map[string]interface{}{
|
||||
"value": time.Now().Format("2006-01-02"),
|
||||
"color": "#2E408E",
|
||||
},
|
||||
"keyword2": map[string]interface{}{
|
||||
"value": title,
|
||||
"color": "#2E408E",
|
||||
},
|
||||
"remark": map[string]interface{}{
|
||||
"value": "",
|
||||
},
|
||||
}
|
||||
return SendMsgToStore(storeID, templateID, "", "", data)
|
||||
}
|
||||
|
||||
func SendUserMessage(ctx *jxcontext.Context, title, content string, userIDs []string, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
db := dao.GetDB()
|
||||
txDB, _ := dao.Begin(db)
|
||||
|
||||
Reference in New Issue
Block a user