From 256b7b659395c770dfee82935beb37110fd22ce8 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 26 Dec 2019 09:55:49 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=A0=A1=E9=AA=8Cupc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sku.go | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/business/jxstore/cms/sku.go b/business/jxstore/cms/sku.go index b4d180b3f..69bb3ca00 100644 --- a/business/jxstore/cms/sku.go +++ b/business/jxstore/cms/sku.go @@ -659,19 +659,14 @@ func AddSkuName(ctx *jxcontext.Context, skuNameExt *model.SkuNameExt, userName s if hasSensitiveWord, err := CheckHasSensitiveWord(skuNameExt.Name); hasSensitiveWord { return nil, err } - if utils.Pointer2String(skuNameExt.Upc) == "" { + upc := utils.Pointer2String(skuNameExt.Upc) + if upc == "" { skuNameExt.Upc = nil + } else if !jxutils.IsUpcValid(upc) { + return nil, fmt.Errorf("upc:%s不合法,请仔细检查", upc) } + db := dao.GetDB() - // if skuNameExt.Upc != "" { - // err = dao.GetEntity(db, &skuNameExt.SkuName, "Upc") - // if err == nil { - // return nil, fmt.Errorf("UPC:%s重复", skuNameExt.Upc) - // } else if !dao.IsNoRowsError(err) { - // return nil, err - // } - // err = nil - // } skuNameExt.SkuName.Status = model.SkuStatusNormal if skuNameExt.IsSpu == 1 { return nil, fmt.Errorf("不允许创建多规格商品") @@ -794,21 +789,11 @@ func UpdateSkuName(ctx *jxcontext.Context, nameID int, payload map[string]interf if valid["Upc"] != nil { if upc, _ := valid["Upc"].(string); upc == "" { valid["Upc"] = nil + } else if !jxutils.IsUpcValid(upc) { + return 0, fmt.Errorf("upc:%s不合法,请仔细检查", upc) } } globals.SugarLogger.Debugf("UpdateSkuName valid:%s", utils.Format4Output(valid, false)) - // if upc, _ := valid["Upc"].(string); upc != "" { - // skuName := &model.SkuName{ - // Upc: upc, - // } - // err = dao.GetEntity(db, skuName, "Upc") - // if err == nil { - // return 0, fmt.Errorf("UPC:%s重复", upc) - // } else if !dao.IsNoRowsError(err) { - // return 0, err - // } - // err = nil - // } for _, imgName := range []string{"img", "img2"} { if valid[imgName] != nil { if imgStr := utils.Interface2String(valid[imgName]); imgStr != "" { From deadc8f56312f39f1f140152a9ec472410b1a23d Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 26 Dec 2019 14:18:16 +0800 Subject: [PATCH 2/4] UpdateOrderWaybillTip --- business/jxcallback/orderman/order.go | 13 +++++ .../scheduler/basesch/basesch_ext.go | 55 +++++++++++++++++++ .../jxcallback/scheduler/defsch/defsch.go | 17 ++++++ business/model/const.go | 2 + business/partner/partner.go | 10 ++++ business/partner/purchase/ebai/order.go | 20 +++++++ business/partner/purchase/jd/order.go | 6 +- controllers/jd_callback.go | 4 ++ controllers/jx_order.go | 16 ++++++ routers/commentsRouter_controllers.go | 9 +++ 10 files changed, 151 insertions(+), 1 deletion(-) diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index ab2da58d6..88cdab2b6 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -163,6 +163,19 @@ func (c *OrderManager) OnOrderStatusChanged(vendorOrgCode string, orderStatus *m isDuplicated, order, err := c.addOrderStatus(orderStatus, db) if err == nil { dao.Commit(db) + if orderStatus.Status == model.OrderStatusWaybillTipChanged { + if handler := partner.GetWaybillTipUpdater(orderStatus.RefVendorID); handler != nil { + tipFee, err2 := handler.GetWaybillTip(jxcontext.AdminCtx, vendorOrgCode, orderStatus.RefVendorOrderID, orderStatus.VendorOrderID, "") + if err2 == nil { + c.UpdateOrderFields(&model.GoodsOrder{ + VendorOrderID: orderStatus.RefVendorOrderID, + VendorID: orderStatus.RefVendorID, + VendorOrgCode: vendorOrgCode, + WaybillTipMoney: tipFee, + }, []string{"WaybillTipMoney"}) + } + } + } if !isDuplicated { if order != nil { order.Skus = c.loadOrderSku(db, order.VendorOrderID, order.VendorID) diff --git a/business/jxcallback/scheduler/basesch/basesch_ext.go b/business/jxcallback/scheduler/basesch/basesch_ext.go index 31d20b865..e05cda61d 100644 --- a/business/jxcallback/scheduler/basesch/basesch_ext.go +++ b/business/jxcallback/scheduler/basesch/basesch_ext.go @@ -236,6 +236,61 @@ func (c *BaseScheduler) ConfirmSelfTake(ctx *jxcontext.Context, vendorOrderID st return err } +func (c *BaseScheduler) SetOrderWaybillTip(ctx *jxcontext.Context, vendorOrderID string, vendorID int, tipFee int64) (err error) { + order, err2 := partner.CurOrderManager.LoadOrder(vendorOrderID, vendorID) + if err = err2; err == nil { + err = c.SetOrderWaybillTipByOrder(ctx, order, tipFee) + } + return err +} + +func isWaybillCanAddTip(waybill *model.Waybill) (isCan bool) { + isCan = waybill.Status >= model.WaybillStatusNew && waybill.Status < model.WaybillStatusAccepted && partner.GetWaybillTipUpdater(waybill.WaybillVendorID) != nil + return isCan +} + +func (c *BaseScheduler) SetOrderWaybillTipByOrder(ctx *jxcontext.Context, order *model.GoodsOrder, tipFee int64) (err error) { + roundTipFee := tipFee / 100 * 100 + if roundTipFee != tipFee { + return fmt.Errorf("小费必须是元的整数倍") + } + if order.WaybillTipMoney >= tipFee { + return fmt.Errorf("当前小费已经是%s元,想要设置%s元", jxutils.IntPrice2StandardString(roundTipFee), jxutils.IntPrice2StandardString(tipFee)) + } + order.WaybillTipMoney = roundTipFee + partner.CurOrderManager.UpdateOrderFields(order, []string{"WaybillTipMoney"}) + + db := dao.GetDB() + waybills, err := dao.GetWayBillByOrderID(db, 0, order.VendorID, 0, order.VendorOrderID) + if err == nil { + var waybills2 []*model.Waybill + for _, v := range waybills { + if isWaybillCanAddTip(v) { + waybills2 = append(waybills2, v) + } + } + if len(waybills2) > 0 { + task := tasksch.NewParallelTask("setOrderWaybillTip", nil, ctx, + func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { + waybill := batchItemList[0].(*model.Waybill) + handler := partner.GetWaybillTipUpdater(waybill.WaybillVendorID) + curTipFee, err := handler.GetWaybillTip(ctx, waybill.VendorOrgCode, waybill.VendorOrderID, waybill.VendorWaybillID, waybill.VendorWaybillID2) + if err == nil { + tip2Add := order.WaybillTipMoney - curTipFee + storeDetail, err2 := dao.GetStoreDetail(db, jxutils.GetSaleStoreIDFromOrder(order), order.VendorID) + if err = err2; err == nil { + err = handler.AddWaybillTip(ctx, waybill.VendorOrgCode, waybill.VendorOrderID, waybill.VendorWaybillID, waybill.VendorWaybillID2, utils.Int2Str(storeDetail.CityCode), tip2Add) + } + } + return nil, err + }, waybills2) + tasksch.HandleTask(task, nil, false).Run() + _, err = task.GetResult(0) + } + } + return err +} + func (c *BaseScheduler) confirmSelfTake(ctx *jxcontext.Context, order *model.GoodsOrder, selfTakeCode string) (err error) { globals.SugarLogger.Debugf("confirmSelfTake orderID:%s, selfTakeCode:%s", order.VendorOrderID, selfTakeCode) if order.VendorID == model.VendorIDJD { diff --git a/business/jxcallback/scheduler/defsch/defsch.go b/business/jxcallback/scheduler/defsch/defsch.go index 49a71f3d4..aa89f9c63 100644 --- a/business/jxcallback/scheduler/defsch/defsch.go +++ b/business/jxcallback/scheduler/defsch/defsch.go @@ -1191,6 +1191,23 @@ func (s *DefScheduler) watchOrderWaybills(savedOrderInfo *WatchOrderInfo) { savedOrderInfo.SetOrder(order) if isNeedWatch3rdWaybill(order) { if isNeedWatchWaybillTip(order) { + // tipFee := getWaybillTip(order) + // if tipFee > order.WaybillTipMoney { + // vendorStatus := fmt.Sprintf("应设置小费:%s", jxutils.IntPrice2StandardCurrencyString(tipFee)) + // remark := "" + // if false { + // err = s.SetOrderWaybillTipByOrder(jxcontext.AdminCtx, order, tipFee) + // if err == nil { + // vendorStatus += "成功" + // } else { + // vendorStatus += "失败" + // remark = fmt.Sprint(err) + // } + // } else { + // vendorStatus += "空操作" + // } + // partner.CurOrderManager.OnOrderMsg(order, vendorStatus, remark) + // } if handler, ok := partner.GetPurchaseOrderHandlerFromVendorID(order.VendorID).(partner.IAddWaybillTip); ok && handler != nil { var remark string tipFee := getWaybillTip(order) diff --git a/business/model/const.go b/business/model/const.go index 2c85c1ee3..cd2c03f43 100644 --- a/business/model/const.go +++ b/business/model/const.go @@ -160,6 +160,8 @@ const ( const ( OrderStatusMsg = -100 + OrderStatusWaybillTipChanged = -80 // 订单小费变化 + OrderStatusRefuseFailedGetGoods = -70 // 取货失败审核驳回 OrderStatusAdjust = -65 // 原值-35 订单调整完成 OrderStatusApplyUrgeOrder = -55 // 原值-15 diff --git a/business/partner/partner.go b/business/partner/partner.go index dbdce3b9b..990edfb9b 100644 --- a/business/partner/partner.go +++ b/business/partner/partner.go @@ -287,3 +287,13 @@ func GetRidderPositionGetter(vendorID int) (handler IRidderPositionGetter) { handler, _ = GetPurchasePlatformFromVendorID(vendorID).(IRidderPositionGetter) return handler } + +func GetWaybillTipUpdater(vendorID int) (handler IAddWaybillTip) { + if handlerInfo := GetDeliveryPlatformFromVendorID(vendorID); handlerInfo != nil { + if handler, _ = handlerInfo.Handler.(IAddWaybillTip); handler != nil { + return handler + } + } + handler, _ = GetPurchasePlatformFromVendorID(vendorID).(IAddWaybillTip) + return handler +} diff --git a/business/partner/purchase/ebai/order.go b/business/partner/purchase/ebai/order.go index ed698afae..63080f8bc 100644 --- a/business/partner/purchase/ebai/order.go +++ b/business/partner/purchase/ebai/order.go @@ -660,3 +660,23 @@ func (c *PurchaseHandler) ListOrders(ctx *jxcontext.Context, vendorOrgCode strin } return vendorOrderIDs, err } + +func (c *PurchaseHandler) GetWaybillTip(ctx *jxcontext.Context, vendorOrgCode, vendorOrderID, vendorWaybillID, vendorWaybillID2 string) (tipFee int64, err error) { + orderInfo, err := api.EbaiAPI.GetStoreOrderInfo(vendorOrderID) + if err == nil { + if orderBasic, _ := orderInfo["order_basic"].(map[string]interface{}); orderBasic != nil { + tipFee = jxutils.StandardPrice2Int(utils.Interface2Float64WithDefault(orderBasic["delivery_tip_amount"], 0)) + } + } + return tipFee, err +} + +func (c *PurchaseHandler) AddWaybillTip(ctx *jxcontext.Context, vendorOrgCode, vendorOrderID, vendorWaybillID, vendorWaybillID2, cityCode string, tipFee2Add int64) (err error) { + tipFee, err := c.GetWaybillTip(ctx, vendorOrgCode, vendorOrderID, vendorWaybillID, vendorWaybillID2) + if err == nil { + if globals.EnableEbaiStoreWrite { + err = api.EbaiAPI.ModifyTip4OrderWaybill(vendorOrderID, "", jxutils.IntPrice2Standard(tipFee), 0) + } + } + return err +} diff --git a/business/partner/purchase/jd/order.go b/business/partner/purchase/jd/order.go index f47577449..022817508 100644 --- a/business/partner/purchase/jd/order.go +++ b/business/partner/purchase/jd/order.go @@ -37,6 +37,7 @@ var ( jdapi.OrderStatusVenderAgreeCancel: model.OrderStatusVendorAgreeCancel, jdapi.OrderStatusVenderRejectCancel: model.OrderStatusVendorRejectCancel, + jdapi.CallbackMsgOrderAddTips: model.OrderStatusWaybillTipChanged, } deliveryTypeMap = map[int]string{ jdapi.CarrierNoCrowdSourcing: model.OrderDeliveryTypePlatform, @@ -286,10 +287,13 @@ func (c *PurchaseHandler) callbackMsg2Status(msg *jdapi.CallbackOrderMsg) *model RefVendorOrderID: msg.BillID, RefVendorID: model.VendorIDJD, VendorStatus: msg.StatusID, - Status: c.getStatusFromVendorStatus(msg.StatusID), StatusTime: utils.Str2Time(msg.Timestamp), Remark: msg.Remark, } + if msg.MsgURL == jdapi.CallbackMsgOrderAddTips { + orderStatus.VendorStatus = jdapi.CallbackMsgOrderAddTips + } + orderStatus.Status = c.getStatusFromVendorStatus(orderStatus.VendorStatus) return orderStatus } diff --git a/controllers/jd_callback.go b/controllers/jd_callback.go index e641027c6..476e2cdfe 100644 --- a/controllers/jd_callback.go +++ b/controllers/jd_callback.go @@ -212,3 +212,7 @@ func (c *DjswController) nullOperation() { func (c *DjswController) UpdateSku() { c.nullOperation() } + +func (c *DjswController) OrderAddTips() { + c.orderStatus() +} diff --git a/controllers/jx_order.go b/controllers/jx_order.go index ebec2b769..7bbef01a4 100644 --- a/controllers/jx_order.go +++ b/controllers/jx_order.go @@ -231,6 +231,22 @@ func (c *OrderController) GetOrderWaybillInfo() { }) } +// @Title 补全遗漏的订单 +// @Description 补全遗漏的订单 +// @Param token header string true "认证token" +// @Param vendorOrderID formData string true "订单ID" +// @Param vendorID formData int true "订单所属的厂商ID" +// @Param tipFee formData int true "小费" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /UpdateOrderWaybillTip [post] +func (c *OrderController) UpdateOrderWaybillTip() { + c.callUpdateOrderWaybillTip(func(params *tOrderUpdateOrderWaybillTipParams) (retVal interface{}, errCode string, err error) { + err = defsch.FixedScheduler.SetOrderWaybillTip(params.Ctx, params.VendorOrderID, params.VendorID, int64(params.TipFee)) + return retVal, "", err + }) +} + // @Title 导出美团运单 // @Description 导出美团运单(excel文件),注意时间跨度不要太长,最多只能是一个月 // @Param token header string true "认证token" diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 197aceda0..5035e0c11 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -1071,6 +1071,15 @@ func init() { Filters: nil, Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"], + beego.ControllerComments{ + Method: "UpdateOrderWaybillTip", + Router: `/UpdateOrderWaybillTip`, + AllowHTTPMethods: []string{"post"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:ReportController"], beego.ControllerComments{ Method: "PriceRefer", From f13a8bbea2d1ab3a214d3e653f057e7d7060fcd5 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 26 Dec 2019 14:33:58 +0800 Subject: [PATCH 3/4] =?UTF-8?q?OrderStatusWaybillTipChanged=E6=8F=8F?= =?UTF-8?q?=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/model/const.go | 1 + 1 file changed, 1 insertion(+) diff --git a/business/model/const.go b/business/model/const.go index cd2c03f43..fab94d0b3 100644 --- a/business/model/const.go +++ b/business/model/const.go @@ -33,6 +33,7 @@ var ( OrderStatusName = map[int]string{ OrderStatusMsg: "通知消息", + OrderStatusWaybillTipChanged: "小费变动", OrderStatusRefuseFailedGetGoods: "取货失败审核驳回", OrderStatusAdjust: "订单调整完成", OrderStatusApplyUrgeOrder: "催单", From 381d1b2f217a2226015d517e0a2e47d91f80d4e3 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 26 Dec 2019 16:19:04 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=8A=A0=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E9=85=8D=E9=80=81=E5=B0=8F=E8=B4=B9=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E6=B7=BB=E5=8A=A0=E7=BE=8E=E5=9B=A2=E5=A4=96=E5=8D=96?= =?UTF-8?q?=E5=B9=B3=E5=8F=B0=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxcallback/orderman/order.go | 16 ++--- .../scheduler/basesch/basesch_ext.go | 32 +++++---- .../jxcallback/scheduler/defsch/defsch.go | 70 ++++++++++--------- business/partner/delivery/dada/waybill.go | 12 ++-- business/partner/partner_order.go | 4 +- business/partner/purchase/ebai/order.go | 11 ++- business/partner/purchase/jd/order.go | 27 +++---- business/partner/purchase/mtwm/order.go | 15 ++++ conf/app.conf | 6 ++ globals/api/api.go | 3 + 10 files changed, 108 insertions(+), 88 deletions(-) diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index 88cdab2b6..ecaed2d7f 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -164,15 +164,13 @@ func (c *OrderManager) OnOrderStatusChanged(vendorOrgCode string, orderStatus *m if err == nil { dao.Commit(db) if orderStatus.Status == model.OrderStatusWaybillTipChanged { - if handler := partner.GetWaybillTipUpdater(orderStatus.RefVendorID); handler != nil { - tipFee, err2 := handler.GetWaybillTip(jxcontext.AdminCtx, vendorOrgCode, orderStatus.RefVendorOrderID, orderStatus.VendorOrderID, "") - if err2 == nil { - c.UpdateOrderFields(&model.GoodsOrder{ - VendorOrderID: orderStatus.RefVendorOrderID, - VendorID: orderStatus.RefVendorID, - VendorOrgCode: vendorOrgCode, - WaybillTipMoney: tipFee, - }, []string{"WaybillTipMoney"}) + if order, err2 := c.LoadOrder(orderStatus.VendorOrderID, orderStatus.VendorID); err2 == nil { + if handler := partner.GetWaybillTipUpdater(orderStatus.RefVendorID); handler != nil { + tipFee, err2 := handler.GetWaybillTip(jxcontext.AdminCtx, vendorOrgCode, order.VendorStoreID, orderStatus.RefVendorOrderID, orderStatus.VendorOrderID, "") + if err2 == nil { + order.WaybillTipMoney = tipFee + c.UpdateOrderFields(order, []string{"WaybillTipMoney"}) + } } } } diff --git a/business/jxcallback/scheduler/basesch/basesch_ext.go b/business/jxcallback/scheduler/basesch/basesch_ext.go index e05cda61d..ed6afc1d4 100644 --- a/business/jxcallback/scheduler/basesch/basesch_ext.go +++ b/business/jxcallback/scheduler/basesch/basesch_ext.go @@ -252,35 +252,43 @@ func isWaybillCanAddTip(waybill *model.Waybill) (isCan bool) { func (c *BaseScheduler) SetOrderWaybillTipByOrder(ctx *jxcontext.Context, order *model.GoodsOrder, tipFee int64) (err error) { roundTipFee := tipFee / 100 * 100 if roundTipFee != tipFee { - return fmt.Errorf("小费必须是元的整数倍") + return fmt.Errorf("小费必须是1元的整数倍") } if order.WaybillTipMoney >= tipFee { - return fmt.Errorf("当前小费已经是%s元,想要设置%s元", jxutils.IntPrice2StandardString(roundTipFee), jxutils.IntPrice2StandardString(tipFee)) + return fmt.Errorf("当前小费已经是%s元,想要设置%s元", jxutils.IntPrice2StandardString(order.WaybillTipMoney), jxutils.IntPrice2StandardString(tipFee)) } - order.WaybillTipMoney = roundTipFee - partner.CurOrderManager.UpdateOrderFields(order, []string{"WaybillTipMoney"}) db := dao.GetDB() + storeDetail, err2 := dao.GetStoreDetail(db, jxutils.GetSaleStoreIDFromOrder(order), order.VendorID) + if err = err2; err != nil { + return err + } + + // 如果平台支持设置配送小费,必须要成功设置 + if handler := partner.GetWaybillTipUpdater(order.VendorID); handler != nil { + if err = handler.UpdateWaybillTip(ctx, order.VendorOrgCode, order.VendorStoreID, order.VendorOrderID, "", "", utils.Int2Str(storeDetail.CityCode), tipFee); err != nil { + return err + } + } + order.WaybillTipMoney = tipFee + partner.CurOrderManager.UpdateOrderFields(order, []string{"WaybillTipMoney"}) + waybills, err := dao.GetWayBillByOrderID(db, 0, order.VendorID, 0, order.VendorOrderID) if err == nil { var waybills2 []*model.Waybill for _, v := range waybills { - if isWaybillCanAddTip(v) { + // 必须是三方配送 + if !model.IsWaybillPlatformOwn(v) && isWaybillCanAddTip(v) { waybills2 = append(waybills2, v) } } if len(waybills2) > 0 { - task := tasksch.NewParallelTask("setOrderWaybillTip", nil, ctx, + task := tasksch.NewParallelTask("SetOrderWaybillTipByOrder", nil, ctx, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { waybill := batchItemList[0].(*model.Waybill) handler := partner.GetWaybillTipUpdater(waybill.WaybillVendorID) - curTipFee, err := handler.GetWaybillTip(ctx, waybill.VendorOrgCode, waybill.VendorOrderID, waybill.VendorWaybillID, waybill.VendorWaybillID2) if err == nil { - tip2Add := order.WaybillTipMoney - curTipFee - storeDetail, err2 := dao.GetStoreDetail(db, jxutils.GetSaleStoreIDFromOrder(order), order.VendorID) - if err = err2; err == nil { - err = handler.AddWaybillTip(ctx, waybill.VendorOrgCode, waybill.VendorOrderID, waybill.VendorWaybillID, waybill.VendorWaybillID2, utils.Int2Str(storeDetail.CityCode), tip2Add) - } + err = handler.UpdateWaybillTip(ctx, waybill.VendorOrgCode, storeDetail.VendorStoreID, waybill.VendorOrderID, waybill.VendorWaybillID, waybill.VendorWaybillID2, utils.Int2Str(storeDetail.CityCode), tipFee) } return nil, err }, waybills2) diff --git a/business/jxcallback/scheduler/defsch/defsch.go b/business/jxcallback/scheduler/defsch/defsch.go index aa89f9c63..fa5e9cc67 100644 --- a/business/jxcallback/scheduler/defsch/defsch.go +++ b/business/jxcallback/scheduler/defsch/defsch.go @@ -459,24 +459,35 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo if !isPending { if order.Status > model.OrderStatusEndBegin { s.ProxyCancelWaybill(order, bill, partner.CancelWaybillReasonNotAcceptIntime, partner.CancelWaybillReasonStrNotAcceptIntime) - } else if model.IsOrderHaveWaybill(order) { - globals.SugarLogger.Debugf("OnWaybillStatusChanged multiple waybill created, bill:%v", bill) - if model.IsWaybillPlatformOwn(bill) { // 是购物平台运单 - if !model.IsOrderHaveOwnWaybill(order) { // 既有运单不是购物平台运单 - globals.SugarLogger.Infof("OnWaybillStatusChanged bill:%v purchase platform bill came later than others, strange!!!", bill) - oldBill := savedOrderInfo.waybills[order.WaybillVendorID] - if oldBill != nil { - s.ProxyCancelWaybill(order, oldBill, partner.CancelWaybillReasonNotAcceptIntime, partner.CancelWaybillReasonStrNotAcceptIntime) - } else { - globals.SugarLogger.Warnf("OnWaybillStatusChanged bill:%v, oldBill is null, strange!!!", bill) + } else { + needAddTip := order.WaybillTipMoney > 0 && !model.IsWaybillPlatformOwn(bill) + if model.IsOrderHaveWaybill(order) { + globals.SugarLogger.Debugf("OnWaybillStatusChanged multiple waybill created, bill:%v", bill) + if model.IsWaybillPlatformOwn(bill) { // 是购物平台运单 + if !model.IsOrderHaveOwnWaybill(order) { // 既有运单不是购物平台运单 + globals.SugarLogger.Infof("OnWaybillStatusChanged bill:%v purchase platform bill came later than others, strange!!!", bill) + oldBill := savedOrderInfo.waybills[order.WaybillVendorID] + if oldBill != nil { + s.ProxyCancelWaybill(order, oldBill, partner.CancelWaybillReasonNotAcceptIntime, partner.CancelWaybillReasonStrNotAcceptIntime) + } else { + globals.SugarLogger.Warnf("OnWaybillStatusChanged bill:%v, oldBill is null, strange!!!", bill) + } + } + s.updateOrderByBill(order, nil, false) + if time.Now().Sub(order.OrderCreatedAt) < 2*time.Minute { // 京东一些门店设置成了接单即拣货完成,这种情况下自动调用拣货完成 + s.autoPickupGood(savedOrderInfo) + } + } else { + needAddTip = false + s.ProxyCancelWaybill(order, bill, partner.CancelWaybillReasonNotAcceptIntime, partner.CancelWaybillReasonStrNotAcceptIntime) + } + } + if needAddTip { + if handler := partner.GetWaybillTipUpdater(bill.WaybillVendorID); handler != nil { + if storeDetail, err2 := dao.GetStoreDetail(dao.GetDB(), jxutils.GetSaleStoreIDFromOrder(order), order.VendorID); err2 == nil { + handler.UpdateWaybillTip(jxcontext.AdminCtx, order.VendorOrgCode, order.VendorStoreID, order.VendorOrderID, bill.VendorWaybillID, bill.VendorWaybillID2, utils.Int2Str(storeDetail.CityCode), order.WaybillTipMoney) } } - s.updateOrderByBill(order, nil, false) - if time.Now().Sub(order.OrderCreatedAt) < 2*time.Minute { // 京东一些门店设置成了接单即拣货完成,这种情况下自动调用拣货完成 - s.autoPickupGood(savedOrderInfo) - } - } else { - s.ProxyCancelWaybill(order, bill, partner.CancelWaybillReasonNotAcceptIntime, partner.CancelWaybillReasonStrNotAcceptIntime) } } flag2Clear := model.WaybillVendorID2Mask(bill.WaybillVendorID) @@ -1212,25 +1223,20 @@ func (s *DefScheduler) watchOrderWaybills(savedOrderInfo *WatchOrderInfo) { var remark string tipFee := getWaybillTip(order) vendorStatus := fmt.Sprintf("设置小费:%s", jxutils.IntPrice2StandardCurrencyString(tipFee)) - if curTipFee, err := handler.GetWaybillTip(jxcontext.AdminCtx, order.VendorOrgCode, order.VendorOrderID, order.VendorOrderID, ""); err == nil { - tipFee2Add := tipFee - curTipFee - vendorStatus += fmt.Sprintf(", 本次添加:%s", jxutils.IntPrice2StandardCurrencyString(tipFee2Add)) - if false { //tipFee2Add > 0 { - err := handler.AddWaybillTip(jxcontext.AdminCtx, order.VendorOrgCode, order.VendorOrderID, order.VendorOrderID, "", "", tipFee2Add) - if err == nil { - vendorStatus += "成功" - order.WaybillTipMoney += tipFee2Add - partner.CurOrderManager.UpdateOrderFields(order, []string{"WaybillTipMoney"}) - } else { - vendorStatus += "失败" - remark = fmt.Sprint(err) - } + tipFee2Add := tipFee - order.WaybillTipMoney + vendorStatus += fmt.Sprintf(", 本次添加:%s", jxutils.IntPrice2StandardCurrencyString(tipFee2Add)) + if false { //tipFee2Add > 0 { + err := handler.UpdateWaybillTip(jxcontext.AdminCtx, order.VendorOrgCode, order.VendorStoreID, order.VendorOrderID, order.VendorOrderID, "", "", tipFee) + if err == nil { + vendorStatus += "成功" + order.WaybillTipMoney = tipFee + partner.CurOrderManager.UpdateOrderFields(order, []string{"WaybillTipMoney"}) } else { - vendorStatus += "空操作" + vendorStatus += "失败" + remark = fmt.Sprint(err) } } else { - vendorStatus += "失败" - remark = fmt.Sprint(err) + vendorStatus += "空操作" } partner.CurOrderManager.OnOrderMsg(order, vendorStatus, remark) } diff --git a/business/partner/delivery/dada/waybill.go b/business/partner/delivery/dada/waybill.go index e9e732629..68a6b6704 100644 --- a/business/partner/delivery/dada/waybill.go +++ b/business/partner/delivery/dada/waybill.go @@ -392,7 +392,7 @@ func (c *DeliveryHandler) ComplaintRider(bill *model.Waybill, resonID int, reson return err } -func (c *DeliveryHandler) GetWaybillTip(ctx *jxcontext.Context, vendorOrgCode, vendorOrderID, vendorWaybillID, vendorWaybillID2 string) (tipFee int64, err error) { +func (c *DeliveryHandler) GetWaybillTip(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID, vendorOrderID, vendorWaybillID, vendorWaybillID2 string) (tipFee int64, err error) { order, err := api.DadaAPI.QueryOrderInfo2(vendorOrderID) if err == nil { tipFee = jxutils.StandardPrice2Int(order.Tips) @@ -400,13 +400,9 @@ func (c *DeliveryHandler) GetWaybillTip(ctx *jxcontext.Context, vendorOrgCode, v return tipFee, err } -func (c *DeliveryHandler) AddWaybillTip(ctx *jxcontext.Context, vendorOrgCode, vendorOrderID, vendorWaybillID, vendorWaybillID2, cityCode string, tipFee2Add int64) (err error) { - curTip, err := c.GetWaybillTip(ctx, vendorOrgCode, vendorOrderID, vendorWaybillID, vendorWaybillID2) - if err == nil { - totalTip := curTip + tipFee2Add - if globals.EnableStoreWrite { - err = api.DadaAPI.AddTip(vendorOrderID, jxutils.IntPrice2Standard(totalTip), cityCode, "") - } +func (c *DeliveryHandler) UpdateWaybillTip(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID, vendorOrderID, vendorWaybillID, vendorWaybillID2, cityCode string, tipFee int64) (err error) { + if globals.EnableStoreWrite { + err = api.DadaAPI.AddTip(vendorOrderID, jxutils.IntPrice2Standard(tipFee), cityCode, "") } return err } diff --git a/business/partner/partner_order.go b/business/partner/partner_order.go index b68b07e95..dace71dc7 100644 --- a/business/partner/partner_order.go +++ b/business/partner/partner_order.go @@ -58,8 +58,8 @@ type IPurchasePlatformOrderHandler interface { } type IAddWaybillTip interface { - GetWaybillTip(ctx *jxcontext.Context, vendorOrgCode, vendorOrderID, vendorWaybillID, vendorWaybillID2 string) (tipFee int64, err error) - AddWaybillTip(ctx *jxcontext.Context, vendorOrgCode, vendorOrderID, vendorWaybillID, vendorWaybillID2, cityCode string, tipFee2Add int64) (err error) + GetWaybillTip(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID, vendorOrderID, vendorWaybillID, vendorWaybillID2 string) (tipFee int64, err error) + UpdateWaybillTip(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID, vendorOrderID, vendorWaybillID, vendorWaybillID2, cityCode string, tipFee int64) (err error) } type IRidderPositionGetter interface { diff --git a/business/partner/purchase/ebai/order.go b/business/partner/purchase/ebai/order.go index 63080f8bc..7f13d3ec8 100644 --- a/business/partner/purchase/ebai/order.go +++ b/business/partner/purchase/ebai/order.go @@ -661,7 +661,7 @@ func (c *PurchaseHandler) ListOrders(ctx *jxcontext.Context, vendorOrgCode strin return vendorOrderIDs, err } -func (c *PurchaseHandler) GetWaybillTip(ctx *jxcontext.Context, vendorOrgCode, vendorOrderID, vendorWaybillID, vendorWaybillID2 string) (tipFee int64, err error) { +func (c *PurchaseHandler) GetWaybillTip(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID, vendorOrderID, vendorWaybillID, vendorWaybillID2 string) (tipFee int64, err error) { orderInfo, err := api.EbaiAPI.GetStoreOrderInfo(vendorOrderID) if err == nil { if orderBasic, _ := orderInfo["order_basic"].(map[string]interface{}); orderBasic != nil { @@ -671,12 +671,9 @@ func (c *PurchaseHandler) GetWaybillTip(ctx *jxcontext.Context, vendorOrgCode, v return tipFee, err } -func (c *PurchaseHandler) AddWaybillTip(ctx *jxcontext.Context, vendorOrgCode, vendorOrderID, vendorWaybillID, vendorWaybillID2, cityCode string, tipFee2Add int64) (err error) { - tipFee, err := c.GetWaybillTip(ctx, vendorOrgCode, vendorOrderID, vendorWaybillID, vendorWaybillID2) - if err == nil { - if globals.EnableEbaiStoreWrite { - err = api.EbaiAPI.ModifyTip4OrderWaybill(vendorOrderID, "", jxutils.IntPrice2Standard(tipFee), 0) - } +func (c *PurchaseHandler) UpdateWaybillTip(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID, vendorOrderID, vendorWaybillID, vendorWaybillID2, cityCode string, tipFee int64) (err error) { + if globals.EnableEbaiStoreWrite { + err = api.EbaiAPI.ModifyTip4OrderWaybill(vendorOrderID, "", jxutils.IntPrice2Standard(tipFee), 0) } return err } diff --git a/business/partner/purchase/jd/order.go b/business/partner/purchase/jd/order.go index 022817508..2f307f2ba 100644 --- a/business/partner/purchase/jd/order.go +++ b/business/partner/purchase/jd/order.go @@ -484,21 +484,7 @@ func (c *PurchaseHandler) ListOrders(ctx *jxcontext.Context, vendorOrgCode strin return vendorOrderIDs, err } -func (c *PurchaseHandler) UpdateWaybillTip(ctx *jxcontext.Context, order *model.GoodsOrder, tipFee int64) (err error) { - a := getAPI(order.VendorOrgCode) - orderInfo, err := a.QuerySingleOrder2(order.VendorOrderID) - if err == nil { - tip2Add := int(tipFee) - orderInfo.Tips - if tip2Add != 0 { - if globals.EnableJdStoreWrite { - err = a.OrderAddTips(order.VendorOrderID, tip2Add, ctx.GetUserName()) - } - } - } - return err -} - -func (c *PurchaseHandler) GetWaybillTip(ctx *jxcontext.Context, vendorOrgCode, vendorOrderID, vendorWaybillID, vendorWaybillID2 string) (tipFee int64, err error) { +func (c *PurchaseHandler) GetWaybillTip(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID, vendorOrderID, vendorWaybillID, vendorWaybillID2 string) (tipFee int64, err error) { orderInfo, err := getAPI(vendorOrgCode).QuerySingleOrder2(vendorOrderID) if err == nil { tipFee = int64(orderInfo.Tips) @@ -506,9 +492,14 @@ func (c *PurchaseHandler) GetWaybillTip(ctx *jxcontext.Context, vendorOrgCode, v return tipFee, err } -func (c *PurchaseHandler) AddWaybillTip(ctx *jxcontext.Context, vendorOrgCode, vendorOrderID, vendorWaybillID, vendorWaybillID2, cityCode string, tipFee2Add int64) (err error) { - if globals.EnableJdStoreWrite { - err = getAPI(vendorOrgCode).OrderAddTips(vendorOrderID, int(tipFee2Add), ctx.GetUserName()) +func (c *PurchaseHandler) UpdateWaybillTip(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID, vendorOrderID, vendorWaybillID, vendorWaybillID2, cityCode string, tipFee int64) (err error) { + curTipFee, err := c.GetWaybillTip(ctx, vendorOrgCode, vendorStoreID, vendorOrderID, vendorWaybillID, vendorWaybillID2) + if err == nil { + if tipFee2Add := tipFee - curTipFee; tipFee2Add > 0 { + if globals.EnableJdStoreWrite { + err = getAPI(vendorOrgCode).OrderAddTips(vendorOrderID, int(tipFee2Add), ctx.GetUserName()) + } + } } return err } diff --git a/business/partner/purchase/mtwm/order.go b/business/partner/purchase/mtwm/order.go index 74d7d7e30..2be1bca8a 100644 --- a/business/partner/purchase/mtwm/order.go +++ b/business/partner/purchase/mtwm/order.go @@ -755,3 +755,18 @@ func (p *PurchaseHandler) onNumberDowngrade(msg *mtwmapi.CallbackMsg) (response tasksch.HandleTask(task, nil, true).Run() return response } + +func (c *PurchaseHandler) GetWaybillTip(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID, vendorOrderID, vendorWaybillID, vendorWaybillID2 string) (tipFee int64, err error) { + orderInfo, err := api.MtwmAPI.GetDistributeOrderDetail(vendorOrderID, vendorStoreID) + if err == nil { + tipFee = jxutils.StandardPrice2Int(orderInfo.TipAmount) + } + return tipFee, err +} + +func (c *PurchaseHandler) UpdateWaybillTip(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID, vendorOrderID, vendorWaybillID, vendorWaybillID2, cityCode string, tipFee int64) (err error) { + if globals.EnableMtwmStoreWrite { + err = api.MtwmAPI.OrderModityTips(vendorOrderID, vendorStoreID, jxutils.IntPrice2Standard(tipFee)) + } + return err +} diff --git a/conf/app.conf b/conf/app.conf index e938b7a8d..7f424bacf 100644 --- a/conf/app.conf +++ b/conf/app.conf @@ -15,6 +15,7 @@ dadaAppSecret = "2c717ad914767d6e2beb3f743db9e477" mtwmAppID = "589" mtwmSecret = "a81eb3df418d83d6a1a4b7c572156d2f" mtwmCallbackURL = "http://callback.jxc4.com" +mtwmCookieStr = "_lxsdk_cuid=16eb02a8a02c8-0a92cb9af9798c-3d375b01-15f900-16eb02a8a02c8; _lxsdk=16eb02a8a02c8-0a92cb9af9798c-3d375b01-15f900-16eb02a8a02c8; device_uuid=!aaa93749-2445-4e1e-b178-956ac0ea5e45; pushToken=0sMxJkF87HeJFNGInMgnpvQ3ohIqeo_UMZ8VDif29S6s*; _lx_utm=utm_source%3DBaidu%26utm_medium%3Dorganic; wpush_server_url=wss://wpush.meituan.com; acctId=26599188; token=0o7UnNs2yauqdj86R145ow78W9cT9krlWpKPmCan2z7Q*; brandId=-1; wmPoiId=-1; isOfflineSelfOpen=0; city_id=0; isChain=1; existBrandPoi=true; ignore_set_router_proxy=true; region_id=; region_version=0; newCategory=false; bsid=PgNahlgfXvqnBiqv9tIi9zg7LDWtV8n70tkl_GhfueXgrLxV9BEb1rP9emUMnUUKPI6rANs_Y-chSdYLZS3KCA; cityId=510100; provinceId=510000; city_location_id=0; location_id=0; JSESSIONID=uht6v2iau9s6fx86r1ue6vzd; set_info=%7B%22wmPoiId%22%3A-1%2C%22ignoreSetRouterProxy%22%3Atrue%7D; igateApp=shangouepc; LX_SC_CONSTANT=c_nehoktcu; shopCategory=food; _lxsdk_s=16f40af4486-049-a66-a48%7C26337904%7C37" autonaviKey = "ef64f638f31e05cb7bde28790f7309fe" @@ -208,6 +209,7 @@ ebaiStorePageCookieWMSTOKEN = "gAAA4OkFSZBsOayRIAnRqd24YRRVvWgRFE2w2CGtjKlAIsYg1 mtwmAppID = "4123" mtwmSecret = "df2c88338b85f830cebce2a9eab56628" mtwmCallbackURL = "http://callback-jxgy.jxc4.com" +mtwmCookieStr = "_lxsdk_cuid=16f413bd94fc8-0daccb808f461b-1d336b5a-13c680-16f413bd94fc8; _lxsdk=16f413bd94fc8-0daccb808f461b-1d336b5a-13c680-16f413bd94fc8; uuid=d1e8adb3d2774b89fe6e.1577347439.1.0.0; uuid_update=true; wpush_server_url=wss://wpush.meituan.com; acctId=62884810; token=0LhaIAAgrL1Hy0DDATjZqt4lRHauN_bBL3q0AvxUFUWo*; brandId=-1; wmPoiId=-1; isOfflineSelfOpen=0; city_id=0; isChain=1; existBrandPoi=true; ignore_set_router_proxy=true; region_id=; region_version=0; newCategory=false; bsid=SUVq2IfzZ53EHaTVoCE3UsmKkH5ZevxTjkwpNcaLKkbUOBkEyuZp8mPFwhgqkxsCGNjZILNj5aV8uVSQc888bg; device_uuid=!625e0297-431a-49ad-8b18-a0562c38a8eb; cityId=510100; provinceId=510000; city_location_id=0; location_id=0; pushToken=0LhaIAAgrL1Hy0DDATjZqt4lRHauN_bBL3q0AvxUFUWo*; set_info=%7B%22wmPoiId%22%3A-1%2C%22ignoreSetRouterProxy%22%3Atrue%7D; igateApp=shangouepc; LX_SC_CONSTANT=c_nehoktcu; shopCategory=food; JSESSIONID=unlrbu07lvm2s734eyedxr0j; _lxsdk_s=16f413bd950-189-8bb-8df%7C%7C33" enableStoreWrite = true enableJdStoreWrite = true @@ -284,6 +286,10 @@ jdStorePageCookie = "5EOCZRXVCRXBTYD5EPV6FOXRCQWFFQO75FRMJ3BAKZ5JXY6XTJECMWXK5OZ ebaiSource = "62289" ebaiSecret = "d3ec2358d6a819ea" +ebaiStorePageCookieWMUSS = "AHYHAAApIX5oBXUFKFsXKEdObiclRUhTFRZ1MUh7KEMiClB7MnB5G3VvIB5KN0USAABjQ4KngBfQ4Wcj9ebWYiEHBxCyNiBT1Yc111PhQ7UBluCENnCUB0HjIzfCAaHjAKEDoscT8sDL8JDDuQD81NaQ1dW3kN1MS9DeFMPgwC2YYROVy7AV3cKhMPkQrBwA" +ebaiStorePageCookieWMSTOKEN = "UAABRL3ZhLykdGFQBBDxXVDBuYisaB3tQHjUmHlQ5cEAs5dxMdG0R-EwVILAy_CV1Vlw_nbQAA0ijuEe-F2xUzAQAAAdujHKzhohkrxY0c5LsAAH0CeSGnywAHBQAAMA" + +mtwmCookieStr = "_lxsdk_cuid=169b7bc1b9fc8-05092471a96611-12376d51-1fa400-169b7bc1b9fc8; _lxsdk=169b7bc1b9fc8-05092471a96611-12376d51-1fa400-169b7bc1b9fc8; uuid=7a6a1345b4a3f7aa5f81.1553565752.1.0.0; _ga=GA1.2.285163436.1559264188; uuid_update=true; pushToken=0sz3wYPQoNug6okzOjEacuvrEWGRhuv6gL5ZWX98prCw*; device_uuid=!88124822-2b68-4425-865d-a3ffffe355af; wpush_server_url=wss://wpush.meituan.com; acctId=26535718; token=0vt6ufSF1X8GXpVq3N5zhE5FhcgONSuNTg4LiqkqEyTM*; brandId=-1; wmPoiId=2523687; isOfflineSelfOpen=0; city_id=999999; isChain=0; existBrandPoi=false; ignore_set_router_proxy=false; region_id=2000000001; region_version=1522820107; newCategory=false; bsid=g54gdBCxg9fu4t99gGLf770bFzBT_eUQXA3_FWLgDeCWrEtsNdXkJtckKTvMEthURtXVg_j0mhDauKPgDUgZyQ; cityId=510100; provinceId=510000; city_location_id=10000004; location_id=10000005; set_info=%7B%22wmPoiId%22%3A2523687%2C%22region_id%22%3A%222000000001%22%2C%22region_version%22%3A1522820107%7D; igateApp=shangouepc; shopCategory=market; LX_SC_CONSTANT=c_nehoktcu; JSESSIONID=43y9tjdcnjh2kojf6qfehvdy; _lxsdk_s=16f4145a84c-d6a-c22-64c%7C%7C19" mtpsAppKey = "25e816550bc9484480642f19a95f13fd" mtpsSecret = "r4$HqrKx9~=7?2Jfo,$Z~a7%~k!Au&pEdI2)oPJvSbH2ao@2N0[8wSIvtuumh_J^" diff --git a/globals/api/api.go b/globals/api/api.go index 8e180df56..b22fbca19 100644 --- a/globals/api/api.go +++ b/globals/api/api.go @@ -97,6 +97,9 @@ func Init() { } if !beego.AppConfig.DefaultBool("disableMtwm", false) { MtwmAPI = mtwmapi.New(beego.AppConfig.String("mtwmAppID"), beego.AppConfig.String("mtwmSecret"), beego.AppConfig.String("mtwmCallbackURL")) + if mtwmCookieStr := beego.AppConfig.DefaultString("mtwmCookieStr", ""); mtwmCookieStr != "" { + MtwmAPI.SetCookieWithStr(mtwmCookieStr) + } } else { MtwmAPI = nil }