[FIX]b端接口联调一些bug

This commit is contained in:
virus 2019-11-28 10:25:51 +08:00
parent 48f65ae84d
commit 568ceeeb80
8 changed files with 61 additions and 27 deletions

View File

@ -2,7 +2,7 @@
port="8080" port="8080"
debug=true debug=true
env="production" env="production"
risewinter_url="http://apiv2-staging.risewinter.com:8080" risewinter_url="http://bapi.stage.risewinter.cn"
risewinter_tenant_id=2 risewinter_tenant_id=2
white_ip="127.0.0.1,192.168.31.189,13.250.10.109,3.0.200.71" white_ip="127.0.0.1,192.168.31.189,13.250.10.109,3.0.200.71"
private_key_path="rsa/private_key.pem" private_key_path="rsa/private_key.pem"

View File

@ -45,8 +45,8 @@ func main() {
// 日志初始化 // 日志初始化
log.Init() log.Init()
log.Info("xxxxx")
go initialize.InitData(5) go initialize.InitData(5)
e.Logger.Fatal(e.Start(":" + util.Config.PORT)) e.Logger.Fatal(e.Start(":" + util.Config.PORT))
} }

View File

@ -14,7 +14,7 @@ type League struct {
Alias []string `json:"alias"` // 联赛别名 Alias []string `json:"alias"` // 联赛别名
Logo string `json:"logo"` // 联赛logo Logo string `json:"logo"` // 联赛logo
Organizer string `json:"organizer"` // 联赛组织者 Organizer string `json:"organizer"` // 联赛组织者
Level int `json:"lever"` // 联赛等级 Level string `json:"lever"` // 联赛等级
Local string `json:"local"` // 联赛地区 Local string `json:"local"` // 联赛地区
LimitTeam int `json:"limit_team"` // 联赛队伍数量 LimitTeam int `json:"limit_team"` // 联赛队伍数量
Description string `json:"description"` // 联赛简介 Description string `json:"description"` // 联赛简介

View File

@ -1,5 +1,7 @@
package dota2 package dota2
import "encoding/json"
// dota2队伍信息 // dota2队伍信息
type Team struct { type Team struct {
Name string `json:"name"` // 队伍名称 Name string `json:"name"` // 队伍名称
@ -18,3 +20,12 @@ type Team struct {
BanRwRoleIDs []int64 `json:"bans_rw_role_ids"` // 队伍被禁英雄ID数组 BanRwRoleIDs []int64 `json:"bans_rw_role_ids"` // 队伍被禁英雄ID数组
Players []Player `json:"players"` // 队伍队员比赛数据 Players []Player `json:"players"` // 队伍队员比赛数据
} }
func (t *Team) FromDB(bytes []byte) error {
return json.Unmarshal(bytes, t)
}
func (t *Team) ToDB() (bytes []byte, err error) {
bytes, err = json.Marshal(t)
return
}

View File

@ -18,7 +18,7 @@ type League struct {
Alias []string `json:"alias"` Alias []string `json:"alias"`
Logo string `json:"logo"` Logo string `json:"logo"`
Organizer string `json:"organizer"` Organizer string `json:"organizer"`
Level int `json:"level"` Level string `json:"level"`
Local string `json:"local"` Local string `json:"local"`
RwGameID int64 `json:"game_id"` RwGameID int64 `json:"game_id"`
RwAreaID int64 `json:"area_id"` RwAreaID int64 `json:"area_id"`

View File

@ -41,6 +41,7 @@ func FindSeriesByRwID(rwID int64) (findSeries models.Series, findErr error) {
if has, err := util.Engine.Where("rw_id = ?", rwID).Desc("id").Get(&findSeries); err != nil || !has { if has, err := util.Engine.Where("rw_id = ?", rwID).Desc("id").Get(&findSeries); err != nil || !has {
findErr = errors.New("系列赛不存在!") findErr = errors.New("系列赛不存在!")
go InitSeriesDetailData(rwID)
return return
} }
@ -95,12 +96,9 @@ func (series *Series) CreateSeries() (createdSeries models.Series, createErr err
if fCourse, findErr := course.FindCourseByRwID(series.RwCourseID); findErr == nil { if fCourse, findErr := course.FindCourseByRwID(series.RwCourseID); findErr == nil {
// 找到赛事 // 找到赛事
if series.Course.RwID > 0 { if series.Course.RwID > 0 {
var buildCourse models.Course if fCourse, createErr = series.Course.BuildCourse(fCourse); createErr == nil {
var updatedCourse models.Course
buildCourse.ID = fCourse.ID
if updatedCourse, createErr = series.Course.BuildCourse(buildCourse); createErr == nil {
// 参数正常提交到session // 参数正常提交到session
if i, err := session.ID(updatedCourse.ID).Update(&updatedCourse); err != nil || i != 1 { if i, err := session.ID(fCourse.ID).Update(&fCourse); err != nil || i != 1 {
createErr = errors.New(fmt.Sprintf("系列赛关联赛事更新失败: %v", err)) createErr = errors.New(fmt.Sprintf("系列赛关联赛事更新失败: %v", err))
_ = session.Rollback() _ = session.Rollback()
return return
@ -113,11 +111,9 @@ func (series *Series) CreateSeries() (createdSeries models.Series, createErr err
} else { } else {
// 没找到对应的联赛 // 没找到对应的联赛
if series.Course.League.RwID > 0 { if series.Course.League.RwID > 0 {
var buildCourse models.Course if fCourse, createErr = series.Course.BuildCourse(fCourse); createErr == nil {
var createdCourse models.Course
if createdCourse, createErr = series.Course.BuildCourse(buildCourse); createErr == nil {
// 参数正常提交到session // 参数正常提交到session
if _, err := session.Insert(&createdCourse); err != nil { if _, err := session.Insert(&fCourse); err != nil {
createErr = errors.New(fmt.Sprintf("系列赛关联赛事创建失败: %v", err)) createErr = errors.New(fmt.Sprintf("系列赛关联赛事创建失败: %v", err))
_ = session.Rollback() _ = session.Rollback()
return return
@ -198,12 +194,9 @@ func (series *Series) UpdateSeries(seriesID int64) (updatedSeries models.Series,
if fCourse, findErr := course.FindCourseByRwID(series.RwCourseID); findErr == nil { if fCourse, findErr := course.FindCourseByRwID(series.RwCourseID); findErr == nil {
// 找到赛事 // 找到赛事
if series.Course.RwID > 0 { if series.Course.RwID > 0 {
var buildCourse models.Course if fCourse, updateErr = series.Course.BuildCourse(fCourse); updateErr == nil {
var updatedCourse models.Course
buildCourse.ID = fCourse.ID
if updatedCourse, updateErr = series.Course.BuildCourse(buildCourse); updateErr == nil {
// 参数正常提交到session // 参数正常提交到session
if i, err := session.ID(updatedCourse.ID).Update(&updatedCourse); err != nil || i != 1 { if i, err := session.ID(fCourse.ID).Update(&fCourse); err != nil || i != 1 {
updateErr = errors.New(fmt.Sprintf("系列赛关联赛事更新失败: %v", err)) updateErr = errors.New(fmt.Sprintf("系列赛关联赛事更新失败: %v", err))
_ = session.Rollback() _ = session.Rollback()
return return
@ -216,11 +209,9 @@ func (series *Series) UpdateSeries(seriesID int64) (updatedSeries models.Series,
} else { } else {
// 没找到对应的联赛 // 没找到对应的联赛
if series.Course.RwID > 0 { if series.Course.RwID > 0 {
var buildCourse models.Course if fCourse, updateErr = series.Course.BuildCourse(fCourse); updateErr == nil {
var createdCourse models.Course
if createdCourse, updateErr = series.Course.BuildCourse(buildCourse); updateErr == nil {
// 参数正常提交到session // 参数正常提交到session
if _, err := session.Insert(&createdCourse); err != nil { if _, err := session.Insert(&fCourse); err != nil {
updateErr = errors.New(fmt.Sprintf("系列赛关联赛事创建失败: %v", err)) updateErr = errors.New(fmt.Sprintf("系列赛关联赛事创建失败: %v", err))
_ = session.Rollback() _ = session.Rollback()
return return
@ -241,7 +232,7 @@ func (series *Series) UpdateSeries(seriesID int64) (updatedSeries models.Series,
if _, err := session.ID(updatedSeries.ID).Cols( if _, err := session.ID(updatedSeries.ID).Cols(
"status", "start_time", "end_time", "status", "start_time", "end_time",
"season_info", "description", "info", "season_info", "description", "info",
"game_id", "area_id").Update(&updatedSeries); err != nil { "game_id", "area_id", "course_id", "league_id").Update(&updatedSeries); err != nil {
updateErr = errors.New(fmt.Sprintf("系列赛更新失败:%v", err)) updateErr = errors.New(fmt.Sprintf("系列赛更新失败:%v", err))
_ = session.Rollback() _ = session.Rollback()
return return
@ -292,7 +283,7 @@ func (series *Series) BuildSeries(buildSeries models.Series) (builderSeries mode
} }
if mGame, err := game.FindGameByRwID(series.RwGameID); err != nil { if mGame, err := game.FindGameByRwID(series.RwGameID); err != nil {
buildErr = errors.New("游戏不存在!") buildErr = errors.New("系列赛游戏不存在!")
return return
} else { } else {
buildSeries.GameID = mGame.ID buildSeries.GameID = mGame.ID
@ -300,13 +291,31 @@ func (series *Series) BuildSeries(buildSeries models.Series) (builderSeries mode
if series.RwAreaID > 0 { if series.RwAreaID > 0 {
if mArea, err := area.FindAreaByRwID(series.RwAreaID); err != nil { if mArea, err := area.FindAreaByRwID(series.RwAreaID); err != nil {
buildErr = errors.New("赛区不存在!") buildErr = errors.New("系列赛赛区不存在!")
return return
} else { } else {
buildSeries.AreaID = mArea.ID buildSeries.AreaID = mArea.ID
} }
} }
if series.RwCourseID > 0 {
if mCourse, err := course.FindCourseByRwID(series.RwCourseID); err != nil {
buildErr = errors.New("系列赛赛事不存在!")
return
} else {
buildSeries.CourseID = mCourse.ID
}
}
if series.RwLeagueID > 0 {
if mLeague, err := course.FindCourseByRwID(series.RwLeagueID); err != nil {
buildErr = errors.New("系列赛赛事不存在!")
return
} else {
buildSeries.LeagueID = mLeague.ID
}
}
buildSeries.RwID = series.RwID buildSeries.RwID = series.RwID
buildSeries.Status = series.Status buildSeries.Status = series.Status
buildSeries.StartTime = series.StartTime buildSeries.StartTime = series.StartTime

View File

@ -3,7 +3,9 @@ package series
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"gitee.com/risewinter/sheep/models"
"gitee.com/risewinter/sheep/util" "gitee.com/risewinter/sheep/util"
"runtime"
"time" "time"
) )
@ -100,6 +102,18 @@ func CurlSeriesDetailRequest(rwSeriesID int64) (seriesDetailRep DetailResponse)
return return
} }
func InitSeriesDetailData(rwSeriesID int64) {
seriesDetailRep := CurlSeriesDetailRequest(rwSeriesID)
var findSeries models.Series
if has, err := util.Engine.Where("rw_id = ?", rwSeriesID).Desc("id").Get(&findSeries); err != nil || !has {
findSeries, _ = seriesDetailRep.Result.CreateSeries()
} else {
findSeries, _ = seriesDetailRep.Result.UpdateSeries(findSeries.ID)
}
runtime.Goexit()
}
func InitSeriesListData(rwGameID int64, rwAreaID int64, rwLeagueID int64, rwCourseID int64, beginTime int64, endTime int64, status, limit int) { func InitSeriesListData(rwGameID int64, rwAreaID int64, rwLeagueID int64, rwCourseID int64, beginTime int64, endTime int64, status, limit int) {
var offset, total int var offset, total int

View File

@ -15,7 +15,7 @@ import (
// url: 请求地址 // url: 请求地址
// response请求返回的内容 // response请求返回的内容
func Get(url string, params map[string]interface{}) string { func Get(url string, params map[string]interface{}) string {
client := http.Client{Timeout: 10 * time.Second} client := http.Client{Timeout: 30 * time.Second}
// 排序后的请求参数 // 排序后的请求参数
signString := SignString(params) signString := SignString(params)
// 请求的地址 // 请求的地址