1
This commit is contained in:
@@ -450,6 +450,53 @@ func filterOrderInfo(order *model.GoodsOrder) {
|
||||
order.ConsigneeAddress = strings.ReplaceAll(order.ConsigneeAddress, "·", "")
|
||||
}
|
||||
|
||||
// FinisOrderWaybillFee 订单完成时,计算结算信息
|
||||
func FinisOrderWaybillFee(db *dao.DaoDB, order *model.GoodsOrder, bill *model.Waybill) (err error) {
|
||||
if db == nil {
|
||||
db = dao.GetDB()
|
||||
}
|
||||
if bill.WaybillVendorID != model.VendorIDMTPS && bill.WaybillVendorID != model.VendorIDDada && bill.WaybillVendorID != model.VendorIDFengNiao && bill.WaybillVendorID != model.VendorIDUUPT {
|
||||
return nil
|
||||
}
|
||||
// 查询所有运单
|
||||
bills, err := dao.GetWaybills(db, order.VendorOrderID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
store, _ := dao.GetStoreDetail(db, order.JxStoreID, order.VendorID, order.VendorOrgCode)
|
||||
// 正常来说只会出现一个完成运单,之前有bug会出现多个完成订单,这不做考虑.默认一个运单完成,其他运单取消状态
|
||||
// 1.完成当前运单的金额核算,正常完成的订单金额不需要核算
|
||||
// 2.取消运单的金额核算
|
||||
cancelWaybill := make(map[string]*model.Waybill, 0)
|
||||
for _, v := range bills {
|
||||
if v.Status != model.WaybillStatusCanceled {
|
||||
continue
|
||||
}
|
||||
if v.VendorWaybillID == bill.VendorWaybillID {
|
||||
continue
|
||||
}
|
||||
cancelWaybill[v.VendorWaybillID] = v
|
||||
}
|
||||
// 已经全部运单取消,退款结算
|
||||
for _, v := range bills {
|
||||
if v.VendorWaybillID == bill.VendorWaybillID {
|
||||
continue
|
||||
}
|
||||
// 已经取消订单的违约金计算
|
||||
if err = countWaybillSettleInfo(db, order, v, store); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// 3.总的收支核算
|
||||
if err = orderFeeSettle(db, order, bill, bills, store); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ResetCreateWaybillFee 取消所有运单时计算结算信息
|
||||
func ResetCreateWaybillFee(db *dao.DaoDB, order *model.GoodsOrder, bill *model.Waybill) (err error) {
|
||||
if db == nil {
|
||||
db = dao.GetDB()
|
||||
@@ -459,12 +506,56 @@ func ResetCreateWaybillFee(db *dao.DaoDB, order *model.GoodsOrder, bill *model.W
|
||||
return nil
|
||||
}
|
||||
|
||||
// 获取订单运单详情列表
|
||||
store, _ := dao.GetStoreDetail(db, jxutils.GetSaleStoreIDFromOrder(order), order.VendorID, order.VendorOrgCode)
|
||||
|
||||
// 订单被取消了,所有运单应该也被取消了,检查是否退还配送费
|
||||
// 1.查询订单创建的所有运单,三方配送运单(达达,蜂鸟,uu,美团配送),平台自配送订单不参与
|
||||
if err := countWaybillSettleInfo(db, order, bill, store); err != nil {
|
||||
return err
|
||||
}
|
||||
// 所有运单停止调度之后才开始退还余额
|
||||
bills, err := dao.GetWaybills(db, order.VendorOrderID, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 所有取消的运单
|
||||
cancelWaybill := make(map[string]*model.Waybill, 0)
|
||||
for _, v := range bills {
|
||||
if v.Status == model.WaybillStatusCanceled && v.VendorWaybillID != bill.VendorWaybillID {
|
||||
cancelWaybill[v.VendorWaybillID] = v
|
||||
}
|
||||
}
|
||||
cancelWaybill[bill.VendorWaybillID] = bill
|
||||
// 已经全部运单取消,退款结算
|
||||
if len(bills) == len(cancelWaybill) {
|
||||
for _, v := range bills {
|
||||
if v.VendorWaybillID == bill.VendorWaybillID {
|
||||
continue
|
||||
}
|
||||
// 已经取消订单的违约金计算
|
||||
if err = countWaybillSettleInfo(db, order, v, store); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// 最终的金额核算,多退少补
|
||||
if err = orderFeeSettle(db, order, bill, bills, store); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// countWaybillSettleInfo 计算订单的结算信息
|
||||
func countWaybillSettleInfo(db *dao.DaoDB, order *model.GoodsOrder, bill *model.Waybill, store *dao.StoreDetail) error {
|
||||
if handlerInfo := partner.GetDeliveryPlatformFromVendorID(bill.WaybillVendorID); handlerInfo != nil {
|
||||
// 这一步必须要做,可能不是最后取消订单,需要更新违约金和取消状态
|
||||
deductFee, err := handlerInfo.Handler.GetDeliverLiquidatedDamages(bill.VendorOrderID, bill.VendorWaybillID)
|
||||
if err != nil {
|
||||
partner.CurOrderManager.OnOrderMsg(order, fmt.Sprintf("订单[%s],运单平台[%d],运单[%s]取消,获取违约金异常:%v", order.VendorOrderID, bill.WaybillVendorID, bill.VendorWaybillID, err), "")
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -475,102 +566,104 @@ func ResetCreateWaybillFee(db *dao.DaoDB, order *model.GoodsOrder, bill *model.W
|
||||
_, err = dao.UpdateEntity(db, bill, "ActualFee", "DesiredFee")
|
||||
}
|
||||
|
||||
// 获取订单运单详情列表
|
||||
store, _ := dao.GetStoreDetail(db, jxutils.GetSaleStoreIDFromOrder(order), order.VendorID, order.VendorOrgCode)
|
||||
// 门店发单,支付运单违约金
|
||||
if store != nil && store.CreateDeliveryType == model.YES && deductFee != model.NO {
|
||||
err = partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(jxcontext.AdminCtx, store.ID, int(deductFee), partner.StoreAcctTypeExpendCreateWaybillDeductFee, bill.VendorOrderID, bill.VendorWaybillID, 0)
|
||||
if err != nil {
|
||||
partner.CurOrderManager.OnOrderMsg(order, fmt.Sprintf("订单[%s],运单平台[%d],运单[%s]取消,获取违约金门店扣除失败:%v,金额[%d]", order.VendorOrderID, bill.WaybillVendorID, bill.VendorWaybillID, err, deductFee), "")
|
||||
globals.SugarLogger.Errorf("InsertStoreAcctIncomeAndUpdateStoreAcctBalance 483 : %v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if store != nil && store.CreateDeliveryType == model.NO && deductFee != model.NO {
|
||||
err = partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, int(deductFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeDeductFee, order.VendorOrderID, order.VendorWaybillID)
|
||||
if err != nil {
|
||||
partner.CurOrderManager.OnOrderMsg(order, fmt.Sprintf("订单[%s],运单平台[%d],运单[%s]取消,获取违约金品牌扣除失败:%v,金额[%d]", order.VendorOrderID, bill.WaybillVendorID, bill.VendorWaybillID, err, deductFee), "")
|
||||
globals.SugarLogger.Errorf("InsertBrandBill 489 : %v", err)
|
||||
return err
|
||||
}
|
||||
//// 获取运单的支出记录
|
||||
//orderBill, _ := dao.GetBrandBill(db, store.BrandID, order.VendorOrderID, model.BrandBillTypeExpend, model.BrandBillFeeTypeDelivery, order.VendorWaybillID)
|
||||
//if len(orderBill) == 0 {
|
||||
//} else {
|
||||
// // 退回扣除的配送费
|
||||
// partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, orderBill[0].Price, model.BrandBillTypeIncome, model.BrandBillFeeTypeDeductFee, order.VendorOrderID, order.VendorWaybillID)
|
||||
// // 支出配送费违约金
|
||||
// partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, int(deductFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeDeductFee, order.VendorOrderID, order.VendorWaybillID)
|
||||
//}
|
||||
}
|
||||
|
||||
// 所有运单停止调度之后才开始退还余额
|
||||
bills, err := dao.GetWaybills(db, order.VendorOrderID, nil)
|
||||
if err != nil {
|
||||
if err == nil {
|
||||
partner.CurOrderManager.OnOrderMsg(order, fmt.Sprintf("订单[%s],运单平台[%d],运单[%s]取消,违约金扣除成功:%d", order.VendorOrderID, bill.WaybillVendorID, bill.VendorWaybillID, deductFee), "")
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 所有取消的运单
|
||||
cancelWaybill := make(map[string]*model.Waybill, 0)
|
||||
//finishWaybill := make(map[string]*model.Waybill, 0)
|
||||
//deliveryWaybill := make(map[string]*model.Waybill, 0)
|
||||
for _, v := range bills {
|
||||
if v.Status == model.WaybillStatusCanceled && v.VendorWaybillID != bill.VendorWaybillID {
|
||||
cancelWaybill[v.VendorWaybillID] = v
|
||||
}
|
||||
//if (v.Status == model.WaybillStatusDelivered || v.Status == model.OrderStatusFinished) && v.VendorWaybillID != bill.VendorWaybillID {
|
||||
// finishWaybill[v.VendorWaybillID] = v
|
||||
//}
|
||||
//if v.Status < model.WaybillStatusDelivered && v.VendorWaybillID != bill.VendorWaybillID {
|
||||
// deliveryWaybill[v.VendorOrderID] = v
|
||||
//}
|
||||
// 订单金额核算
|
||||
func orderFeeSettle(db *dao.DaoDB, order *model.GoodsOrder, bill *model.Waybill, bills []*model.Waybill, store *dao.StoreDetail) (err error) {
|
||||
billExpend := 0
|
||||
billIncome := 0
|
||||
allFee := 0
|
||||
// 门店结算,全部支出
|
||||
if store.CreateDeliveryType == model.YES {
|
||||
// 此订单支出的费用
|
||||
expendType := []int{partner.StoreAcctTypeExpendCreateWaybillEx, partner.StoreAcctTypeExpendCreateWaybillTip, partner.StoreAcctTypeExpendCreateWaybill2ndMore, partner.StoreAcctTypeExpendCreateWaybillDeductFee, partner.StoreAcctTypeRealFeeExpend}
|
||||
billExpend, err = dao.GetStoreAcctExpendTotal(db, store.ID, expendType, bill.VendorOrderID, utils.ZeroTimeValue, utils.ZeroTimeValue)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Errorf("GetStoreAcctExpendTotal 545 err :%v", err)
|
||||
return err
|
||||
}
|
||||
cancelWaybill[bill.VendorWaybillID] = bill
|
||||
// 还有配送中的订单,暂不退款
|
||||
//if len(deliveryWaybill) != model.NO {
|
||||
// return nil
|
||||
//}
|
||||
//// 如果已经有完成订单
|
||||
//if len(finishWaybill) != model.NO {
|
||||
// var cancelDeductFee int64 = 0
|
||||
// var tipFee int64 = 0
|
||||
// for _, v := range cancelWaybill {
|
||||
// cancelDeductFee += v.ActualFee
|
||||
// tipFee += v.TipFee
|
||||
// }
|
||||
//
|
||||
//}
|
||||
// 已经全部运单取消,退款结算
|
||||
if len(bills) == len(cancelWaybill) {
|
||||
// 门店结算,全部支出
|
||||
if store.CreateDeliveryType == model.YES {
|
||||
// 此订单支出的费用
|
||||
expendType := []int{partner.StoreAcctTypeExpendCreateWaybillEx, partner.StoreAcctTypeExpendCreateWaybillTip, partner.StoreAcctTypeExpendCreateWaybill2ndMore, partner.StoreAcctTypeExpendCreateWaybillDeductFee, partner.StoreAcctTypeRealFeeExpend}
|
||||
billExpend, err := dao.GetStoreAcctExpendTotal(db, store.ID, expendType, bill.VendorOrderID, utils.ZeroTimeValue, utils.ZeroTimeValue)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Errorf("GetStoreAcctExpendTotal 545 err :%v", err)
|
||||
return err
|
||||
}
|
||||
// 此订单退还的费用
|
||||
incomeType := []int{partner.StoreAcctTypeRealFeeIncome, partner.StoreAcctTypeIncomeCancelTemp, partner.StoreAcctTypeIncomeCancelReal}
|
||||
billIncome, err := dao.GetStoreAcctIncomeTotal(db, store.ID, incomeType, bill.VendorOrderID, utils.ZeroTimeValue, utils.ZeroTimeValue)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Errorf("GetStoreAcctIncomeTotal 551 err :%v", err)
|
||||
return err
|
||||
}
|
||||
var allFee int = 0
|
||||
for _, v := range bills {
|
||||
allFee += int(v.ActualFee)
|
||||
allFee += int(v.TipFee)
|
||||
}
|
||||
globals.SugarLogger.Errorf("计算错误:订单支出费用应该=退还费用+运单支出费用,支出费用:%d,已经退还费用:%d,剩余退还费用:%d", billExpend, billIncome, billExpend-billIncome)
|
||||
if allFee != billExpend-billIncome {
|
||||
globals.SugarLogger.Errorf("计算错误:订单支出费用应该=退还费用+运单支出费用,支出费用:%d,已经退还费用:%d,剩余退还费用:%d", billExpend, billIncome, billExpend-billIncome)
|
||||
}
|
||||
}
|
||||
// 品牌结算
|
||||
if store.CreateDeliveryType == model.NO {
|
||||
// 此订单退还的费用
|
||||
incomeType := []int{partner.StoreAcctTypeRealFeeIncome, partner.StoreAcctTypeIncomeCancelTemp, partner.StoreAcctTypeIncomeCancelReal}
|
||||
billIncome, err = dao.GetStoreAcctIncomeTotal(db, store.ID, incomeType, bill.VendorOrderID, utils.ZeroTimeValue, utils.ZeroTimeValue)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Errorf("GetStoreAcctIncomeTotal 551 err :%v", err)
|
||||
return err
|
||||
}
|
||||
for _, v := range bills {
|
||||
allFee += int(v.DesiredFee)
|
||||
allFee += int(v.TipFee)
|
||||
}
|
||||
// 运单支出费用统计,应该等于 支出费用- 退还费用
|
||||
globals.SugarLogger.Errorf("计算错误:订单支出费用应该=退还费用+运单支出费用,支出费用:%d,已经退还费用:%d,运单计算费用:%d", billExpend, billIncome, allFee)
|
||||
if allFee != billExpend-billIncome {
|
||||
globals.SugarLogger.Errorf("计算错误:订单支出费用应该=退还费用+运单支出费用,支出费用:%d,已经退还费用:%d,剩余退还费用:%d", billExpend, billIncome, billExpend-billIncome)
|
||||
}
|
||||
}
|
||||
if billExpend-billIncome == allFee {
|
||||
globals.SugarLogger.Debugf("计算正确,运单消耗[%d],账户支出[%d],账户退回[%d]", allFee, billExpend, billIncome)
|
||||
partner.CurOrderManager.OnOrderMsg(order, fmt.Sprintf("计算正确,运单消耗[%d],账户支出[%d],账户退回[%d]", allFee, billExpend, billIncome), "")
|
||||
return nil
|
||||
}
|
||||
|
||||
abnormalAmount := billExpend - billIncome - allFee
|
||||
switch store.CreateDeliveryType {
|
||||
case model.NO: // 品牌结算
|
||||
if abnormalAmount > 0 { // 多退
|
||||
err = partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, abnormalAmount, model.BrandBillTypeIncome, model.BrandBillFeeTypeSys, order.VendorOrderID, order.VendorWaybillID)
|
||||
if err != nil {
|
||||
partner.CurOrderManager.OnOrderMsg(order, fmt.Sprintf("订单[%s],运单平台[%d],运单[%s]取消,品牌支出大于消耗,多退:%v,金额[%d]", order.VendorOrderID, bill.WaybillVendorID, bill.VendorWaybillID, err, abnormalAmount), "")
|
||||
globals.SugarLogger.Errorf("InsertBrandBill 489 : %v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
if abnormalAmount < 0 {
|
||||
err = partner.CurStoreAcctManager.InsertBrandBill(jxcontext.AdminCtx, store.BrandID, abnormalAmount*-1, model.BrandBillTypeExpend, model.BrandBillFeeTypeSys, order.VendorOrderID, order.VendorWaybillID)
|
||||
if err != nil {
|
||||
partner.CurOrderManager.OnOrderMsg(order, fmt.Sprintf("订单[%s],运单平台[%d],运单[%s]取消,品牌支出小于消耗,少补:%v,金额[%d]", order.VendorOrderID, bill.WaybillVendorID, bill.VendorWaybillID, err, abnormalAmount), "")
|
||||
globals.SugarLogger.Errorf("InsertBrandBill 489 : %v", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
case model.YES: // 门店结算
|
||||
if abnormalAmount > 0 { // 多退
|
||||
err = partner.CurStoreAcctManager.InsertStoreAcctIncomeAndUpdateStoreAcctBalance(jxcontext.AdminCtx, store.ID, int(billExpend-billIncome-allFee), partner.StoreAcctTypeIncomeCancelReal, bill.VendorOrderID, bill.VendorWaybillID, 0)
|
||||
if err != nil {
|
||||
partner.CurOrderManager.OnOrderMsg(order, fmt.Sprintf("订单[%s],运单平台[%d],运单[%s]取消,支出大于消耗,多退:%v,金额[%d]", order.VendorOrderID, bill.WaybillVendorID, bill.VendorWaybillID, err, abnormalAmount), "")
|
||||
globals.SugarLogger.Errorf("InsertStoreAcctIncomeAndUpdateStoreAcctBalance 483 : %v", err)
|
||||
}
|
||||
}
|
||||
if abnormalAmount < 0 {
|
||||
err = partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(jxcontext.AdminCtx, store.ID, int(abnormalAmount)*-1, partner.StoreAcctTypeExpendCreateWaybill2ndMore, bill.VendorOrderID, bill.VendorWaybillID, 0)
|
||||
if err != nil {
|
||||
partner.CurOrderManager.OnOrderMsg(order, fmt.Sprintf("订单[%s],运单平台[%d],运单[%s]取消,支出小于消耗,少补:%v,金额[%d]", order.VendorOrderID, bill.WaybillVendorID, bill.VendorWaybillID, err, abnormalAmount), "")
|
||||
globals.SugarLogger.Errorf("InsertStoreAcctIncomeAndUpdateStoreAcctBalance 483 : %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -715,6 +715,24 @@ func (c *OrderManager) GetLogisticsOrderStatusList(orderId, LogisticsId string,
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetWayBillStatusList 根据订单号和物流号查询运单的变化状态
|
||||
func (c *OrderManager) GetWayBillStatusList(orderId, LogisticsId string, vendorId int) ([]*model.OrderStatus, error) {
|
||||
sql := `SELECT *
|
||||
FROM order_status t1
|
||||
WHERE t1.vendor_order_id = ? AND t1.ref_vendor_order_id = ? AND t1.vendor_id = ?`
|
||||
sqlParams := []interface{}{
|
||||
LogisticsId,
|
||||
orderId,
|
||||
vendorId,
|
||||
}
|
||||
sql += ` ORDER BY status_time ASC `
|
||||
var result []*model.OrderStatus
|
||||
if err := dao.GetRows(dao.GetDB(), &result, sql, sqlParams...); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// GetOrderStatusList2 查询订单流程 refVendorOrderID 订单Id
|
||||
func GetOrderStatusList2(refVendorOrderID string, wayBillId string, orderType int, vendorID int) (statusList []*model.OrderStatus, err error) {
|
||||
sql := `
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"fmt"
|
||||
tiktokShop "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/tiktok_api"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
@@ -283,8 +282,9 @@ func (c *BaseScheduler) CancelWaybill(bill *model.Waybill, cancelReasonID int, c
|
||||
if err := handlerInfo.Handler.CancelWaybill(bill, cancelReasonID, cancelReason); err != nil {
|
||||
return err
|
||||
}
|
||||
order, _ := partner.CurOrderManager.LoadOrder(bill.VendorOrderID, bill.OrderVendorID)
|
||||
return orderman.ResetCreateWaybillFee(nil, order, bill)
|
||||
return nil
|
||||
//order, _ := partner.CurOrderManager.LoadOrder(bill.VendorOrderID, bill.OrderVendorID)
|
||||
//return orderman.ResetCreateWaybillFee(nil, order, bill)
|
||||
}, "CancelWaybill bill:%v", bill); err == nil {
|
||||
bill.Status = model.WaybillStatusCanceled
|
||||
bill.DeliveryFlag |= model.WaybillDeliveryFlagMaskActiveCancel
|
||||
|
||||
@@ -376,7 +376,7 @@ func (c *BaseScheduler) CheckStoreBalanceWithTip(ctx *jxcontext.Context, order *
|
||||
return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("门店账户余额不足,不能加小费!")
|
||||
}
|
||||
if tipFee > 1000 {
|
||||
return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("小费单次加价金额大于五元")
|
||||
return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("小费单次加价金额大于十元")
|
||||
}
|
||||
} else {
|
||||
// 品牌发单
|
||||
@@ -393,7 +393,7 @@ func (c *BaseScheduler) CheckStoreBalanceWithTip(ctx *jxcontext.Context, order *
|
||||
return model.ErrCodeAccountBalanceNotEnough, fmt.Errorf("品牌账户余额不足,不能加小费!")
|
||||
}
|
||||
if tipFee > 1000 {
|
||||
return model.ErrCodeOnePayTipFeeMore, fmt.Errorf("小费单次加价金额大于五元")
|
||||
return model.ErrCodeOnePayTipFeeMore, fmt.Errorf("小费单次加价金额大于十元")
|
||||
}
|
||||
}
|
||||
// 是否确认支付
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/fnpsapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi/mtpsapi"
|
||||
"git.rosy.net.cn/baseapi/platformapi/uuptapi"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/smsmsg"
|
||||
"math/rand"
|
||||
"strings"
|
||||
@@ -511,20 +512,6 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
|
||||
savedOrderInfo := s.loadSavedOrderFromMap(model.Waybill2Status(bill), true)
|
||||
order := savedOrderInfo.order
|
||||
|
||||
// 打印通知
|
||||
//netprinter.PrintOrderByOrder(jxcontext.AdminCtx, order, model.PrintTypeWayBill)
|
||||
|
||||
// 获取订单配送平台,如果是美团则需要获取门店配置的配送方式
|
||||
//isBlendWay := false
|
||||
//if bill.OrderVendorID == model.VendorIDMTWM {
|
||||
// mtStoreInfo, err := api.MtwmAPI.PoiGet(utils.Int2Str(order.JxStoreID))
|
||||
// globals.SugarLogger.Debugf("从美团上获取门店失败:%s", err)
|
||||
// isBlendWay = strings.Contains(mtStoreInfo.LogisticsCodes, model.MTWMStorePSWay8)
|
||||
//}
|
||||
//if order.VendorID == model.VendorIDDD {
|
||||
// partner.GetPurchaseOrderHandlerFromVendorID(order.VendorID).GetOrderRider()
|
||||
//}
|
||||
|
||||
// 暂时只处理抖音平台,抖音暂无配送,只要是抖音订单,三方配送压单了,直接通知送出
|
||||
if bill.Status == model.WaybillStatusNew {
|
||||
s.addWaybill2Map(savedOrderInfo, bill)
|
||||
@@ -634,10 +621,7 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
|
||||
if order.VendorID == model.VendorIDJDShop {
|
||||
s.solutionJdsOrder(bill)
|
||||
}
|
||||
//如果是商城的订单, 骑手取货时,需要发短信提醒
|
||||
//if bill.Status == model.WaybillStatusDelivering && order.VendorID == model.VendorIDJX && order.OrderType == model.OrderTypeNormal {
|
||||
// smsmsg.NotifyJxOrder(order, bill)
|
||||
//}
|
||||
|
||||
// 当运单时三方配送时,美团状态20
|
||||
if bill.WaybillVendorID == model.VendorIDDada || bill.WaybillVendorID == model.VendorIDMTPS || bill.WaybillVendorID == model.VendorIDFengNiao || bill.WaybillVendorID == model.VendorIDUUPT {
|
||||
if (bill.VendorStatus == utils.Int64ToStr(mtpsapi.OrderStatusPickedUp) && bill.OrderVendorID == model.VendorIDMTWM) ||
|
||||
@@ -747,9 +731,6 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
|
||||
if model.IsOrderHaveWaybill(order) {
|
||||
s.updateOrderByBill(order, nil, true)
|
||||
}
|
||||
//if order.VendorID == model.VendorIDMTWM {
|
||||
// order, _ = partner.CurOrderManager.LoadOrder(order.VendorOrderID, order.VendorID)
|
||||
//}
|
||||
// 3方的运单取消才会重新发起创建3方订单,购物平台的运单取消后,它本身还会再创建新运单(NewWaybill事件有相应TIMER)),至少京东是这样的,暂时按京东的行为来
|
||||
// 现在发现饿百取消订单后不会再创建运单了,所以饿百运单取消也允许直接创建三方运单
|
||||
// 之前的条件是order.Status < model.OrderStatusDelivering,但像订单902322817000122确实有在配送中取消状态,改成非订单结束状态都可以
|
||||
@@ -761,21 +742,12 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
|
||||
//}
|
||||
globals.SugarLogger.Debugf("auto cancelWaybill created second, orderID:%s", order.VendorOrderID)
|
||||
}
|
||||
//if order.Status < model.OrderStatusDelivering {
|
||||
// if order.VendorID == model.VendorIDMTWM && order.DeliveryType == model.OrderDeliveryTypePlatform {
|
||||
// s.CancelOrder(jxcontext.AdminCtx, order, "")
|
||||
// }
|
||||
//}
|
||||
}
|
||||
}
|
||||
// case model.WaybillStatusDelivering:
|
||||
// s.resetTimer(savedOrderInfo, bill, isPending)
|
||||
// if s.isBillCandidate(order, bill) {
|
||||
// // do nothing
|
||||
// } else {
|
||||
// // s.ProxyCancelWaybill(order, bill, partner.CancelWaybillReasonNotAcceptIntime, partner.CancelWaybillReasonStrNotAcceptIntime)
|
||||
// globals.SugarLogger.Infof("OnWaybillStatusChanged Delivering order(%d, %s) bill(%d, %s), bill:%v shouldn't get here", order.WaybillVendorID, order.VendorWaybillID, bill.WaybillVendorID, bill.VendorWaybillID, bill)
|
||||
// }
|
||||
|
||||
if err := orderman.ResetCreateWaybillFee(nil, order, bill); err != nil {
|
||||
globals.SugarLogger.Errorf("ResetCreateWaybillFee err : %v", err)
|
||||
}
|
||||
|
||||
case model.WaybillStatusDelivered:
|
||||
s.resetTimer(savedOrderInfo, bill, isPending)
|
||||
@@ -805,22 +777,18 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
|
||||
if !isPending {
|
||||
s.notify3rdPartyWaybill(order, bill, false)
|
||||
}
|
||||
// case model.WaybillStatusNeverSend: // 平台不配送,直接创建三方运单
|
||||
// s.resetTimer(savedOrderInfo, bill, isPending)
|
||||
// s.removeWaybillFromMap(savedOrderInfo, bill.WaybillVendorID)
|
||||
// if order.WaybillVendorID == model.VendorIDUnknown {
|
||||
// s.createWaybillOn3rdProviders(savedOrderInfo, 0, nil)
|
||||
// }
|
||||
// 将订单修改为完成状态
|
||||
order.Status = model.OrderStatusFinished
|
||||
order.OrderFinishedAt = time.Now()
|
||||
partner.CurOrderManager.UpdateOrderFields(order, []string{"status", "OrderFinishedAt"})
|
||||
if err := orderman.FinisOrderWaybillFee(nil, order, bill); err != nil {
|
||||
globals.SugarLogger.Debugf("FinisOrderWaybillFee count err : %v", err)
|
||||
}
|
||||
|
||||
default:
|
||||
s.resetTimer(savedOrderInfo, bill, isPending)
|
||||
}
|
||||
// s.updateBillsInfo(savedOrderInfo, bill) // 更新可能的运单状态变化
|
||||
}
|
||||
// }
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1328,19 +1328,19 @@ func updateOrCreateSkuVendorCategoryMap(db *dao.DaoDB, ctx *jxcontext.Context, n
|
||||
if payload["descImg"] != nil {
|
||||
imgs = append(imgs, payload["descImg"].(string))
|
||||
}
|
||||
if payload["img"] != "" {
|
||||
if payload["img"] != nil {
|
||||
imgs = append(imgs, payload["descImg"].(string))
|
||||
}
|
||||
if payload["img2"] != "" {
|
||||
if payload["img2"] != nil {
|
||||
imgs = append(imgs, payload["img2"].(string))
|
||||
}
|
||||
if payload["img3"] != "" {
|
||||
if payload["img3"] != nil {
|
||||
imgs = append(imgs, payload["img3"].(string))
|
||||
}
|
||||
if payload["img4"] != "" {
|
||||
if payload["img4"] != nil {
|
||||
imgs = append(imgs, payload["img4"].(string))
|
||||
}
|
||||
if payload["img5"] != "" {
|
||||
if payload["img5"] != nil {
|
||||
imgs = append(imgs, payload["img5"].(string))
|
||||
}
|
||||
ddCategoryID = getCategoryByImg(imgs...)
|
||||
|
||||
@@ -234,7 +234,7 @@ type Waybill struct {
|
||||
Status int `json:"status"` // 参见WaybillStatus*相关的常量定义
|
||||
VendorStatus string `orm:"size(255)" json:"-"`
|
||||
ActualFee int64 `json:"actualFee"` // 实际要支付给快递公司的费用
|
||||
DesiredFee int64 `json:"desiredFee"` // 运单总费用
|
||||
DesiredFee int64 `json:"desiredFee"` // 运单总费用(原价+两毛)统计使用
|
||||
TipFee int64 `json:"tipFee"` // 运单小费,不含在上两项中
|
||||
DuplicatedCount int `json:"-"` // 重复新订单消息数,这个一般不是由于消息重发造成的(消息重发由OrderStatus过滤),一般是业务逻辑造成的
|
||||
DeliveryFlag int8 `json:"deliveryFlag"`
|
||||
|
||||
@@ -283,7 +283,7 @@ func (c *DeliveryHandler) GetWaybillFee(order *model.GoodsOrder) (deliveryFeeInf
|
||||
return nil, err
|
||||
}
|
||||
globals.SugarLogger.Debugf("QueryDeliverFee===============预下单获取配送费:%s", utils.Format4Output(result, false))
|
||||
deliveryFeeInfo.DeliveryFee = jxutils.StandardPrice2Int(result.Fee)
|
||||
deliveryFeeInfo.DeliveryFee = jxutils.StandardPrice2Int(result.DeliverFee) // jxutils.StandardPrice2Int(result.Fee)
|
||||
deliveryFeeInfo.RefDeliveryFee = deliveryFeeInfo.DeliveryFee
|
||||
}
|
||||
return deliveryFeeInfo, err
|
||||
@@ -388,8 +388,8 @@ func (c *DeliveryHandler) CreateWaybill(order *model.GoodsOrder, maxDeliveryFee
|
||||
VendorOrderID: order.VendorOrderID,
|
||||
OrderVendorID: order.VendorID,
|
||||
WaybillVendorID: model.VendorIDDada,
|
||||
DesiredFee: jxutils.StandardPrice2Int(result.Fee),
|
||||
ActualFee: jxutils.StandardPrice2Int(result.Fee),
|
||||
DesiredFee: jxutils.StandardPrice2Int(result.DeliverFee),
|
||||
ActualFee: jxutils.StandardPrice2Int(result.DeliverFee),
|
||||
}
|
||||
delivery.OnWaybillCreated(bill)
|
||||
return bill, err
|
||||
@@ -571,8 +571,14 @@ func (c *DeliveryHandler) GetDeliverLiquidatedDamages(orderId string, deliverId
|
||||
return 200, nil
|
||||
}
|
||||
|
||||
// fetchTime 已经有时间了,代表已经取货.次数取消扣除此订单全部金额
|
||||
// 达达存在多个订单的运单违约金额统计在一起的情况
|
||||
if dadaOrder.FetchTime != "" {
|
||||
return jxutils.StandardPrice2Int(dadaOrder.ActualFee), nil
|
||||
bill, err := partner.CurOrderManager.LoadWaybill(deliverId, model.VendorIDDada)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return bill.DesiredFee, nil
|
||||
}
|
||||
|
||||
return 0, err
|
||||
|
||||
@@ -234,11 +234,11 @@ func OnWaybillMsg(msg *fnpsapi.OrderStatusNottify) (resp *fnpsapi.CallbackRespon
|
||||
order.DesiredFee, order.ActualFee = GetDesiredFee(order.VendorOrderID)
|
||||
order.Status = model.WaybillStatusNew //5 带调度
|
||||
case fnpsapi.OrderStatusAssigned: //20分配骑手
|
||||
order.DesiredFee, order.ActualFee = GetDesiredFee(order.VendorOrderID)
|
||||
//order.DesiredFee, order.ActualFee = GetDesiredFee(order.VendorOrderID)
|
||||
order.Status = model.WaybillStatusCourierAssigned //12
|
||||
order.Remark = order.CourierName + "," + order.CourierMobile
|
||||
case fnpsapi.OrderStatusArrived: // 80 到店
|
||||
order.DesiredFee, order.ActualFee = GetDesiredFee(order.VendorOrderID)
|
||||
//order.DesiredFee, order.ActualFee = GetDesiredFee(order.VendorOrderID)
|
||||
order.Status = model.WaybillStatusCourierArrived
|
||||
case fnpsapi.OrderStatusDelivering: // 2 配送中
|
||||
order.Status = model.WaybillStatusDelivering
|
||||
@@ -324,7 +324,7 @@ func (c *DeliveryHandler) OnWaybillExcept(msg *fnpsapi.AbnormalReportNotify) (re
|
||||
// 查询订单配送费
|
||||
func GetDesiredFee(vendorOrderID string) (desiredFee, acuteFee int64) {
|
||||
if result, err := api.FnAPI.QueryOrder(vendorOrderID); err == nil {
|
||||
return result.OrderActualAmountCent, result.OrderTotalAmountCent
|
||||
return result.OrderTotalAmountCent + int64(utils.WayBillDeliveryMarkUp), result.OrderActualAmountCent
|
||||
}
|
||||
return desiredFee, acuteFee
|
||||
}
|
||||
@@ -398,7 +398,7 @@ func (c *DeliveryHandler) GetDeliverLiquidatedDamages(orderId string, deliverId
|
||||
for i := len(order.EventLogDetails) - 1; i >= 0; i-- {
|
||||
switch order.EventLogDetails[i].OrderStatus {
|
||||
case fnpsapi.OrderStatusDelivered, fnpsapi.OrderStatusArrived, fnpsapi.OrderStatusDelivering: // 送达,到店,配送中 取消订单全额扣款
|
||||
return order.OrderActualAmountCent, nil
|
||||
return order.OrderTotalAmountCent, nil
|
||||
case fnpsapi.OrderStatusAcceptCacle, fnpsapi.OrderStatusException: // 取消和异常状态,跳过查看上一状态
|
||||
continue
|
||||
case fnpsapi.OrderStatusAcceptCreate, fnpsapi.OrderStatusAccept: // 生成运单和系统接单取消不扣除费用
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/platformapi/mtpsapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
@@ -485,6 +486,36 @@ func (c *DeliveryHandler) GetRiderInfo(orderId string, deliveryId int64, mtPeiso
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c *DeliveryHandler) GetDeliverLiquidatedDamages(orderId string, deliverId string) (money int64, err error) {
|
||||
statusList, err := orderman.FixedOrderManager.GetWayBillStatusList(orderId, deliverId, model.VendorIDMTPS)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// 已经分配骑手,且超过十五分钟,不扣款
|
||||
if len(statusList) != model.NO {
|
||||
for i := len(statusList) - 1; i >= 0; i-- {
|
||||
switch statusList[i].VendorStatus {
|
||||
case utils.Int2Str(mtpsapi.OrderStatusWaitingForSchedule): // 待调度
|
||||
return 0, nil
|
||||
case utils.Int2Str(mtpsapi.OrderStatusCanceled): // 取消不管
|
||||
continue
|
||||
case utils.Int2Str(mtpsapi.OrderStatusDeliverred): // 送达
|
||||
continue
|
||||
case utils.Int2Str(mtpsapi.OrderStatusAccepted): // 接单
|
||||
// 接单取消扣凉快
|
||||
return 200, nil
|
||||
case utils.Int2Str(mtpsapi.OrderStatusPickedUp): // 取货
|
||||
bill, err := partner.CurOrderManager.LoadWaybill(deliverId, model.VendorIDDada)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return bill.DesiredFee, nil
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ func (d DeliveryHandler) CreateWaybill(order *model.GoodsOrder, maxDeliveryFee i
|
||||
VendorWaybillID: orderCode,
|
||||
VendorWaybillID2: originID,
|
||||
WaybillVendorID: model.VendorIDUUPT,
|
||||
DesiredFee: jxutils.StandardPrice2Int(utils.Str2Float64(price.NeedPayMoney)),
|
||||
DesiredFee: jxutils.StandardPrice2Int(utils.Str2Float64(price.TotalMoney)),
|
||||
}
|
||||
}
|
||||
delivery.OnWaybillCreated(bill)
|
||||
@@ -192,7 +192,8 @@ func (d DeliveryHandler) GetWaybillFee(order *model.GoodsOrder) (deliveryFeeInfo
|
||||
return nil, err
|
||||
} else {
|
||||
deliveryFeeInfo = &partner.WaybillFeeInfo{}
|
||||
deliveryFeeInfo.DeliveryFee = jxutils.StandardPrice2Int(utils.Str2Float64(orderPrice.NeedPayMoney))
|
||||
// deliveryFeeInfo.DeliveryFee = jxutils.StandardPrice2Int(utils.Str2Float64(orderPrice.NeedPayMoney)) 优惠后金额
|
||||
deliveryFeeInfo.DeliveryFee = jxutils.StandardPrice2Int(utils.Str2Float64(orderPrice.TotalMoney)) // 原始金额
|
||||
}
|
||||
return deliveryFeeInfo, err
|
||||
}
|
||||
@@ -308,37 +309,39 @@ func OnWaybillMsg(req *uuptapi.WaybillCallbackParam) (resp *uuptapi.CallbackResp
|
||||
dao.GetRow(dao.GetDB(), &good, sql, sqlParams)
|
||||
param.OrderVendorID = good.VendorID
|
||||
//查询运单价格
|
||||
if uuPrice, err := api.UuAPI.GetOrderDetail(req.OrderCode); err != nil {
|
||||
uuPrice, err := api.UuAPI.GetOrderDetail(req.OrderCode)
|
||||
if err != nil {
|
||||
reallyPrice = 0
|
||||
} else {
|
||||
reallyPrice = int64((utils.Str2Float64(uuPrice.OrderPrice) - utils.Str2Float64(uuPrice.PriceOff)) * 100)
|
||||
reallyPrice = int64(utils.Str2Float64(uuPrice.OrderPrice) * 100)
|
||||
}
|
||||
actualFee := int64((utils.Str2Float64(uuPrice.OrderPrice)-utils.Str2Float64(uuPrice.PriceOff))*100) - int64(utils.WayBillDeliveryMarkUp)
|
||||
switch req.State {
|
||||
case uuptapi.StateConfirmSuccess:
|
||||
param.Status = model.WaybillStatusNew //5 待调度
|
||||
param.DesiredFee = reallyPrice
|
||||
param.ActualFee = reallyPrice
|
||||
param.ActualFee = actualFee
|
||||
case uuptapi.StateRMGrabsOrder:
|
||||
param.Status = model.WaybillStatusCourierAssigned
|
||||
param.Remark = req.DriverName + "," + req.DriverMobile
|
||||
param.DesiredFee = reallyPrice
|
||||
param.ActualFee = reallyPrice
|
||||
param.ActualFee = actualFee
|
||||
case uuptapi.StateArrivedStore:
|
||||
param.Status = model.WaybillStatusCourierArrived
|
||||
param.DesiredFee = reallyPrice
|
||||
param.ActualFee = reallyPrice
|
||||
param.ActualFee = actualFee
|
||||
case uuptapi.StatePickUp:
|
||||
param.Status = model.WaybillStatusUuPickUp
|
||||
param.DesiredFee = reallyPrice
|
||||
param.ActualFee = reallyPrice
|
||||
param.ActualFee = actualFee
|
||||
case uuptapi.StateArrivedDestination:
|
||||
param.Status = model.WaybillStatusUuArrivedDestination
|
||||
param.DesiredFee = reallyPrice
|
||||
param.ActualFee = reallyPrice
|
||||
param.ActualFee = actualFee
|
||||
case uuptapi.StateReceiverGetGoods:
|
||||
param.Status = model.WaybillStatusDelivered
|
||||
param.DesiredFee = reallyPrice
|
||||
param.ActualFee = reallyPrice
|
||||
param.ActualFee = actualFee
|
||||
case uuptapi.StateOrderCancel:
|
||||
param.Status = model.WaybillStatusCanceled
|
||||
default:
|
||||
|
||||
@@ -8,8 +8,6 @@ import (
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
@@ -114,7 +112,7 @@ func WriteMessage() {
|
||||
clientInfo := <-ToClientChan
|
||||
//广播发送通知所有京西客户端
|
||||
i++
|
||||
fmt.Printf("WriteMessage clientInfo=%s i=%d\n", utils.Format4Output(clientInfo, false), i)
|
||||
//fmt.Printf("WriteMessage clientInfo=%s i=%d\n", utils.Format4Output(clientInfo, false), i)
|
||||
if Manager.AllClient() != nil {
|
||||
for _, conn := range Manager.AllClient() {
|
||||
if conn.ClientType == ClientTypeJx { //只发送给京西
|
||||
|
||||
@@ -40,16 +40,15 @@ func pay4OrderByKs(ctx *jxcontext.Context, order *model.GoodsOrder, vendorPayTyp
|
||||
}
|
||||
|
||||
param := &kuaishou_mini.PreCreateOrderReq{
|
||||
OutOrderNo: utils.Int64ToStr(GenPayOrderID(order)),
|
||||
OpenId: authBindList[0].AuthID,
|
||||
TotalAmount: order.ActualPayPrice,
|
||||
Subject: "蔬菜水果日用品",
|
||||
Detail: getOrderBriefKs(order),
|
||||
TypeDetail: 1832, // 蔬菜:费率2%,水果:1833%2
|
||||
ExpireTime: 60 * 10,
|
||||
Sign: "",
|
||||
Attach: "",
|
||||
//NotifyUrl: "https://callback.jxc4.com/kuaishou/kuaiShouCallback",
|
||||
OutOrderNo: utils.Int64ToStr(GenPayOrderID(order)),
|
||||
OpenId: authBindList[0].AuthID,
|
||||
TotalAmount: order.ActualPayPrice,
|
||||
Subject: "蔬菜水果日用品",
|
||||
Detail: getOrderBriefKs(order),
|
||||
TypeDetail: 1832, // 蔬菜:费率2%,水果:1833%2
|
||||
ExpireTime: 60 * 10,
|
||||
Sign: "",
|
||||
Attach: "",
|
||||
GoodsId: "",
|
||||
GoodsDetailUrl: "",
|
||||
MultiCopiesGoodsInfo: "",
|
||||
|
||||
Reference in New Issue
Block a user