diff --git a/business/jxcallback/auto_delivery/auto_delivery.go b/business/jxcallback/auto_delivery/auto_delivery.go index 02df8318c..424a6bccb 100644 --- a/business/jxcallback/auto_delivery/auto_delivery.go +++ b/business/jxcallback/auto_delivery/auto_delivery.go @@ -129,7 +129,6 @@ func AutoSettingFakeDelivery() { return } } - globals.SugarLogger.Debugf("===============riderListInfo= : %s", riderKey) randNumber, _ := rand.Int(rand.Reader, big.NewInt(int64(len(riderListInfo[riderKey])))) randTime := randNumber.Int64() if randTime < 0 { diff --git a/business/jxcallback/orderman/orderman_ext.go b/business/jxcallback/orderman/orderman_ext.go index cb5a9aa2f..18a815801 100644 --- a/business/jxcallback/orderman/orderman_ext.go +++ b/business/jxcallback/orderman/orderman_ext.go @@ -173,7 +173,7 @@ func (c *OrderManager) GetOrderInfo(ctx *jxcontext.Context, vendorOrderID string ` } sql += ` - t1.*, t2.status waybill_status, t2.courier_name, t2.courier_mobile, t2.desired_fee, + t1.*, t2.status waybill_status, t2.courier_name, t2.courier_mobile, t2.desired_fee,t2.punctual_fee, CAST(t1.consignee_lng AS DECIMAL(15,6))/1000000 float_lng, CAST(t1.consignee_lat AS DECIMAL(15,6))/1000000 float_lat, ts.brand_id diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index e8665dabb..12e8ac500 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -5898,7 +5898,7 @@ func doStoreSkuAudit(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*Sto return false, err } - if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini && ctx.GetLoginType() != weixin.AuthTypeWxApp && ctx.GetLoginType() != weixin.AuthTypeWxAppCaishi && ctx.GetLoginType() != auth2.AuthTypeMobile && ctx.GetLoginType() != auth2.AuthTypePassword { + if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini && ctx.GetLoginType() != weixin.AuthTypeWxApp && ctx.GetLoginType() != weixin.AuthTypeWxAppCaishi && ctx.GetLoginType() != auth2.AuthTypeMobile { authInfo, err := ctx.GetV2AuthInfo() if err == nil && authInfo != nil && (ctx.GetFullUser().Type&model.UserTypeOperator) != 0 { if len(storeAudits) > 0 { diff --git a/business/jxstore/misc/misc.go b/business/jxstore/misc/misc.go index d9131d22b..1ce45fbc0 100644 --- a/business/jxstore/misc/misc.go +++ b/business/jxstore/misc/misc.go @@ -220,6 +220,13 @@ func Init() { "04:00:00", }) + // 每天更新美团门当的结算信息和配送费等等 + ScheduleTimerFunc("LoadingStoreOrderSettleAmount", func() { + // delivery.LoadingStoreOrderSettleAmount(0, 0, nil) + }, []string{ + "04:50:00", + }) + // 定时任务更新昨天的都要商品和本地商品id的映射关系 //ScheduleTimerFunc("RefreshStoreOperator", func() { // t := time.Now() diff --git a/business/model/api.go b/business/model/api.go index ac163d118..50ecaeb4d 100644 --- a/business/model/api.go +++ b/business/model/api.go @@ -30,8 +30,9 @@ type GoodsOrderExt struct { CourierVendorName string `json:"courierVendorName"` Status2 string `json:"status2"` - ActualFee int64 `json:"actualFee"` // 实际要支付给快递公司的费用 - DesiredFee int64 `json:"desiredFee"` // 运单总费用 + ActualFee int64 `json:"actualFee"` // 实际要支付给快递公司的费用 + DesiredFee int64 `json:"desiredFee"` // 运单总费用 + PunctualFee int64 `json:"punctualFee"` // 订单保险费 WaybillCreatedAt time.Time `orm:"type(datetime);index" json:"waybillCreatedAt"` WaybillFinishedAt time.Time `orm:"type(datetime)" json:"waybillFinishedAt"` VendorWaybillId2Waybill string `orm:"column(vendor_waybill_id2);size(48)" json:"vendorWaybillId2Waybill"` // 某些平台有多个ID,比如美团配送,当前美团配送的 delivery_id存这里 diff --git a/business/model/dao/dao_order.go b/business/model/dao/dao_order.go index e056158e1..749211ec9 100644 --- a/business/model/dao/dao_order.go +++ b/business/model/dao/dao_order.go @@ -897,7 +897,7 @@ func GetOrders(db *DaoDB, ids []int64, isIncludeSku, isIncludeFake bool, fromDat DISTINCT t1.*, -- CAST(IF(t1.earning_price <> 0, t1.earning_price, IF(t1.shop_price <> 0 && t1.shop_price < t1.sale_price, t1.shop_price, t1.sale_price) * IF(t1.order_pay_percentage > 0, t1.order_pay_percentage, %d) / 100) AS SIGNED) earning_price, t2.status waybill_status, t2.courier_name, t2.courier_mobile, - t2.actual_fee, t2.desired_fee, t2.waybill_created_at, t2.waybill_finished_at, t2.vendor_waybill_id2 vendor_waybill_id2_waybill, + t2.actual_fee, t2.desired_fee,t2.punctual_fee, t2.waybill_created_at, t2.waybill_finished_at, t2.vendor_waybill_id2 vendor_waybill_id2_waybill, t5.pay_percentage, t5.comment ,t5.old_pay_percentage, t5.market_man_phone, tu.name market_man_name, t5.operator_phone, t5.operator_phone2, t5.operator_phone3, tu1.name operator_name, tu2.name operator_name2, tu3.name operator_name3, t6.vendor_pay_percentage, diff --git a/business/model/order.go b/business/model/order.go index acf5b7e22..2ec5a648c 100644 --- a/business/model/order.go +++ b/business/model/order.go @@ -243,9 +243,9 @@ type Waybill struct { StatusTime time.Time `orm:"type(datetime)" json:"-"` // last status time ModelTimeInfo `json:"-"` OriginalData string `orm:"type(text)" json:"-"` - Remark string `orm:"-" json:"-"` // 用于传递remark - //PunctualFee int64 `orm:"column(punctual_fee)" json:"punctualFee"` // 对应美团外卖运单的准时保险费 - VendorOrgCode string `orm:"size(64)" json:"vendorOrgCode"` // 同一平台下不同的商户代码,如果只有一个,可以为空 + Remark string `orm:"-" json:"-"` // 用于传递remark + PunctualFee int64 `orm:"column(punctual_fee)" json:"punctualFee"` // 对应美团外卖运单的准时保险费 + VendorOrgCode string `orm:"size(64)" json:"vendorOrgCode"` // 同一平台下不同的商户代码,如果只有一个,可以为空 } func (w *Waybill) TableUnique() [][]string { diff --git a/business/partner/delivery/rider.go b/business/partner/delivery/rider.go index 3564f6139..fbebed0d2 100644 --- a/business/partner/delivery/rider.go +++ b/business/partner/delivery/rider.go @@ -3,6 +3,11 @@ package delivery import ( "crypto/rand" "fmt" + "git.rosy.net.cn/baseapi" + "git.rosy.net.cn/baseapi/platformapi/mtwmapi" + "git.rosy.net.cn/jx-callback/business/jxutils/jxcontext" + "git.rosy.net.cn/jx-callback/business/jxutils/tasksch" + "git.rosy.net.cn/jx-callback/business/partner/purchase/mtwm" "math/big" "time" @@ -35,7 +40,7 @@ func GetOrderRiderInfoToPlatform(orderId string, wayBillStatus int) { params["isIncludeFake"] = true params["mustInvoice"] = false params["adjustCount"] = 0 - params["waybillVendorIDs"] = `[101,102,103,105]` + //params["waybillVendorIDs"] = `[101,102,103,105]` if orderId != "" { // 订单id会忽略其他参数 params["keyword"] = orderId } else { @@ -84,9 +89,14 @@ func GetOrderRiderInfoToPlatform(orderId string, wayBillStatus int) { if riderInfo == nil || wayBillStatus == model.OrderStatusNew || wayBillStatus == model.OrderStatusCanceled || (riderInfo.CourierName == "" && v.WaybillVendorID == -1 && v.DeliveryType == "store") { // 真商家自送 riderInfo.OrderId = v.VendorOrderID - riderInfo.CourierName = "石锋" + riderInfo.CourierName = "门店老板" riderInfo.CourierPhone = "18048531223" riderInfo.LogisticsProviderCode = "10017" + riderInfo.LogisticsStatus = v.Status + storeDetail, err := dao.GetStoreDetail(dao.GetDB(), v.JxStoreID, 0, "") + if err != nil { + riderInfo.CourierPhone = storeDetail.Tel1 + } } switch riderInfo.LogisticsStatus { @@ -208,7 +218,7 @@ func PullTiktokRiderInfo(riderInfo *mtpsapi.RiderInfo) { } } -//将以过期订单状态为配送中的订单修改为完成状态 +// UpdateOrder2Complete 将以过期订单状态为配送中的订单修改为完成状态 func UpdateOrder2Complete() { sql := `UPDATE goods_order g SET g.status=110 WHERE g.status=20 AND g.order_created_at < ?` sqlParams := []interface{}{ @@ -352,3 +362,66 @@ func UpdateFakeWayBillToTiktok() { } } + +// LoadingStoreOrderSettleAmount 获取平台门店的结算信息(订单的配送费和准时保险费) +func LoadingStoreOrderSettleAmount(startTime, endTime int64, jxStoreId []int) error { + var ( + db = dao.GetDB() + now = time.Now() + from = time.Date(now.Year(), now.Month(), now.Day()-2, 0, 0, 0, 0, time.Local).Unix() + to = time.Date(now.Year(), now.Month(), now.Day()-1, 23, 59, 59, 59, time.Local).Unix() + ) + + if startTime != 0 && endTime != 0 { + from = startTime + to = endTime + } + storeMapList, err := dao.GetStoresMapList(db, []int{model.VendorIDMTWM}, jxStoreId, []int{model.StoreStatusClosed, model.StoreStatusHaveRest, model.StoreStatusOpened}, model.StoreStatusAll, 0, "", "", "") + if err != nil || len(storeMapList) == model.NO { + globals.SugarLogger.Errorf("获取美团门店列表异常: %v", err) + return err + } + + taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { + storeListValue := batchItemList[0].([]*model.StoreMap) + for _, v := range storeListValue { + storeOrder, err := mtwm.GetAPI(v.VendorOrgCode, v.StoreID, v.VendorStoreID).GetStoreBillList(&mtwmapi.Bill{ + AppPoiCode: v.VendorStoreID, + StartDate: from, + EndDate: to, + Offset: 0, + Limit: 200, + }) + if err != nil { + return nil, err + } + + for _, so := range storeOrder { + // 更新订单的结算信息 + if so.PlatformSettlement > 0 { + goodsOrderSql := `UPDATE goods_order g SET g.total_shop_money = ? WHERE g.vendor_order_id = ? ` + if _, err := dao.ExecuteSQL(db, goodsOrderSql, []interface{}{so.PlatformSettlement + so.TimingFee + so.DeliveryFee, so.OrderId}...); err != nil { + globals.SugarLogger.Debugf("更新订单结算信息错误: %v", err) + } + } + // 更新订单的配送信息 + if so.TimingFee != 0 || so.DeliveryFee != 0 { + wayBillSql := `UPDATE waybill w SET w.desired_fee = ?,w.punctual_fee = ? WHERE g.vendor_order_id = ? AND g.vendor_waybill_id = ? ` + if _, err := dao.ExecuteSQL(db, wayBillSql, []interface{}{so.DeliveryFee * -1, so.TimingFee * -1, so.OrderId, so.OrderId}...); err != nil { + globals.SugarLogger.Debugf("更新订单物流结算信息错误: %v", err) + } + } + + } + + } + return retVal, err + } + task := tasksch.NewParallelTask("更新美团订单配送费/保险费/结算信息", tasksch.NewParallelConfig().SetParallelCount(4), jxcontext.AdminCtx, taskFunc, storeMapList) + tasksch.HandleTask(task, nil, true).Run() + if _, err = task.GetResult(0); err != nil { + baseapi.SugarLogger.Debugf("LoadingStoreOrderSettleAmount :%v", err) + return err + } + return nil +} diff --git a/controllers/jx_order.go b/controllers/jx_order.go index f5fad4a41..2549f1536 100644 --- a/controllers/jx_order.go +++ b/controllers/jx_order.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "git.rosy.net.cn/jx-callback/business/bidding" + "git.rosy.net.cn/jx-callback/business/partner/delivery" "strings" "time" @@ -1352,3 +1353,19 @@ func (c *OrderController) ExportOrderWithSku() { return retVal, "", err }) } + +// @Title 更新美团订单结算信息 +// @Description 更新美团订单结算信息 +// @Param token header string true "认证token" +// @Param startTime formData int64 true "开始时间" +// @Param endTime formData int64 true "结束时间" +// @Param storeId formData int true "京西门店id" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /UpdateMTOrderSettle [post] +func (c *OrderController) UpdateMTOrderSettle() { + c.callUpdateMTOrderSettle(func(params *tOrderUpdateMTOrderSettleParams) (interface{}, string, error) { + err := delivery.LoadingStoreOrderSettleAmount(int64(params.StartTime), int64(params.EndTime), []int{params.StoreId}) + return nil, "", err + }) +} diff --git a/routers/commentsRouter_controllers.go b/routers/commentsRouter_controllers.go index 6e2ea4650..8be0ac30c 100644 --- a/routers/commentsRouter_controllers.go +++ b/routers/commentsRouter_controllers.go @@ -1556,6 +1556,16 @@ func init() { Filters: nil, Params: nil}) + // 更新指定时间的订单结算费用(美团) + web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"] = append(web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"], + web.ControllerComments{ + Method: "UpdateMTOrderSettle", + Router: `/UpdateMTOrderSettle`, + AllowHTTPMethods: []string{"post"}, + MethodParams: param.Make(), + Filters: nil, + Params: nil}) + web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"] = append(web.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:OrderController"], web.ControllerComments{ Method: "ExportOrderWithSku",