From 7f94d2b48fd5e4253785991e1ead630afe99e427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 23 Feb 2021 10:16:36 +0800 Subject: [PATCH] aa --- business/jxcallback/orderman/fake_jd_order.go | 2 +- business/jxstore/cms/store.go | 14 ++++ business/jxutils/weixinmsg/weixinmsg.go | 77 +++++++++++++------ business/model/message.go | 11 +-- controllers/cms_msg.go | 4 +- controllers/cms_store.go | 14 ++++ routers/commentsRouter_controllers.go | 9 +++ 7 files changed, 102 insertions(+), 29 deletions(-) diff --git a/business/jxcallback/orderman/fake_jd_order.go b/business/jxcallback/orderman/fake_jd_order.go index d51444458..2467d5ae1 100644 --- a/business/jxcallback/orderman/fake_jd_order.go +++ b/business/jxcallback/orderman/fake_jd_order.go @@ -69,6 +69,6 @@ func notifyWxNewFakeJdOrder(order *model.GoodsOrder, storeID int) (err error) { title := fmt.Sprintf("你有到家菜市新订单%d", order.OrderSeq) content := sb.String() // globals.SugarLogger.Debugf("notifyWxNewFakeJdOrder, orderID:%s, content:%s", order.VendorOrderID, content) - _, err = weixinmsg.SendStoreMessage(jxcontext.AdminCtx, title, content, []int{storeID}, true, true) + _, err = weixinmsg.SendStoreMessage(jxcontext.AdminCtx, title, content, []int{storeID}, "", model.MessageTypeStore, true, true) return err } diff --git a/business/jxstore/cms/store.go b/business/jxstore/cms/store.go index 47c7f6898..13fb27e8d 100644 --- a/business/jxstore/cms/store.go +++ b/business/jxstore/cms/store.go @@ -3992,3 +3992,17 @@ func RefreshMTWMToken(ctx *jxcontext.Context) (err error) { // dao.GetStoresMapList(db, []int{model.VendorIDMTWM}, nil, nil, status, isSync, "", "", globals.Mtwm2Code) return err } + +func StoreConfirmAct(ctx *jxcontext.Context, msgStatusID int) (err error) { + msgStatus := &model.MessageStatus{} + msgStatus.ID = msgStatusID + db := dao.GetDB() + if err = dao.GetEntity(db, msgStatus); err != nil { + return err + } + msgStatus.ReadCount++ + msgStatus.ConfirmStatus = model.YES + dao.WrapUpdateULEntity(msgStatus, ctx.GetUserName()) + _, err = dao.UpdateEntity(db, msgStatus, "ReadCount", "ConfirmStatus") + return err +} diff --git a/business/jxutils/weixinmsg/weixinmsg.go b/business/jxutils/weixinmsg/weixinmsg.go index 69ad135db..57bdb0061 100644 --- a/business/jxutils/weixinmsg/weixinmsg.go +++ b/business/jxutils/weixinmsg/weixinmsg.go @@ -1,6 +1,7 @@ package weixinmsg import ( + "encoding/json" "fmt" "math" "strings" @@ -60,6 +61,7 @@ const ( WX_SALE_BILL_TEMPLATE_ID = "eTUuFZMWH7IsVBfcxNMpmaHYaxRkUaD6zG8wSGJDcic" + WX_NORMAL_STORE_ACT_MSG_TEMPLATE_ID = "eXsfOMvDOKVSht0Q0v4IsDrx3MBlRCVYwYl7Hi2uuuI" WX_NORMAL_STORE_MSG_TEMPLATE_ID = "EUeIJEz2TLUAn4TU2EffOGYLd3dEaYndD_y6Sw9FcSU" WX_CHANGE_APPROVED_TEMPLATE_ID = "gIG2olBZtQbjXmp6doNB_dESu60By5xuXYOGxksLv3Y" WX_CHANGE_REJECTED_TEMPLATE_ID = "OBF4-d5inK95epHcUltpdb1zq9boVp2HESpASVRh1Oo" @@ -604,26 +606,56 @@ func NotifyStoreOpRequestStatus(isAccepted bool, storeID, nameID int, spuName st return err } -func NotifyStoreMessage(storeID, msgID, msgStatusID int, title, content string) (err error) { - globals.SugarLogger.Debugf("NotifyStoreMessage storeID:%d, msgID:%d, title:%s, content:%s", storeID, msgID, title, content) - templateID := WX_NORMAL_STORE_MSG_TEMPLATE_ID +func NotifyStoreMessage(storeID, msgID, msgStatusID int, msg *model.Message) (err error) { + globals.SugarLogger.Debugf("NotifyStoreMessage storeID:%d, msgID:%d, title:%s, content:%s", storeID, msgID, msg.Title, msg.Content) + templateID := "" fileURL := globals.WxBackstageHost + fmt.Sprintf(WX_TO_SHOW_MSG, msgID, msgStatusID) - data := map[string]interface{}{ - "first": map[string]interface{}{ - "value": content, - "color": "#333333", - }, - "keyword1": map[string]interface{}{ - "value": title, - "color": "#2E408E", - }, - "keyword2": map[string]interface{}{ - "value": utils.GetCurTimeStr(), - "color": "#2E408E", - }, - "remark": map[string]interface{}{ - "value": "", - }, + data := make(map[string]interface{}) + switch msg.Type { + case model.MessageTypeStore: + templateID = WX_NORMAL_STORE_MSG_TEMPLATE_ID + data = map[string]interface{}{ + "first": map[string]interface{}{ + "value": msg.Content, + "color": "#333333", + }, + "keyword1": map[string]interface{}{ + "value": msg.Title, + "color": "#2E408E", + }, + "keyword2": map[string]interface{}{ + "value": utils.GetCurTimeStr(), + "color": "#2E408E", + }, + "remark": map[string]interface{}{ + "value": "", + }, + } + case model.MessageTypeStoreAct: + actMap := make(map[string]interface{}) + err = json.Unmarshal([]byte(msg.ActInfo), &actMap) + templateID = WX_NORMAL_STORE_ACT_MSG_TEMPLATE_ID + data = map[string]interface{}{ + "first": map[string]interface{}{ + "value": "即将开展[" + msg.Title + "]活动,详情点击", + "color": "#333333", + }, + "keyword1": map[string]interface{}{ + "value": msg.Title, + "color": "#2E408E", + }, + "keyword2": map[string]interface{}{ + "value": actMap["beginAt"].(string) + "-" + actMap["endAt"].(string), + "color": "#2E408E", + }, + "keyword3": map[string]interface{}{ + "value": model.VendorNames[int(utils.MustInterface2Int64(actMap["vendorID"]))], + "color": "#2E408E", + }, + "remark": map[string]interface{}{ + "value": msg.Content, + }, + } } return SendMsgToStore(storeID, templateID, fileURL, fmt.Sprintf(WX_MINI_TO_SHOW_MSG, msgID, msgStatusID), data) } @@ -763,7 +795,7 @@ 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) { +func SendStoreMessage(ctx *jxcontext.Context, title, content string, storeIDs []int, actInfo string, messageType int, isAsync, isContinueWhenError bool) (hint string, err error) { db := dao.GetDB() //权限 if permission.IsRoled(ctx) { @@ -794,7 +826,8 @@ func SendStoreMessage(ctx *jxcontext.Context, title, content string, storeIDs [] msg := &model.Message{ Title: title, Content: content, - Type: model.MessageTypeStore, + Type: int8(messageType), + ActInfo: actInfo, } dao.WrapAddIDCULDEntity(msg, ctx.GetUserName()) if err = dao.CreateEntity(db, msg); err != nil { @@ -820,7 +853,7 @@ func SendStoreMessage(ctx *jxcontext.Context, title, content string, storeIDs [] 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 { + if err = NotifyStoreMessage(msgStatus.StoreID, msgStatus.MessageID, msgStatus.ID, msg); err == nil { msgStatus.Status = model.MessageStatusSendAllSuccess } else { msgStatus.Status = model.MessageStatusSendAllFailed diff --git a/business/model/message.go b/business/model/message.go index 5996a93c3..31f7868d1 100644 --- a/business/model/message.go +++ b/business/model/message.go @@ -49,11 +49,12 @@ type MessageActInfo struct { type MessageStatus struct { ModelIDCULD - MessageID int `orm:"column(message_id)" json:"messageID"` - StoreID int `orm:"column(store_id)" json:"storeID"` - Status int8 `json:"status"` - ReadCount int `json:"readCount"` - UserID string `orm:"column(user_id)" json:"userID"` + MessageID int `orm:"column(message_id)" json:"messageID"` + StoreID int `orm:"column(store_id)" json:"storeID"` + Status int8 `json:"status"` + ReadCount int `json:"readCount"` + UserID string `orm:"column(user_id)" json:"userID"` + ConfirmStatus int `json:"confirmStatus"` //商家确认活动,默认0不确认,1确认 } func (*MessageStatus) TableIndex() [][]string { diff --git a/controllers/cms_msg.go b/controllers/cms_msg.go index b408c8876..b5bda1413 100644 --- a/controllers/cms_msg.go +++ b/controllers/cms_msg.go @@ -21,6 +21,8 @@ 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 actInfo formData string true "如果是活动内容通知需传" // @Param isAsync formData bool false "是否异步操作,缺省否" // @Param isContinueWhenError formData bool false "单个失败是否继续,缺省false" // @Success 200 {object} controllers.CallResult @@ -32,7 +34,7 @@ func (c *MsgController) SendStoreMessage() { if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs); err != nil { return retVal, "", err } - retVal, err = weixinmsg.SendStoreMessage(params.Ctx, params.Title, params.Content, storeIDs, params.IsAsync, params.IsContinueWhenError) + retVal, err = weixinmsg.SendStoreMessage(params.Ctx, params.Title, params.Content, storeIDs, params.ActInfo, params.MessageType, params.IsAsync, params.IsContinueWhenError) return retVal, "", err }) } diff --git a/controllers/cms_store.go b/controllers/cms_store.go index 689f3e7a1..071609cf4 100644 --- a/controllers/cms_store.go +++ b/controllers/cms_store.go @@ -1038,3 +1038,17 @@ func (c *StoreController) GetBrandStore() { return retVal, "", err }) } + +// @Title 商家确认参与活动 +// @Description 商家确认参与活动 +// @Param token header string false "认证token" +// @Param msgStatusID formData int true "消息状态ID" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /StoreConfirmAct [post] +func (c *StoreController) StoreConfirmAct() { + c.callStoreConfirmAct(func(params *tStoreStoreConfirmActParams) (retVal interface{}, errCode string, err error) { + err = cms.StoreConfirmAct(params.Ctx, params.MsgStatusID) + return retVal, "", err + }) +} diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 1d2c7192b..f9fe82d4b 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -2304,6 +2304,15 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"], + beego.ControllerComments{ + Method: "StoreConfirmAct", + Router: `/StoreConfirmAct`, + AllowHTTPMethods: []string{"post"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"], beego.ControllerComments{ Method: "SyncJdStore",