- 添加订单取消微信与短信通知

This commit is contained in:
gazebo
2019-09-18 10:53:33 +08:00
parent 96bb72f87a
commit 285d7d68ec
3 changed files with 171 additions and 92 deletions

View File

@@ -373,6 +373,8 @@ func (s *DefScheduler) OnOrderStatusChanged(order *model.GoodsOrder, status *mod
status.Status == model.OrderStatusDeliverFailed {
if status.Status == model.OrderStatusApplyCancel {
s.notifyUserApplyCancel(savedOrderInfo.order, status.Remark)
} else if status.Status == model.OrderStatusCanceled {
s.notifyOrderCanceled(savedOrderInfo.order)
}
msghub.OnKeyOrderStatusChanged(savedOrderInfo.order)
}
@@ -1120,6 +1122,15 @@ func (s *DefScheduler) notifyUserApplyCancel(order *model.GoodsOrder, cancelReas
})
}
func (s *DefScheduler) notifyOrderCanceled(order *model.GoodsOrder) {
if order.Flag&model.OrderFlagMaskFake == 0 {
utils.CallFuncAsync(func() {
weixinmsg.NotifyOrderCanceled(order)
smsmsg.NotifyOrderCanceled(order)
})
}
}
func (s *DefScheduler) notify3rdPartyWaybill(order *model.GoodsOrder, bill *model.Waybill, isBillAlreadyCandidate bool) {
if order.Flag&model.OrderFlagMaskFake == 0 {
utils.CallFuncAsync(func() {

View File

@@ -24,41 +24,62 @@ var (
)
func SendSMSMsg(mobileList []string, signName, templateCode string, templateParam map[string]interface{}) (err error) {
errList := errlist.New()
mobileList = jxutils.StringMap2List(jxutils.StringList2Map(mobileList))
for _, mobileNum := range mobileList {
if mobileNum != "" {
globals.SugarLogger.Debugf("SendSMSMsg mobileNum:%s, templateCode:%s", mobileNum, templateCode)
if globals.EnableStoreWrite {
if response, err := api.SMSClient.Execute(globals.AliKey, globals.AliSecret, mobileNum, signName, templateCode, string(utils.MustMarshal(templateParam))); err != nil {
globals.SugarLogger.Warnf("SendSMSMsg mobileNum:%s failed with error:%v", mobileNum, err)
errList.AddErr(err)
} else if response.Code != aliyunsmsclient.ResponseCodeOk {
errMsg := fmt.Sprintf("SendSMSMsg mobileNum:%s failed with response:%s", mobileNum, utils.Format4Output(response, false))
errList.AddErr(fmt.Errorf(errMsg))
if warningMap[response.Code] == 1 {
globals.SugarLogger.Warnf(errMsg)
} else {
globals.SugarLogger.Infof(errMsg)
if len(mobileList) > 0 {
errList := errlist.New()
mobileList = jxutils.StringMap2List(jxutils.StringList2Map(mobileList))
for _, mobileNum := range mobileList {
if mobileNum != "" {
globals.SugarLogger.Debugf("SendSMSMsg mobileNum:%s, templateCode:%s", mobileNum, templateCode)
if globals.EnableStoreWrite {
if response, err := api.SMSClient.Execute(globals.AliKey, globals.AliSecret, mobileNum, signName, templateCode, string(utils.MustMarshal(templateParam))); err != nil {
globals.SugarLogger.Warnf("SendSMSMsg mobileNum:%s failed with error:%v", mobileNum, err)
errList.AddErr(err)
} else if response.Code != aliyunsmsclient.ResponseCodeOk {
errMsg := fmt.Sprintf("SendSMSMsg mobileNum:%s failed with response:%s", mobileNum, utils.Format4Output(response, false))
errList.AddErr(fmt.Errorf(errMsg))
if warningMap[response.Code] == 1 {
globals.SugarLogger.Warnf(errMsg)
} else {
globals.SugarLogger.Infof(errMsg)
}
}
}
}
}
}
return errList.GetErrListAsOne()
}
func NotifyNewOrder(order *model.GoodsOrder) (err error) {
store := &model.Store{}
store.ID = jxutils.GetSaleStoreIDFromOrder(order)
if err = dao.GetEntity(dao.GetDB(), store); err == nil {
if store.SMSNotify != 0 {
err = SendSMSMsg([]string{store.Tel1, store.Tel2}, "京西菜市", "SMS_173477895", map[string]interface{}{
"daySeq": order.OrderSeq,
"consigneeName": order.ConsigneeName,
"payMoney": jxutils.IntPrice2StandardString(order.ActualPayPrice),
})
}
err = errList.GetErrListAsOne()
}
return err
}
func getOrderNotifyPhone(order *model.GoodsOrder) (phoneList []string) {
store := &model.Store{}
store.ID = jxutils.GetSaleStoreIDFromOrder(order)
if err := dao.GetEntity(dao.GetDB(), store); err == nil {
if store.SMSNotify != 0 {
for _, v := range []string{store.Tel1, store.Tel2} {
if v != "" {
phoneList = append(phoneList, v)
}
}
}
}
return phoneList
}
func NotifyNewOrder(order *model.GoodsOrder) (err error) {
err = SendSMSMsg(getOrderNotifyPhone(order), "京西菜市", "SMS_173477895", map[string]interface{}{
"daySeq": order.OrderSeq,
"consigneeName": order.ConsigneeName,
"payMoney": jxutils.IntPrice2StandardString(order.ActualPayPrice),
})
return err
}
func NotifyOrderCanceled(order *model.GoodsOrder) (err error) {
err = SendSMSMsg(getOrderNotifyPhone(order), "京西菜市", "SMS_174275301", map[string]interface{}{
"vendorName": model.VendorChineseNames[order.VendorID],
"seq": order.OrderSeq,
"orderID": order.VendorOrderID,
})
return err
}

View File

@@ -55,9 +55,10 @@ const (
WX_SALE_BILL_TEMPLATE_ID = "eTUuFZMWH7IsVBfcxNMpmaHYaxRkUaD6zG8wSGJDcic"
WX_NORMAL_STORE_MSG_TEMPLATE_ID = "7ngcTFYiUFw66BMzIYntM1tpy-xZkJwlcCT5pVtXwtw"
WX_CHANGE_APPROVED_TEMPLATE_ID = "gIG2olBZtQbjXmp6doNB_dESu60By5xuXYOGxksLv3Y"
WX_CHANGE_REJECTED_TEMPLATE_ID = "tn2QXWi4HtSIwaztmtN6Bb2uzNL-jBxWltCZTDNJuYE"
WX_ORDER_CANCLED_TEMPLATE_ID = "iFozwiCsQdMs7VTiPXoBne45jKIQkoyxdGHSeAExP9U"
// WX_CHANGE_APPROVED_TEMPLATE_ID = "gIG2olBZtQbjXmp6doNB_dESu60By5xuXYOGxksLv3Y"
// WX_CHANGE_REJECTED_TEMPLATE_ID = "tn2QXWi4HtSIwaztmtN6Bb2uzNL-jBxWltCZTDNJuYE"
WX_ORDER_APPLY_CANCEL_TEMPLATE_ID = "e6urTtcm4PL0rgDMG_1qWNOwrE3Qxqcm_dx0kWWCmEI"
WX_ORDER_ORDER_CANCELED_TEMPLATE_ID = "HXjuSAbIk77Xh18hjgwoxHzbciR9jX3Rn2CpLJz9dZw"
WX_AFS_ORDER_WAIT4APPROVE_TEMPLATE_ID = "X29udtANvhX6x1Lyh-T40NGNjRXBbUj5oSBTfDhZAqU"
WX_AFS_ORDER_STATUS_CHANGED_TEMPLATE_ID = "99T33rrXX0VboO1hljs4x8dDoLiSj3QX_rOikPHIXkg"
@@ -186,6 +187,19 @@ func SmartMessageTemplateSend(userOpenID, templateID, downloadURL, miniPageURL s
return err
}
func getOrderDetailBrief(order *model.GoodsOrder) (brief string) {
sb := new(strings.Builder)
sb.WriteString(order.Skus[0].SkuName)
sb.WriteString("等共")
sb.WriteString(utils.Int2Str(order.Skus[0].Count))
sb.WriteString("份(")
sb.WriteString(jxutils.IntPrice2StandardString(order.Skus[0].SalePrice))
sb.WriteString("元/份)等,共支付了")
sb.WriteString(jxutils.IntPrice2StandardString(order.ActualPayPrice))
sb.WriteString("元")
return sb.String()
}
func NotifyNewOrder(order *model.GoodsOrder) (err error) {
globals.SugarLogger.Debugf("NotifyNewOrder orderID:%s", order.VendorOrderID)
if order.VendorID == model.VendorIDELM {
@@ -200,14 +214,7 @@ func NotifyNewOrder(order *model.GoodsOrder) (err error) {
sb.WriteString("老板,")
sb.WriteString(order.ConsigneeName)
sb.WriteString("购买了商品")
sb.WriteString(order.Skus[0].SkuName)
sb.WriteString("共")
sb.WriteString(utils.Int2Str(order.Skus[0].Count))
sb.WriteString("份(")
sb.WriteString(jxutils.IntPrice2StandardString(order.Skus[0].SalePrice))
sb.WriteString("元/份)等,共支付了")
sb.WriteString(jxutils.IntPrice2StandardString(order.ActualPayPrice))
sb.WriteString("元")
sb.WriteString(getOrderDetailBrief(order))
data := map[string]interface{}{
"first": map[string]interface{}{
"value": sb.String(),
@@ -321,15 +328,15 @@ func NotifyUserApplyCancel(order *model.GoodsOrder, cancelReason string) (err er
"value": title,
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"keyword1": map[string]interface{}{
"value": order.VendorOrderID,
"keyword1": map[string]interface{}{ // 订单编号
"value": fmt.Sprintf("%s第%d号订单, %s", model.VendorChineseNames[order.VendorID], order.OrderSeq, order.VendorOrderID),
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"keyword2": map[string]interface{}{
"value": fmt.Sprintf("%s 第%d号订单", model.VendorChineseNames[order.VendorID], order.OrderSeq),
"keyword2": map[string]interface{}{ // 订单日期
"value": utils.Time2Str(order.OrderCreatedAt),
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"keyword3": map[string]interface{}{
"keyword3": map[string]interface{}{ // 订单内容
"value": cancelReason,
"color": venderColors[order.VendorID],
},
@@ -339,7 +346,46 @@ func NotifyUserApplyCancel(order *model.GoodsOrder, cancelReason string) (err er
},
}
storeID := jxutils.GetSaleStoreIDFromOrder(order)
err = SendMsgToStore(storeID, WX_ORDER_CANCLED_TEMPLATE_ID, "", "", data)
err = SendMsgToStore(storeID, WX_ORDER_APPLY_CANCEL_TEMPLATE_ID, "", "", data)
netprinter.NofityOrderMsg(jxcontext.AdminCtx, jxutils.GetSaleStoreIDFromOrder(order), order.VendorOrderID, title)
return err
}
func NotifyOrderCanceled(order *model.GoodsOrder) (err error) {
globals.SugarLogger.Debugf("NotifyOrderCanceled orderID:%s", order.VendorOrderID)
if order.VendorID == model.VendorIDELM {
return nil
}
if !model.IsOrderSolid(order) {
globals.SugarLogger.Infof("NotifyOrderCanceled orderID:%s is not solid", order.VendorOrderID)
return nil
}
title := fmt.Sprintf("老板,您的订单%s第%d号订单, %s被取消了", model.VendorChineseNames[order.VendorID], order.OrderSeq, order.VendorOrderID)
data := map[string]interface{}{
"first": map[string]interface{}{
"value": title,
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"orderProductPrice": map[string]interface{}{
"value": jxutils.IntPrice2StandardCurrencyString(order.ActualPayPrice),
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"orderProductName": map[string]interface{}{
"value": getOrderDetailBrief(order),
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"orderAddress": map[string]interface{}{
"value": order.ConsigneeAddress,
"color": venderColors[order.VendorID],
},
"remark": map[string]interface{}{
"value": order.ConsigneeMobile,
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
}
storeID := jxutils.GetSaleStoreIDFromOrder(order)
err = SendMsgToStore(storeID, WX_ORDER_ORDER_CANCELED_TEMPLATE_ID, "", "", data)
netprinter.NofityOrderMsg(jxcontext.AdminCtx, jxutils.GetSaleStoreIDFromOrder(order), order.VendorOrderID, title)
return err
}
@@ -412,50 +458,51 @@ func NotifySaleBill(storeID int, title, shopName, fileURL string) (err error) {
}
func NotifyStoreOpRequestStatus(isAccepted bool, storeID, nameID int, spuName string, originalUnitPrice, unitPrice int, rejectReason string) (err error) {
globals.SugarLogger.Debugf("NotifyStoreOpRequestStatus isAccepted:%t, storeID:%d, nameID:%d, spuName:%s, originalUnitPrice:%d, unitPrice:%d, rejectReason:%s", isAccepted, storeID, nameID, spuName, originalUnitPrice, unitPrice, rejectReason)
templateID := ""
fileURL := globals.WxBackstageHost + fmt.Sprintf("%s%d", WX_TO_STORE_SKU_PAGE_URL, storeID)
data := make(map[string]interface{})
if isAccepted {
templateID = WX_CHANGE_APPROVED_TEMPLATE_ID
data = map[string]interface{}{
"first": map[string]interface{}{
"value": fmt.Sprintf("%s%s元修改为%s元已经通过审核。^_^", spuName, jxutils.IntPrice2StandardString(int64(originalUnitPrice)), jxutils.IntPrice2StandardString(int64(unitPrice))),
"color": "#333333",
},
"keyword1": map[string]interface{}{
"value": "审核通过",
"color": "#2E408E",
},
"keyword2": map[string]interface{}{
"value": utils.Time2Str(time.Now()),
"color": "#2E408E",
},
"remark": map[string]interface{}{
"value": "点击查看详情",
},
}
} else {
templateID = WX_CHANGE_REJECTED_TEMPLATE_ID
data = map[string]interface{}{
"first": map[string]interface{}{
"value": fmt.Sprintf("您好!抱歉的通知您。%s%s元修改为%s元未通过审核。原因%s", spuName, jxutils.IntPrice2StandardString(int64(originalUnitPrice)), jxutils.IntPrice2StandardString(int64(unitPrice)), rejectReason),
"color": "#E80000",
},
"keyword1": map[string]interface{}{
"value": "1",
"color": "#2E408E",
},
"keyword2": map[string]interface{}{
"value": utils.Time2Str(time.Now()),
"color": "#2E408E",
},
"remark": map[string]interface{}{
"value": "请您及时到商品管理修改价格,修改后请重新提交。",
},
}
}
return SendMsgToStore(storeID, templateID, fileURL, WX_MINI_TO_STORE_SKU_PAGE_URL, data)
// globals.SugarLogger.Debugf("NotifyStoreOpRequestStatus isAccepted:%t, storeID:%d, nameID:%d, spuName:%s, originalUnitPrice:%d, unitPrice:%d, rejectReason:%s", isAccepted, storeID, nameID, spuName, originalUnitPrice, unitPrice, rejectReason)
// templateID := ""
// fileURL := globals.WxBackstageHost + fmt.Sprintf("%s%d", WX_TO_STORE_SKU_PAGE_URL, storeID)
// data := make(map[string]interface{})
// if isAccepted {
// templateID = WX_CHANGE_APPROVED_TEMPLATE_ID
// data = map[string]interface{}{
// "first": map[string]interface{}{
// "value": fmt.Sprintf("%s%s元修改为%s元已经通过审核。^_^", spuName, jxutils.IntPrice2StandardString(int64(originalUnitPrice)), jxutils.IntPrice2StandardString(int64(unitPrice))),
// "color": "#333333",
// },
// "keyword1": map[string]interface{}{
// "value": "审核通过",
// "color": "#2E408E",
// },
// "keyword2": map[string]interface{}{
// "value": utils.Time2Str(time.Now()),
// "color": "#2E408E",
// },
// "remark": map[string]interface{}{
// "value": "点击查看详情",
// },
// }
// } else {
// templateID = WX_CHANGE_REJECTED_TEMPLATE_ID
// data = map[string]interface{}{
// "first": map[string]interface{}{
// "value": fmt.Sprintf("您好!抱歉的通知您。%s%s元修改为%s元未通过审核。原因%s", spuName, jxutils.IntPrice2StandardString(int64(originalUnitPrice)), jxutils.IntPrice2StandardString(int64(unitPrice)), rejectReason),
// "color": "#E80000",
// },
// "keyword1": map[string]interface{}{
// "value": "1",
// "color": "#2E408E",
// },
// "keyword2": map[string]interface{}{
// "value": utils.Time2Str(time.Now()),
// "color": "#2E408E",
// },
// "remark": map[string]interface{}{
// "value": "请您及时到商品管理修改价格,修改后请重新提交。",
// },
// }
// }
// err = SendMsgToStore(storeID, templateID, fileURL, WX_MINI_TO_STORE_SKU_PAGE_URL, data)
return err
}
func NotifyStoreMessage(storeID, msgID, msgStatusID int, title, content string) (err error) {