新增药品订单退款
This commit is contained in:
parent
0dac42527f
commit
ad242af2c4
@ -23,6 +23,7 @@ type OrderProduct struct {
|
||||
IsDelete int `gorm:"column:is_delete;type:tinyint(1);default:0;comment:删除状态(0:否 1:是)" json:"is_delete"`
|
||||
CancelReason int `gorm:"column:cancel_reason;type:tinyint(1);comment:订单取消原因(1:主动取消 2:复核失败/库存不足 3:支付超时 4:客服取消)" json:"cancel_reason"`
|
||||
AmountTotal float64 `gorm:"column:amount_total;type:decimal(10,2);default:0.00;comment:订单金额" json:"amount_total"`
|
||||
CouponAmountTotal float64 `gorm:"column:coupon_amount_total;type:decimal(10,2);default:0.00;comment:优惠卷总金额" json:"coupon_amount_total"`
|
||||
PaymentAmountTotal float64 `gorm:"column:payment_amount_total;type:decimal(10,2);default:0.00;comment:实际付款金额" json:"payment_amount_total"`
|
||||
LogisticsFee float64 `gorm:"column:logistics_fee;type:decimal(10,2);default:0.00;comment:运费金额" json:"logistics_fee"`
|
||||
LogisticsNo string `gorm:"column:logistics_no;type:varchar(100);comment:物流编号" json:"logistics_no"`
|
||||
|
||||
@ -161,67 +161,78 @@ func (r *OrderProductService) CancelOrderProduct(req requests.CancelOrderProduct
|
||||
var successTime time.Time
|
||||
var refundId string
|
||||
|
||||
// // 通知处方平台订单取消
|
||||
// _, err = prescription.NoticePreOrderCancel(orderProduct.OrderProductNo)
|
||||
// if err != nil {
|
||||
// tx.Rollback()
|
||||
// return false, err
|
||||
// }
|
||||
|
||||
// 微信退款
|
||||
refundRequest := weChat.RefundRequest{
|
||||
TransactionId: orderProduct.EscrowTradeNo,
|
||||
OutTradeNo: orderProduct.OrderProductNo,
|
||||
OutRefundNo: refundNo,
|
||||
Reason: "客服取消",
|
||||
RefundAmount: int64(orderProduct.PaymentAmountTotal * 100),
|
||||
PaymentAmountTotal: int64(orderProduct.PaymentAmountTotal * 100),
|
||||
NotifyUrl: config.C.Wechat.RefundNotifyDomain + config.C.Wechat.PatientProductRefundNotifyUrl,
|
||||
}
|
||||
|
||||
refund, err := refundRequest.Refund(2)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
if refund.Status == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("退款状态错误")
|
||||
}
|
||||
|
||||
if *refund.Status == "SUCCESS" {
|
||||
// 退款成功
|
||||
refundStatus = 3
|
||||
|
||||
if refund.SuccessTime != nil {
|
||||
successTime = *refund.SuccessTime
|
||||
if orderProduct.PaymentAmountTotal > 0 {
|
||||
// 微信退款
|
||||
refundRequest := weChat.RefundRequest{
|
||||
TransactionId: orderProduct.EscrowTradeNo,
|
||||
OutTradeNo: orderProduct.OrderProductNo,
|
||||
OutRefundNo: refundNo,
|
||||
Reason: "客服取消",
|
||||
RefundAmount: int64(orderProduct.PaymentAmountTotal * 100),
|
||||
PaymentAmountTotal: int64(orderProduct.PaymentAmountTotal * 100),
|
||||
NotifyUrl: config.C.Wechat.RefundNotifyDomain + config.C.Wechat.PatientProductRefundNotifyUrl,
|
||||
}
|
||||
} else if *refund.Status == "CLOSED" {
|
||||
// 退款关闭
|
||||
refundStatus = 5
|
||||
|
||||
} else if *refund.Status == "PROCESSING" {
|
||||
// 退款处理中
|
||||
refundStatus = 2
|
||||
refund, err := refundRequest.Refund(2)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New(err.Error())
|
||||
}
|
||||
|
||||
} else if *refund.Status == "ABNORMAL" {
|
||||
// 退款异常
|
||||
tx.Rollback()
|
||||
return false, errors.New("退款状态错误")
|
||||
if refund.Status == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("退款状态错误")
|
||||
}
|
||||
|
||||
if *refund.Status == "SUCCESS" {
|
||||
// 退款成功
|
||||
refundStatus = 3
|
||||
|
||||
if refund.SuccessTime != nil {
|
||||
successTime = *refund.SuccessTime
|
||||
}
|
||||
} else if *refund.Status == "CLOSED" {
|
||||
// 退款关闭
|
||||
refundStatus = 5
|
||||
|
||||
} else if *refund.Status == "PROCESSING" {
|
||||
// 退款处理中
|
||||
refundStatus = 2
|
||||
|
||||
} else if *refund.Status == "ABNORMAL" {
|
||||
// 退款异常
|
||||
tx.Rollback()
|
||||
return false, errors.New("退款状态错误")
|
||||
} else {
|
||||
tx.Rollback()
|
||||
return false, errors.New("退款状态错误")
|
||||
}
|
||||
|
||||
if refund.RefundId == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("缺少退款订单编号")
|
||||
}
|
||||
|
||||
// 退款编号
|
||||
refundId = *refund.RefundId
|
||||
} else {
|
||||
tx.Rollback()
|
||||
return false, errors.New("退款状态错误")
|
||||
}
|
||||
// 支付金额为0,模拟退款
|
||||
refundId = "模拟退款:" + strconv.FormatInt(global.Snowflake.Generate().Int64(), 10)
|
||||
refundStatus = 3
|
||||
successTime = time.Now()
|
||||
|
||||
if refund.RefundId == nil {
|
||||
tx.Rollback()
|
||||
return false, errors.New("缺少退款订单编号")
|
||||
// 模拟退款时手动退还优惠卷
|
||||
if orderProduct.CouponAmountTotal > 0 {
|
||||
orderService := OrderService{}
|
||||
res, err := orderService.ReturnOrderCoupon(orderProduct.OrderProductNo, tx)
|
||||
if err != nil || !res {
|
||||
// 退还优惠卷失败
|
||||
tx.Rollback()
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 退款编号
|
||||
refundId = *refund.RefundId
|
||||
|
||||
// 修改问诊订单退款状态
|
||||
orderProductData["refund_status"] = refundStatus
|
||||
orderProductData["order_product_status"] = 5 // 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user