+weimob_order.go,根据微盟集中供货订单自动关注,修改相应的门店商品价格

This commit is contained in:
gazebo
2019-10-31 11:13:30 +08:00
parent e587723cf5
commit af4444648e
2 changed files with 74 additions and 4 deletions

View File

@@ -0,0 +1,68 @@
package cs
import (
"git.rosy.net.cn/baseapi/platformapi/weimobapi"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"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/api"
)
const (
minCSOrderPayment = 0 // 供货订单的最小金额
maxUnitPrice = 3000 // 为防止误填单价,限制单价最高
)
func OnCallbackMsg(msg *weimobapi.CallbackMsg) (response *weimobapi.CallbackResponse) {
orderID := utils.Int64ToStr(msg.OrderNo)
jxutils.CallMsgHandler(func() {
response = onOrderMsg(msg)
}, jxutils.ComposeUniversalOrderID(orderID, model.VendorIDWSC))
return response
}
func onOrderMsg(msg *weimobapi.CallbackMsg) (response *weimobapi.CallbackResponse) {
if msg.Event == weimobapi.MsgEventOrderStatusChange {
if orderDetail, err := api.WeimobAPI.QueryOrderDetail2(msg.OrderNo, false); err == nil {
if orderDetail.OrderStatus == weimobapi.OrderStatusFinished && orderDetail.PaymentAmount >= minCSOrderPayment {
changeStoreSkusByOrder(orderDetail)
}
}
}
return response
}
func changeStoreSkusByOrder(order *weimobapi.OrderDetail) {
receiverMobile := order.DeliveryDetail.LogisticsDeliveryDetail.ReceiverMobile
storeList, err := dao.GetStoreList(dao.GetDB(), nil, []string{receiverMobile}, "")
if err != nil {
if len(storeList) == 1 {
var skuBindInfos []*cms.StoreSkuBindInfo
storeID := storeList[0].ID
for _, v := range order.ItemList {
nameID := int(utils.Str2Int64WithDefault(v.SkuCode, 0))
unitPrice := v.OriginalPrice
if nameID > 0 && (unitPrice > 0 && unitPrice < maxUnitPrice) {
skuBindInfos = append(skuBindInfos, &cms.StoreSkuBindInfo{
StoreID: storeID,
NameID: nameID,
UnitPrice: int(jxutils.StandardPrice2Int(unitPrice)),
IsFocus: 1,
IsSale: 1,
})
} else {
globals.SugarLogger.Infof("[运营],微商城订单:%s商品:%s没有设置正确的SkuName编码或单价当前商家编码:%s市场价:%s", order.OrderNo, v.SkuNum, v.SkuCode, jxutils.IntPrice2StandardString(jxutils.StandardPrice2Int(unitPrice)))
}
}
if len(skuBindInfos) > 0 {
cms.UpdateStoreSkus(jxcontext.NewWithUserName(nil, utils.LimitStringLen(utils.Int64ToStr(order.OrderNo), 32), nil, nil), storeID, skuBindInfos, true, true)
}
} else {
globals.SugarLogger.Infof("[运营],微商城订单:%s手机:%s找不到唯一一个京西门店%d", order.OrderNo, receiverMobile, len(storeList))
}
}
}

View File

@@ -3,6 +3,7 @@ package controllers
import ( import (
"git.rosy.net.cn/baseapi/platformapi/weimobapi" "git.rosy.net.cn/baseapi/platformapi/weimobapi"
"git.rosy.net.cn/jx-callback/business/jxutils/tasks" "git.rosy.net.cn/jx-callback/business/jxutils/tasks"
"git.rosy.net.cn/jx-callback/business/cs"
"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"
"github.com/astaxie/beego" "github.com/astaxie/beego"
@@ -15,10 +16,11 @@ type WeimobController struct {
func (c *WeimobController) onCallbackMsg() { func (c *WeimobController) onCallbackMsg() {
if true { //c.Ctx.Input.Method() == http.MethodPost { if true { //c.Ctx.Input.Method() == http.MethodPost {
callbackResponse := weimobapi.SuccessResponse callbackResponse := weimobapi.SuccessResponse
// msg, callbackResponse := api.WeimobAPI.GetCallbackMsg(c.Ctx.Input.RequestBody) msg, callbackResponse := api.WeimobAPI.GetCallbackMsg(c.Ctx.Input.RequestBody)
// if callbackResponse == nil { if callbackResponse == nil {
// callbackResponse = wsc.OnCallbackMsg(msg) // callbackResponse = wsc.OnCallbackMsg(msg)
// } callbackResponse = cs.OnCallbackMsg(msg)
}
c.Data["json"] = callbackResponse c.Data["json"] = callbackResponse
c.ServeJSON() c.ServeJSON()
} else { } else {