|
@@ -18,7 +18,7 @@ import (
|
|
|
"go.uber.org/zap"
|
|
|
)
|
|
|
|
|
|
-func Check(appID string, productID int, c *gin.Context, getData func() ([]map[string]interface{}, int, error), param, ip string) {
|
|
|
+func Check(appID string, productID int, c *gin.Context, getData func() ([]map[string]interface{}, int, error), param, ip string, concurrentTest bool) {
|
|
|
lock.MainLock.Lock()
|
|
|
userLock := lock.UserLockMap[appID]
|
|
|
lock.MainLock.Unlock()
|
|
@@ -65,27 +65,6 @@ func Check(appID string, productID int, c *gin.Context, getData func() ([]map[st
|
|
|
product := GetProductByID(productID)
|
|
|
userLock.Lock()
|
|
|
log.Println(param + "锁住......")
|
|
|
- //
|
|
|
- // ctx, _ := context.WithTimeout(c, 20*time.Second)
|
|
|
- // go func() {
|
|
|
- // var i = 0
|
|
|
- // for {
|
|
|
- // select {
|
|
|
- // case <-ctx.Done():
|
|
|
- // userLock.Unlock()
|
|
|
- // return
|
|
|
- // case <-time.After(time.Second * time.Duration(2)):
|
|
|
- // i++
|
|
|
- // if i == 10 {
|
|
|
- // userLock.Unlock()
|
|
|
- // return
|
|
|
- // }
|
|
|
- // continue
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }()
|
|
|
- // time.Sleep(time.Second * time.Duration(25))
|
|
|
- //
|
|
|
db.GetSFISDB().First(userProduct, &model.UserProduct{AppID: appID, ProductID: productID})
|
|
|
// costModel = 0
|
|
|
switch costModel {
|
|
@@ -112,7 +91,9 @@ func Check(appID string, productID int, c *gin.Context, getData func() ([]map[st
|
|
|
})
|
|
|
limittodaykey := fmt.Sprintf("limittoday_%d_%d_%s", time.Now().Day(), userProduct.ProductID, userProduct.AppID)
|
|
|
redis.Incr("limit", limittodaykey)
|
|
|
- response.FailWithDetailed(response.SUCCESS, datas, "OK", c)
|
|
|
+ if !concurrentTest {
|
|
|
+ response.FailWithDetailed(response.SUCCESS, datas, "OK", c)
|
|
|
+ }
|
|
|
} else {
|
|
|
if strings.Contains(errStr, "不足") {
|
|
|
response.FailWithDetailed(response.LeftNumEmpty, nil, errStr, c)
|