美团门店订单账单信息收集(配送费以及定时保险费)

This commit is contained in:
邹宗楠
2023-04-27 14:24:45 +08:00
parent 878e84252f
commit fd0585b963
10 changed files with 119 additions and 12 deletions

View File

@@ -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 {

View File

@@ -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

View File

@@ -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()

View File

@@ -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存这里

View File

@@ -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,

View File

@@ -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 {

View File

@@ -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
}