diff --git a/api/amqp/consumer/CancelUnPayOrder.go b/api/amqp/consumer/CancelUnPayOrder.go index 3284f1e..05f9a2c 100644 --- a/api/amqp/consumer/CancelUnPayOrder.go +++ b/api/amqp/consumer/CancelUnPayOrder.go @@ -76,7 +76,7 @@ func CancelUnPayOrder(msg amqp091.Delivery) { if err != nil { tx.Rollback() utils.LogJsonErr("consumer.CancelUnPayOrder:", "订单异常") - _ = msg.Ack(false) + _ = msg.Reject(false) return } @@ -101,7 +101,7 @@ func CancelUnPayOrder(msg amqp091.Delivery) { if err != nil { tx.Rollback() utils.LogJsonErr("consumer.CancelUnPayOrder:", "订单异常") - _ = msg.Ack(false) + _ = msg.Reject(false) return } diff --git a/api/amqp/consumer/base.go b/api/amqp/consumer/base.go index 1931fdc..1d52b97 100644 --- a/api/amqp/consumer/base.go +++ b/api/amqp/consumer/base.go @@ -1,5 +1,37 @@ package consumer -func checkHandleNumber(key string) { +import ( + "context" + "hepa-calc-api/global" + "strconv" + "time" +) +// 检测执行次数 +func checkHandleNumber(key string) bool { + c := context.Background() + res, _ := global.Redis.Get(c, key).Result() + if res == "" { + // 添加缓存 + _, _ = global.Redis.Set(c, key, 1, (60*60*2)*time.Second).Result() + return true + } + + // string转int + handleNum, err := strconv.Atoi(res) + if err != nil { + return false + } + + if handleNum > 3 { + // 加入短信队列,通知管理员 + + // 返回false,删除掉缓存 + global.Redis.Del(c, key) + } + + // 增加1次 + global.Redis.Incr(c, key) + + return true } diff --git a/api/controller/UserCollection.go b/api/controller/UserCollection.go index f4b9f39..d0e5f66 100644 --- a/api/controller/UserCollection.go +++ b/api/controller/UserCollection.go @@ -61,6 +61,8 @@ func (b *UserCollection) GetUserCollectionPage(c *gin.Context) { // PutUserCollection 收藏题目 func (r *UserCollection) PutUserCollection(c *gin.Context) { + utils.LogJsonInfo("test", "1222333") + userCollectionRequest := requests.UserCollectionRequest{} req := userCollectionRequest.PutUserCollection if err := c.ShouldBindJSON(&req); err != nil { diff --git a/api/service/OrderSingle.go b/api/service/OrderSingle.go index 7128993..7d94b05 100644 --- a/api/service/OrderSingle.go +++ b/api/service/OrderSingle.go @@ -226,6 +226,7 @@ func (r *OrderSingleService) AddOrderSingle(tx *gorm.DB, UserId, QuestionId int6 utils.LogJsonErr("添加处理取消未支付订单队列失败:", err.Error()) return nil, errors.New("订单创建失败") } + fmt.Println("添加队列成功") } // 会员支付