From f04749607444740334555e7271c8404270ab6e66 Mon Sep 17 00:00:00 2001 From: 李旭 <> Date: Thu, 14 Apr 2022 11:06:57 +0800 Subject: [PATCH] 单个用户没提50次,每次最大200金币加好了 --- src/HttpServer/logic/function.go | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/src/HttpServer/logic/function.go b/src/HttpServer/logic/function.go index bbc0e9d..073c9f8 100644 --- a/src/HttpServer/logic/function.go +++ b/src/HttpServer/logic/function.go @@ -275,11 +275,60 @@ func GetCoinFromToutiao(openid string, deviceid int) (int, error) { return tmp.Data, nil } +//检查今日次数上限 +func checkTodayAddCoinCount(openid string, amount int) (nums int, err error) { + + tim := time.Unix(time.Now().Unix(), 0).Format("0102") + redkey := "ttcc::" + openid + tim + + numstr, err := redishandler.GetRedisClient().GetString(redkey) + if err != nil { + return + } + + if numstr != "" { + nums, _ = strconv.Atoi(numstr) + } + + return +} + +//添加头条金币今日次数 +func addTodayAddCoinCount(openid string, amount int, nums int) (err error) { + nums++ + + tim := time.Unix(time.Now().Unix(), 0).Format("0102") + redkey := "ttcc::" + openid + tim + + expiretime := 86400 + redishandler.GetRedisClient().SetString(redkey, fmt.Sprintf("%d", nums)) + redishandler.GetRedisClient().Expire(redkey, expiretime) + + return +} + func AddCoinToTouTiao(openid string, deviceid, amount int, descr string, btype string, appname string) (int, int, int, bool, error) { gold_coin_extra_add := 0 gold_coin_extra_limit := false + if amount > 200 { + err := errors.New("amount > 200") + logger.Error("AddCoinToTouTiao amount err=%v", err) + return 0, 0, gold_coin_extra_add, gold_coin_extra_limit, err + } + + ttnums, err := checkTodayAddCoinCount(openid, amount) + if err != nil { + logger.Error("AddCoinToTouTiao checkTodayAddCoinCount err=%v", err) + } + + if ttnums > 50 { + err := errors.New(fmt.Sprintf("ttnums > 50::%d", ttnums)) + logger.Error("AddCoinToTouTiao ttnums err=%v", err) + return 0, 0, gold_coin_extra_add, gold_coin_extra_limit, err + } + acctoken, err := GetAccessToken() if err != nil { logger.Error("AddCoinToTouTiao err=%v", err) @@ -307,7 +356,7 @@ func AddCoinToTouTiao(openid string, deviceid, amount int, descr string, btype s reqdata.TaskID = aidconfig.TaskID reqdata.Extra.TaskKey = aidconfig.TaskKey if aidconfig.Description != "" { - reqdata.Description = fmt.Sprintf("%s+%d", aidconfig.Description, amount) + reqdata.Description = aidconfig.Description } } @@ -325,22 +374,25 @@ func AddCoinToTouTiao(openid string, deviceid, amount int, descr string, btype s res, err := BeegoHttpPost(apiurl, reqdata) if err != nil { - logger.Error("AddCoinToTouTiao failed=%v", err) + logger.Error("AddCoinToTouTiao failed=%v", err, apiurl) return 0, 0, gold_coin_extra_add, gold_coin_extra_limit, err } var resp AddcointotoutiaoResp err = json.Unmarshal([]byte(res), &resp) if err != nil { - logger.Error("AddCoinToTouTiao failed=%v", err) + logger.Error("AddCoinToTouTiao failed=%v", err, apiurl) return 0, 0, gold_coin_extra_add, gold_coin_extra_limit, err } if resp.Errcode != 0 { - logger.Error("AddCoinToTouTiao failed=%v", resp) + logger.Error("AddCoinToTouTiao failed=%v", resp, apiurl) return 0, 0, gold_coin_extra_add, gold_coin_extra_limit, errors.New(resp.Errmsg) } + //添加今日调用次数 + go addTodayAddCoinCount(openid, amount, ttnums) + newcoin, err := GetCoinFromToutiao(openid, 1) if err != nil { logger.Error("AddCoinToTouTiao failed=%v", err) -- libgit2 0.21.0