- refactor config ReallyCallPlatformAPI, ReallySendWeixinMsg and ReallyReplyComment
This commit is contained in:
@@ -114,9 +114,7 @@ func (c *OrderManager) OnOrderComments(orderCommentList []*model.OrderComment) (
|
||||
}
|
||||
comment2.Userphone = orderComment.ConsigneeMobile
|
||||
if orderComment.StoreID > 0 && orderComment.Score <= JX_BAD_COMMENTS_MAX_LEVEL && time.Now().Sub(orderComment.CommentCreatedAt) < MAX_REAPLY_TIME {
|
||||
if globals.ReallyCallPlatformAPI {
|
||||
weixinmsg.PushJDBadCommentToWeiXin(comment2)
|
||||
}
|
||||
weixinmsg.PushJDBadCommentToWeiXin(comment2)
|
||||
}
|
||||
}
|
||||
} else { // 修改评价,但是仍然低于或等于JX_BAD_COMMENTS_MAX_LEVEL
|
||||
@@ -165,15 +163,12 @@ func (c *OrderManager) replyOrderComment(orderComment *model.OrderComment) (err
|
||||
content := config.comments[rand.Intn(len(config.comments))]
|
||||
globals.SugarLogger.Debugf("replyOrderComment orderID:%s, delaySeconds:%d, content:%s", orderComment.VendorOrderID, delaySeconds, content)
|
||||
utils.AfterFuncWithRecover(time.Duration(delaySeconds)*time.Second, func() {
|
||||
if globals.ReallySendWeixinMsg {
|
||||
if handler := partner.GetPurchasePlatformFromVendorID(orderComment.VendorID); handler != nil {
|
||||
err = handler.ReplyOrderComment(jxcontext.AdminCtx, orderComment, content)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Debugf("replyOrderComment orderID:%s, error:%v", orderComment.VendorOrderID, err)
|
||||
}
|
||||
} else {
|
||||
globals.SugarLogger.Warnf("replyOrderComment can not find handler orderID:%s", orderComment.VendorOrderID)
|
||||
if handler := partner.GetPurchasePlatformFromVendorID(orderComment.VendorID); handler != nil {
|
||||
if err = handler.ReplyOrderComment(jxcontext.AdminCtx, orderComment, content); err != nil {
|
||||
globals.SugarLogger.Debugf("replyOrderComment orderID:%s, error:%v", orderComment.VendorOrderID, err)
|
||||
}
|
||||
} else {
|
||||
globals.SugarLogger.Warnf("replyOrderComment can not find handler orderID:%s", orderComment.VendorOrderID)
|
||||
}
|
||||
})
|
||||
return err
|
||||
|
||||
@@ -107,31 +107,29 @@ 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 globals.ReallySendWeixinMsg {
|
||||
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)
|
||||
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
|
||||
}
|
||||
@@ -145,8 +143,10 @@ func SmartMessageTemplateSend(userOpenID, templateID, downloadURL, miniPageURL s
|
||||
}
|
||||
}
|
||||
globals.SugarLogger.Debugf("SmartMessageTemplateSend openID:%s, templateID:%s, downloadURL:%s, miniProgram:%s", userOpenID, templateID, downloadURL, utils.Format4Output(miniProgram, true))
|
||||
if err = api.WeixinAPI.CBMessageTemplateSend(userOpenID, templateID, downloadURL, miniProgram, data); err != nil {
|
||||
globals.SugarLogger.Debugf("SmartMessageTemplateSend openID:%s, templateID:%s, downloadURL:%s, miniProgram:%s, failed with error:%v", userOpenID, templateID, downloadURL, utils.Format4Output(miniProgram, true), err)
|
||||
if globals.ReallySendWeixinMsg {
|
||||
if err = api.WeixinAPI.CBMessageTemplateSend(userOpenID, templateID, downloadURL, miniProgram, data); err != nil {
|
||||
globals.SugarLogger.Debugf("SmartMessageTemplateSend openID:%s, templateID:%s, downloadURL:%s, miniProgram:%s, failed with error:%v", userOpenID, templateID, downloadURL, utils.Format4Output(miniProgram, true), err)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -92,7 +92,9 @@ func (c *PurchaseHandler) RefreshComment(fromTime, toTime time.Time) (err error)
|
||||
|
||||
func (c *PurchaseHandler) ReplyOrderComment(ctx *jxcontext.Context, orderComment *model.OrderComment, replyComment string) (err error) {
|
||||
if orderComment.VendorStoreID != "" && orderComment.UserCommentID != "" {
|
||||
err = api.EbaiAPI.OrderRatesReply("", utils.Str2Int64(orderComment.VendorStoreID), orderComment.UserCommentID, replyComment)
|
||||
if globals.ReallyReplyComment {
|
||||
err = api.EbaiAPI.OrderRatesReply("", utils.Str2Int64(orderComment.VendorStoreID), orderComment.UserCommentID, replyComment)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -244,9 +244,7 @@ func (c *PurchaseHandler) onOrderUserUrgeOrder(msg *elmapi.CallbackOrderUrgeMsg)
|
||||
VendorStatus: utils.Int2Str(msg.MsgType),
|
||||
StatusTime: utils.Timestamp2Time(msg.UpdateTime),
|
||||
}
|
||||
if globals.ReallyCallPlatformAPI {
|
||||
c.ClientUrgeOrder(msg.OrderID)
|
||||
}
|
||||
c.ClientUrgeOrder(msg.OrderID)
|
||||
return elmapi.Err2CallbackResponse(partner.CurOrderManager.OnOrderStatusChanged(status), status.VendorStatus)
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,9 @@ func (c *PurchaseHandler) ClientUrgeOrder(orderID string) (err error) {
|
||||
}
|
||||
if templateCode != "" {
|
||||
smsClient := aliyunsmsclient.New("http://dysmsapi.aliyuncs.com/")
|
||||
_, err = smsClient.Execute(globals.AliKey, globals.AliSecret, order.ConsigneeMobile, ELM_SMS_SIGN_NAME, templateCode, string(utils.MustMarshal(templateParams)))
|
||||
if globals.ReallyCallPlatformAPI {
|
||||
_, err = smsClient.Execute(globals.AliKey, globals.AliSecret, order.ConsigneeMobile, ELM_SMS_SIGN_NAME, templateCode, string(utils.MustMarshal(templateParams)))
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
|
||||
@@ -49,11 +49,9 @@ func (c *PurchaseHandler) onOrderMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi
|
||||
} else {
|
||||
status := c.callbackMsg2Status(msg)
|
||||
if msg.StatusID == jdapi.OrderStatusAddComment || msg.StatusID == jdapi.OrderStatusModifyComment {
|
||||
if globals.ReallyCallPlatformAPI {
|
||||
utils.CallFuncAsync(func() {
|
||||
c.onOrderComment2(msg)
|
||||
})
|
||||
}
|
||||
utils.CallFuncAsync(func() {
|
||||
c.onOrderComment2(msg)
|
||||
})
|
||||
}
|
||||
err := partner.CurOrderManager.OnOrderStatusChanged(status)
|
||||
// if globals.HandleLegacyJxOrder && err == nil {
|
||||
|
||||
@@ -39,5 +39,8 @@ func (c *PurchaseHandler) onOrderComment2(msg *jdapi.CallbackOrderMsg) (err erro
|
||||
}
|
||||
|
||||
func (c *PurchaseHandler) ReplyOrderComment(ctx *jxcontext.Context, orderComment *model.OrderComment, replyComment string) (err error) {
|
||||
return api.JdAPI.OrgReplyComment(utils.Str2Int64(orderComment.VendorOrderID), orderComment.VendorStoreID, replyComment, ctx.GetUserName())
|
||||
if globals.ReallyReplyComment {
|
||||
err = api.JdAPI.OrgReplyComment(utils.Str2Int64(orderComment.VendorOrderID), orderComment.VendorStoreID, replyComment, ctx.GetUserName())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -125,9 +125,7 @@ func (c *PurchaseHandler) onOrderComment(msg *jdapi.CallbackOrderMsg) (err error
|
||||
comment.Status = COMMENT_RESOLVED
|
||||
}
|
||||
if score <= JX_BAD_COMMENTS_MAX_LEVEL && comment.Jxstoreid != "" {
|
||||
if globals.ReallyCallPlatformAPI {
|
||||
weixinmsg.PushJDBadCommentToWeiXin(comment)
|
||||
}
|
||||
weixinmsg.PushJDBadCommentToWeiXin(comment)
|
||||
}
|
||||
if err == nil {
|
||||
if isNewComment {
|
||||
@@ -157,13 +155,7 @@ func (c *PurchaseHandler) replyOrderComment(intOrderID int64, jdStoreNo string,
|
||||
content := config.comments[rand.Intn(len(config.comments))]
|
||||
globals.SugarLogger.Debugf("replyOrderComment orderID:%d, delaySeconds:%d, content:%s", intOrderID, delaySeconds, content)
|
||||
utils.AfterFuncWithRecover(time.Duration(delaySeconds)*time.Second, func() {
|
||||
// err2 := utils.CallFuncLogError(func() error {
|
||||
// if globals.ReallyCallPlatformAPI {
|
||||
// return api.JdAPI.OrgReplyComment(intOrderID, jdStoreNo, content, utils.GetAPIOperator(""))
|
||||
// }
|
||||
// return nil
|
||||
// }, "replyOrderComment %d", intOrderID)
|
||||
if globals.ReallySendWeixinMsg {
|
||||
if globals.ReallyReplyComment {
|
||||
err2 := api.JdAPI.OrgReplyComment(intOrderID, jdStoreNo, content, utils.GetAPIOperator(""))
|
||||
globals.SugarLogger.Debugf("replyOrderComment orderID:%d, error:%v", intOrderID, err2)
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ const (
|
||||
var (
|
||||
ReallyCallPlatformAPI bool
|
||||
ReallySendWeixinMsg bool
|
||||
ReallyReplyComment bool
|
||||
|
||||
SugarLogger *zap.SugaredLogger
|
||||
|
||||
@@ -49,17 +50,18 @@ func init() {
|
||||
}
|
||||
|
||||
func Init() {
|
||||
ReallySendWeixinMsg = beego.BConfig.RunMode == "prod"
|
||||
ReallyCallPlatformAPI = true
|
||||
ReallyCallPlatformAPI = (beego.BConfig.RunMode != "dev" && beego.BConfig.RunMode != "test")
|
||||
ReallySendWeixinMsg = ReallyCallPlatformAPI && beego.BConfig.RunMode == "prod"
|
||||
ReallyReplyComment = ReallyCallPlatformAPI && beego.BConfig.RunMode == "prod"
|
||||
|
||||
AliKey = beego.AppConfig.DefaultString("aliKey", "")
|
||||
AliSecret = beego.AppConfig.DefaultString("aliSecret", "")
|
||||
|
||||
EnableStoreWrite = beego.AppConfig.DefaultBool("enableStoreWrite", false)
|
||||
EnableEbaiStoreWrite = beego.AppConfig.DefaultBool("enableEbaiStoreWrite", false)
|
||||
EnableElmStoreWrite = beego.AppConfig.DefaultBool("enableElmStoreWrite", false)
|
||||
EnableMtwmStoreWrite = beego.AppConfig.DefaultBool("enableMtwmStoreWrite", false)
|
||||
EnableWscStoreWrite = beego.AppConfig.DefaultBool("enableWscStoreWrite", false)
|
||||
EnableEbaiStoreWrite = EnableStoreWrite && beego.AppConfig.DefaultBool("enableEbaiStoreWrite", false)
|
||||
EnableElmStoreWrite = EnableStoreWrite && beego.AppConfig.DefaultBool("enableElmStoreWrite", false)
|
||||
EnableMtwmStoreWrite = EnableStoreWrite && beego.AppConfig.DefaultBool("enableMtwmStoreWrite", false)
|
||||
EnableWscStoreWrite = EnableStoreWrite && beego.AppConfig.DefaultBool("enableWscStoreWrite", false)
|
||||
EnablePendingChange = beego.AppConfig.DefaultBool("enablePendingChange", false)
|
||||
|
||||
QiniuBucket = beego.AppConfig.String("qiniuBucket")
|
||||
|
||||
Reference in New Issue
Block a user