|
|
|
@ -242,70 +242,86 @@ func insertGiftExchangeConfig(ctx context.Context, req *game.RandomGenerateCodeR
|
|
|
|
|
return id, err |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// http://192.168.2.100:4111/frontApi/game/exchangeCodeVerification?code=M1CUnxocRN&account=lq0001&time=10000&token
|
|
|
|
|
// http://192.168.2.100:4111/frontApi/game/exchangeCodeVerification?code=1ipq61NK&account=lq0001&time=10000&server=1&channel=000000000000&token
|
|
|
|
|
func GetGenerateCode(ctx context.Context, req *game.GetGenerateCodeReq) (res *game.GetGenerateCodeRes, err error) { |
|
|
|
|
res = new(game.GetGenerateCodeRes) |
|
|
|
|
if req.Code == "" { |
|
|
|
|
log.Printf("[%d]CodeExchange failed, code not exist, req.Code: %s", req.Account, req.Code) |
|
|
|
|
log.Printf("[%d-%d]CodeExchange failed, code not exist, req.Code: %s", req.Account, req.Server, req.Code) |
|
|
|
|
res.Code = 292 |
|
|
|
|
return res, nil |
|
|
|
|
} |
|
|
|
|
token := fmt.Sprintf("%x", md5.Sum([]byte("#colony"+fmt.Sprint(req.Account)+fmt.Sprint(req.Time)+fmt.Sprint(req.Code)+"$"))) |
|
|
|
|
if req.Time != 10000 && req.Token != token { |
|
|
|
|
log.Printf("[%d]CodeExchange failed, token error, req.Token: %s, md5: %s", req.Account, req.Token, token) |
|
|
|
|
res.Code = 290 |
|
|
|
|
return res, nil |
|
|
|
|
} |
|
|
|
|
unit := []entity.GameUnit{} |
|
|
|
|
err1 := dao.GameUnit.Ctx(ctx).Where("uid=?", req.Account).Scan(&unit) |
|
|
|
|
if err1 != nil { |
|
|
|
|
log.Printf("[%d]CodeExchange get unit error %s", req.Account, err1.Error()) |
|
|
|
|
res.Code = 250 |
|
|
|
|
if req.Channel == "" { |
|
|
|
|
log.Printf("[%d-%d]CodeExchange failed, channel not exist, req.channel: %s", req.Account, req.Server, req.Channel) |
|
|
|
|
res.Code = 292 |
|
|
|
|
return res, nil |
|
|
|
|
} |
|
|
|
|
if len(unit) == 0 { |
|
|
|
|
log.Printf("[%d]CodeExchange unit is null", req.Account) |
|
|
|
|
res.Code = 294 |
|
|
|
|
token := fmt.Sprintf("%x", md5.Sum([]byte("#colony"+fmt.Sprint(req.Account)+fmt.Sprint(req.Time)+fmt.Sprint(req.Code)+fmt.Sprint(req.Server)+req.Channel+"$"))) |
|
|
|
|
if req.Time != 10000 && req.Token != token { |
|
|
|
|
log.Printf("[%d-%d]CodeExchange failed, token error, req.Token: %s, md5: %s", req.Account, req.Server, req.Token, token) |
|
|
|
|
res.Code = 290 |
|
|
|
|
return res, nil |
|
|
|
|
} |
|
|
|
|
//units := []entity.GameUnit{}
|
|
|
|
|
//err1 := dao.GameUnit.Ctx(ctx).Where("uid=?", req.Account).Scan(&units)
|
|
|
|
|
//if err1 != nil {
|
|
|
|
|
// log.Printf("[%d-%d]CodeExchange get unit error %s", req.Account, req.Server, err1.Error())
|
|
|
|
|
// res.Code = 250
|
|
|
|
|
// return res, nil
|
|
|
|
|
//}
|
|
|
|
|
//if len(units) == 0 {
|
|
|
|
|
// log.Printf("[%d-%d]CodeExchange unit is null", req.Account, req.Server)
|
|
|
|
|
// res.Code = 294
|
|
|
|
|
// return res, nil
|
|
|
|
|
//}
|
|
|
|
|
//unit := entity.GameUnit{}
|
|
|
|
|
//for _, v := range units {
|
|
|
|
|
// if v.Server == req.Server {
|
|
|
|
|
// unit = v
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
//if unit.Id == 0 {
|
|
|
|
|
// log.Printf("[%d-%d]CodeExchange unit is null", req.Account, req.Server)
|
|
|
|
|
// res.Code = 294
|
|
|
|
|
// return res, nil
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
res, err = getPasswordKey(ctx, req, unit[0].Channel) |
|
|
|
|
res, err = getPasswordKey(ctx, req, req.Channel) |
|
|
|
|
if res.Code != 1 { |
|
|
|
|
return res, nil |
|
|
|
|
} |
|
|
|
|
detail := []entity.GameCdKey{} |
|
|
|
|
err1 = dao.GameCdKey.Ctx(ctx).Where("code=?", req.Code).Scan(&detail) |
|
|
|
|
err1 := dao.GameCdKey.Ctx(ctx).Where("code=?", req.Code).Scan(&detail) |
|
|
|
|
if err1 != nil { |
|
|
|
|
log.Printf("[%d]CodeExchange get code error %s", req.Account, err1.Error()) |
|
|
|
|
log.Printf("[%d-%d]CodeExchange get code error %s", req.Account, req.Server, err1.Error()) |
|
|
|
|
res.Code = 250 |
|
|
|
|
return res, nil |
|
|
|
|
} |
|
|
|
|
if len(detail) <= 0 { |
|
|
|
|
log.Printf("[%d]CodeExchange code not exist", req.Account) |
|
|
|
|
log.Printf("[%d-%d]CodeExchange code[%s] not exist", req.Account, req.Server, req.Code) |
|
|
|
|
res.Code = 291 |
|
|
|
|
return res, nil |
|
|
|
|
} |
|
|
|
|
if detail[0].Used != 0 { |
|
|
|
|
log.Printf("[%d]CodeExchange GetGenerateCode code is used: %d", req.Account, detail[0].Used) |
|
|
|
|
log.Printf("[%d-%d]CodeExchange GetGenerateCode code is used: %d", req.Account, req.Server, detail[0].Used) |
|
|
|
|
res.Code = 299 |
|
|
|
|
return res, nil |
|
|
|
|
} |
|
|
|
|
exchange := []entity.GameGiftExchange{} |
|
|
|
|
err3 := dao.GameGiftExchange.Ctx(ctx).WherePri(detail[0].ConfigId).Scan(&exchange) |
|
|
|
|
if err3 != nil { |
|
|
|
|
log.Printf("[%d]CodeExchange get code error %s", req.Account, err3.Error()) |
|
|
|
|
log.Printf("[%d-%d]CodeExchange get code error %s", req.Account, req.Server, err3.Error()) |
|
|
|
|
res.Code = 250 |
|
|
|
|
return res, nil |
|
|
|
|
} |
|
|
|
|
if exchange[0].Channel != "" && !strings.Contains(exchange[0].Channel, unit[0].Channel) { |
|
|
|
|
log.Printf("[%d]CodeExchange channel error exchange[0].Channel: %s, unit[0].Channel: %s", req.Account, exchange[0].Channel, unit[0].Channel) |
|
|
|
|
if exchange[0].Channel != "" && !strings.Contains(exchange[0].Channel, req.Channel) { |
|
|
|
|
log.Printf("[%d-%d]CodeExchange channel error exchange[0].Channel: %s, req.Channel: %s", req.Account, req.Server, exchange[0].Channel, req.Channel) |
|
|
|
|
res.Code = 293 |
|
|
|
|
return res, nil |
|
|
|
|
} |
|
|
|
|
//if exchange[0].StartTime != "" {
|
|
|
|
|
begin, _ := time.ParseInLocation(consts.TIME_FORMAT, exchange[0].StartTime, time.Local) |
|
|
|
|
if begin.Unix() > time.Now().Unix() { |
|
|
|
|
log.Printf("[%d]CodeExchange not activated", req.Account) |
|
|
|
|
log.Printf("[%d-%d]CodeExchange not activated", req.Account, req.Server) |
|
|
|
|
res.Code = 297 |
|
|
|
|
return res, nil |
|
|
|
|
} |
|
|
|
@ -313,33 +329,33 @@ func GetGenerateCode(ctx context.Context, req *game.GetGenerateCodeReq) (res *ga
|
|
|
|
|
//if exchange[0].StopTime != "" {
|
|
|
|
|
end, _ := time.ParseInLocation(consts.TIME_FORMAT, exchange[0].StopTime, time.Local) |
|
|
|
|
if end.Unix() < time.Now().Unix() { |
|
|
|
|
log.Printf("[%d]CodeExchange code is expired", req.Account) |
|
|
|
|
log.Printf("[%d-%d]CodeExchange code is expired", req.Account, req.Server) |
|
|
|
|
res.Code = 295 |
|
|
|
|
return res, nil |
|
|
|
|
} |
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
detail1 := []entity.GameCdKey{} |
|
|
|
|
err2 := dao.GameCdKey.Ctx(ctx).Where("used=?", req.Account).Where("configId=?", detail[0].ConfigId).Scan(&detail1) |
|
|
|
|
err2 := dao.GameCdKey.Ctx(ctx).Where("used=?", req.Account).Where("server=?", req.Server).Where("configId=?", detail[0].ConfigId).Scan(&detail1) |
|
|
|
|
if err2 != nil { |
|
|
|
|
log.Printf("[%d]CodeExchange get code error %s", req.Account, err2.Error()) |
|
|
|
|
log.Printf("[%d-%d]CodeExchange get code error %s", req.Account, req.Server, err2.Error()) |
|
|
|
|
res.Code = 250 |
|
|
|
|
return res, nil |
|
|
|
|
} |
|
|
|
|
if len(detail1) >= exchange[0].Times { |
|
|
|
|
log.Printf("[%d]CodeExchange The usage limit has been reached used: %d, times: %d", req.Account, len(detail1), exchange[0].Times) |
|
|
|
|
log.Printf("[%d-%d]CodeExchange The usage limit has been reached used: %d, times: %d", req.Account, req.Server, len(detail1), exchange[0].Times) |
|
|
|
|
res.Code = 296 |
|
|
|
|
return res, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
_, err4 := dao.GameCdKey.Ctx(ctx).Where("code=?", req.Code).Update(g.Map{dao.GameCdKey.Columns().Used: req.Account}) |
|
|
|
|
_, err4 := dao.GameCdKey.Ctx(ctx).Where("code=?", req.Code).Update(g.Map{dao.GameCdKey.Columns().Used: req.Account, dao.GameCdKey.Columns().Server: req.Server}) |
|
|
|
|
if err4 != nil { |
|
|
|
|
log.Printf("[%d]CodeExchange UpdateOne err: %s", req.Account, err4.Error()) |
|
|
|
|
log.Printf("[%d-%d]CodeExchange UpdateOne err: %s", req.Account, req.Server, err4.Error()) |
|
|
|
|
res.Code = 250 |
|
|
|
|
return res, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
log.Printf("[%d]CodeExchange success: %d", req.Account, detail[0].ConfigId) |
|
|
|
|
log.Printf("[%d-%d]CodeExchange success: %d", req.Account, req.Server, detail[0].ConfigId) |
|
|
|
|
res.Code = 200 |
|
|
|
|
res.Rewards = exchange[0].Rewards |
|
|
|
|
return res, nil |
|
|
|
@ -350,17 +366,17 @@ func getPasswordKey(ctx context.Context, req *game.GetGenerateCodeReq, channel s
|
|
|
|
|
exchange := []entity.GameGiftExchange{} |
|
|
|
|
err1 := dao.GameGiftExchange.Ctx(ctx).Where("password=?", req.Code).Scan(&exchange) |
|
|
|
|
if err1 != nil { |
|
|
|
|
log.Printf("[%d]CodeExchange get exchange error %s", req.Account, err1.Error()) |
|
|
|
|
log.Printf("[%d-%d]CodeExchange get exchange error %s", req.Account, req.Server, err1.Error()) |
|
|
|
|
res.Code = 250 |
|
|
|
|
return res, nil |
|
|
|
|
} |
|
|
|
|
if len(exchange) <= 0 { |
|
|
|
|
//log.Printf("[%d]CodeExchange password nil %s", req.Account, err1.Error())
|
|
|
|
|
//log.Printf("[%d-%d]CodeExchange password nil: code: %s err: %s", req.Account, req.Server, req.Code, err1.Error())
|
|
|
|
|
res.Code = 1 |
|
|
|
|
return res, nil |
|
|
|
|
} |
|
|
|
|
if exchange[0].Channel != "" && !strings.Contains(exchange[0].Channel, channel) { |
|
|
|
|
log.Printf("[%d]CodeExchange channel error exchange[0].Channel: %s, unit[0].Channel: %s", req.Account, exchange[0].Channel, channel) |
|
|
|
|
log.Printf("[%d-%d]CodeExchange channel error exchange[0].Channel: %s, req.Channel: %s", req.Account, req.Server, exchange[0].Channel, channel) |
|
|
|
|
res.Code = 293 |
|
|
|
|
return res, nil |
|
|
|
|
} |
|
|
|
@ -368,7 +384,7 @@ func getPasswordKey(ctx context.Context, req *game.GetGenerateCodeReq, channel s
|
|
|
|
|
//if exchange[0].StartTime != "" {
|
|
|
|
|
begin, _ := time.ParseInLocation(consts.TIME_FORMAT, exchange[0].StartTime, time.Local) |
|
|
|
|
if begin.Unix() > time.Now().Unix() { |
|
|
|
|
log.Printf("[%d]CodeExchange not activated", req.Account) |
|
|
|
|
log.Printf("[%d-%d]CodeExchange not activated", req.Account, req.Server) |
|
|
|
|
res.Code = 297 |
|
|
|
|
return res, nil |
|
|
|
|
} |
|
|
|
@ -376,27 +392,27 @@ func getPasswordKey(ctx context.Context, req *game.GetGenerateCodeReq, channel s
|
|
|
|
|
//if exchange[0].StopTime != "" {
|
|
|
|
|
end, _ := time.ParseInLocation(consts.TIME_FORMAT, exchange[0].StopTime, time.Local) |
|
|
|
|
if end.Unix() < time.Now().Unix() { |
|
|
|
|
log.Printf("[%d]CodeExchange code is expired", req.Account) |
|
|
|
|
log.Printf("[%d-%d]CodeExchange code is expired", req.Account, req.Server) |
|
|
|
|
res.Code = 295 |
|
|
|
|
return res, nil |
|
|
|
|
} |
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
model := dao.GameCdPassword.Ctx(ctx) |
|
|
|
|
total, err1 := model.Where("account=?", req.Account).Where("config_id=?", exchange[0].Id).Count() |
|
|
|
|
total, err1 := model.Where("account=?", req.Account).Where("server=?", req.Server).Where("config_id=?", exchange[0].Id).Count() |
|
|
|
|
if err1 != nil { |
|
|
|
|
log.Printf("[%d]CodeExchange get GameCdPassword error %s", req.Account, err1.Error()) |
|
|
|
|
log.Printf("[%d-%d]CodeExchange get GameCdPassword error %s", req.Account, req.Server, err1.Error()) |
|
|
|
|
res.Code = 250 |
|
|
|
|
return res, nil |
|
|
|
|
} |
|
|
|
|
if total >= exchange[0].Times { |
|
|
|
|
log.Printf("[%d]CodeExchange The usage limit has been reached used: %d, times: %d", req.Account, total, exchange[0].Times) |
|
|
|
|
log.Printf("[%d-%d]CodeExchange The usage limit has been reached used: %d, times: %d", req.Account, req.Server, total, exchange[0].Times) |
|
|
|
|
res.Code = 296 |
|
|
|
|
return res, nil |
|
|
|
|
} |
|
|
|
|
_, err1 = model.Insert(do.GameCdPassword{Account: req.Account, ConfigId: exchange[0].Id}) |
|
|
|
|
_, err1 = model.Insert(do.GameCdPassword{Account: req.Account, Server: req.Server, ConfigId: exchange[0].Id}) |
|
|
|
|
if err1 != nil { |
|
|
|
|
log.Printf("[%d]CodeExchange insert GameCdPassword error %s", req.Account, err1.Error()) |
|
|
|
|
log.Printf("[%d-%d]CodeExchange insert GameCdPassword error %s", req.Account, req.Server, err1.Error()) |
|
|
|
|
res.Code = 250 |
|
|
|
|
return res, nil |
|
|
|
|
} |
|
|
|
|