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)
|
||||
|
||||
@@ -21,7 +21,7 @@ type MsgController struct {
|
||||
// @Param storeIDs formData string true "门店 ID列表"
|
||||
// @Param title formData string true "消息标题"
|
||||
// @Param content formData string true "消息内容"
|
||||
// @Param messageType formData int true "消息类型,1为普通给商家发的消息,3为活动内容通知"
|
||||
// @Param messageType formData int true "消息类型,1为普通给商家发的消息,3为活动内容通知, 4为知识库"
|
||||
// @Param actInfo formData string false "如果是活动内容通知需传"
|
||||
// @Param imgs formData string false "图片s"
|
||||
// @Param isAsync formData bool false "是否异步操作,缺省否"
|
||||
@@ -41,6 +41,26 @@ func (c *MsgController) SendStoreMessage() {
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 发送微信消息(知识库
|
||||
// @Description 发送微信消息(知识库
|
||||
// @Param token header string true "认证token"
|
||||
// @Param storeIDs formData string true "门店 ID列表"
|
||||
// @Param title formData string true "消息标题"
|
||||
// @Param knowIDs formData string true "消息类型,1为普通给商家发的消息,3为活动内容通知"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /SendStoreMessageKnowledge [post]
|
||||
func (c *MsgController) SendStoreMessageKnowledge() {
|
||||
c.callSendStoreMessageKnowledge(func(params *tMsgSendStoreMessageKnowledgeParams) (retVal interface{}, errCode string, err error) {
|
||||
var knowIDs, storeIDs []int
|
||||
if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs, params.KnowIDs, &knowIDs); err != nil {
|
||||
return retVal, "", err
|
||||
}
|
||||
retVal, err = weixinmsg.SendStoreMessageKnowledge(params.Ctx, params.Title, knowIDs, storeIDs)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 发送用户微信消息
|
||||
// @Description 发送用户微信消息
|
||||
// @Param token header string true "认证token"
|
||||
|
||||
@@ -963,6 +963,15 @@ func init() {
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:MsgController"] = append(web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:MsgController"],
|
||||
web.ControllerComments{
|
||||
Method: "SendStoreMessageKnowledge",
|
||||
Router: `/SendStoreMessageKnowledge`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Filters: nil,
|
||||
Params: nil})
|
||||
|
||||
web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:MsgController"] = append(web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:MsgController"],
|
||||
web.ControllerComments{
|
||||
Method: "SendUserMessage",
|
||||
|
||||
Reference in New Issue
Block a user