新增了 取消未支付订单
This commit is contained in:
@@ -187,7 +187,7 @@ func (r *OrderMemberService) AddOrderMember(tx *gorm.DB, UserId, SystemMemberId
|
||||
// cancelReason:订单取消原因(1:主动取消 2:后台取消 3:支付超时取消)
|
||||
func (r *OrderMemberService) PutCancelOrderMember(tx *gorm.DB, userId, orderId int64, cancelReason int) (bool, error) {
|
||||
// 检测多次请求
|
||||
redisKey := "PutCancelOrderSingle" + fmt.Sprintf("%d", userId) + fmt.Sprintf("%d", orderId)
|
||||
redisKey := "CancelOrderSingle" + fmt.Sprintf("%d", userId) + fmt.Sprintf("%d", orderId)
|
||||
res, _ := global.Redis.Get(context.Background(), redisKey).Result()
|
||||
if res != "" {
|
||||
return false, errors.New("请勿重复操作")
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"hepa-calc-api/api/dao"
|
||||
"hepa-calc-api/api/model"
|
||||
"hepa-calc-api/config"
|
||||
"hepa-calc-api/extend/rabbitMq"
|
||||
"hepa-calc-api/extend/weChat"
|
||||
"hepa-calc-api/global"
|
||||
"hepa-calc-api/utils"
|
||||
@@ -171,19 +172,43 @@ func (r *OrderSingleService) AddOrderSingle(tx *gorm.DB, UserId, QuestionId int6
|
||||
}
|
||||
}
|
||||
|
||||
// 增加至未支付取消订单延迟队列
|
||||
// 增加未支付取消订单延迟队列
|
||||
if payChannel == 1 || payChannel == 2 {
|
||||
delay := 30 * time.Minute
|
||||
|
||||
if config.C.Env == "dev" {
|
||||
delay = 3 * time.Minute
|
||||
}
|
||||
|
||||
data := make(map[string]interface{})
|
||||
data["order_id"] = fmt.Sprintf("%d", orderSingle.OrderId)
|
||||
data["order_no"] = orderSingle.OrderNo
|
||||
data["user_id"] = fmt.Sprintf("%d", orderSingle.UserId)
|
||||
data["order_type"] = 1
|
||||
data["pay_channel"] = orderSingle.PayChannel
|
||||
|
||||
p := rabbitMq.PublishS{
|
||||
QueueName: "cancel.unpay.order.delay.queue",
|
||||
ExchangeName: "amqp.delay.direct",
|
||||
RoutingKey: "CancelUnPayOrder",
|
||||
Message: data,
|
||||
Delay: delay,
|
||||
}
|
||||
err := p.PublishWithDelay()
|
||||
if err != nil {
|
||||
utils.LogJsonErr("添加处理取消未支付订单队列失败:", err.Error())
|
||||
return nil, errors.New("订单创建失败")
|
||||
}
|
||||
}
|
||||
|
||||
return orderSingle, nil
|
||||
}
|
||||
|
||||
// PutCancelOrderSingle 取消单项订单
|
||||
// CancelOrderSingle 取消单项订单
|
||||
// cancelReason:订单取消原因(1:主动取消 2:后台取消 3:支付超时取消)
|
||||
func (r *OrderSingleService) PutCancelOrderSingle(tx *gorm.DB, userId, orderId int64, cancelReason int) (bool, error) {
|
||||
func (r *OrderSingleService) CancelOrderSingle(tx *gorm.DB, userId, orderId int64, cancelReason int) (bool, error) {
|
||||
// 检测多次请求
|
||||
redisKey := "PutCancelOrderSingle" + fmt.Sprintf("%d", userId) + fmt.Sprintf("%d", orderId)
|
||||
redisKey := "CancelOrderSingle" + fmt.Sprintf("%d", userId) + fmt.Sprintf("%d", orderId)
|
||||
res, _ := global.Redis.Get(context.Background(), redisKey).Result()
|
||||
if res != "" {
|
||||
return false, errors.New("请勿重复操作")
|
||||
@@ -373,6 +398,13 @@ func (r *OrderSingleService) CompleteUnPayOrderSingle(tx *gorm.DB, userId int64)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
// 增加题目支付次数
|
||||
questionDao := dao.QuestionDao{}
|
||||
err = questionDao.Inc(tx, single.QuestionId, "pay_count", 1)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
}
|
||||
|
||||
return true, nil
|
||||
|
||||
Reference in New Issue
Block a user