取消快递订单
This commit is contained in:
@@ -197,31 +197,22 @@ func CreateWayOrder(ctx *jxcontext.Context, param *model.MakeOrderParamReq, user
|
||||
}
|
||||
|
||||
// CancelWayOrder 取消运单 todo
|
||||
func CancelWayOrder(ctx *jxcontext.Context, userId string, param *bida.CancelOrderReq) error {
|
||||
func CancelWayOrder(ctx *jxcontext.Context, userId string, param *bida.CancelOrderReq) (int, error) {
|
||||
var (
|
||||
FailCode = -1
|
||||
SuccessCode = 0
|
||||
tmp_orderNo = param.OrderNo
|
||||
db = dao.GetDB()
|
||||
)
|
||||
// 查询订单
|
||||
globals.SugarLogger.Debug("userid==================", userId)
|
||||
globals.SugarLogger.Debug("param.order_no==================", param.OrderNo)
|
||||
order, err := dao.GetUserVendorOrder(db, userId, param.OrderNo)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Debug("err=================", err)
|
||||
return err
|
||||
return FailCode, err
|
||||
}
|
||||
//order := &model.UserVendorOrder{UserId: userId, LocalWayBill: param.OrderNo}
|
||||
//if err := dao.GetEntity(dao.GetDB(), order, "UserId", "LocalWayBill"); err != nil {
|
||||
// return err
|
||||
//}
|
||||
globals.SugarLogger.Debugf("sdhgeagqweg344w33qgweag== %s ", order.OtherWayBill)
|
||||
globals.SugarLogger.Debugf("jbhbhjdsgbgjhghiwsg== %s ", order.LastOperator)
|
||||
if time.Now().Unix()-order.CreatedAt.Unix() <= 30 {
|
||||
return errors.New("支付成功后,超过30s才能取消")
|
||||
return FailCode, errors.New("支付成功后,超过30s才能取消")
|
||||
}
|
||||
|
||||
// 待支付或者支付失败
|
||||
globals.SugarLogger.Debugf("order.order_status====================== %d", order.OrderStatus)
|
||||
switch order.OrderStatus {
|
||||
case model.OrderStatusFailPay, model.OrderStatusWaitPay: // 待支付订单,或者支付失败订单,不需要退款,取消本地订单以及order记录表
|
||||
db := dao.GetDB()
|
||||
@@ -235,11 +226,11 @@ func CancelWayOrder(ctx *jxcontext.Context, userId string, param *bida.CancelOrd
|
||||
order.OrderStatus = model.OrderStatusCancel
|
||||
if _, err := dao.UpdateEntityTx(tx, order, "OrderStatus"); err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
return FailCode, err
|
||||
}
|
||||
if _, err := dao.UpdateEntityTx(tx, &model.Order{OrderID: param.OrderNo, UserID: userId, Status: model.OrderStatusCancel}, "Status"); err != nil {
|
||||
tx.Rollback()
|
||||
return err
|
||||
return FailCode, err
|
||||
}
|
||||
tx.Commit()
|
||||
case model.OrderStatusSuccessPay, model.OrderStatusWaitPickup: // 支付成功,取消三方订单,本地转取消状态,,原路退款
|
||||
@@ -250,30 +241,26 @@ func CancelWayOrder(ctx *jxcontext.Context, userId string, param *bida.CancelOrd
|
||||
Type: param.Type,
|
||||
}
|
||||
if err := api.QBiDaAPI.CancelOrder(cancelParma); err != nil {
|
||||
globals.SugarLogger.Debug("err==========================", err)
|
||||
return FailCode, err
|
||||
}
|
||||
// 暂时考虑余额支付渠道,加载order表判断支付渠道方式
|
||||
orderWay, err := dao.GetOrderByID(db, tmp_orderNo)
|
||||
if err != nil {
|
||||
|
||||
return err
|
||||
return FailCode, err
|
||||
}
|
||||
globals.SugarLogger.Debug("orderWay.PayPrice==============", orderWay.PayPrice)
|
||||
globals.SugarLogger.Debug("orderWay.PayMethod==============", orderWay.PayMethod)
|
||||
//orderWay := &model.Order{OrderID: param.OrderNo, UserID: userId}
|
||||
//if err := dao.GetEntity(dao.GetDB(), orderWay, "OrderID", "UserID"); err != nil {
|
||||
// return err
|
||||
//}
|
||||
if orderWay.PayMethod == 1 { // 余额支付
|
||||
// 支付方式为余额支付,则需要修改order/userVendorOrder,修改订单状态,给用户账户价钱,生成一个价钱数据
|
||||
} else if orderWay.PayMethod == 2 { // 微信支付
|
||||
// 微信支付原路退款,发起退款申请
|
||||
_, err := RefundOrderByTL(ctx, orderWay, order, order.OtherWayBill, int(order.ChannelFee*100), "申请退款")
|
||||
return err
|
||||
res, err := RefundOrderByTL(ctx, orderWay, order, order.OtherWayBill, int(order.ChannelFee*100), "申请退款")
|
||||
if len(res.VendorRefundID) > 0 {
|
||||
return SuccessCode, err
|
||||
} else {
|
||||
return FailCode, err
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return nil
|
||||
return SuccessCode, nil
|
||||
}
|
||||
|
||||
// QueryOrderDetail 获取订单详细信息
|
||||
|
||||
@@ -151,11 +151,11 @@ func (c *QBiDaExpressController) CancelWayVendorOrder() {
|
||||
OrderNo: params.OrderNo,
|
||||
Type: params.Type,
|
||||
}
|
||||
|
||||
if err := bidaServer.CancelWayOrder(params.Ctx, params.Ctx.GetUserID(), cancel); err != nil {
|
||||
return nil, "", err
|
||||
code, err := bidaServer.CancelWayOrder(params.Ctx, params.Ctx.GetUserID(), cancel)
|
||||
if err != nil {
|
||||
return code, "", err
|
||||
}
|
||||
return nil, "", nil
|
||||
return code, "", nil
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user