Commit f04749607444740334555e7271c8404270ab6e66
1 parent
35b0ac74
Exists in
master
单个用户没提50次,每次最大200金币加好了
Showing
1 changed file
with
56 additions
and
4 deletions
Show diff stats
src/HttpServer/logic/function.go
@@ -275,11 +275,60 @@ func GetCoinFromToutiao(openid string, deviceid int) (int, error) { | @@ -275,11 +275,60 @@ func GetCoinFromToutiao(openid string, deviceid int) (int, error) { | ||
275 | return tmp.Data, nil | 275 | return tmp.Data, nil |
276 | } | 276 | } |
277 | 277 | ||
278 | +//检查今日次数上限 | ||
279 | +func checkTodayAddCoinCount(openid string, amount int) (nums int, err error) { | ||
280 | + | ||
281 | + tim := time.Unix(time.Now().Unix(), 0).Format("0102") | ||
282 | + redkey := "ttcc::" + openid + tim | ||
283 | + | ||
284 | + numstr, err := redishandler.GetRedisClient().GetString(redkey) | ||
285 | + if err != nil { | ||
286 | + return | ||
287 | + } | ||
288 | + | ||
289 | + if numstr != "" { | ||
290 | + nums, _ = strconv.Atoi(numstr) | ||
291 | + } | ||
292 | + | ||
293 | + return | ||
294 | +} | ||
295 | + | ||
296 | +//添加头条金币今日次数 | ||
297 | +func addTodayAddCoinCount(openid string, amount int, nums int) (err error) { | ||
298 | + nums++ | ||
299 | + | ||
300 | + tim := time.Unix(time.Now().Unix(), 0).Format("0102") | ||
301 | + redkey := "ttcc::" + openid + tim | ||
302 | + | ||
303 | + expiretime := 86400 | ||
304 | + redishandler.GetRedisClient().SetString(redkey, fmt.Sprintf("%d", nums)) | ||
305 | + redishandler.GetRedisClient().Expire(redkey, expiretime) | ||
306 | + | ||
307 | + return | ||
308 | +} | ||
309 | + | ||
278 | func AddCoinToTouTiao(openid string, deviceid, amount int, descr string, btype string, appname string) (int, int, int, bool, error) { | 310 | func AddCoinToTouTiao(openid string, deviceid, amount int, descr string, btype string, appname string) (int, int, int, bool, error) { |
279 | 311 | ||
280 | gold_coin_extra_add := 0 | 312 | gold_coin_extra_add := 0 |
281 | gold_coin_extra_limit := false | 313 | gold_coin_extra_limit := false |
282 | 314 | ||
315 | + if amount > 200 { | ||
316 | + err := errors.New("amount > 200") | ||
317 | + logger.Error("AddCoinToTouTiao amount err=%v", err) | ||
318 | + return 0, 0, gold_coin_extra_add, gold_coin_extra_limit, err | ||
319 | + } | ||
320 | + | ||
321 | + ttnums, err := checkTodayAddCoinCount(openid, amount) | ||
322 | + if err != nil { | ||
323 | + logger.Error("AddCoinToTouTiao checkTodayAddCoinCount err=%v", err) | ||
324 | + } | ||
325 | + | ||
326 | + if ttnums > 50 { | ||
327 | + err := errors.New(fmt.Sprintf("ttnums > 50::%d", ttnums)) | ||
328 | + logger.Error("AddCoinToTouTiao ttnums err=%v", err) | ||
329 | + return 0, 0, gold_coin_extra_add, gold_coin_extra_limit, err | ||
330 | + } | ||
331 | + | ||
283 | acctoken, err := GetAccessToken() | 332 | acctoken, err := GetAccessToken() |
284 | if err != nil { | 333 | if err != nil { |
285 | logger.Error("AddCoinToTouTiao err=%v", err) | 334 | logger.Error("AddCoinToTouTiao err=%v", err) |
@@ -307,7 +356,7 @@ func AddCoinToTouTiao(openid string, deviceid, amount int, descr string, btype s | @@ -307,7 +356,7 @@ func AddCoinToTouTiao(openid string, deviceid, amount int, descr string, btype s | ||
307 | reqdata.TaskID = aidconfig.TaskID | 356 | reqdata.TaskID = aidconfig.TaskID |
308 | reqdata.Extra.TaskKey = aidconfig.TaskKey | 357 | reqdata.Extra.TaskKey = aidconfig.TaskKey |
309 | if aidconfig.Description != "" { | 358 | if aidconfig.Description != "" { |
310 | - reqdata.Description = fmt.Sprintf("%s+%d", aidconfig.Description, amount) | 359 | + reqdata.Description = aidconfig.Description |
311 | } | 360 | } |
312 | } | 361 | } |
313 | 362 | ||
@@ -325,22 +374,25 @@ func AddCoinToTouTiao(openid string, deviceid, amount int, descr string, btype s | @@ -325,22 +374,25 @@ func AddCoinToTouTiao(openid string, deviceid, amount int, descr string, btype s | ||
325 | 374 | ||
326 | res, err := BeegoHttpPost(apiurl, reqdata) | 375 | res, err := BeegoHttpPost(apiurl, reqdata) |
327 | if err != nil { | 376 | if err != nil { |
328 | - logger.Error("AddCoinToTouTiao failed=%v", err) | 377 | + logger.Error("AddCoinToTouTiao failed=%v", err, apiurl) |
329 | return 0, 0, gold_coin_extra_add, gold_coin_extra_limit, err | 378 | return 0, 0, gold_coin_extra_add, gold_coin_extra_limit, err |
330 | } | 379 | } |
331 | 380 | ||
332 | var resp AddcointotoutiaoResp | 381 | var resp AddcointotoutiaoResp |
333 | err = json.Unmarshal([]byte(res), &resp) | 382 | err = json.Unmarshal([]byte(res), &resp) |
334 | if err != nil { | 383 | if err != nil { |
335 | - logger.Error("AddCoinToTouTiao failed=%v", err) | 384 | + logger.Error("AddCoinToTouTiao failed=%v", err, apiurl) |
336 | return 0, 0, gold_coin_extra_add, gold_coin_extra_limit, err | 385 | return 0, 0, gold_coin_extra_add, gold_coin_extra_limit, err |
337 | } | 386 | } |
338 | 387 | ||
339 | if resp.Errcode != 0 { | 388 | if resp.Errcode != 0 { |
340 | - logger.Error("AddCoinToTouTiao failed=%v", resp) | 389 | + logger.Error("AddCoinToTouTiao failed=%v", resp, apiurl) |
341 | return 0, 0, gold_coin_extra_add, gold_coin_extra_limit, errors.New(resp.Errmsg) | 390 | return 0, 0, gold_coin_extra_add, gold_coin_extra_limit, errors.New(resp.Errmsg) |
342 | } | 391 | } |
343 | 392 | ||
393 | + //添加今日调用次数 | ||
394 | + go addTodayAddCoinCount(openid, amount, ttnums) | ||
395 | + | ||
344 | newcoin, err := GetCoinFromToutiao(openid, 1) | 396 | newcoin, err := GetCoinFromToutiao(openid, 1) |
345 | if err != nil { | 397 | if err != nil { |
346 | logger.Error("AddCoinToTouTiao failed=%v", err) | 398 | logger.Error("AddCoinToTouTiao failed=%v", err) |