diff --git a/business/jxcallback/orderman/order.go b/business/jxcallback/orderman/order.go index 0aecd9ba0..b38108f1a 100644 --- a/business/jxcallback/orderman/order.go +++ b/business/jxcallback/orderman/order.go @@ -173,6 +173,22 @@ func (c *OrderManager) OnOrderStatusChanged(vendorOrgCode string, orderStatus *m } } } + } else if orderStatus.Status == model.OrderStatusFinished { + if order, err2 := c.LoadOrder(orderStatus.VendorOrderID, orderStatus.VendorID); err2 == nil { + // 当前只针对三方运单更新配送费信息 + if order.WaybillVendorID >= 0 && order.VendorWaybillID != "" && order.WaybillVendorID != order.VendorID { + if waybill, err2 := c.LoadWaybill(order.VendorWaybillID, order.WaybillVendorID); err2 == nil { + if handler := partner.GetWaybillTipUpdater(waybill.WaybillVendorID); handler != nil { + tipFee, err2 := handler.GetWaybillTip(jxcontext.AdminCtx, waybill.VendorOrgCode, "", order.VendorOrderID, waybill.VendorWaybillID, waybill.VendorWaybillID2) + if err2 == nil && waybill.TipFee != tipFee { + waybill.ActualFee += tipFee - waybill.TipFee + waybill.TipFee = tipFee + dao.UpdateEntity(db, waybill, "TipFee", "ActualFee") + } + } + } + } + } } if !isDuplicated { if order != nil { diff --git a/business/jxcallback/orderman/waybill.go b/business/jxcallback/orderman/waybill.go index ae4831c20..43b93b567 100644 --- a/business/jxcallback/orderman/waybill.go +++ b/business/jxcallback/orderman/waybill.go @@ -102,6 +102,9 @@ func (w *OrderManager) onWaybillNew(bill2 *model.Waybill, db *dao.DaoDB) (isDupl func (w *OrderManager) OnWaybillStatusChanged(bill *model.Waybill) (err error) { var isDuplicated bool + if bill.ActualFee == 0 { + bill.ActualFee = bill.DesiredFee + bill.TipFee + } bill.CourierMobile = jxutils.FormalizeMobile(bill.CourierMobile) db := dao.GetDB() dao.Begin(db) diff --git a/business/jxstore/act/act.go b/business/jxstore/act/act.go index f53fc1247..a1ca25b47 100644 --- a/business/jxstore/act/act.go +++ b/business/jxstore/act/act.go @@ -320,8 +320,12 @@ func checkDiscountValidation(vendorIDs []int, actType int, pricePercentage float } else if len(vendorIDs) > 0 && vendorIDs[0] == model.VendorIDMTWM && pricePercentageMin < minDiscount4SkuDirectDownMTWM { err = fmt.Errorf("美团平台%s活动折扣必须大于:%d", model.ActTypeName[actType], minDiscount4SkuDirectDownMTWM) } - } else if actType == model.ActSkuSecKill && pricePercentageMax > maxDiscount4SkuSecKill { - err = fmt.Errorf("%s活动折扣必须小于:%d", model.ActTypeName[actType], maxDiscount4SkuSecKill) + } else if actType == model.ActSkuSecKill { + if len(vendorIDs) > 0 && vendorIDs[0] == model.VendorIDMTWM && pricePercentageMax > minDiscount4SkuDirectDownMTWM { + err = fmt.Errorf("美团平台%s活动折扣必须小于:%d", model.ActTypeName[actType], minDiscount4SkuDirectDownMTWM) + } else if pricePercentageMax > maxDiscount4SkuSecKill { + err = fmt.Errorf("%s活动折扣必须小于:%d", model.ActTypeName[actType], maxDiscount4SkuSecKill) + } } return err } @@ -343,8 +347,6 @@ func checkActValidation(act *model.Act, vendorIDs []int) (err error) { errList.AddErr(fmt.Errorf("必须指定缺省活动折扣")) } else if err = checkDiscountValidation(vendorIDs, act.Type, float64(act.PricePercentage)); err != nil { errList.AddErr(err) - } else if act.Type == model.ActSkuSecKill && vendorIDMap[model.VendorIDMTWM] == 1 { - errList.AddErr(fmt.Errorf("%s平台不支持%s活动", model.VendorChineseNames[model.VendorIDMTWM], model.ActTypeName[model.ActSkuSecKill])) } } else if act.Type == model.ActSkuFake { diff --git a/business/jxstore/cms/sync2.go b/business/jxstore/cms/sync2.go index e18979671..03a7fc223 100644 --- a/business/jxstore/cms/sync2.go +++ b/business/jxstore/cms/sync2.go @@ -42,7 +42,7 @@ func getMultiStoreVendorInfoList() (list []*MultiStoreVendorInfo) { func syncCategories(ctx *jxcontext.Context, db *dao.DaoDB, parentTask tasksch.ITask, catList []*dao.SkuStoreCatInfo, isAsync bool) (hint string, err error) { if len(catList) > 0 { // todo 按vendorID orgCode合并操作 - task := tasksch.NewParallelTask(fmt.Sprintf("同步分类2:%D", len(catList)), tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, + task := tasksch.NewParallelTask(fmt.Sprintf("同步分类2:%d", len(catList)), tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { catVendorInfo := batchItemList[0].(*dao.SkuStoreCatInfo) if catVendorInfo.Level != 1 && catVendorInfo.ParentVendorCatID == "" { diff --git a/business/jxstore/cms/sync_store_sku_test.go b/business/jxstore/cms/sync_store_sku_test.go index 0df67e1a0..23c8cbd6d 100644 --- a/business/jxstore/cms/sync_store_sku_test.go +++ b/business/jxstore/cms/sync_store_sku_test.go @@ -33,7 +33,7 @@ func TestFreeBatchStoreSkuInfo(t *testing.T) { } func TestGetTimeMixByInt(t *testing.T) { - var ( + const ( time1 = 1100 time2 = 2300 time3 = 1200 diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index 8236638f0..8f1b302cf 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -117,7 +117,7 @@ func Init() { }, 5*time.Second, 1*time.Hour) ScheduleTimerFuncByInterval(func() { - defsch.FixedScheduler.ConfirmSelfTakeOrders(jxcontext.AdminCtx, nil, time.Now().Add(-48*time.Hour), time.Now().Add(-30*time.Minute), true, true) + defsch.FixedScheduler.ConfirmSelfTakeOrders(jxcontext.AdminCtx, []int{model.VendorIDJD}, time.Now().Add(-48*time.Hour), time.Now().Add(-30*time.Minute), true, true) }, 5*time.Second, 10*time.Minute) ScheduleTimerFunc("auto enable remote store", func() { diff --git a/business/model/order.go b/business/model/order.go index ad64422f4..4010a25af 100644 --- a/business/model/order.go +++ b/business/model/order.go @@ -173,6 +173,7 @@ type Waybill struct { VendorStatus string `orm:"size(255)" json:"-"` ActualFee int64 `json:"actualFee"` // 实际要支付给快递公司的费用 DesiredFee int64 `json:"desiredFee"` // 运单总费用 + TipFee int64 `json:"tipFee"` // 运单小费,不含在上两项中 DuplicatedCount int `json:"-"` // 重复新订单消息数,这个一般不是由于消息重发造成的(消息重发由OrderStatus过滤),一般是业务逻辑造成的 DeliveryFlag int8 `json:"deliveryFlag"` WaybillCreatedAt time.Time `orm:"type(datetime);index" json:"waybillCreatedAt"` diff --git a/business/partner/purchase/elm/order.go b/business/partner/purchase/elm/order.go index 41f2130a5..4d94b4600 100644 --- a/business/partner/purchase/elm/order.go +++ b/business/partner/purchase/elm/order.go @@ -120,7 +120,7 @@ func (c *PurchaseHandler) onOrderCancelRefundMsg(msg *elmapi.CallbackOrderCancel default: status.Status = model.OrderStatusUnknown } - return elmapi.Err2CallbackResponse(partner.CurOrderManager.OnOrderStatusChanged(status), status.VendorStatus) + return elmapi.Err2CallbackResponse(partner.CurOrderManager.OnOrderStatusChanged("", status), status.VendorStatus) } func (c *PurchaseHandler) GetOrder(vendorOrgCode, orderID string) (order *model.GoodsOrder, err error) { @@ -223,7 +223,7 @@ func (c *PurchaseHandler) onOrderUserUrgeOrder(msg *elmapi.CallbackOrderUrgeMsg) StatusTime: utils.Timestamp2Time(msg.UpdateTime), } c.ClientUrgeOrder(msg.OrderID) - return elmapi.Err2CallbackResponse(partner.CurOrderManager.OnOrderStatusChanged(status), status.VendorStatus) + return elmapi.Err2CallbackResponse(partner.CurOrderManager.OnOrderStatusChanged("", status), status.VendorStatus) } func (c *PurchaseHandler) stateAndType2Str(state string, msgType int) string { diff --git a/business/partner/purchase/mtwm/act.go b/business/partner/purchase/mtwm/act.go index 91f244458..4571a5b4b 100644 --- a/business/partner/purchase/mtwm/act.go +++ b/business/partner/purchase/mtwm/act.go @@ -13,6 +13,17 @@ import ( "git.rosy.net.cn/jx-callback/globals/api" ) +func jxActType2Mtwm(actType int) int { + if actType == model.ActSkuDirectDown { + actType = mtwmapi.RetailActTypeDirectDown + } else if actType == model.ActSkuSecKill { + actType = mtwmapi.RetailActTypeSecKill + } else { + actType = 0 + } + return actType +} + func actOrderRules2Mtwm(actOrderRules []*model.ActOrderRule) (actDetails []*mtwmapi.FullDiscountActDetail) { for _, v := range actOrderRules { actDetails = append(actDetails, &mtwmapi.FullDiscountActDetail{ @@ -73,7 +84,7 @@ func createOneShopAct(act *model.Act2, vendorStoreID string, actStoreSku []*mode actData := storeSku2ActData(act, actStoreSku, isCreateOrUpdate) if len(actData) > 0 { if globals.EnableMtwmStoreWrite { - actResult, err2 := api.MtwmAPI.RetailDiscountBatchSave(vendorStoreID, actData) + actResult, err2 := api.MtwmAPI.RetailDiscountBatchSave(vendorStoreID, jxActType2Mtwm(act.Type), actData) globals.SugarLogger.Debugf("mtwm createOneShopAct err2:%v", err2) if err = err2; err != nil { return err @@ -96,10 +107,10 @@ func createOneShopAct(act *model.Act2, vendorStoreID string, actStoreSku []*mode return err } -func cancelOneShopAct(ctx *jxcontext.Context, actStoreSku []*model.ActStoreSku2) (err error) { +func cancelOneShopAct(ctx *jxcontext.Context, act *model.Act2, actStoreSku []*model.ActStoreSku2) (err error) { if list := storeSku2ActData4Delete(actStoreSku, nil /*model.IsSyncStatusNeedDelete*/); len(list) > 0 { if globals.EnableMtwmStoreWrite { - err = api.MtwmAPI.RetailDiscountDelete(actStoreSku[0].VendorStoreID, list) + err = api.MtwmAPI.RetailDiscountDelete(actStoreSku[0].VendorStoreID, jxActType2Mtwm(act.Type), list) } } return err @@ -129,13 +140,13 @@ func createSkuAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.A return getActStoreSkuFromTaskResult(result), err } -func cancelSkuAct(ctx *jxcontext.Context, parentTask tasksch.ITask, actStoreSku []*model.ActStoreSku2) (canceledList []*model.ActStoreSku2, err error) { +func cancelSkuAct(ctx *jxcontext.Context, parentTask tasksch.ITask, act *model.Act2, actStoreSku []*model.ActStoreSku2) (canceledList []*model.ActStoreSku2, err error) { globals.SugarLogger.Debugf("mtwm cancelSkuAct") actStoreSkuListList := partner.SplitActStoreSku2List(actStoreSku) task := tasksch.NewParallelTask("mtwm cancelSkuAct", nil, ctx, func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { actStoreSkuList := batchItemList[0].([]*model.ActStoreSku2) - if err = cancelOneShopAct(ctx, actStoreSkuList); err == nil { + if err = cancelOneShopAct(ctx, act, actStoreSkuList); err == nil { retVal = []interface{}{actStoreSkuList} } return retVal, err @@ -162,7 +173,7 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa } err = func() (err error) { if model.IsSyncStatusDelete(act.SyncStatus) { - canceledList, err2 := cancelSkuAct(ctx, nil, actStoreSkuList) + canceledList, err2 := cancelSkuAct(ctx, nil, act, actStoreSkuList) updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, canceledList, model.SyncFlagModifiedMask)...) if err = err2; err == nil { updateItems = append(updateItems, partner.Act2Update(ctx, act, model.SyncFlagModifiedMask)) @@ -183,7 +194,7 @@ func (c *PurchaseHandler) SyncAct(ctx *jxcontext.Context, parentTask tasksch.ITa } } if len(actStoreSkuList4Delete) > 0 { - deletedList, err2 := cancelSkuAct(ctx, nil, actStoreSkuList4Delete) + deletedList, err2 := cancelSkuAct(ctx, nil, act, actStoreSkuList4Delete) updateItems = append(updateItems, partner.ActStoreSku2Update(ctx, deletedList, model.SyncFlagDeletedMask)...) if err = err2; err != nil { return err diff --git a/business/partner/purchase/mtwm/store_sku2.go b/business/partner/purchase/mtwm/store_sku2.go index 8ac6b50be..eff8ab3e0 100644 --- a/business/partner/purchase/mtwm/store_sku2.go +++ b/business/partner/purchase/mtwm/store_sku2.go @@ -413,7 +413,9 @@ func (p *PurchaseHandler) GetStoreSkusFullInfo(ctx *jxcontext.Context, parentTas if err != nil { return nil, err } - skuNameList = append(skuNameList, vendorSku2Jx(skuInfo)) + if skuName := vendorSku2Jx(skuInfo); skuName != nil { + skuNameList = append(skuNameList, skuName) + } } else { var storeSkuMap map[string]*partner.StoreSkuInfo if storeSkuList != nil { @@ -430,7 +432,9 @@ func (p *PurchaseHandler) GetStoreSkusFullInfo(ctx *jxcontext.Context, parentTas } else { for _, v := range result { if storeSkuMap[v.AppFoodCode] != nil { - skuNameList = append(skuNameList, vendorSku2Jx(v)) + if skuName := vendorSku2Jx(v); skuName != nil { + skuNameList = append(skuNameList, skuName) + } } } } @@ -443,6 +447,10 @@ func (p *PurchaseHandler) GetStoreSkusFullInfo(ctx *jxcontext.Context, parentTas } func vendorSku2Jx(appFood *mtwmapi.AppFood) (skuName *partner.SkuNameInfo) { + if len(appFood.SkuList) == 0 { + globals.SugarLogger.Warnf("vendorSku2Jx, strange appFood:%s", utils.Format4Output(appFood, true)) + return nil + } prefix, name, comment, specUnit, unit, specQuality := jxutils.SplitSkuName(appFood.Name) vendorSku := appFood.SkuList[0] weight := int(utils.Str2Int64WithDefault(vendorSku.Weight, 0)) @@ -488,7 +496,9 @@ func vendorSku2Jx(appFood *mtwmapi.AppFood) (skuName *partner.SkuNameInfo) { func vendorSkuList2Jx(appFoodList []*mtwmapi.AppFood) (skuNameList []*partner.SkuNameInfo) { for _, appFood := range appFoodList { - skuNameList = append(skuNameList, vendorSku2Jx(appFood)) + if skuName := vendorSku2Jx(appFood); skuName != nil { + skuNameList = append(skuNameList, skuName) + } } return skuNameList }