新增取消商品订单
This commit is contained in:
parent
906dfc3abd
commit
615982cd19
@ -368,7 +368,7 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
|||||||
inquiryGroup.GET("/:order_inquiry_id", api.OrderInquiry.GetOrderInquiry)
|
inquiryGroup.GET("/:order_inquiry_id", api.OrderInquiry.GetOrderInquiry)
|
||||||
|
|
||||||
// 取消问诊订单
|
// 取消问诊订单
|
||||||
inquiryGroup.PUT("/:order_inquiry_id", api.OrderInquiry.CancelOrderInquiry)
|
inquiryGroup.PUT("/cancel/:order_inquiry_id", api.OrderInquiry.CancelOrderInquiry)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 问诊订单
|
// 问诊订单
|
||||||
@ -381,7 +381,7 @@ func privateRouter(r *gin.Engine, api controller.Api) {
|
|||||||
productGroup.GET("/:order_product_id", api.OrderProduct.GetOrderProduct)
|
productGroup.GET("/:order_product_id", api.OrderProduct.GetOrderProduct)
|
||||||
|
|
||||||
// 取消药品订单
|
// 取消药品订单
|
||||||
productGroup.PUT("/:order_product_id", api.OrderProduct.CancelOrderProduct)
|
productGroup.PUT("/cancel/:order_product_id", api.OrderProduct.CancelOrderProduct)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,13 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"hospital-admin-api/api/dao"
|
"hospital-admin-api/api/dao"
|
||||||
|
"hospital-admin-api/api/model"
|
||||||
"hospital-admin-api/api/responses/orderProductResponse"
|
"hospital-admin-api/api/responses/orderProductResponse"
|
||||||
|
"hospital-admin-api/config"
|
||||||
|
"hospital-admin-api/extend/weChat"
|
||||||
|
"hospital-admin-api/global"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type OrderProductService struct {
|
type OrderProductService struct {
|
||||||
@ -111,90 +117,162 @@ func (r *OrderProductService) GetOrderProduct(orderProductId int64) (getOrderPro
|
|||||||
|
|
||||||
// CancelOrderProduct 取消药品订单
|
// CancelOrderProduct 取消药品订单
|
||||||
func (r *OrderProductService) CancelOrderProduct(orderProductId int64) (bool, error) {
|
func (r *OrderProductService) CancelOrderProduct(orderProductId int64) (bool, error) {
|
||||||
// // 获取药品订单详情
|
// 获取药品订单详情
|
||||||
// orderProductDao := dao.OrderProductDao{}
|
orderProductDao := dao.OrderProductDao{}
|
||||||
// orderProduct, err := orderProductDao.GetOrderProductPreloadById(orderProductId)
|
orderProduct, err := orderProductDao.GetOrderProductPreloadById(orderProductId)
|
||||||
// if err != nil || orderProduct == nil {
|
if err != nil || orderProduct == nil {
|
||||||
// return false, errors.New("订单数据错误")
|
return false, errors.New("订单数据错误")
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// // 检测订单状态
|
// 检测订单状态
|
||||||
// if orderProduct.OrderProductStatus == 1 {
|
if orderProduct.OrderProductStatus == 1 {
|
||||||
// return false, errors.New("订单处于待支付状态,无法取消")
|
return false, errors.New("订单处于待支付状态,无法取消")
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if orderProduct.OrderProductStatus == 3 {
|
if orderProduct.OrderProductStatus == 3 {
|
||||||
// return false, errors.New("订单已发货,无法取消")
|
return false, errors.New("订单已发货,无法取消")
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if orderProduct.OrderProductStatus == 4 {
|
if orderProduct.OrderProductStatus == 4 {
|
||||||
// return false, errors.New("订单已签收,无法取消")
|
return false, errors.New("订单已签收,无法取消")
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if orderProduct.OrderProductStatus == 5 {
|
if orderProduct.OrderProductStatus == 5 {
|
||||||
// return false, errors.New("订单已取消,无法取消")
|
return false, errors.New("订单已取消,无法取消")
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// // 检测订单退款状态
|
// 已上报暂不允许取消订单
|
||||||
// if orderProduct.RefundStatus == 1 {
|
if orderProduct.ReportPreStatus == 1 {
|
||||||
// return false, errors.New("订单申请退款中,无法取消")
|
return false, errors.New("订单已上报,暂不允许取消")
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// if orderProduct.RefundStatus == 2 {
|
// 检测订单退款状态
|
||||||
// return false, errors.New("订单正在退款中,无法取消")
|
if orderProduct.RefundStatus == 1 {
|
||||||
// }
|
return false, errors.New("订单申请退款中,无法取消")
|
||||||
//
|
}
|
||||||
// if orderProduct.RefundStatus == 3 {
|
|
||||||
// return false, errors.New("订单已退款成功,无法取消")
|
if orderProduct.RefundStatus == 2 {
|
||||||
// }
|
return false, errors.New("订单正在退款中,无法取消")
|
||||||
//
|
}
|
||||||
// if orderProduct.RefundStatus == 6 {
|
|
||||||
// return false, errors.New("订单退款异常,请联系技术人员")
|
if orderProduct.RefundStatus == 3 {
|
||||||
// }
|
return false, errors.New("订单已退款成功,无法取消")
|
||||||
//
|
}
|
||||||
// // 检测订单支付状态
|
|
||||||
// if orderProduct.PayStatus != 2 {
|
if orderProduct.RefundStatus == 6 {
|
||||||
// return false, errors.New("订单未支付,无需取消")
|
return false, errors.New("订单退款异常,请联系技术人员")
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// // 开始事务
|
// 检测订单支付状态
|
||||||
// tx := global.Db.Begin()
|
if orderProduct.PayStatus != 2 {
|
||||||
// defer func() {
|
return false, errors.New("订单未支付,无需取消")
|
||||||
// if r := recover(); r != nil {
|
}
|
||||||
// tx.Rollback()
|
|
||||||
// }
|
// 开始事务
|
||||||
// }()
|
tx := global.Db.Begin()
|
||||||
//
|
defer func() {
|
||||||
// // 药品订单修改数据
|
if r := recover(); r != nil {
|
||||||
// orderProductData := make(map[string]interface{})
|
tx.Rollback()
|
||||||
//
|
}
|
||||||
// // 退款编号
|
}()
|
||||||
// refundNo := strconv.FormatInt(global.Snowflake.Generate().Int64(), 10)
|
|
||||||
//
|
// 药品订单修改数据
|
||||||
// // 退款状态转换
|
orderProductData := make(map[string]interface{})
|
||||||
// var productRefundStatus int
|
|
||||||
// var successTime time.Time
|
// 退款编号
|
||||||
// var refundId string
|
refundNo := strconv.FormatInt(global.Snowflake.Generate().Int64(), 10)
|
||||||
//
|
|
||||||
// refundRequest := weChat.RefundRequest{
|
// 退款状态转换
|
||||||
// TransactionId: orderProduct.EscrowTradeNo,
|
var refundStatus int
|
||||||
// OutTradeNo: orderProduct.OrderProductNo,
|
var successTime time.Time
|
||||||
// OutRefundNo: refundNo,
|
var refundId string
|
||||||
// Reason: "客服取消",
|
|
||||||
// PaymentAmountTotal: int64(orderProduct.PaymentAmountTotal * 100),
|
refundRequest := weChat.RefundRequest{
|
||||||
// NotifyUrl: config.C.Wechat.RefundNotifyDomain + config.C.Wechat.PatientProductRefundNotifyUrl,
|
TransactionId: orderProduct.EscrowTradeNo,
|
||||||
// }
|
OutTradeNo: orderProduct.OrderProductNo,
|
||||||
//
|
OutRefundNo: refundNo,
|
||||||
// refund, err := refundRequest.Refund()
|
Reason: "客服取消",
|
||||||
// if err != nil {
|
PaymentAmountTotal: int64(orderProduct.PaymentAmountTotal * 100),
|
||||||
// tx.Rollback()
|
NotifyUrl: config.C.Wechat.RefundNotifyDomain + config.C.Wechat.PatientProductRefundNotifyUrl,
|
||||||
// return false, errors.New(err.Error())
|
}
|
||||||
// }
|
|
||||||
//
|
refund, err := refundRequest.Refund()
|
||||||
// if refund.Status == nil {
|
if err != nil {
|
||||||
// tx.Rollback()
|
tx.Rollback()
|
||||||
// return false, errors.New("退款状态错误")
|
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
|
||||||
|
}
|
||||||
|
} 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
|
||||||
|
|
||||||
|
orderProductData["refund_status"] = refundStatus
|
||||||
|
orderProductData["order_product_status"] = 5 // 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||||||
|
orderProductData["cancel_time"] = time.Now().Format("2006-01-02 15:04:05") // 订单取消时间
|
||||||
|
orderProductData["cancel_reason"] = 4 // 订单取消原因(1:主动取消 2:复核失败/库存不足 3:支付超时 4:客服取消)
|
||||||
|
orderProductData["cancel_remarks"] = "客服取消" // 取消订单备注(自动添加)
|
||||||
|
|
||||||
|
// 修改问诊订单退款状态
|
||||||
|
err = orderProductDao.EditOrderProductById(tx, orderProductId, orderProductData)
|
||||||
|
if err != nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return false, errors.New("取消订单失败")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 新增退款表
|
||||||
|
orderProductRefund := &model.OrderProductRefund{
|
||||||
|
PatientId: orderProduct.PatientId,
|
||||||
|
OrderProductId: orderProductId,
|
||||||
|
OrderProductNo: orderProduct.OrderProductNo,
|
||||||
|
ProductRefundNo: refundNo,
|
||||||
|
RefundId: refundId,
|
||||||
|
ProductRefundStatus: refundStatus,
|
||||||
|
RefundTotal: orderProduct.PaymentAmountTotal,
|
||||||
|
RefundReason: "客服取消",
|
||||||
|
SuccessTime: model.LocalTime(successTime),
|
||||||
|
}
|
||||||
|
|
||||||
|
orderProductRefundDao := dao.OrderProductRefundDao{}
|
||||||
|
orderProductRefund, err = orderProductRefundDao.AddOrderProductRefund(tx, orderProductRefund)
|
||||||
|
if err != nil || orderProductRefund == nil {
|
||||||
|
tx.Rollback()
|
||||||
|
return false, errors.New(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
tx.Commit()
|
||||||
|
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user