From af4444648eea9d2eb6c91038e73f24048f843287 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 31 Oct 2019 11:13:30 +0800 Subject: [PATCH] =?UTF-8?q?+weimob=5Forder.go=EF=BC=8C=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E5=BE=AE=E7=9B=9F=E9=9B=86=E4=B8=AD=E4=BE=9B=E8=B4=A7=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E8=87=AA=E5=8A=A8=E5=85=B3=E6=B3=A8=EF=BC=8C=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E7=9B=B8=E5=BA=94=E7=9A=84=E9=97=A8=E5=BA=97=E5=95=86?= =?UTF-8?q?=E5=93=81=E4=BB=B7=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/cs/weimob_order.go | 68 ++++++++++++++++++++++++++++++++++ controllers/weimob_callback.go | 10 +++-- 2 files changed, 74 insertions(+), 4 deletions(-) create mode 100644 business/cs/weimob_order.go diff --git a/business/cs/weimob_order.go b/business/cs/weimob_order.go new file mode 100644 index 000000000..e5d89e979 --- /dev/null +++ b/business/cs/weimob_order.go @@ -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)) + } + } +} diff --git a/controllers/weimob_callback.go b/controllers/weimob_callback.go index 8e8123ad7..7989ae264 100644 --- a/controllers/weimob_callback.go +++ b/controllers/weimob_callback.go @@ -3,6 +3,7 @@ package controllers import ( "git.rosy.net.cn/baseapi/platformapi/weimobapi" "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/api" "github.com/astaxie/beego" @@ -15,10 +16,11 @@ type WeimobController struct { func (c *WeimobController) onCallbackMsg() { if true { //c.Ctx.Input.Method() == http.MethodPost { callbackResponse := weimobapi.SuccessResponse - // msg, callbackResponse := api.WeimobAPI.GetCallbackMsg(c.Ctx.Input.RequestBody) - // if callbackResponse == nil { - // callbackResponse = wsc.OnCallbackMsg(msg) - // } + msg, callbackResponse := api.WeimobAPI.GetCallbackMsg(c.Ctx.Input.RequestBody) + if callbackResponse == nil { + // callbackResponse = wsc.OnCallbackMsg(msg) + callbackResponse = cs.OnCallbackMsg(msg) + } c.Data["json"] = callbackResponse c.ServeJSON() } else {