diff --git a/src/HttpServer/jsonconf/NewTask.json b/src/HttpServer/jsonconf/NewTask.json new file mode 100644 index 0000000..a378875 --- /dev/null +++ b/src/HttpServer/jsonconf/NewTask.json @@ -0,0 +1,186 @@ +[ + { + "id": 3, + "tasktype": 2, + "aims": 2, + "taskdes": "累计使用%d%次道具", + "active": 4, + "days": 1 + }, + { + "id": 4, + "tasktype": 1, + "aims": 8, + "taskdes": "合到数字%d%", + "active": 4, + "days": 2 + }, + { + "id": 5, + "tasktype": 4, + "aims": 20, + "taskdes": "累计赚到%d%元", + "active": 4, + "days": 2 + }, + { + "id": 6, + "tasktype": 2, + "aims": 5, + "taskdes": "累计使用%d%次道具", + "active": 4, + "days": 2 + }, + { + "id": 7, + "tasktype": 5, + "aims": 15, + "taskdes": "累计过%d%关", + "active": 4, + "days": 3 + }, + { + "id": 8, + "tasktype": 4, + "aims": 30, + "taskdes": "累计赚到%d%元", + "active": 4, + "days": 3 + }, + { + "id": 9, + "tasktype": 3, + "aims": 50, + "taskdes": "累计观看%d%次广告", + "active": 4, + "days": 3 + }, + { + "id": 10, + "tasktype": 1, + "aims": 12, + "taskdes": "合到数字%d%", + "active": 4, + "days": 4 + }, + { + "id": 11, + "tasktype": 5, + "aims": 20, + "taskdes": "累计过%d%关", + "active": 4, + "days": 4 + }, + { + "id": 12, + "tasktype": 4, + "aims": 40, + "taskdes": "累计赚到%d%元", + "active": 4, + "days": 4 + }, + { + "id": 13, + "tasktype": 2, + "aims": 15, + "taskdes": "累计使用%d%次道具", + "active": 4, + "days": 4 + }, + { + "id": 14, + "tasktype": 5, + "aims": 30, + "taskdes": "累计过%d%关", + "active": 4, + "days": 5 + }, + { + "id": 15, + "tasktype": 4, + "aims": 50, + "taskdes": "累计赚到%d%元", + "active": 4, + "days": 5 + }, + { + "id": 16, + "tasktype": 2, + "aims": 30, + "taskdes": "累计使用%d%次道具", + "active": 4, + "days": 5 + }, + { + "id": 17, + "tasktype": 3, + "aims": 100, + "taskdes": "累计观看%d%次广告", + "active": 4, + "days": 5 + }, + { + "id": 18, + "tasktype": 1, + "aims": 15, + "taskdes": "合到数字%d%", + "active": 4, + "days": 6 + }, + { + "id": 19, + "tasktype": 4, + "aims": 60, + "taskdes": "累计赚到%d%元", + "active": 4, + "days": 6 + }, + { + "id": 20, + "tasktype": 2, + "aims": 50, + "taskdes": "累计使用%d%次道具", + "active": 4, + "days": 6 + }, + { + "id": 21, + "tasktype": 3, + "aims": 200, + "taskdes": "累计观看%d%次广告", + "active": 4, + "days": 6 + }, + { + "id": 22, + "tasktype": 5, + "aims": 100, + "taskdes": "累计过%d%关", + "active": 4, + "days": 7 + }, + { + "id": 23, + "tasktype": 4, + "aims": 100, + "taskdes": "累计赚到%d%元", + "active": 4, + "days": 7 + }, + { + "id": 24, + "tasktype": 2, + "aims": 100, + "taskdes": "累计使用%d%次道具", + "active": 4, + "days": 7 + }, + { + "id": 25, + "tasktype": 3, + "aims": 500, + "taskdes": "累计观看%d%次广告", + "active": 4, + "days": 7 + } +] \ No newline at end of file diff --git a/src/HttpServer/jsonconf/jsonconf.go b/src/HttpServer/jsonconf/jsonconf.go index 7a12448..c6d86fa 100644 --- a/src/HttpServer/jsonconf/jsonconf.go +++ b/src/HttpServer/jsonconf/jsonconf.go @@ -82,6 +82,15 @@ type RedpacketConfigDesc struct { Cash int `json:"cash"` } +type NewTaskConfigDesc struct { + Id int `json:"id"` + Tasktype int `json:"tasktype"` + Aims int `json:"aims"` + Taskdes string `json:"taskdes"` + Active int `json:"active"` + Days int `json:"days"` +} + type GameConfig struct { AchieventConfig []AchieveDesc TaskConfig []AchieveDesc @@ -92,6 +101,7 @@ type GameConfig struct { SignConfig SignConfigDesc ActiveWithdrawConfig []ActiveWithdrawConfigDesc RedpacketConfig []RedpacketConfigDesc + NewTaskConfig []NewTaskConfigDesc } func GetJsonConf() *GameConfig { @@ -260,10 +270,32 @@ func LoadJsonConf() error { return err } + path = "../jsonconf/NewTask.json" + content, err = file_get_contents(path) + if err != nil { + logger.Info("loadJsonConf failed1,err=%v", err) + return err + } + + err = json.Unmarshal([]byte(content), &g_jsonconf.NewTaskConfig) + if err != nil { + logger.Info("loadJsonConf failed1,err=%v", err) + return err + } + logger.Info("loadJsonConf success pconf=%v,err=%v", *g_jsonconf, err) return err } +func GetNewTaskInfo (id int) *NewTaskConfigDesc { + for _,val := range g_jsonconf.NewTaskConfig { + if val.Id == id { + return &val + } + } + return nil +} + func GetRedpacketNum(id int) int { if len(g_jsonconf.RedpacketConfig) == 0 { diff --git a/src/HttpServer/logic/constdef.go b/src/HttpServer/logic/constdef.go index 9a2eb0b..c0d23bc 100644 --- a/src/HttpServer/logic/constdef.go +++ b/src/HttpServer/logic/constdef.go @@ -12,6 +12,7 @@ const ( TASKTYPE_WATCHADSPAY = 8 //领取付费红包 TASKTYPE_WATCHADSTIME = 9 //领取时长红包 TASKTYPE_SHAKETIME = 10 //摇一摇次数 + TASKTYPE_HENUM = 11 //合道数字 ) diff --git a/src/HttpServer/logic/datadef.go b/src/HttpServer/logic/datadef.go index 1cabf92..a259a81 100644 --- a/src/HttpServer/logic/datadef.go +++ b/src/HttpServer/logic/datadef.go @@ -336,6 +336,50 @@ type FetchredbagResp struct { Data FetchredbagData `json:"data"` } + + +type QuerynewtaskReq struct { + Gameid string `json:"gameid"` + Channel string `json:"channel"` +} + +type QuerynewTaskInfoList struct { + Taskid int `json:"taskid"` + Taskstatus int `json:"taskstatus"` + Days int `json:"days"` + Taskprogress int `json:"taskprogress"` + +} + +type QuerynewtaskData struct { + Curloginday int `json:"curloginday"` + Sumactive int `json:"sumactive"` + Taskinfolist []QuerynewTaskInfoList `json:"taskinfolist"` +} +type QuerynewtaskResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data QuerynewtaskData `json:"data"` +} + + +type HandlerFetchnewtaskReq struct { + Gameid string `json:"gameid"` + Channel string `json:"channel"` + Taskid int `json:"taskid"` +} + +type HandlerFetchnewtaskData struct { + Rewardactive int `json:"rewardactive"` + Sumactive int `json:"sumactive"` +} +type HandlerFetchnewtaskResp struct { + Code int `json:"code"` + Message string `json:"message"` + Data HandlerFetchnewtaskData `json:"data"` +} + + //********************************************************************************************************** type TaskListDesc struct { @@ -367,6 +411,14 @@ type AchieveMentInfo struct { SumUseItemCnt int //使用道具次数累计 } +type NewAchieveInfo struct { + HeNum int //合道数字 + UseItem int //累计使用道具 + WatchAdsCnt int //累计观看广告 + GetRebBag int //累计赚到x元 + PassGuan int //累计过关 +} + type WithDrawList struct { Withdata []WithDrawRecord `json:"withdata"` } @@ -445,11 +497,15 @@ type UserData struct { IsNew int //新手状态// 现次数 FetchRdBagNum int //当天已领的红包 ShakeTime int //摇一摇 + SumAc int //累计活跃度 + RegT int //注册时间 WithDraw WithDrawInfo //提现记录信息 Cdkeys []CashCdKeyInfo //记录提现的cdkeys //SpecialWithDraw WithDrawInfo //活跃提现记录信息 Task TaskInfo //玩家任务完成相关信息 Achieve AchieveMentInfo //玩家成就完成相关数据 + NewAchieve NewAchieveInfo //新手12元 + FetchNewAchieved []int //已经领取的新任务id } //---------------------------------------------------------------------------------------------------------------------- diff --git a/src/HttpServer/logic/function.go b/src/HttpServer/logic/function.go index a4b1c48..afb7000 100644 --- a/src/HttpServer/logic/function.go +++ b/src/HttpServer/logic/function.go @@ -112,6 +112,46 @@ func GetAchieveConfig(taskid int) *jsonconf.AchieveDesc { return nil } +func (uinfo *UserData) CalcNewTask(resp *QuerynewtaskResp) { +//todo + for _,val := range jsonconf.GetJsonConf().NewTaskConfig { + var tmp QuerynewTaskInfoList + tmp.Taskid = val.Id + tmp.Days = val.Days + tmp.Taskstatus = 1 + usrvalue :=0 + if val.Tasktype == 1 { + usrvalue = uinfo.NewAchieve.HeNum + } + if val.Tasktype == 2 { + usrvalue = uinfo.NewAchieve.UseItem + } + if val.Tasktype == 3 { + usrvalue = uinfo.NewAchieve.WatchAdsCnt + } + if val.Tasktype == 4 { + usrvalue = uinfo.NewAchieve.GetRebBag / 10000 + } + if val.Tasktype == 5 { + usrvalue = uinfo.NewAchieve.PassGuan + } + + tmp.Taskprogress = usrvalue + if usrvalue >= val.Aims { + tmp.Taskstatus = 2 + } + + //需要判断下是否已经领取 + for _,val := range uinfo.FetchNewAchieved { + if val == tmp.Taskid { + tmp.Taskstatus = 3 + } + } + + resp.Data.Taskinfolist = append(resp.Data.Taskinfolist,tmp) + } +} + func (uinfo *UserData) CalcTaskList(list *TaskList, uniqueid string) *TaskList{ newlist := new(TaskList) curtype := -1 //记录当前类型 @@ -586,6 +626,7 @@ func InitUserInfo(data *UserLoginReq, resp *UserLoginResp, uuid int, uniqueuid s initdata.UpLvCostTimeSec = int(time.Now().Unix()) initdata.ShakeTime = SHAKELIMIT initdata.IsNew = 1 + initdata.RegT = int(time.Now().Unix()) for _, val := range jsonconf.GetJsonConf().WithDrawConfig { var tmp WithDrawDesc diff --git a/src/HttpServer/logic/httpserver.go b/src/HttpServer/logic/httpserver.go index fefaa52..c415c51 100644 --- a/src/HttpServer/logic/httpserver.go +++ b/src/HttpServer/logic/httpserver.go @@ -63,6 +63,8 @@ func startServerHttpServe() { http.HandleFunc("/eliminatestar/querysigndata", Querysigndata) //获取签到数据 http.HandleFunc("/eliminatestar/usersign", Usersign) //玩家签到 http.HandleFunc("/eliminatestar/fetchredbag", Fetchredbag) //领取红包 + http.HandleFunc("/eliminatestar/querynewtask", Querynewtask) //请求当前新手12元任务数据 + http.HandleFunc("/eliminatestar/fetchnewtask", Fetchnewtask) //领取新手12元红包任务 // http.HandleFunc("/eliminatestar/readNumUpload", ReadNumUpload) //阅读量上报 http.HandleFunc("/eliminatestar/queryreadgold", QueryReadGold) //获取微转发金币数 @@ -122,6 +124,49 @@ func ReadNumUpload(w http.ResponseWriter, r *http.Request) { HandlerReadNumUpload(w, s) } + +func Fetchnewtask(w http.ResponseWriter, r *http.Request) { + + Uuid := 0 + if len(r.Header) > 0 { + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) + } + + if Uuid == 0 { + SetHeader(w) + //logger.Error("Uuid is nil!") + return + } + result, _ := ioutil.ReadAll(r.Body) + r.Body.Close() + + s := string(result) + logger.Info("Fetchnewtask , body:%v,uuid=%v", s, Uuid) + + HandlerFetchnewtask(w, s, Uuid) +} + +func Querynewtask(w http.ResponseWriter, r *http.Request) { + + Uuid := 0 + if len(r.Header) > 0 { + Uuid, _ = strconv.Atoi(r.Header.Get("Uuid")) + } + + if Uuid == 0 { + SetHeader(w) + //logger.Error("Uuid is nil!") + return + } + result, _ := ioutil.ReadAll(r.Body) + r.Body.Close() + + s := string(result) + logger.Info("Querynewtask , body:%v,uuid=%v", s, Uuid) + + HandlerQuerynewtask(w, s, Uuid) +} + func Fetchredbag(w http.ResponseWriter, r *http.Request) { Uuid := 0 diff --git a/src/HttpServer/logic/logic.go b/src/HttpServer/logic/logic.go index 58b7473..32a493e 100644 --- a/src/HttpServer/logic/logic.go +++ b/src/HttpServer/logic/logic.go @@ -12,6 +12,7 @@ import ( "strconv" "strings" "sync" + "time" ) var llock sync.Mutex @@ -683,6 +684,140 @@ func HandlerReadNumUpload(w http.ResponseWriter, data string) { fmt.Fprint(w, string(respstr)) } +func HandlerFetchnewtask(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp HandlerFetchnewtaskResp + resp.Code = 0 + var rdata HandlerFetchnewtaskReq + err := json.Unmarshal([]byte(data), &rdata) + for { + if err != nil { + logger.Info("json decode HandlerFetchnewtask data failed:%v,for:%v", err, data) + resp.Message = "网络错误" + resp.Code = ERROR_JSONUNMASH_ERROR + break + } + + //需要加上渠道才是唯一的玩家id,不同渠道视为不同数据 + uniqueuuid := strconv.Itoa(uuid) + rdata.Channel + uinfo, err := GetUserInfo(uniqueuuid) + if err != nil || uinfo == nil { + logger.Error("redis failed err=%v", err) + resp.Message = "服务器错误" + resp.Code = ERROR_SRV_ERROR + break + } + + + taskcfg := jsonconf.GetNewTaskInfo(rdata.Taskid) + if taskcfg == nil { + logger.Error("get GetNewTaskInfo err=%v", err) + resp.Message = "读取配置表失败" + resp.Code = ERROR_SRV_ERROR + break + } + + //需要判断是否已经领取过 + isdone := false + for _,val := range uinfo.FetchNewAchieved { + if val == rdata.Taskid { + isdone = true + } + } + + if isdone { + logger.Error("get GetNewTaskInfo err=%v", err) + resp.Message = "该任务已经领取过了!" + resp.Code = ERROR_SRV_ERROR + break + } + + //判断任务是否已经完成 + usrvalue :=0 + if taskcfg.Tasktype == 1 { + usrvalue = uinfo.NewAchieve.HeNum + } + if taskcfg.Tasktype == 2 { + usrvalue = uinfo.NewAchieve.UseItem + } + if taskcfg.Tasktype == 3 { + usrvalue = uinfo.NewAchieve.WatchAdsCnt + } + if taskcfg.Tasktype == 4 { + usrvalue = uinfo.NewAchieve.GetRebBag / 10000 + } + if taskcfg.Tasktype == 5 { + usrvalue = uinfo.NewAchieve.PassGuan + } + + if usrvalue < taskcfg.Aims { + logger.Error("get GetNewTaskInfo err=%v", err) + resp.Message = "任务还未完成无法领取!" + resp.Code = ERROR_SRV_ERROR + break + } + + //领取 + uinfo.SumAc += taskcfg.Active + uinfo.FetchNewAchieved = append(uinfo.FetchNewAchieved,rdata.Taskid) + + resp.Data.Sumactive = uinfo.SumAc + resp.Data.Rewardactive = taskcfg.Active + + SaveUserInfo(uinfo,uniqueuuid) + + + resp.Code = ERROR_OK + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) +} + +func HandlerQuerynewtask(w http.ResponseWriter, data string, uuid int) { + SetHeader(w) + var resp QuerynewtaskResp + resp.Code = 0 + var rdata QuerynewtaskReq + err := json.Unmarshal([]byte(data), &rdata) + for { + if err != nil { + logger.Info("json decode HandlerQuerynewtask data failed:%v,for:%v", err, data) + resp.Message = "网络错误" + resp.Code = ERROR_JSONUNMASH_ERROR + break + } + + //需要加上渠道才是唯一的玩家id,不同渠道视为不同数据 + uniqueuuid := strconv.Itoa(uuid) + rdata.Channel + uinfo, err := GetUserInfo(uniqueuuid) + if err != nil || uinfo == nil { + logger.Error("redis failed err=%v", err) + resp.Message = "服务器错误" + resp.Code = ERROR_SRV_ERROR + break + } + + nowdaynum := time.Now().Day() + regdaynum := time.Unix(int64(uinfo.RegT), 0).Day() + resp.Data.Curloginday = nowdaynum+1-regdaynum + resp.Data.Sumactive = uinfo.SumAc + + //计算一下任务 + uinfo.CalcNewTask(&resp) + + + resp.Code = ERROR_OK + break + } + + //回包 + respstr, _ := json.Marshal(&resp) + fmt.Fprint(w, string(respstr)) +} + func HandlerFetchredbag(w http.ResponseWriter, data string, uuid int) { SetHeader(w) llock.Lock() @@ -711,6 +846,9 @@ func HandlerFetchredbag(w http.ResponseWriter, data string, uuid int) { readaddgold := uinfo.FetchRedPacket(rdata.Gameid, rdata.Channel, uuid) + //需要计算一下实际赚的钱 + uinfo.NewAchieve.GetRebBag += readaddgold + resp.Data.Walletgold = uinfo.RealGold resp.Data.Getgoldnum = readaddgold @@ -960,6 +1098,7 @@ func HandlerUpdatetaskandachieve(w http.ResponseWriter, data string, uuid int) { switch rdata.Tasktype { case TASKTYPE_PASSLEVEL: uinfo.Task.PassLevel += rdata.Value + uinfo.NewAchieve.PassGuan += rdata.Value case TASKTYPE_GETREDBAG: uinfo.Task.GetRedbagCnt += rdata.Value case TASKTYPE_WATCHADS: @@ -968,6 +1107,7 @@ func HandlerUpdatetaskandachieve(w http.ResponseWriter, data string, uuid int) { if uinfo.LeftFreeRB > 0 { uinfo.LeftFreeRB-- } + uinfo.NewAchieve.WatchAdsCnt += rdata.Value /*if uinfo.WatchAddsTime > 0 { uinfo.WatchAddsTime-- }*/ @@ -976,6 +1116,7 @@ func HandlerUpdatetaskandachieve(w http.ResponseWriter, data string, uuid int) { case TASKTYPE_USEITEM: uinfo.Task.UseItemCnt += rdata.Value uinfo.Achieve.SumUseItemCnt += rdata.Value + uinfo.NewAchieve.UseItem += rdata.Value case TASKTYPE_PLAYSMALLGAMES: uinfo.Task.PlaySmall += 1 case TASKTYPE_WATCHADSSURPRICE: @@ -995,6 +1136,10 @@ func HandlerUpdatetaskandachieve(w http.ResponseWriter, data string, uuid int) { if uinfo.ShakeTime < 0 { uinfo.ShakeTime = 0 } + case TASKTYPE_HENUM: + if uinfo.NewAchieve.HeNum < rdata.Value { + uinfo.NewAchieve.HeNum = rdata.Value + } } logger.Info("HandlerUpdatetaskandachieve uinfo=%v rdata=%v", uinfo, rdata) SaveUserInfo(uinfo, uniqueuuid) -- libgit2 0.21.0