Merge branch 'jdshop' of https://e.coding.net/rosydev/jx-callback into jdshop

This commit is contained in:
richboo111
2023-06-01 17:22:45 +08:00
13 changed files with 104 additions and 50 deletions

View File

@@ -539,16 +539,6 @@ func ResetCreateWaybillFee(db *dao.DaoDB, order *model.GoodsOrder, bill *model.W
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
@@ -630,7 +620,7 @@ func orderFeeSettle(db *dao.DaoDB, order *model.GoodsOrder, bill *model.Waybill,
for _, v := range bills {
allFee += int(v.DesiredFee)
allFee += int(v.TipFee)
//allFee += int(v.TipFee)
}
// 运单支出费用统计,应该等于 支出费用- 退还费用
globals.SugarLogger.Errorf("计算错误:订单支出费用应该=退还费用+运单支出费用,支出费用:%d,已经退还费用:%d,运单计算费用:%d", billExpend, billIncome, allFee)

View File

@@ -382,8 +382,8 @@ func (c *OrderManager) GetOrders(ctx *jxcontext.Context, isIncludeFake bool, fro
var damages = &struct {
Damages int64 `json:"damages"`
}{}
sqlDamages := ` SELECT SUM(w.desired_fee) damages FROM waybill w WHERE w.vendor_order_id = ? AND w.status = ? `
paramDamages := []interface{}{order.VendorOrderID, model.OrderStatusCanceled}
sqlDamages := ` SELECT SUM(w.desired_fee) damages FROM waybill w WHERE w.vendor_order_id = ? AND w.status = ? AND w.vendor_waybill_id <> ? `
paramDamages := []interface{}{order.VendorOrderID, model.OrderStatusCanceled, order.VendorWaybillID}
if err := dao.GetRow(db, damages, sqlDamages, paramDamages); err == nil {
order.LiquidatedDamages = damages.Damages
}

View File

@@ -247,20 +247,23 @@ func GetComplaintReasons() (complaintReasonList []*dadaapi.ComplaintReason) {
return complaintReasonList
}
func ComplaintRider(ctx *jxcontext.Context, vendorOrderID string, vendorID, waybillVendorID, complaintID int) (err error) {
db := dao.GetDB()
p := partner.GetDeliveryPlatformFromVendorID(waybillVendorID).Handler
wayBillList, err := dao.GetWayBillByOrderID(db, 0, vendorID, waybillVendorID, vendorOrderID)
func ComplaintRider(ctx *jxcontext.Context, vendorOrderID string, vendorWaybillId string, complaintID int) (err error) {
wayBillList, err := dao.GetComplaintList(dao.GetDB(), vendorOrderID, vendorWaybillId)
if err != nil {
return err
}
if len(wayBillList) != model.YES {
return fmt.Errorf("订单所属运单不存在,或运单为分配骑手,无法投诉")
}
p := partner.GetDeliveryPlatformFromVendorID(wayBillList[0].WaybillVendorID).Handler
if err == nil && len(wayBillList) > 0 {
err = p.ComplaintRider(wayBillList[0], complaintID, complaintReasonsMap[complaintID])
} else {
return fmt.Errorf("未查询到到相关订单!订单号:[%v] ,厂商:[%v],运送厂商:[%v]", vendorOrderID, vendorID, waybillVendorID)
}
return err
}
func ComplaintRiderPlatform(ctx *jxcontext.Context, vendorOrderID string, vendorID, waybillVendorID, complaintID int) (err error) {
return fmt.Errorf("只支持三方配送投诉!")
//handler := partner.GetPurchaseOrderHandlerFromVendorID(vendorID)
//return handler.ComplaintRider(vendorOrderID, complaintID, "")
// GetComplaintList 获取投诉列表
func GetComplaintList(orderId string) ([]*model.Waybill, error) {
return dao.GetComplaintList(dao.GetDB(), orderId, "")
}

View File

@@ -275,7 +275,6 @@ func (c *BaseScheduler) CreateWaybill(platformVendorID int, order *model.GoodsOr
func (c *BaseScheduler) CancelWaybill(bill *model.Waybill, cancelReasonID int, cancelReason string) (err error) {
// 部分快递平台在取消成功后有时会不发运单取消消息过来比如达达904200512000442为避免二次取消报错添加状态判断
//if c.IsReallyCallPlatformAPI && bill.Status != model.WaybillStatusCanceled { //此行测试用
if c.IsReallyCallPlatformAPI && bill.OrderVendorID != bill.WaybillVendorID && bill.Status != model.WaybillStatusCanceled {
if handlerInfo := partner.GetDeliveryPlatformFromVendorID(bill.WaybillVendorID); handlerInfo != nil {
if err = utils.CallFuncLogErrorWithInfo(func() error {
@@ -283,8 +282,6 @@ func (c *BaseScheduler) CancelWaybill(bill *model.Waybill, cancelReasonID int, c
return err
}
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

View File

@@ -370,6 +370,9 @@ func (c *BaseScheduler) CheckStoreBalanceWithTip(ctx *jxcontext.Context, order *
if roundTipFee != tipFee {
return model.ErrCodeOnePayTipFeeMore, fmt.Errorf("小费必须是1元的整数倍")
}
if order.WaybillTipMoney >= tipFee {
return model.ErrCodeOnePayTipFeeMore, fmt.Errorf("本次小费金额不能小于已经支付的小费")
}
if order.CreateDeliveryType == model.YES {
//加小费只判断余额
storeAcct, err := cms.GetStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order))
@@ -415,20 +418,21 @@ func isWaybillCanAddTip(waybill *model.Waybill) (isCan bool) {
func (c *BaseScheduler) SetOrderWaybillTipByOrder(ctx *jxcontext.Context, order *model.GoodsOrder, tipFee int64) (err error) {
db := dao.GetDB()
thisTimeTipFee := tipFee - order.WaybillTipMoney
storeDetail, _ := dao.GetStoreDetail(db, jxutils.GetSaleStoreIDFromOrder(order), order.VendorID, "")
flag := false
// 如果平台支持设置配送小费,必须要成功设置
if handler := partner.GetWaybillTipUpdater(order.VendorID); handler != nil {
if err = handler.UpdateWaybillTip(ctx, order.VendorOrgCode, order.VendorStoreID, order.VendorOrderID, "", "", utils.Int2Str(storeDetail.CityCode), tipFee); err != nil {
if err = handler.UpdateWaybillTip(ctx, order.VendorOrgCode, order.VendorStoreID, order.VendorOrderID, "", "", utils.Int2Str(storeDetail.CityCode), thisTimeTipFee); err != nil {
return err
} else {
//加小费成功扣钱
if order.CreateDeliveryType == model.YES {
if err = partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), int(tipFee), partner.StoreAcctTypeExpendCreateWaybillTip, order.VendorOrderID, "", 0); err == nil {
if err = partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), int(thisTimeTipFee), partner.StoreAcctTypeExpendCreateWaybillTip, order.VendorOrderID, "", 0); err == nil {
flag = true
}
} else if order.CreateDeliveryType == model.NO {
if err = partner.CurStoreAcctManager.InsertBrandBill(ctx, storeDetail.BrandID, int(tipFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeTipFee, order.VendorOrderID, ""); err == nil {
if err = partner.CurStoreAcctManager.InsertBrandBill(ctx, storeDetail.BrandID, int(thisTimeTipFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeTipFee, order.VendorOrderID, ""); err == nil {
flag = true
}
}
@@ -452,8 +456,10 @@ func (c *BaseScheduler) SetOrderWaybillTipByOrder(ctx *jxcontext.Context, order
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
waybill := batchItemList[0].(*model.Waybill)
handler := partner.GetWaybillTipUpdater(waybill.WaybillVendorID)
if err == nil {
if waybill.WaybillVendorID == model.VendorIDDada {
err = handler.UpdateWaybillTip(ctx, waybill.VendorOrgCode, storeDetail.VendorStoreID, waybill.VendorOrderID, waybill.VendorWaybillID, waybill.VendorWaybillID2, utils.Int2Str(storeDetail.CityCode), tipFee)
} else {
err = handler.UpdateWaybillTip(ctx, waybill.VendorOrgCode, storeDetail.VendorStoreID, waybill.VendorOrderID, waybill.VendorWaybillID, waybill.VendorWaybillID2, utils.Int2Str(storeDetail.CityCode), thisTimeTipFee)
}
return nil, err
}, waybills2)
@@ -464,9 +470,9 @@ func (c *BaseScheduler) SetOrderWaybillTipByOrder(ctx *jxcontext.Context, order
if !flag {
//加小费成功扣钱
if order.CreateDeliveryType == model.YES {
partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), int(tipFee), partner.StoreAcctTypeExpendCreateWaybillTip, order.VendorOrderID, "", 0)
partner.CurStoreAcctManager.InsertStoreAcctExpendAndUpdateStoreAcctBalance(ctx, jxutils.GetSaleStoreIDFromOrder(order), int(thisTimeTipFee), partner.StoreAcctTypeExpendCreateWaybillTip, order.VendorOrderID, "", 0)
} else if order.CreateDeliveryType == model.NO {
partner.CurStoreAcctManager.InsertBrandBill(ctx, storeDetail.BrandID, int(tipFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeTipFee, order.VendorOrderID, "")
partner.CurStoreAcctManager.InsertBrandBill(ctx, storeDetail.BrandID, int(thisTimeTipFee), model.BrandBillTypeExpend, model.BrandBillFeeTypeTipFee, order.VendorOrderID, "")
}
}
}

View File

@@ -776,6 +776,7 @@ func (s *DefScheduler) OnWaybillStatusChanged(bill *model.Waybill, isPending boo
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)
}
@@ -999,9 +1000,7 @@ func (s *DefScheduler) solutionJdsOrder(bill *model.Waybill) (err error) {
func (s *DefScheduler) cancelOtherWaybills(savedOrderInfo *WatchOrderInfo, bill2Keep *model.Waybill, cancelReasonID int, cancelReason string) (err error) {
for _, v := range savedOrderInfo.waybills {
if v.Status < model.WaybillStatusEndBegin &&
!model.IsWaybillPlatformOwn(v) &&
(bill2Keep == nil || !(v.WaybillVendorID == bill2Keep.WaybillVendorID && v.VendorWaybillID == bill2Keep.VendorWaybillID)) {
if v.Status < model.WaybillStatusEndBegin && !model.IsWaybillPlatformOwn(v) && (bill2Keep == nil || !(v.WaybillVendorID == bill2Keep.WaybillVendorID && v.VendorWaybillID == bill2Keep.VendorWaybillID)) {
err2 := s.CancelWaybill(v, cancelReasonID, cancelReason)
if err2 == nil {
// 在这里就从map里删除而不是等收到运单结束事件才删除可避免不必要的重复取消第二次取消还会失败
@@ -1011,8 +1010,7 @@ func (s *DefScheduler) cancelOtherWaybills(savedOrderInfo *WatchOrderInfo, bill2
if err == nil {
err = err2
}
partner.CurOrderManager.OnOrderMsg(savedOrderInfo.order, ""+
"", err2.Error())
partner.CurOrderManager.OnOrderMsg(savedOrderInfo.order, "", err2.Error())
}
}

View File

@@ -1291,6 +1291,25 @@ func GetWayBillByOrderID(db *DaoDB, orderStatus, vendorID, waybillVendorID int,
return wayBillList, err
}
func GetComplaintList(db *DaoDB, orderId string, vendorWaybillId string) ([]*model.Waybill, error) {
sql := ` SELECT * FROM waybill WHERE vendor_order_id = ? `
var param []interface{}
param = append(param, orderId)
if vendorWaybillId != "" {
sql += ` AND vendor_waybill_id = ? `
param = append(param, vendorWaybillId)
}
sql += ` AND waybill_vendor_id IN (?,?,?) AND courier_name <> '' AND courier_mobile <> '' ORDER BY waybill_created_at `
param = append(param, model.VendorIDFengNiao, model.VendorIDDada, model.VendorIDMTPS)
var data []*model.Waybill
if err := GetRows(db, &data, sql, param...); err != nil {
return nil, err
}
return data, nil
}
func GetOrdersSupplement(db *DaoDB, storIDs, vendorIDs, statuss []int, vendorOrderID string, fromTime, toTime time.Time, stype, IsReverse, offset, pageSize int) (orderSupplementFee []*model.OrderSupplementFee, totalCount int, err error) {
sql := `
SELECT SQL_CALC_FOUND_ROWS *

View File

@@ -589,6 +589,8 @@ func (c *DeliveryHandler) GetDeliverLiquidatedDamages(orderId string, deliverId
}
}
// 直接返回的 原因是,一个订单在达达发布多次运单时,QueryOrderInfo获取到的运单始终是最后一个运单的配送价格!所以直接返回算了!
return localPrice, nil
// 平台状态兑换金额
var vendorPrice int64 = 0
// 未接单不扣款

View File

@@ -88,12 +88,11 @@ func (c *DeliveryHandler) onWaybillMsg(msg *mtpsapi.CallbackOrderMsg) (retVal *m
order := c.callbackMsg2Waybill(msg)
// 多次取消,只处理第一次
if msg.Status == mtpsapi.OrderStatusCanceled {
bill, err := partner.CurOrderManager.LoadWaybill(msg.MtPeisongID, model.VendorIDMTPS)
if err != nil {
return mtpsapi.Err2CallbackResponse(err, fmt.Sprintf("%s", "获取订单状态错误"))
}
if bill.Status == model.OrderStatusCanceled {
return mtpsapi.SuccessResponse
orderStatus, _ := orderman.FixedOrderManager.GetWayBillStatusList(msg.OrderID, msg.MtPeisongID, model.VendorIDMTPS)
for _, v := range orderStatus {
if v.VendorStatus == "99" {
return mtpsapi.SuccessResponse
}
}
}

View File

@@ -290,6 +290,14 @@ func (d DeliveryHandler) GetRiderInfo(orderId string, deliveryId int64, mtPeison
return result, nil
}
func (c *DeliveryHandler) GetWaybillTip(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID, vendorOrderID, vendorWaybillID, vendorWaybillID2 string) (tipFee int64, err error) {
return api.SfPsAPI.QueryTipFee(vendorWaybillID)
}
func (c *DeliveryHandler) UpdateWaybillTip(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID, vendorOrderID, vendorWaybillID, vendorWaybillID2, cityCode string, tipFee int64) (err error) {
return api.SfPsAPI.AddTipFee(vendorWaybillID, tipFee)
}
// OnWaybillMsg 配送状态更改回调
func OnWaybillMsg(urlIndex string, msg interface{}) (resp *sfps2.CallbackResponse) {
order := GetWaybillByStatus(urlIndex, msg)

View File

@@ -198,6 +198,20 @@ func (d DeliveryHandler) GetWaybillFee(order *model.GoodsOrder) (deliveryFeeInfo
return deliveryFeeInfo, err
}
func (c *DeliveryHandler) GetWaybillTip(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID, vendorOrderID, vendorWaybillID, vendorWaybillID2 string) (tipFee int64, err error) {
// uu跑腿没有获取小费的接口,直接返回系统支付的金额
//order, err := api.UuAPI.GetOrderDetail(vendorOrderID)
//if err == nil {
// tipFee = jxutils.StandardPrice2Int(order.Tips)
//}
//return tipFee, err
return 0, nil
}
func (c *DeliveryHandler) UpdateWaybillTip(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID, vendorOrderID, vendorWaybillID, vendorWaybillID2, cityCode string, tipFee int64) (err error) {
return api.UuAPI.AddTip(vendorOrderID, vendorWaybillID, int(tipFee))
}
func (d DeliveryHandler) ComplaintRider(bill *model.Waybill, resonID int, resonContent string) (err error) {
return fmt.Errorf("UU跑腿暂不支持此操作")
}

View File

@@ -987,19 +987,28 @@ func (c *OrderController) GetComplaintReasons() {
// @Description 投诉骑手
// @Param token header string true "认证token"
// @Param vendorOrderID formData string true "订单ID"
// @Param vendorID formData int true "单所属厂商ID"
// @Param waybillVendorID formData int true "运单所属厂商ID"
// @Param waybillVendorID formData string true "单所属厂商ID"
// @Param complaintID formData int true "投诉原因ID"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /ComplaintRider [post]
func (c *OrderController) ComplaintRider() {
c.callComplaintRider(func(params *tOrderComplaintRiderParams) (retVal interface{}, errCode string, err error) {
if params.WaybillVendorID > 100 {
err = orderman.ComplaintRider(params.Ctx, params.VendorOrderID, params.VendorID, params.WaybillVendorID, params.ComplaintID)
} else {
err = orderman.ComplaintRiderPlatform(params.Ctx, params.VendorOrderID, params.VendorID, params.WaybillVendorID, params.ComplaintID)
}
err = orderman.ComplaintRider(params.Ctx, params.VendorOrderID, params.WaybillVendorID, params.ComplaintID)
return retVal, "", err
})
}
// @Title 获取可投诉骑手列表
// @Description 获取可投诉骑手列表
// @Param token header string true "认证token"
// @Param vendorOrderID formData string true "订单ID"
// @Success 200 {object} controllers.CallResult
// @Failure 200 {object} controllers.CallResult
// @router /ComplaintRiderList [get]
func (c *OrderController) ComplaintRiderList() {
c.callComplaintRiderList(func(params *tOrderComplaintRiderListParams) (retVal interface{}, errCode string, err error) {
retVal, err = orderman.GetComplaintList(params.VendorOrderID)
return retVal, "", err
})
}

View File

@@ -1223,6 +1223,15 @@ 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: "ComplaintRiderList",
Router: `/ComplaintRiderList`,
AllowHTTPMethods: []string{"get"},
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: "ConfirmReceiveGoods",