新增药品订单退款

This commit is contained in:
wucongxing8150 2024-06-03 17:11:48 +08:00
parent 0dac42527f
commit ad242af2c4
2 changed files with 66 additions and 54 deletions

View File

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

View File

@ -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:已取消)