Commit 800d3095fe084fc739b07e0c373e995b73facd5f
1 parent
664229f0
Exists in
master
提交
Showing
1 changed file
with
58 additions
and
5 deletions
Show diff stats
src/HttpServer/logic/httpserver.go
... | ... | @@ -110,11 +110,12 @@ func CheckErr(err error) { |
110 | 110 | |
111 | 111 | func startServerHttpServe() { |
112 | 112 | //test |
113 | - http.HandleFunc("/api/test/addCat", TestaddCat) //增加猫 | |
114 | - http.HandleFunc("/api/test/changeCoin", ChangeCoin) //增加猫 | |
115 | - http.HandleFunc("/api/test/addAdCount", AddAdCount) //增加广告次数 | |
116 | - http.HandleFunc("/api/test/addFlop", AddFlop) //增加翻牌 | |
117 | - http.HandleFunc("/api/test/settlement", Settlement) //发财猫开奖 | |
113 | + http.HandleFunc("/api/test/addCat", TestaddCat) //增加猫 | |
114 | + http.HandleFunc("/api/test/changeCoin", ChangeCoin) //增加猫 | |
115 | + http.HandleFunc("/api/test/addAdCount", AddAdCount) //增加广告次数 | |
116 | + http.HandleFunc("/api/test/addFlop", AddFlop) //增加翻牌 | |
117 | + http.HandleFunc("/api/test/settlement", Settlement) //发财猫开奖 | |
118 | + http.HandleFunc("/api/test/addresource", Addresource) //增加资源 | |
118 | 119 | |
119 | 120 | //real |
120 | 121 | http.HandleFunc("/api/account/login", UserLogin) //登录 |
... | ... | @@ -1335,6 +1336,58 @@ func Getrandredbag(w http.ResponseWriter, r *http.Request) { |
1335 | 1336 | HandlerGetrandredbag(w, s, Uuid) |
1336 | 1337 | } |
1337 | 1338 | |
1339 | +func Addresource(w http.ResponseWriter, r *http.Request) { | |
1340 | + Uuid := 0 | |
1341 | + if len(r.Header) > 0 { | |
1342 | + Uuid, _ = strconv.Atoi(r.Header.Get("uid")) | |
1343 | + } | |
1344 | + if Uuid == 0 { | |
1345 | + SetHeader(w) | |
1346 | + return | |
1347 | + } | |
1348 | + result, _ := ioutil.ReadAll(r.Body) | |
1349 | + r.Body.Close() | |
1350 | + | |
1351 | + type TesaApiData struct { | |
1352 | + Type int `json:"type"` //1红包 2登录天数 红包value为乘以10000倍的 比如0.1元就是1000 | |
1353 | + Value int `json:"value"` | |
1354 | + } | |
1355 | + | |
1356 | + s := string(result) | |
1357 | + logger.Info("Addresource , body:%v,uuid=%v", s, Uuid) | |
1358 | + var rdata TesaApiData | |
1359 | + err := json.Unmarshal([]byte(s), &rdata) | |
1360 | + | |
1361 | + if err != nil { | |
1362 | + logger.Info("json decode Testapi data failed:%v,for:%v", err, s) | |
1363 | + fmt.Fprint(w, "failed") | |
1364 | + return | |
1365 | + } | |
1366 | + | |
1367 | + uinfo, err := GetUserInfo(strconv.Itoa(Uuid)) | |
1368 | + if err != nil || uinfo == nil { | |
1369 | + logger.Error("redis failed err=%v", err) | |
1370 | + fmt.Fprint(w, "failed") | |
1371 | + return | |
1372 | + } | |
1373 | + | |
1374 | + if rdata.Type == 1 { | |
1375 | + addmoney := float32(rdata.Value) / 10000 | |
1376 | + _, err := uinfo.AddRedPackect(addmoney, 99) | |
1377 | + if err != nil { | |
1378 | + logger.Error("redis failed err=%v", err) | |
1379 | + fmt.Fprint(w, "failed") | |
1380 | + return | |
1381 | + } | |
1382 | + } else if rdata.Type == 2 { | |
1383 | + uinfo.SumLoginDay += rdata.Value | |
1384 | + uinfo.ContinueLoginDay += rdata.Value | |
1385 | + } | |
1386 | + | |
1387 | + SaveUserInfo(uinfo, strconv.Itoa(Uuid)) | |
1388 | + fmt.Fprint(w, "success") | |
1389 | +} | |
1390 | + | |
1338 | 1391 | func Settlement(w http.ResponseWriter, r *http.Request) { |
1339 | 1392 | Uuid := 0 |
1340 | 1393 | if len(r.Header) > 0 { | ... | ... |