From 45948e4b09a1f5ba3747532ca509111cb2f33612 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 1 Aug 2019 17:32:43 +0800 Subject: [PATCH 1/6] - up --- business/jxutils/jxutils_act_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/business/jxutils/jxutils_act_test.go b/business/jxutils/jxutils_act_test.go index 758de51bd..19b36010d 100644 --- a/business/jxutils/jxutils_act_test.go +++ b/business/jxutils/jxutils_act_test.go @@ -15,4 +15,5 @@ func TestGetActStoreSku(t *testing.T) { t.Fatal(err) } storeSkuMap := NewActStoreSkuMap(actStoreSkuList, false) + t.Log(storeSkuMap.GetActStoreSku(1, 2, 3)) } From 1d0aa132f9d0b65b2c21cc45a681c3924bc6f281 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 1 Aug 2019 18:09:23 +0800 Subject: [PATCH 2/6] =?UTF-8?q?-=20GoodsOrder.WaybillTipMoney=E7=9A=84?= =?UTF-8?q?=E5=90=AB=E4=B9=89=E6=94=B9=E4=B8=BA=E4=BA=AC=E8=A5=BF=E4=B8=BB?= =?UTF-8?q?=E5=8A=A8=E5=8A=A0=E7=9A=84=E5=B0=8F=E8=B4=B9=20-=20partner.IUp?= =?UTF-8?q?dateWaybillTip=E6=94=B9=E4=B8=BAIAddWaybillTip?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxcallback/orderman/orderman_ext.go | 1 + .../jxcallback/scheduler/defsch/defsch.go | 27 +++++++++++++------ business/jxstore/misc/misc2_test.go | 2 +- business/model/order.go | 2 +- business/partner/partner_order.go | 6 ++--- business/partner/purchase/jd/order.go | 19 +++++++++++-- 6 files changed, 42 insertions(+), 15 deletions(-) diff --git a/business/jxcallback/orderman/orderman_ext.go b/business/jxcallback/orderman/orderman_ext.go index 156531b8c..c68ed69c2 100644 --- a/business/jxcallback/orderman/orderman_ext.go +++ b/business/jxcallback/orderman/orderman_ext.go @@ -521,6 +521,7 @@ func (c *OrderManager) ExportOrders(ctx *jxcontext.Context, fromDateStr, toDateS "waybillFinishedAt", "status2", "skuInfo", + "waybillTipMoney", }, } excelBin = excel.Obj2Excel([]*excel.Obj2ExcelSheetConfig{excelConf}) diff --git a/business/jxcallback/scheduler/defsch/defsch.go b/business/jxcallback/scheduler/defsch/defsch.go index 03d71753d..759ddecd5 100644 --- a/business/jxcallback/scheduler/defsch/defsch.go +++ b/business/jxcallback/scheduler/defsch/defsch.go @@ -1032,14 +1032,25 @@ func (s *DefScheduler) handleWaybillTip(savedOrderInfo *WatchOrderInfo) { if !utils.IsTimeZero(savedOrderInfo.pmWaybillCreatedAt) && !savedOrderInfo.isAddWaybillTipDisabled { if tipFee := s.getWaybillTip(savedOrderInfo); tipFee > 0 { - if handler, ok := partner.GetPurchasePlatformFromVendorID(order.VendorID).(partner.IUpdateWaybillTip); ok && handler != nil { - err := handler.UpdateWaybillTip(jxcontext.AdminCtx, order, tipFee) - vendorStatus := fmt.Sprintf("添加小费:%s", jxutils.IntPrice2StandardCurrencyString(tipFee)) - remark := "" - if err == nil { - vendorStatus += "成功" - order.WaybillTipMoney = tipFee - partner.CurOrderManager.UpdateOrderFields(order, []string{"WaybillTipMoney"}) + if handler, ok := partner.GetPurchasePlatformFromVendorID(order.VendorID).(partner.IAddWaybillTip); ok && handler != nil { + var remark string + vendorStatus := fmt.Sprintf("设置小费:%s", jxutils.IntPrice2StandardCurrencyString(tipFee)) + if curTipFee, err := handler.GetWaybillTip(jxcontext.AdminCtx, order); err == nil { + tipFee2Add := tipFee - curTipFee + vendorStatus += fmt.Sprintf(", 本次添加:%s", jxutils.IntPrice2StandardCurrencyString(tipFee2Add)) + if tipFee2Add > 0 { + err := handler.AddWaybillTip(jxcontext.AdminCtx, order, tipFee2Add) + if err == nil { + vendorStatus += "成功" + order.WaybillTipMoney += tipFee2Add + partner.CurOrderManager.UpdateOrderFields(order, []string{"WaybillTipMoney"}) + } else { + vendorStatus += "失败" + remark = fmt.Sprint(err) + } + } else { + vendorStatus += "空操作" + } } else { vendorStatus += "失败" remark = fmt.Sprint(err) diff --git a/business/jxstore/misc/misc2_test.go b/business/jxstore/misc/misc2_test.go index 3973944c7..c683e0bb7 100644 --- a/business/jxstore/misc/misc2_test.go +++ b/business/jxstore/misc/misc2_test.go @@ -5,5 +5,5 @@ import ( ) func TestStartOrEndOpStore(t *testing.T) { - StartOrEndOpStore(true, 0, 0) + StartOrEndOpStore(true, 0, 0, false, true) } diff --git a/business/model/order.go b/business/model/order.go index 34ea315e8..b3dbcbdb6 100644 --- a/business/model/order.go +++ b/business/model/order.go @@ -23,7 +23,7 @@ type GoodsOrder struct { TotalShopMoney int64 `json:"totalShopMoney"` // 应结金额-第三方平台结算给京西的金额(包括了所有的补贴,扣除) PmSubsidyMoney int64 `json:"pmSubsidyMoney"` // 平台活动补贴(订单主体活动补贴+订单单条sku补贴)1+ DistanceFreightMoney int64 `json:"distanceFreightMoney"` // 商户承担的远距离配送费(当前只有京东到家有值) - WaybillTipMoney int64 `json:"waybillTipMoney"` // 平台配送小费 + WaybillTipMoney int64 `json:"waybillTipMoney"` // 京西加的平台配送小费 EarningPrice int64 `json:"earningPrice"` // 结算给门店老板的钱(未扣除可能的三方配送费) Weight int `json:"weight"` // 单位为克 ConsigneeName string `orm:"size(32)" json:"consigneeName"` diff --git a/business/partner/partner_order.go b/business/partner/partner_order.go index a7bb1f987..dae76ee03 100644 --- a/business/partner/partner_order.go +++ b/business/partner/partner_order.go @@ -49,7 +49,7 @@ type IPurchasePlatformOrderHandler interface { ConfirmReceivedReturnGoods(ctx *jxcontext.Context, order *model.AfsOrder) (err error) } -type IUpdateWaybillTip interface { - // 添加快递小费,这个不是递增的,最后一次操作会覆盖之前的设置,但只能增加,不能减少,且tipFee只能为100的倍数 - UpdateWaybillTip(ctx *jxcontext.Context, order *model.GoodsOrder, tipFee int64) (err error) +type IAddWaybillTip interface { + GetWaybillTip(ctx *jxcontext.Context, order *model.GoodsOrder) (tipFee int64, err error) + AddWaybillTip(ctx *jxcontext.Context, order *model.GoodsOrder, tipFee2Add int64) (err error) } diff --git a/business/partner/purchase/jd/order.go b/business/partner/purchase/jd/order.go index bc2a31016..28919bf05 100644 --- a/business/partner/purchase/jd/order.go +++ b/business/partner/purchase/jd/order.go @@ -52,7 +52,7 @@ func (c *PurchaseHandler) updateOrderFinancialInfo(orderID string) (err error) { if err == nil { if orderSettlement != nil { updateOrderBySettleMent(order, orderSettlement) - err = partner.CurOrderManager.UpdateOrderFields(order, []string{"WaybillTipMoney", "TotalShopMoney", "PmSubsidyMoney"}) + err = partner.CurOrderManager.UpdateOrderFields(order, []string{ /*"WaybillTipMoney", */ "TotalShopMoney", "PmSubsidyMoney"}) } } return err @@ -95,7 +95,7 @@ func (c *PurchaseHandler) onOrderMsg(msg *jdapi.CallbackOrderMsg) (retVal *jdapi func updateOrderBySettleMent(order *model.GoodsOrder, orderSettlement *jdapi.OrderSettlementInfo) { if orderSettlement != nil { - order.WaybillTipMoney = orderSettlement.VenderPaidTips + // order.WaybillTipMoney = orderSettlement.VenderPaidTips order.TotalShopMoney = orderSettlement.SettlementAmount order.PmSubsidyMoney = orderSettlement.PlatOrderGoodsDiscountMoney + orderSettlement.PlatSkuGoodsDiscountMoney } @@ -456,3 +456,18 @@ func (c *PurchaseHandler) UpdateWaybillTip(ctx *jxcontext.Context, order *model. } return err } + +func (c *PurchaseHandler) GetWaybillTip(ctx *jxcontext.Context, order *model.GoodsOrder) (tipFee int64, err error) { + orderInfo, err := api.JdAPI.QuerySingleOrder2(order.VendorOrderID) + if err == nil { + tipFee = int64(orderInfo.Tips) + } + return tipFee, err +} + +func (c *PurchaseHandler) AddWaybillTip(ctx *jxcontext.Context, order *model.GoodsOrder, tipFee2Add int64) (err error) { + if globals.EnableJdStoreWrite { + err = api.JdAPI.OrderAddTips(order.VendorOrderID, int(tipFee2Add), ctx.GetUserName()) + } + return err +} From 76d18173481e13b7aa04b55e7768575b561a2aef Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 1 Aug 2019 19:51:40 +0800 Subject: [PATCH 3/6] =?UTF-8?q?-=20=E5=8A=A0=E5=B0=8F=E8=B4=B9=E7=AD=96?= =?UTF-8?q?=E7=95=A5=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxcallback/scheduler/defsch/defsch.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/business/jxcallback/scheduler/defsch/defsch.go b/business/jxcallback/scheduler/defsch/defsch.go index 759ddecd5..6cd79d984 100644 --- a/business/jxcallback/scheduler/defsch/defsch.go +++ b/business/jxcallback/scheduler/defsch/defsch.go @@ -46,8 +46,9 @@ const ( time2Schedule3rdCarrierKey = "waitminute4mt" dingShiDaAheadTime = 30 * time.Minute // 定时达订单开始召唤配送的提前时间 - minAddWaybillTipMinute = 15 // 最少开始加小费分钟(距离拣货完成) - addWaybillTipGap = 10 // 加一元小费间隔的分钟数 + minAddWaybillTipMinute = 20 // 最少开始加小费分钟(距离拣货完成) + addWaybillTipGap = 15 // 加一元小费间隔的分钟数 + baseWaybillFee = 600 // 基本运费 ) const ( @@ -1017,7 +1018,7 @@ func (s *DefScheduler) getWaybillTip(savedOrderInfo *WatchOrderInfo) (tipFee int } func (s *DefScheduler) getMaxDeliveryFee(savedOrderInfo *WatchOrderInfo) (maxDeliveryFee int64) { - maxDeliveryFee = 400 + savedOrderInfo.order.DistanceFreightMoney + s.getWaybillTip(savedOrderInfo) + maxDeliveryFee = baseWaybillFee + savedOrderInfo.order.DistanceFreightMoney + s.getWaybillTip(savedOrderInfo) return maxDeliveryFee } From 402e60ab50eb5e8da1efdc72271ecf79c119a3e2 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 1 Aug 2019 20:07:39 +0800 Subject: [PATCH 4/6] =?UTF-8?q?-=20=E6=95=B4=E7=90=86tasksch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxutils/tasksch/parallel_task.go | 21 ++++++++++----------- business/jxutils/tasksch/sequence_task.go | 15 +++++++++------ business/jxutils/tasksch/task.go | 4 ++-- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/business/jxutils/tasksch/parallel_task.go b/business/jxutils/tasksch/parallel_task.go index bc59b1a5e..067176391 100644 --- a/business/jxutils/tasksch/parallel_task.go +++ b/business/jxutils/tasksch/parallel_task.go @@ -118,19 +118,18 @@ func (task *ParallelTask) Run() { }) // globals.SugarLogger.Debugf("ParallelTask.Run %s, after call worker result:%v, err:%v", task.Name, result, err) task.finishedOneJob(len(job), err) - if err == nil { - if result != nil { - retVal = append(retVal, utils.Interface2Slice(result)...) - } - } else { - globals.SugarLogger.Infof("ParallelTask.Run %s, subtask(job:%s, params:%s) result:%v, failed with error:%v", task.Name, utils.Format4Output(job, true), utils.Format4Output(task.params, true), result, err) - task.locker.Lock() - task.batchErrList = append(task.batchErrList, err) - task.locker.Unlock() - if !task.IsContinueWhenError { // 出错 + if err != nil { // 出错 + // globals.SugarLogger.Infof("ParallelTask.Run %s, subtask(job:%s, params:%s) result:%v, failed with error:%v", task.Name, utils.Format4Output(job, true), utils.Format4Output(task.params, true), result, err) + if task.IsContinueWhenError { + task.locker.Lock() + task.batchErrList = append(task.batchErrList, err) + task.locker.Unlock() + } else { chanRetVal = err goto end } + } else if result != nil { + retVal = append(retVal, utils.Interface2Slice(result)...) } } } @@ -165,6 +164,7 @@ func (task *ParallelTask) Run() { taskResult = append(taskResult, resultList...) } } + task.locker.Lock() task.Result = taskResult task.mainErr = taskErr @@ -172,7 +172,6 @@ func (task *ParallelTask) Run() { close(task.subFinishChan) task.jobList = nil // 如果不释放,任务被管理的话,会导致内存不能释放 - }) } diff --git a/business/jxutils/tasksch/sequence_task.go b/business/jxutils/tasksch/sequence_task.go index 6c25b26d5..f606d8ffe 100644 --- a/business/jxutils/tasksch/sequence_task.go +++ b/business/jxutils/tasksch/sequence_task.go @@ -41,12 +41,14 @@ func (task *SeqTask) Run() { return task.worker(task, i, task.params...) }) task.finishedOneJob(1, err) - if taskErr = err; taskErr != nil { - task.locker.Lock() - task.batchErrList = append(task.batchErrList, err) - task.locker.Unlock() - globals.SugarLogger.Infof("SeqTask.Run %s step:%d failed with error:%v", task.Name, i, err) - if !task.IsContinueWhenError { + if err != nil { + // globals.SugarLogger.Infof("SeqTask.Run %s step:%d failed with error:%v", task.Name, i, err) + if task.IsContinueWhenError { + task.locker.Lock() + task.batchErrList = append(task.batchErrList, err) + task.locker.Unlock() + } else { + taskErr = err break } } else if result != nil { @@ -54,6 +56,7 @@ func (task *SeqTask) Run() { } } EndFor: + task.locker.Lock() task.Result = taskResult task.mainErr = taskErr diff --git a/business/jxutils/tasksch/task.go b/business/jxutils/tasksch/task.go index 8363ab9d5..80070a1fc 100644 --- a/business/jxutils/tasksch/task.go +++ b/business/jxutils/tasksch/task.go @@ -311,7 +311,7 @@ func (t *BaseTask) GetLeafResult() (finishedItemCount, failedItemCount int) { } func (t *BaseTask) Error() (errMsg string) { - if t.mainErr == nil && len(t.batchErrList) == 0 { + if t.GetErr() == nil { return "" } t.locker.RLock() @@ -397,7 +397,7 @@ func (t *BaseTask) run(taskHandler func()) { task.locker.Unlock() task.Error() - globals.SugarLogger.Debugf("Task:%s, result:%v, err:%v", task.Name, task.Result, task.mainErr) + globals.SugarLogger.Debugf("Task:%s, mainErr:%v, batchErrList:%v", task.Name, task.mainErr, task.batchErrList) select { case <-t.quitChan: From 8af8c4e0e2058a2070c4cff49488b3ea5822b764 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 1 Aug 2019 20:11:07 +0800 Subject: [PATCH 5/6] =?UTF-8?q?-=20=E5=8E=BB=E6=8E=89ebai.market=5Fprice?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/partner/purchase/ebai/store_sku.go | 1 - business/partner/purchase/ebai/store_sku2.go | 1 - 2 files changed, 2 deletions(-) diff --git a/business/partner/purchase/ebai/store_sku.go b/business/partner/purchase/ebai/store_sku.go index 4c4ded994..046f18120 100644 --- a/business/partner/purchase/ebai/store_sku.go +++ b/business/partner/purchase/ebai/store_sku.go @@ -373,7 +373,6 @@ func genSkuParamsFromStoreSkuInfo(pricePercentage int, storeSku *tStoreSkuFullIn } if storeSku.EbaiSyncStatus&(model.SyncFlagPriceMask|model.SyncFlagNewMask) != 0 { params["sale_price"] = price - params["market_price"] = price } if storeSku.EbaiSyncStatus&(model.SyncFlagSaleMask|model.SyncFlagNewMask) != 0 { params["status"] = jxSkuStatus2Ebai(jxutils.MergeSkuStatus(storeSku.SkuStatus, storeSku.Status)) diff --git a/business/partner/purchase/ebai/store_sku2.go b/business/partner/purchase/ebai/store_sku2.go index a7e8d3ddf..fe1d989e3 100644 --- a/business/partner/purchase/ebai/store_sku2.go +++ b/business/partner/purchase/ebai/store_sku2.go @@ -244,7 +244,6 @@ func genSkuParamsFromStoreSkuInfo2(storeSku *dao.StoreSkuSyncInfo) (params map[s } if storeSku.StoreSkuSyncStatus&(model.SyncFlagPriceMask|model.SyncFlagNewMask) != 0 { params["sale_price"] = storeSku.VendorPrice - params["market_price"] = storeSku.VendorPrice } if storeSku.StoreSkuSyncStatus&(model.SyncFlagSaleMask|model.SyncFlagNewMask) != 0 { params["status"] = jxSkuStatus2Ebai(storeSku.MergedStatus) From a5f4f054b236a6c05bc6f617041ceb0ccba94515 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 1 Aug 2019 20:12:33 +0800 Subject: [PATCH 6/6] + purchase/jd/store_sku2_test.go --- .../partner/purchase/jd/store_sku2_test.go | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 business/partner/purchase/jd/store_sku2_test.go diff --git a/business/partner/purchase/jd/store_sku2_test.go b/business/partner/purchase/jd/store_sku2_test.go new file mode 100644 index 000000000..d854873ff --- /dev/null +++ b/business/partner/purchase/jd/store_sku2_test.go @@ -0,0 +1,33 @@ +package jd + +import ( + "testing" + + "git.rosy.net.cn/jx-callback/business/partner/putils" + + "git.rosy.net.cn/baseapi/utils" + "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" +) + +func TestGetStoreSkusBareInfo(t *testing.T) { + // list := []*partner.StoreSkuInfo{ + // &partner.StoreSkuInfo{ + // SkuID: 5246, + // VendorSkuID: "2023747677", + // }, + // } + // for i := 0; i < 3000; i++ { + // list = append(list, list[0]) + // } + skuNameList, err := curPurchaseHandler.GetSkus(jxcontext.AdminCtx, 0, "", "") + if err != nil { + t.Fatal(err) + } + list := putils.StoreSkuFullList2Bare(skuNameList) + storeSkuList, err := curPurchaseHandler.GetStoreSkusBareInfo(jxcontext.AdminCtx, nil, 2, "11053496", list) + if err != nil { + t.Fatal(err.Error()) + } + t.Log(utils.Format4Output(storeSkuList, false)) + t.Log(len(storeSkuList)) +}