From 4fcc94553e4124a552383caeec047ccae3ac5755 Mon Sep 17 00:00:00 2001 From: 李旭 Date: Wed, 15 Sep 2021 11:01:56 +0800 Subject: [PATCH] 返回新增加成金币 --- src/HttpServer/logic/datadef.go | 50 +++++++++++++++++++++++++------------------------- src/HttpServer/logic/function.go | 26 +++++++++++++++----------- src/HttpServer/logic/logic.go | 9 ++++++--- 3 files changed, 46 insertions(+), 39 deletions(-) diff --git a/src/HttpServer/logic/datadef.go b/src/HttpServer/logic/datadef.go index 220b521..0301d8e 100644 --- a/src/HttpServer/logic/datadef.go +++ b/src/HttpServer/logic/datadef.go @@ -4,16 +4,17 @@ type AddcointotoutiaoReq struct { Access_token string `json:"access_token"` Open_id string `json:"open_id"` //Device_id int `json:"device_id"` - Amount int `json:"amount"` - Description string `json:"description"` - Bonus_type string `json:"bonus_type"` - GlobalID int64 `json:"global_id"` + Amount int `json:"amount"` + Description string `json:"description"` + Bonus_type string `json:"bonus_type"` + GlobalID int64 `json:"global_id"` } type AddcointotoutiaoResp struct { - Errcode int `json:"errcode"` - Errmsg string `json:"errmsg"` - Data int `json:"data"` + Errcode int `json:"errcode"` + Errmsg string `json:"errmsg"` + Data int `json:"data"` + Extra_ADD int `json:"gold_coin_extra_add"` } type GetAccessTokenResp struct { @@ -31,9 +32,9 @@ type GetOpenidResp struct { } type GetGlobalIDResp struct { - GlobalID int64 `json:"global_id"` - Errcode int `json:"errcode"` - Errmsg string `json:"errmsg"` + GlobalID int64 `json:"global_id"` + Errcode int `json:"errcode"` + Errmsg string `json:"errmsg"` } //-------------------------------------------------------------------------- @@ -68,6 +69,7 @@ type FetchproteryboxData struct { Curlevle int64 `json:"curlevle"` Leftcnt int `json:"leftcnt"` Curpoerty int64 `json:"curpoerty"` + ExtraGold int `json:"extragold"` } type FetchproteryboxResp struct { @@ -95,12 +97,13 @@ type AddgoldReq struct { Openid string `json:"openid"` Device_id int `json:"device_id"` Gold_num int `json:"gold_num"` - Gold_Type int `json:"gold_type"` + Gold_Type int `json:"gold_type"` } type AddgoldData struct { Taoalgoldnum int `json:"taoalgoldnum"` Rewardgold int `json:"rewardgold"` + ExtraGold int `json:"extragold"` } type AddgoldResp struct { @@ -135,6 +138,7 @@ type DosignData struct { Curday int `json:"curday"` Issigntaday int `json:"issigntaday"` Taoalgoldnum int `json:"taoalgoldnum"` + ExtraGold int `json:"extragold"` } type DosignResp struct { @@ -235,27 +239,24 @@ type PlayerData struct { OnLineGold int `json:"onLineGold"` } - type GetToutiaoGrowthRightResp struct { - StatusCode int `json:"status_code"` - Message string `json:"message"` - ServerTime int `json:"server_time"` - Data GetToutiaoGrowthRightDataResp `json:"data"` + StatusCode int `json:"status_code"` + Message string `json:"message"` + ServerTime int `json:"server_time"` + Data GetToutiaoGrowthRightDataResp `json:"data"` } type GetToutiaoGrowthRightDataResp struct { - GrowthType int `json:"growth_type"` - GrowthLv int `json:"growth_lv"` - CoinBuff int `json:"coin_buff"` - SpeedBuff int `json:"speed_buff"` + GrowthType int `json:"growth_type"` + GrowthLv int `json:"growth_lv"` + CoinBuff int `json:"coin_buff"` + SpeedBuff int `json:"speed_buff"` RewardStatus int `json:"reward_status"` } - - type GetGrowthRightResp struct { - ErrNum int `json:"errNum"` - RetMsg string `json:"retMsg"` + ErrNum int `json:"errNum"` + RetMsg string `json:"retMsg"` RetData GetToutiaoGrowthRightDataResp `json:"retData"` } @@ -263,4 +264,3 @@ type GetGrowthRightReq struct { Openid string `json:"openid"` Device_id int `json:"device_id"` } - diff --git a/src/HttpServer/logic/function.go b/src/HttpServer/logic/function.go index 3663931..b02cf97 100644 --- a/src/HttpServer/logic/function.go +++ b/src/HttpServer/logic/function.go @@ -273,18 +273,21 @@ func GetCoinFromToutiao(openid string, deviceid int) (int, error) { return tmp.Data, nil } -func AddCoinToTouTiao(openid string, deviceid, amount int, descr string, btype string) (int, int, error) { +func AddCoinToTouTiao(openid string, deviceid, amount int, descr string, btype string) (int, int, int, error) { + + gold_coin_extra_add := 0 + acctoken, err := GetAccessToken() if err != nil { logger.Error("AddCoinToTouTiao err=%v", err) - return 0, 0, err + return 0, 0, gold_coin_extra_add, err } //获取 GlobalID globalid, err := GetBytedanceGlobalID(acctoken, openid) if err != nil { logger.Error("AddCoinToTouTiao GetBytedanceGlobalID err=%v", err) - return 0, 0, err + return 0, 0, gold_coin_extra_add, err } var reqdata AddcointotoutiaoReq @@ -299,7 +302,7 @@ func AddCoinToTouTiao(openid string, deviceid, amount int, descr string, btype s bys, err := json.Marshal(&reqdata) if err != nil { logger.Error("AddCoinToTouTiao failed=%v", err) - return 0, 0, err + return 0, 0, gold_coin_extra_add, err } //计算签名 @@ -307,32 +310,33 @@ func AddCoinToTouTiao(openid string, deviceid, amount int, descr string, btype s signature := CreateCommonBytedanceSign(bys, openid) apiurl := ADDCOINTOTOUTIAOURL + "?signature=" + signature - res, err := BeegoHttpPost(apiurl, reqdata) if err != nil { logger.Error("AddCoinToTouTiao failed=%v", err) - return 0, 0, err + return 0, 0, gold_coin_extra_add, err } - var resp AddcointotoutiaoResp err = json.Unmarshal([]byte(res), &resp) if err != nil { logger.Error("AddCoinToTouTiao failed=%v", err) - return 0, 0, err + return 0, 0, gold_coin_extra_add, err } if resp.Errcode != 0 { logger.Error("AddCoinToTouTiao failed=%v", resp) - return 0, 0, errors.New(resp.Errmsg) + return 0, 0, gold_coin_extra_add, errors.New(resp.Errmsg) } newcoin, err := GetCoinFromToutiao(openid, 1) if err != nil { logger.Error("AddCoinToTouTiao failed=%v", err) - return 0, 0, err + return 0, 0, gold_coin_extra_add, err } - return resp.Data, newcoin, nil + + gold_coin_extra_add = resp.Extra_ADD + + return resp.Data, newcoin, gold_coin_extra_add, nil } func BeegoHttpPost(url string, reqdata AddcointotoutiaoReq) (string, error) { diff --git a/src/HttpServer/logic/logic.go b/src/HttpServer/logic/logic.go index 35be0d2..625cd32 100644 --- a/src/HttpServer/logic/logic.go +++ b/src/HttpServer/logic/logic.go @@ -250,7 +250,7 @@ func HandlerDosign(w http.ResponseWriter, data string) { } //加金币 - _, sumgold, err := AddCoinToTouTiao(rdata.Openid, 1, cfg.Reward, "签到奖励", "other") + _, sumgold, extragold, err := AddCoinToTouTiao(rdata.Openid, 1, cfg.Reward, "签到奖励", "other") if err != nil { logger.Info(" HandlerAddgold AddCoinToTouTiao failed:%v,for:%v", err, data) resp.RetMsg = "调用头条接口失败" @@ -262,6 +262,7 @@ func HandlerDosign(w http.ResponseWriter, data string) { resp.RetData.Curround = uinfo.SignRound resp.RetData.Curday = uinfo.SingDay resp.RetData.Taoalgoldnum = sumgold + resp.RetData.ExtraGold = extragold break } @@ -342,7 +343,7 @@ func HandlerAddgold(w http.ResponseWriter, data string) { break } - addnum, sumnum, err := AddCoinToTouTiao(rdata.Openid, 1, rdata.Gold_num, "闯关送金币", "other") + addnum, sumnum, extragold, err := AddCoinToTouTiao(rdata.Openid, 1, rdata.Gold_num, "闯关送金币", "other") if err != nil { logger.Info(" HandlerAddgold property failed:%v,for:%v", err, data) resp.RetMsg = "调用头条接口失败" @@ -353,6 +354,7 @@ func HandlerAddgold(w http.ResponseWriter, data string) { uinfo.PassLvGold += addnum resp.RetData.Taoalgoldnum = sumnum resp.RetData.Rewardgold = rdata.Gold_num + resp.RetData.ExtraGold = extragold //保存 err = SaveUserInfo(uinfo) if err != nil { @@ -475,7 +477,7 @@ func HandlerFetchproterybox(w http.ResponseWriter, data string) { } //加金币 - addgold, sumgold, err := AddCoinToTouTiao(rdata.Openid, 1, cfg.Reward, "每日领取宝箱奖励", "other") + addgold, sumgold, extragold, err := AddCoinToTouTiao(rdata.Openid, 1, cfg.Reward, "每日领取宝箱奖励", "other") if err != nil { logger.Info(" HandlerFetchproterybox property failed:%v,for:%v", err, data) resp.RetMsg = "调用头条接口失败" @@ -493,6 +495,7 @@ func HandlerFetchproterybox(w http.ResponseWriter, data string) { resp.RetData.Leftcnt = uinfo.LeftCnt //resp.RetData.Leftcnt = Decrcurrency(currkey, rdata.Openid) resp.RetData.Curpoerty = uinfo.Property + resp.RetData.ExtraGold = extragold //保存 err = SaveUserInfo(uinfo) -- libgit2 0.21.0