This commit is contained in:
苏尹岚
2020-12-16 11:08:56 +08:00
parent 5927b8b05d
commit bccb99e580
5 changed files with 34 additions and 975 deletions

View File

@@ -6,6 +6,8 @@ import (
"sync" "sync"
"time" "time"
"git.rosy.net.cn/jx-callback/business/jxutils/smsmsg"
"git.rosy.net.cn/jx-callback/business/jxstore/event" "git.rosy.net.cn/jx-callback/business/jxstore/event"
"git.rosy.net.cn/jx-callback/business/jxstore/financial" "git.rosy.net.cn/jx-callback/business/jxstore/financial"
@@ -676,6 +678,28 @@ func UpdateUser(ctx *jxcontext.Context, payload map[string]interface{}) (err err
// } // }
user2, err2 := dao.GetUserByID(db, "user_id", payload["popUser"].(string)) user2, err2 := dao.GetUserByID(db, "user_id", payload["popUser"].(string))
err = err2 err = err2
do := func(user *model.User, flag bool) (err error) {
if user.PopCount%4 == 0 && user.PopFlag == model.NO {
if _, err = InvestMember(ctx, 1, user.UserID, true); err == nil {
//发短信,公众号消息通知
smsmsg.SendSMSMsg([]string{*user.Mobile}, globals.SMSSignName, globals.SMSPopSuccessTemplate, nil)
// weixinmsg.SendMsgToUser(userID, templateID, data)
}
user.PopFlag = model.YES
dao.UpdateEntity(db, user, "PopFlag")
if flag {
if users, _, err := dao.GetUsers(db, 0, "", user.UserID, nil, nil, nil, 0, 999); err == nil {
for _, v := range users {
v.PopedFlag = model.YES
dao.UpdateEntity(db, v, "PopedFlag")
}
}
_, err = event.CreateMessageGroup(ctx, user.UserID, "", "", 5, 100)
}
}
return err
}
if user2 != nil { if user2 != nil {
user2.PopCount++ user2.PopCount++
messageGroupsResult, err3 := dao.GetMessageGroups(db, user2.UserID, 0, model.GroupTypeMulit, false, "") messageGroupsResult, err3 := dao.GetMessageGroups(db, user2.UserID, 0, model.GroupTypeMulit, false, "")
@@ -685,26 +709,10 @@ func UpdateUser(ctx *jxcontext.Context, payload map[string]interface{}) (err err
if len(messageGroupsResult) > 0 { if len(messageGroupsResult) > 0 {
err = event.AddMessageGroup(ctx, messageGroupsResult[0].GroupID, user.UserID) err = event.AddMessageGroup(ctx, messageGroupsResult[0].GroupID, user.UserID)
//邀请过4人直接开通一个月会员 //邀请过4人直接开通一个月会员
if user2.PopCount%4 == 0 && user2.PopFlag == model.NO { do(user2, false)
_, err = InvestMember(ctx, 1, user2.UserID, true)
user2.PopFlag = model.YES
dao.UpdateEntity(db, user2, "PopFlag")
}
} else { } else {
//邀请过4人直接开通一个月会员并创建群组 //邀请过4人直接开通一个月会员并创建群组
if user2.PopCount%4 == 0 && user2.PopFlag == model.NO { do(user2, true)
_, err = InvestMember(ctx, 1, user2.UserID, true)
user2.PopFlag = model.YES
dao.UpdateEntity(db, user2, "PopFlag")
if users, _, err := dao.GetUsers(db, 0, "", user2.UserID, nil, nil, nil, 0, 999); err == nil {
for _, v := range users {
v.PopedFlag = model.YES
dao.UpdateEntity(db, v, "PopedFlag")
}
}
_, err = event.CreateMessageGroup(ctx, user2.UserID, "", "", 5, 100)
}
} }
dao.UpdateEntity(db, user2, "PopCount") dao.UpdateEntity(db, user2, "PopCount")
} }

View File

@@ -8,8 +8,6 @@ import (
"git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/baseapi/utils/errlist" "git.rosy.net.cn/baseapi/utils/errlist"
"git.rosy.net.cn/jx-callback/business/jxutils" "git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/globals" "git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api" "git.rosy.net.cn/jx-callback/globals/api"
) )
@@ -23,7 +21,7 @@ var (
} }
) )
func SendSMSMsg(mobileList []string, signName, templateCode string, templateParam map[string]interface{}, order *model.GoodsOrder) (err error) { func SendSMSMsg(mobileList []string, signName, templateCode string, templateParam map[string]interface{}) (err error) {
if len(mobileList) > 0 { if len(mobileList) > 0 {
errList := errlist.New() errList := errlist.New()
mobileList = jxutils.StringMap2List(jxutils.StringList2Map(mobileList)) mobileList = jxutils.StringMap2List(jxutils.StringList2Map(mobileList))
@@ -42,10 +40,6 @@ func SendSMSMsg(mobileList []string, signName, templateCode string, templatePara
} else { } else {
globals.SugarLogger.Infof(errMsg) globals.SugarLogger.Infof(errMsg)
} }
} else {
if order != nil {
err = updateStoreSMSNotifyMark(order)
}
} }
} }
} }
@@ -54,147 +48,3 @@ func SendSMSMsg(mobileList []string, signName, templateCode string, templatePara
} }
return err return err
} }
func getOrderNotifyPhone(order *model.GoodsOrder) (phoneList []string) {
return dao.GetOrderNotifyPhones(dao.GetDB(), jxutils.GetSaleStoreIDFromOrder(order))
}
func NotifyNewOrder(order *model.GoodsOrder) (err error) {
if isPushSMS(order) {
err = SendSMSMsg(getOrderNotifyPhone(order), globals.SMSSignName, globals.SMSNewOrderTemplate, map[string]interface{}{
"daySeq": order.OrderSeq,
"consigneeName": order.ConsigneeName,
"payMoney": jxutils.IntPrice2StandardString(order.ActualPayPrice),
}, order)
}
return err
}
func NotifyOrderCanceled(order *model.GoodsOrder) (err error) {
err = SendSMSMsg(getOrderNotifyPhone(order), globals.SMSSignName, globals.SMSOrderCanceledTemplate, map[string]interface{}{
"vendorName": model.VendorChineseNames[order.VendorID],
"seq": order.OrderSeq,
"orderID": order.VendorOrderID,
}, order)
return err
}
func isPushSMS(order *model.GoodsOrder) bool {
storeID := 0
if order.StoreID == 0 {
storeID = order.JxStoreID
} else {
storeID = order.StoreID
}
stores, _ := dao.GetStoresMapList(dao.GetDB(), []int{order.VendorID}, []int{storeID}, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", "")
if len(stores) > 0 {
if stores[0].IsOrder == model.NO {
if storeID == model.MatterStoreID {
return false
} else {
return true
}
} else {
return false
}
} else {
return false
}
}
func updateStoreSMSNotifyMark(order *model.GoodsOrder) (err error) {
var db = dao.GetDB()
stores, _ := dao.GetStoreList(db, []int{order.StoreID}, nil, nil, nil, "")
if len(stores) > 0 {
stores[0].SMSNotifyMark = model.YES
_, err = dao.UpdateEntity(db, stores[0], "SMSNotifyMark")
}
return err
}
//每月向用户发送
func NotifyNewUserOrder(order *model.GoodsOrder) (err error) {
var (
db = dao.GetDB()
storeTel string
storeID int
mobile string
)
if order.StoreID == 0 {
storeID = order.JxStoreID
} else {
storeID = order.StoreID
}
if order.ConsigneeMobile2 != "" {
mobile = order.ConsigneeMobile2
uoSMS, err := dao.GetUserOrderSMS(db, mobile, "")
stores, _ := dao.GetStoreList(db, []int{storeID}, nil, nil, nil, "")
if len(stores) > 0 {
if stores[0].Tel1 == "" {
storeTel = stores[0].Tel2
} else {
storeTel = stores[0].Tel1
}
}
if uoSMS == nil {
uoSMSc := &model.UserOrderSms{
Mobile: mobile,
Name: order.ConsigneeName,
VendorUserID: order.VendorUserID,
TotalCount: 0,
SMSMark: model.NO,
}
err = dao.CreateEntity(db, uoSMSc)
err = SendSMSMsg([]string{uoSMSc.Mobile}, globals.SMSSignName, globals.SMSNewUserOrderTemplate, map[string]interface{}{
"tel": storeTel,
}, nil)
if err == nil {
uoSMS2, _ := dao.GetUserOrderSMS(db, mobile, "")
uoSMS2.SMSMark = model.YES
uoSMS2.TotalCount++
_, err = dao.UpdateEntity(db, uoSMS2, "SMSMark", "TotalCount")
}
} else {
if uoSMS.SMSMark != model.YES {
err = SendSMSMsg([]string{uoSMS.Mobile}, globals.SMSSignName, globals.SMSNewUserOrderTemplate, map[string]interface{}{
"tel": storeTel,
}, nil)
if err == nil {
uoSMS.SMSMark = model.YES
uoSMS.TotalCount++
_, err = dao.UpdateEntity(db, uoSMS, "SMSMark", "TotalCount")
}
}
}
}
return err
}
//给配送员发短信
func NotifyNewCourierOrder(bill *model.Waybill) (err error) {
var (
db = dao.GetDB()
storeTel string
storeID int
)
order := &model.GoodsOrder{}
order.VendorOrderID = bill.VendorOrderID
err = dao.GetEntity(db, order, "VendorOrderID")
if order.StoreID == 0 {
storeID = order.JxStoreID
} else {
storeID = order.StoreID
}
stores, _ := dao.GetStoreList(db, []int{storeID}, nil, nil, nil, "")
if len(stores) > 0 {
if stores[0].Tel1 == "" {
storeTel = stores[0].Tel2
} else {
storeTel = stores[0].Tel1
}
}
err = SendSMSMsg([]string{bill.CourierMobile}, globals.SMSSignName, globals.SMSNewOrderTemplate, map[string]interface{}{
"tel": storeTel,
}, nil)
return err
}

View File

@@ -2,26 +2,12 @@ package weixinmsg
import ( import (
"fmt" "fmt"
"strings"
"time"
"github.com/astaxie/beego"
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
"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/tasksch"
"git.rosy.net.cn/jx-callback/business/partner"
"git.rosy.net.cn/baseapi/utils" "git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao" "git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/business/model/legacymodel"
"git.rosy.net.cn/jx-callback/globals" "git.rosy.net.cn/jx-callback/globals"
"git.rosy.net.cn/jx-callback/globals/api" "git.rosy.net.cn/jx-callback/globals/api"
"git.rosy.net.cn/jx-callback/globals/api2"
) )
const ( const (
@@ -93,63 +79,6 @@ var (
} }
) )
func GetWeixinOpenIDsFromStoreID(storeID int) (retVal []string) {
db := dao.GetDB()
openIDMap := make(map[string]int)
if globals.EnableWXAuth2 {
if userIDList, err2 := api2.RoleMan.GetRoleUserList(autils.NewStoreBossRole(storeID)); err2 == nil {
for _, v := range userIDList {
if authList, err2 := dao.GetUserBindAuthInfo(db, v, model.AuthBindTypeAuth, []string{weixin.AuthTypeMP}, "", "", ""); err2 == nil {
for _, v := range authList {
retVal = append(retVal, v.AuthID)
openIDMap[v.AuthID] = 1
}
}
}
}
}
retVal = jxutils.StringMap2List(openIDMap)
if !globals.ReallyCallPlatformAPI {
// todo调试只发给我
globals.SugarLogger.Debugf("GetWeixinOpenIDsFromStoreID store:%d, openids:%v", storeID, retVal)
if storeID == 100146 {
retVal = []string{"oYN_ust9hXKEvEv0X6Mq6nlAWs_E"}
} else {
retVal = nil
}
}
return retVal
}
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_ust9hXKEvEv0X6Mq6nlAWs_E", templateID, downloadURL, miniPageURL, data)
} else {
openIDs := GetWeixinOpenIDsFromStoreID(storeID)
successCount := 0
for _, openID := range openIDs {
realMiniPageURL := miniPageURL
// if testMiniProgramStoreMap[storeID] == 0 && debugOpenIDMap[openID] == 0 {
// realMiniPageURL = ""
// }
globals.SugarLogger.Debugf("SendMsgToStore storeID:%d, openID:%s, templateID:%s, downloadURL:%s, realMiniPageURL:%s", storeID, openID, templateID, downloadURL, realMiniPageURL)
if err2 := SmartMessageTemplateSend(openID, templateID, downloadURL, realMiniPageURL, data); err2 == nil {
successCount++
} else {
err = err2
}
}
if successCount > 0 {
err = nil // 只要成功一个都当成成功
}
if err != nil {
globals.SugarLogger.Debugf("SendMsgToStore all failed storeID:%d, templateID:%s, error:%v", storeID, templateID, err)
}
}
return err
}
func SmartMessageTemplateSend(userOpenID, templateID, downloadURL, miniPageURL string, data interface{}) (err error) { func SmartMessageTemplateSend(userOpenID, templateID, downloadURL, miniPageURL string, data interface{}) (err error) {
var miniProgram map[string]interface{} var miniProgram map[string]interface{}
if miniPageURL != "" { if miniPageURL != "" {
@@ -167,728 +96,6 @@ func SmartMessageTemplateSend(userOpenID, templateID, downloadURL, miniPageURL s
return err 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("元/份)等,预计收入")
//TODO 2020-07-20 果园和菜市不同
var price int64
if beego.BConfig.RunMode == "jxgy" {
price = order.NewEarningPrice
} else {
if order.EarningType == model.EarningTypePoints {
price = order.ActualPayPrice
} else {
price = order.ShopPrice
}
}
sb.WriteString(jxutils.IntPrice2StandardString(price))
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 {
return nil
}
if !model.IsOrderSolid(order) {
globals.SugarLogger.Infof("NotifyNewOrder orderID:%s is not solid", order.VendorOrderID)
return nil
}
sb := new(strings.Builder)
sb.WriteString("老板,")
sb.WriteString(order.ConsigneeName)
sb.WriteString("购买了商品")
sb.WriteString(getOrderDetailBrief(order))
data := map[string]interface{}{
"first": map[string]interface{}{
"value": sb.String(),
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"Day": map[string]interface{}{
"value": FormatDeliveryTime(order),
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"orderId": map[string]interface{}{
"value": order.VendorOrderID,
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"orderType": map[string]interface{}{
"value": fmt.Sprintf("%s 第%d号订单", model.VendorChineseNames[order.VendorID], order.OrderSeq),
"color": VendorColors[order.VendorID],
},
"customerName": map[string]interface{}{
"value": order.ConsigneeName,
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"customerPhone": map[string]interface{}{
"value": order.ConsigneeMobile,
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
}
storeID := jxutils.GetSaleStoreIDFromOrder(order)
return SendMsgToStore(storeID, WX_NEWORDER_TEMPLATE_ID, globals.WxBackstageHost+fmt.Sprintf("%s%d", WX_TO_ORDER_PAGE_URL, storeID), WX_MINI_TO_ORDER_PAGE_URL, data)
}
func NotifyWaybillStatus(bill *model.Waybill, order *model.GoodsOrder, isBillAlreadyCandidate bool) (err error) {
globals.SugarLogger.Debugf("NotifyWaybillStatus orderID:%s bill:%v", order.VendorOrderID, bill)
if order.VendorID == model.VendorIDELM {
return nil
}
if !model.IsOrderSolid(order) {
globals.SugarLogger.Infof("NotifyWaybillStatus orderID:%s is not solid", order.VendorOrderID)
return nil
}
var title string
templateID := ""
remark := ""
titleColor := ""
switch bill.Status {
case model.WaybillStatusAccepted:
if bill.WaybillVendorID == model.VendorIDMTPS {
templateID = WX_MTPS_DELIVERY_GRABDONE_TEMPLATE_ID
} else if bill.WaybillVendorID == model.VendorIDDada {
templateID = WX_DADA_DELIVERY_GRABDONE_TEMPLATE_ID
}
remark = FormatDeliveryTime(order)
if isBillAlreadyCandidate {
titleColor = WX_HIGHLEVEL_TEMPLATE_COLOR
title = fmt.Sprintf("%s 第%d号订单由于之前安排的配送员长时间没有取货我们已重新安排%s配送员%s负责配送。^_^", model.VendorChineseNames[bill.OrderVendorID], order.OrderSeq, model.VendorChineseNames[bill.WaybillVendorID], bill.CourierName)
} else {
titleColor = WX_HIGHLEVEL_TEMPLATE_COLOR2
title = fmt.Sprintf("%s 第%d号订单长时间无人配送我们已安排%s配送员%s负责配送。^_^", model.VendorChineseNames[bill.OrderVendorID], order.OrderSeq, model.VendorChineseNames[bill.WaybillVendorID], bill.CourierName)
}
case model.WaybillStatusDelivered:
if bill.WaybillVendorID == model.VendorIDMTPS {
templateID = WX_MTPS_DELIVERY_DONE_TEMPLATE_ID
} else if bill.WaybillVendorID == model.VendorIDDada {
templateID = WX_DADA_DELIVERY_DONE_TEMPLATE_ID
}
titleColor = VendorColors[bill.OrderVendorID]
title = fmt.Sprintf("%s 第%d号订单的配送完成", model.VendorChineseNames[bill.OrderVendorID], order.OrderSeq)
}
if templateID != "" {
data := map[string]interface{}{
"first": map[string]interface{}{
"value": title,
"color": titleColor,
},
"keyword1": map[string]interface{}{
"value": bill.VendorOrderID,
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"keyword2": map[string]interface{}{
"value": fmt.Sprintf("%s%s", bill.CourierName, model.VendorChineseNames[bill.WaybillVendorID]),
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"keyword3": map[string]interface{}{
"value": bill.CourierMobile,
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"remark": map[string]interface{}{
"value": remark,
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
}
err = SendMsgToStore(jxutils.GetSaleStoreIDFromOrder(order), templateID, "", "", data)
}
return err
}
func NotifyUserApplyCancel(order *model.GoodsOrder, cancelReason string) (err error) {
globals.SugarLogger.Debugf("NotifyUserApplyCancel orderID:%s", order.VendorOrderID)
if order.VendorID == model.VendorIDELM {
return nil
}
if !model.IsOrderSolid(order) {
globals.SugarLogger.Infof("NotifyUserApplyCancel orderID:%s is not solid", order.VendorOrderID)
return nil
}
title := "老板,您有订单申请取消!请及时联系客户处理!"
data := map[string]interface{}{
"first": map[string]interface{}{
"value": title,
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"keyword1": map[string]interface{}{ // 订单编号
"value": fmt.Sprintf("%s第%d号订单, %s", model.VendorChineseNames[order.VendorID], order.OrderSeq, order.VendorOrderID),
"color": VendorColors[order.VendorID],
},
"keyword2": map[string]interface{}{ // 订单日期
"value": utils.Time2Str(order.OrderCreatedAt),
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"keyword3": map[string]interface{}{ // 订单内容
"value": cancelReason,
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"remark": map[string]interface{}{
"value": order.ConsigneeMobile,
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
}
storeID := jxutils.GetSaleStoreIDFromOrder(order)
err = SendMsgToStore(storeID, WX_ORDER_APPLY_CANCEL_TEMPLATE_ID, "", "", data)
return err
}
func NotifyOrderChanged(order *model.GoodsOrder) (err error) {
globals.SugarLogger.Debugf("NotifyOrderChanged orderID:%s", order.VendorOrderID)
if order.VendorID == model.VendorIDELM {
return nil
}
title := fmt.Sprintf("您有订单的信息已被修改")
data := map[string]interface{}{
"first": map[string]interface{}{
"value": title,
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"keyword1": map[string]interface{}{
"value": order.VendorOrderID,
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"keyword2": map[string]interface{}{
"value": "用户修改订单",
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"keyword3": map[string]interface{}{
"value": order.ConsigneeAddress + "" + order.ConsigneeName + "" + order.ConsigneeMobile + "" + order.BuyerComment,
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"keyword4": map[string]interface{}{
"value": utils.Time2Str(order.OrderCreatedAt),
"color": VendorColors[order.VendorID],
},
"remark": map[string]interface{}{
"value": "请及时处理",
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
}
storeID := jxutils.GetSaleStoreIDFromOrder(order)
err = SendMsgToStore(storeID, WX_ORDER_CHANGE_INFO_TEMPLATE_ID, "", "", data)
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": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"orderName": map[string]interface{}{
"value": fmt.Sprintf("%s第%d号订单, %s", model.VendorChineseNames[order.VendorID], order.OrderSeq, order.VendorOrderID),
"color": VendorColors[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)
return err
}
func PushJDBadCommentToWeiXin(comment *legacymodel.JxBadComments, isBadComment bool, order *model.GoodsOrder) (err error) {
globals.SugarLogger.Debugf("PushJDBadCommentToWeiXin orderID:%s", comment.OrderId)
sb := new(strings.Builder)
sb.WriteString(fmt.Sprintf("你收到了%s客户(", model.VendorChineseNames[int(utils.Str2Int64WithDefault(comment.OrderFlag, 0))]))
sb.WriteString(comment.Userphone)
sb.WriteString(")的一条")
sb.WriteString(utils.Int2Str(comment.Score))
if isBadComment {
sb.WriteString("星差评请商家在1小时内及时联系客户处理!")
} else {
sb.WriteString("星中评如有必要请商家在1小时内及时联系客户处理!")
}
title := sb.String()
var orderInfo string
consigneeName := comment.Userphone
if order != nil {
orderInfo = fmt.Sprintf("%s第%d号订单, %s", model.VendorChineseNames[int(utils.Str2Int64WithDefault(comment.OrderFlag, 0))], order.OrderSeq, comment.OrderId)
consigneeName = order.ConsigneeName
} else {
orderInfo = fmt.Sprintf("%s订单, %s", model.VendorChineseNames[int(utils.Str2Int64WithDefault(comment.OrderFlag, 0))] /*comment.OrderId*/, "")
}
data := map[string]interface{}{
"first": map[string]interface{}{
"value": title,
"color": WX_HIGHLEVEL_TEMPLATE_COLOR,
},
"keyword1": map[string]interface{}{
"value": genJdCommentRemark(comment),
"color": WX_TEMPLATE_VENDERCOLOR_BAD_COMMENTS,
},
"keyword2": map[string]interface{}{
"value": comment.Score,
"color": WX_TEMPLATE_VENDERCOLOR_BAD_COMMENTS,
},
"keyword3": map[string]interface{}{
"value": orderInfo,
"color": WX_TEMPLATE_VENDERCOLOR_BAD_COMMENTS,
},
"keyword4": map[string]interface{}{
"value": consigneeName,
"color": WX_TEMPLATE_VENDERCOLOR_BAD_COMMENTS,
},
"keyword5": map[string]interface{}{
"value": comment.Userphone,
"color": WX_TEMPLATE_VENDERCOLOR_BAD_COMMENTS,
},
}
storeID := int(utils.Str2Int64(comment.Jxstoreid))
err = SendMsgToStore(storeID, WX_BAD_COMMENT_PUSH_TEMPLATE_ID, globals.WxBackstageHost+fmt.Sprintf("%s%d", WX_TO_SHOW_COMMENTS_DETAIL_URL, storeID), WX_MINI_TO_SHOW_COMMENTS_DETAIL_URL, data)
return err
}
func NotifySaleBill(storeID int, title, shopName, fileURL string) (err error) {
globals.SugarLogger.Debugf("NotifySaleBill storeID:%d, fileURL:%s", storeID, fileURL)
if title == "" {
title = "当期账单"
}
if shopName == "" {
shopName = globals.StoreName
}
data := map[string]interface{}{
"first": map[string]interface{}{
"value": "新的账单上传成功!",
"color": "#00008B",
},
"keyword1": map[string]interface{}{
"value": title,
},
"keyword2": map[string]interface{}{
"value": "点击查看详情",
"color": "#00008B",
},
"keyword3": map[string]interface{}{
"value": shopName,
},
"keyword4": map[string]interface{}{
"value": utils.GetCurTimeStr(),
},
"remark": map[string]interface{}{
"value": "手机买菜上京西,极速到家送惊喜",
},
}
return SendMsgToStore(storeID, WX_SALE_BILL_TEMPLATE_ID, fileURL, "", data)
}
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": "审核不通过",
"color": "#2E408E",
},
"keyword3": map[string]interface{}{
"value": utils.Time2Str(time.Now()),
"color": "#2E408E",
},
"keyword4": map[string]interface{}{
"value": "审核不通过",
"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) {
globals.SugarLogger.Debugf("NotifyStoreMessage storeID:%d, msgID:%d, title:%s, content:%s", storeID, msgID, title, content)
templateID := WX_NORMAL_STORE_MSG_TEMPLATE_ID
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": "",
},
}
return SendMsgToStore(storeID, templateID, fileURL, fmt.Sprintf(WX_MINI_TO_SHOW_MSG, msgID, msgStatusID), data)
}
func NotifyAfsOrderStatus(afsOrder *model.AfsOrder) (err error) {
globals.SugarLogger.Debugf("NotifyAfsOrderStatus orderID:%s", afsOrder.VendorOrderID)
if afsOrder.VendorID == model.VendorIDELM {
return nil
}
var templateID, comment string
if afsOrder.Status == model.AfsOrderStatusWait4Approve {
templateID = WX_AFS_ORDER_WAIT4APPROVE_TEMPLATE_ID
comment = "您有新售后单,请尽快处理"
} else if afsOrder.Status == model.AfsOrderStatusWait4ReceiveGoods {
templateID = WX_AFS_ORDER_STATUS_CHANGED_TEMPLATE_ID
comment = "商家您好!如顾客商品已成功退回,请点击确认收货"
} else {
return err
}
order, err := partner.CurOrderManager.LoadOrder(afsOrder.VendorOrderID, afsOrder.VendorID)
if err != nil {
return err
}
data := map[string]interface{}{
"first": map[string]interface{}{
"value": fmt.Sprintf("%s 第%d号订单, %s", model.VendorChineseNames[afsOrder.VendorID], order.OrderSeq, afsOrder.VendorOrderID),
"color": WX_HIGHLEVEL_TEMPLATE_COLOR2,
},
"keyword1": map[string]interface{}{
"value": afsOrder.AfsOrderID,
"color": WX_TEMPLATE_VENDERCOLOR_JDDJ,
},
"keyword2": map[string]interface{}{
"value": model.OrderStatusName[afsOrder.Status],
"color": WX_HIGHLEVEL_TEMPLATE_COLOR,
},
"keyword3": map[string]interface{}{
"value": utils.Time2Str(afsOrder.AfsCreatedAt),
"color": VendorColors[order.VendorID],
},
"remark": map[string]interface{}{
"value": comment,
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
}
storeID := jxutils.GetSaleStoreIDFromAfsOrder(afsOrder)
err = SendMsgToStore(storeID, templateID, globals.WxBackstageHost+fmt.Sprintf("%s%d", WX_TO_ORDER_PAGE_URL, storeID), WX_MINI_TO_ORDER_PAGE_URL, data)
return err
}
func FormatDeliveryTime(order *model.GoodsOrder) string {
var tmpTime time.Time
if order.ExpectedDeliveredTime == utils.DefaultTimeValue {
tmpTime = order.OrderCreatedAt.Add(1 * time.Hour)
} else {
tmpTime = order.ExpectedDeliveredTime
}
left := tmpTime.Sub(time.Now()) / time.Minute
leftHours := left / 60
leftMinutes := left % 60
return fmt.Sprintf("请于%s前送达剩余时间%d小时%d分钟", utils.Time2Str(tmpTime), leftHours, leftMinutes)
}
func genJdCommentRemark(comment *legacymodel.JxBadComments) string {
sb := new(strings.Builder)
sb.WriteString("评价标签:")
sb.WriteString(comment.Vendertags)
sb.WriteString(" 评价内容:")
sb.WriteString(comment.Scorecontent)
return sb.String()
}
func NotifyStoreStatusChanged(openUserID, title, content string) (err error) {
SmartMessageTemplateSend(openUserID, WS_NOTIFY_STORE_STATUS_CHHANGED_TEMPLATE_ID, "", "", map[string]interface{}{
"first": map[string]interface{}{
"value": title,
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"keyword1": map[string]interface{}{
"value": "",
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"keyword2": map[string]interface{}{
"value": utils.Time2Str(time.Now()),
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"keyword3": map[string]interface{}{
"value": content,
"color": WX_HIGHLEVEL_TEMPLATE_COLOR,
},
"keyword4": map[string]interface{}{
"value": "",
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"remark": map[string]interface{}{
"value": "",
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
})
return err
}
func NotifyStoreAlertMessage(storeID int, storeName, title, content string) (err error) {
globals.SugarLogger.Debugf("NotifyStoreAlertMessage storeID:%d, storeName:%d, title:%s, content:%s", storeID, storeName, title, content)
templateID := WX_STORE_ALERT_TEMPLATE_ID
data := map[string]interface{}{
"first": map[string]interface{}{
"value": "",
"color": "#333333",
},
"keyword1": map[string]interface{}{
"value": storeName,
"color": "#2E408E",
},
"keyword2": map[string]interface{}{
"value": utils.GetCurTimeStr(),
"color": "#2E408E",
},
"keyword3": map[string]interface{}{
"value": content,
"color": "#2E408E",
},
"remark": map[string]interface{}{
"value": "",
},
}
if false {
err = SendMsgToStore(storeID, templateID, "", "", data)
}
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.HandleTask(rootTask, nil, len(msgStatusList) > 5).Run()
if !isAsync {
_, err = rootTask.GetResult(0)
} else {
hint = rootTask.ID
}
return "", err
}
func NotifyAdjustOrder(order *model.GoodsOrder) (err error) {
globals.SugarLogger.Debugf("NotifyAdjustOrder orderID:%s", order.VendorOrderID)
if order.VendorID == model.VendorIDELM {
return nil
}
if !model.IsOrderSolid(order) {
globals.SugarLogger.Infof("NotifyAdjustOrder orderID:%s is not solid", order.VendorOrderID)
return nil
}
sb := new(strings.Builder)
sb.WriteString("老板,")
sb.WriteString(order.ConsigneeName)
sb.WriteString("调整了订单商品,请及时查看!")
sb.WriteString(getOrderDetailBrief(order))
data := map[string]interface{}{
"first": map[string]interface{}{
"value": sb.String(),
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"keyword1": map[string]interface{}{
"value": jxutils.IntPrice2Standard(order.NewEarningPrice),
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"keyword2": map[string]interface{}{
"value": utils.Time2Str(order.CreatedAt),
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
"keyword3": map[string]interface{}{
"value": model.OrderStatusName[order.Status],
"color": WX_NEW_ORDER_TEMPLATE_COLOR,
},
}
storeID := jxutils.GetSaleStoreIDFromOrder(order)
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 SendUserMessage(ctx *jxcontext.Context, title, content string, userIDs []string, 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.MessageTypeUser,
}
dao.WrapAddIDCULDEntity(msg, ctx.GetUserName())
if err = dao.CreateEntity(db, msg); err != nil {
dao.Rollback(db)
return "", err
}
msgStatusList := make([]*model.MessageStatus, len(userIDs))
for k, userID := range userIDs {
msgStatus := &model.MessageStatus{
MessageID: msg.ID,
UserID: userID,
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("SendUserMessage", nil, ctx, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
db := dao.GetDB()
msgStatus := batchItemList[0].(*model.MessageStatus)
if err = NotifyUserMessage(msgStatus.UserID, msg.Title, msg.Content); err == nil {
msgStatus.Status = model.MessageStatusSendAllSuccess
} else {
msgStatus.Status = model.MessageStatusSendAllFailed
}
dao.WrapUpdateULEntity(msgStatus, ctx.GetUserName())
_, err = dao.UpdateEntity(db, msgStatus)
return nil, err
}, msgStatusList)
tasksch.HandleTask(rootTask, nil, len(msgStatusList) > 5).Run()
if !isAsync {
_, err = rootTask.GetResult(0)
} else {
hint = rootTask.ID
}
return "", err
}
func NotifyUserMessage(userID string, title, content string) (err error) {
globals.SugarLogger.Debugf("NotifyUserMessage userID:%d, title:%s, content:%s", userID, title, content)
templateID := WX_NORMAL_STORE_MSG_TEMPLATE_ID
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": "",
},
}
return SendMsgToUser(userID, templateID, data)
}
func SendMsgToUser(userID string, templateID string, data interface{}) (err error) { func SendMsgToUser(userID string, templateID string, data interface{}) (err error) {
globals.SugarLogger.Debugf("SendMsgToUser userID:%d, templateID:%s", userID, templateID) globals.SugarLogger.Debugf("SendMsgToUser userID:%d, templateID:%s", userID, templateID)
authBinds, err := dao.GetUserBindAuthInfo(dao.GetDB(), userID, model.AuthBindTypeAuth, []string{"weixinsns"}, "", "", "wx2bb99eb5d2c9b82c") authBinds, err := dao.GetUserBindAuthInfo(dao.GetDB(), userID, model.AuthBindTypeAuth, []string{"weixinsns"}, "", "", "wx2bb99eb5d2c9b82c")

View File

@@ -114,11 +114,9 @@ storeName = "京西菜市"
storeNameMtwm = "京西菜市" storeNameMtwm = "京西菜市"
storeNameEbai = "饿鲜达" storeNameEbai = "饿鲜达"
smsSignName = "京西菜市" smsSignName = "冲天猴儿"
smsMobileVerifyTemplate = "SMS_175583158" smsMobileVerifyTemplate = "SMS_206880119"
smsNewOrderTemplate = "SMS_175583150" smsPopSuccessTemplate = "SMS_206885121"
smsOrderCanceledTemplate = "SMS_175573134"
smsNewUserOrderTemplate = "SMS_190284055"
addEvent = true addEvent = true

View File

@@ -46,11 +46,9 @@ var (
StoreNameMtwm string StoreNameMtwm string
StoreNameEbai string StoreNameEbai string
SMSSignName string SMSSignName string
SMSMobileVerifyTemplate string SMSMobileVerifyTemplate string
SMSNewOrderTemplate string SMSPopSuccessTemplate string
SMSOrderCanceledTemplate string
SMSNewUserOrderTemplate string
EnableWXAuth2 bool EnableWXAuth2 bool
DisableWXAuth1 bool DisableWXAuth1 bool
@@ -122,9 +120,7 @@ func Init() {
SMSSignName = beego.AppConfig.String("smsSignName") SMSSignName = beego.AppConfig.String("smsSignName")
SMSMobileVerifyTemplate = beego.AppConfig.String("smsMobileVerifyTemplate") SMSMobileVerifyTemplate = beego.AppConfig.String("smsMobileVerifyTemplate")
SMSNewOrderTemplate = beego.AppConfig.String("smsNewOrderTemplate") SMSPopSuccessTemplate = beego.AppConfig.String("smsPopSuccessTemplate")
SMSOrderCanceledTemplate = beego.AppConfig.String("smsOrderCanceledTemplate")
SMSNewUserOrderTemplate = beego.AppConfig.String("smsNewUserOrderTemplate")
EnableWXAuth2 = true // beego.BConfig.RunMode == "beta" EnableWXAuth2 = true // beego.BConfig.RunMode == "beta"
DisableWXAuth1 = true DisableWXAuth1 = true