到家商城的订单发通知消息

+Store.LinkStoreID
This commit is contained in:
gazebo
2020-02-04 16:20:09 +08:00
parent b76404d31d
commit f118cd8331
14 changed files with 249 additions and 185 deletions

View File

@@ -9,6 +9,7 @@ import (
"git.rosy.net.cn/jx-callback/business/authz/autils"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"git.rosy.net.cn/jx-callback/business/jxutils/netprinter"
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
"git.rosy.net.cn/jx-callback/business/partner"
@@ -30,8 +31,8 @@ const (
WX_MINI_TO_ORDER_PAGE_URL = "pages/order-manager/main"
WX_MINI_TO_STORE_SKU_PAGE_URL = "pages/goods-manager/main"
WX_MINI_TO_SHOW_COMMENTS_DETAIL_URL = "pages/store-comment/main"
WX_MINI_TO_SHOW_MSG = "pages/msg-page/main?msgID=%d&msgStatusID=%d"
WX_MINI_TO_SHOW_COMMENTS_DETAIL_URL = "pages/pagesStore/store-comment/main"
WX_MINI_TO_SHOW_MSG = "pages/pagesStore/msg-page/main?msgID=%d&msgStatusID=%d"
//新订单模板消息文字颜色
WX_NEW_ORDER_TEMPLATE_COLOR = "#173177"
@@ -54,7 +55,7 @@ const (
WX_SALE_BILL_TEMPLATE_ID = "eTUuFZMWH7IsVBfcxNMpmaHYaxRkUaD6zG8wSGJDcic"
WX_NORMAL_STORE_MSG_TEMPLATE_ID = "7ngcTFYiUFw66BMzIYntM1tpy-xZkJwlcCT5pVtXwtw"
WX_NORMAL_STORE_MSG_TEMPLATE_ID = "UlLvTMXDPIX9Ztyu3MMb84Zu-cCFo7trvQI8YRrAFjc" //"7ngcTFYiUFw66BMzIYntM1tpy-xZkJwlcCT5pVtXwtw"
// WX_CHANGE_APPROVED_TEMPLATE_ID = "gIG2olBZtQbjXmp6doNB_dESu60By5xuXYOGxksLv3Y"
// WX_CHANGE_REJECTED_TEMPLATE_ID = "tn2QXWi4HtSIwaztmtN6Bb2uzNL-jBxWltCZTDNJuYE"
WX_ORDER_APPLY_CANCEL_TEMPLATE_ID = "e6urTtcm4PL0rgDMG_1qWNOwrE3Qxqcm_dx0kWWCmEI"
@@ -69,7 +70,7 @@ const (
)
var (
venderColors = map[int]string{
VendorColors = map[int]string{
model.VendorIDJD: WX_TEMPLATE_VENDERCOLOR_JDDJ,
model.VendorIDMTWM: WX_TEMPLATE_VENDERCOLOR_MT,
model.VendorIDELM: WX_TEMPLATE_VENDERCOLOR_ELM,
@@ -92,33 +93,6 @@ var (
func GetWeixinOpenIDsFromStoreID(storeID int) (retVal []string) {
db := dao.GetDB()
openIDMap := make(map[string]int)
// if !globals.DisableWXAuth1 {
// var openIDList []string
// sql := `
// SELECT openid
// FROM weixins t1
// JOIN
// (SELECT id
// FROM weixins
// WHERE jxstoreid = ? AND parentid = -1) t2 ON t2.id = t1.parentid
// WHERE openid IS NOT NULL
// UNION
// SELECT openid
// FROM weixins
// WHERE jxstoreid = ? AND parentid = -1 AND openid IS NOT NULL`
// sqlParams := []interface{}{
// storeID,
// storeID,
// }
// err := dao.GetRows(db, &openIDList, sql, sqlParams...)
// if err != nil || len(openIDList) == 0 {
// globals.SugarLogger.Infof("GetWeixinOpenIDsFromStoreID can not find openid for store:%d, num:%d, error:%v", storeID, len(openIDList), err)
// return retVal
// }
// for _, v := range openIDList {
// openIDMap[v] = 1
// }
// }
if globals.EnableWXAuth2 {
if userIDList, err2 := api2.RoleMan.GetRoleUserList(autils.NewStoreBossRole(storeID)); err2 == nil {
for _, v := range userIDList {
@@ -147,7 +121,7 @@ func GetWeixinOpenIDsFromStoreID(storeID int) (retVal []string) {
func SendMsgToStore(storeID int, templateID, downloadURL, miniPageURL string, data interface{}) (err error) {
globals.SugarLogger.Debugf("SendMsgToStore storeID:%d, templateID:%s, downloadURL:%s, miniPageURL:%s", storeID, templateID, downloadURL, miniPageURL)
if storeID == 0 { // 测试,只发给我
//SmartMessageTemplateSend("oYN_usk0AeGc_C6VEZfmFQP5VHMQ", templateID, downloadURL, miniPageURL, data)
// SmartMessageTemplateSend("oYN_ust9hXKEvEv0X6Mq6nlAWs_E", templateID, downloadURL, miniPageURL, data)
} else {
openIDs := GetWeixinOpenIDsFromStoreID(storeID)
successCount := 0
@@ -233,7 +207,7 @@ func NotifyNewOrder(order *model.GoodsOrder) (err error) {
},
"orderType": map[string]interface{}{
"value": fmt.Sprintf("%s 第%d号订单", model.VendorChineseNames[order.VendorID], order.OrderSeq),
"color": venderColors[order.VendorID],
"color": VendorColors[order.VendorID],
},
"customerName": map[string]interface{}{
"value": order.ConsigneeName,
@@ -283,7 +257,7 @@ func NotifyWaybillStatus(bill *model.Waybill, order *model.GoodsOrder, isBillAlr
} else if bill.WaybillVendorID == model.VendorIDDada {
templateID = WX_DADA_DELIVERY_DONE_TEMPLATE_ID
}
titleColor = venderColors[bill.OrderVendorID]
titleColor = VendorColors[bill.OrderVendorID]
title = fmt.Sprintf("%s 第%d号订单的配送完成", model.VendorChineseNames[bill.OrderVendorID], order.OrderSeq)
}
if templateID != "" {
@@ -333,7 +307,7 @@ func NotifyUserApplyCancel(order *model.GoodsOrder, cancelReason string) (err er
},
"keyword1": map[string]interface{}{ // 订单编号
"value": fmt.Sprintf("%s第%d号订单, %s", model.VendorChineseNames[order.VendorID], order.OrderSeq, order.VendorOrderID),
"color": venderColors[order.VendorID],
"color": VendorColors[order.VendorID],
},
"keyword2": map[string]interface{}{ // 订单日期
"value": utils.Time2Str(order.OrderCreatedAt),
@@ -384,7 +358,7 @@ func NotifyOrderCanceled(order *model.GoodsOrder) (err error) {
},
"orderName": map[string]interface{}{
"value": fmt.Sprintf("%s第%d号订单, %s", model.VendorChineseNames[order.VendorID], order.OrderSeq, order.VendorOrderID),
"color": venderColors[order.VendorID],
"color": VendorColors[order.VendorID],
},
"remark": map[string]interface{}{
"value": order.ConsigneeMobile,
@@ -546,11 +520,7 @@ func NotifyStoreMessage(storeID, msgID, msgStatusID int, title, content string)
"color": "#2E408E",
},
"keyword2": map[string]interface{}{
"value": "无",
"color": "#2E408E",
},
"keyword3": map[string]interface{}{
"value": "无",
"value": utils.GetCurTimeStr(),
"color": "#2E408E",
},
"remark": map[string]interface{}{
@@ -596,7 +566,7 @@ func NotifyAfsOrderStatus(afsOrder *model.AfsOrder) (err error) {
},
"keyword3": map[string]interface{}{
"value": utils.Time2Str(afsOrder.AfsCreatedAt),
"color": venderColors[order.VendorID],
"color": VendorColors[order.VendorID],
},
"remark": map[string]interface{}{
"value": comment,
@@ -690,3 +660,61 @@ func NotifyStoreAlertMessage(storeID int, storeName, title, content string) (err
}
return err
}
func SendStoreMessage(ctx *jxcontext.Context, title, content string, storeIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
db := dao.GetDB()
dao.Begin(db)
defer func() {
if r := recover(); r != nil {
dao.Rollback(db)
panic(r)
}
}()
msg := &model.Message{
Title: title,
Content: content,
Type: model.MessageTypeStore,
}
dao.WrapAddIDCULDEntity(msg, ctx.GetUserName())
if err = dao.CreateEntity(db, msg); err != nil {
dao.Rollback(db)
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)
return "", err
}
msgStatusList[k] = msgStatus
}
dao.Commit(db)
rootTask := tasksch.NewParallelTask("SendStoreMessage", nil, ctx, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
db := dao.GetDB()
msgStatus := batchItemList[0].(*model.MessageStatus)
if err = NotifyStoreMessage(msgStatus.StoreID, msgStatus.MessageID, msgStatus.ID, msg.Title, msg.Content); 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.ManageTask(rootTask).Run()
if !isAsync {
_, err = rootTask.GetResult(0)
} else {
hint = rootTask.ID
}
return "", err
}