From deadc8f56312f39f1f140152a9ec472410b1a23d Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 26 Dec 2019 14:18:16 +0800 Subject: [PATCH] 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",