[ADD]数据库入库module

This commit is contained in:
virus 2019-11-11 16:56:15 +08:00
parent 66b6dc0dcc
commit b800796603
21 changed files with 1337 additions and 164 deletions

View File

@ -34,7 +34,7 @@ func InitGameListData(limit int) {
for offset <= total {
gameListRep := CurlGameListRequest(offset, limit)
for _, item := range gameListRep.Result.Items {
_ = game.CreateGame(item)
_, _ = game.CreateGame(item)
}
offset += limit
total = int(gameListRep.Result.Total)

View File

@ -6,17 +6,17 @@ type League struct {
RwID int64 `json:"rw_id" xorm:"name rw_id"` // B端ID
GameID int64 `json:"game_id" xorm:"game_id not null"` // 游戏ID
AreaID int64 `json:"area_id" xorm:"area_id not null"` // 赛区ID
GameType int64 `json:"game_type"` // 游戏类型 1 电竞 2 体育
GameType int `json:"game_type"` // 游戏类型 1 电竞 2 体育
Name string `json:"name"` // 联赛名称
ShortName string `json:"short_name"` // 联赛简称
Bonus string `json:"bonus"` // 联赛奖金
Bonus int64 `json:"bonus"` // 联赛奖金
BonusType int `json:"bonus_type"` // 联赛奖金单位 1 RMB人民币 2 USD美元
Alias []string `json:"alias"` // 联赛别名
Logo string `json:"logo"` // 联赛logo
Organizer string `json:"organizer"` // 联赛组织者
Level string `json:"lever"` // 联赛等级
Level int `json:"lever"` // 联赛等级
Local string `json:"local"` // 联赛地区
LimitTeam string `json:"limit_team"` // 联赛队伍数量
LimitTeam int `json:"limit_team"` // 联赛队伍数量
Description string `json:"description"` // 联赛简介
}

View File

@ -2,16 +2,16 @@ package models
// 游戏技能
type Skill struct {
ID int64 `json:"id" xorm:"id not null pk autoincr"` // 技能ID
RwID int64 `json:"rw_id" xorm:"name rw_id"` // B端ID
GameID int64 `json:"game_id" xorm:"game_id not null"` // 游戏ID
GameRoleId int64 `json:"game_role_id"` // 所属游戏英雄 0 表示无
GameEquipmentId int64 `json:"game_equipment_id"` // 所属游戏装备 0 表示无
Name string `json:"name"` // 技能名称
NameEnglish string `json:"name_english"` // 技能英文名
Description string `json:"description"` // 技能简介
Alias string `json:"alias"` // 技能别名
Icon string `json:"icon"` // 技能图标
ID int64 `json:"id" xorm:"id not null pk autoincr"` // 技能ID
RwID int64 `json:"rw_id" xorm:"name rw_id"` // B端ID
GameID int64 `json:"game_id" xorm:"game_id not null"` // 游戏ID
RoleId int64 `json:"role_id"` // 所属游戏英雄 0 表示无
EquipmentId int64 `json:"equipment_id"` // 所属游戏装备 0 表示无
Name string `json:"name"` // 技能名称
NameEnglish string `json:"name_english"` // 技能英文名
Description string `json:"description"` // 技能简介
Alias string `json:"alias"` // 技能别名
Icon string `json:"icon"` // 技能图标
}
func (Skill) TableName() string {

View File

@ -5,7 +5,7 @@ type Team struct {
ID int64 `json:"id" xorm:"id not null pk autoincr"` // 战队ID
RwID int64 `json:"rw_id" xorm:"name rw_id"` // B端ID
GameID int64 `json:"game_id" xorm:"game_id not null"` // 游戏ID
GameType int64 `json:"game_type"` // 游戏类型 1 电竞 2 体育
GameType int `json:"game_type"` // 游戏类型 1 电竞 2 体育
Name string `json:"name"` // 战队名称
NameEnglish string `json:"name_english"` // 战队英文名
ShortName string `json:"short_name"` // 战队简称

View File

@ -1,9 +0,0 @@
package area
type Area struct {
RwID int64 `json:"id"`
Name string `json:"name"`
Area string `json:"area"`
RwGameID int64 `json:"game_id"`
Description string `json:"description"`
}

100
modules/area/CurdArea.go Normal file
View File

@ -0,0 +1,100 @@
package area
import (
"errors"
"gitee.com/risewinter/sheep/models"
"gitee.com/risewinter/sheep/modules/game"
"gitee.com/risewinter/sheep/util"
)
type Area struct {
RwID int64 `json:"id"`
Name string `json:"name"`
Area string `json:"area"`
RwGameID int64 `json:"game_id"`
Description string `json:"description"`
}
func FindAreaByRwID(rwID int64) (findArea models.Area, findErr error) {
if rwID <= 0 {
findErr = errors.New("B端ID不能小于或者等于0")
return
}
if has, err := util.Engine.Where("rw_id = ?", rwID).Desc("id").Get(&findArea); err != nil || !has {
findErr = errors.New("赛区不存在!")
return
}
return
}
func CreateArea(area Area) (createArea models.Area, createErr error) {
if area.RwID <= 0 {
createErr = errors.New("B端ID不能小于或者等于0")
return
}
if area.Name == "" {
createErr = errors.New("赛区名称不能为空!")
return
}
if area.Area == "" {
createErr = errors.New("赛区区域不能为空!")
return
}
if area.RwGameID <= 0 {
createErr = errors.New("B端游戏ID不能小于或者等于0")
return
}
if mGame, err := game.FindGameByRwID(area.RwGameID); err != nil {
createErr = errors.New("赛区游戏不存在!")
return
} else {
createArea.GameID = mGame.ID
}
createArea.RwID = area.RwID
createArea.Name = area.Name
createArea.Area = area.Area
createArea.Description = area.Description
_, createErr = util.Engine.Insert(&createArea)
return
}
func (area *Area) UpdateArea() (result bool, updateArea models.Area, updateErr error) {
if area.Name == "" {
updateErr = errors.New("赛区名称不能为空!")
return
}
if area.Area == "" {
updateErr = errors.New("赛区区域不能为空!")
return
}
if area.RwGameID <= 0 {
updateErr = errors.New("B端游戏ID不能小于或者等于0")
}
if mGame, err := game.FindGameByRwID(area.RwGameID); err != nil {
updateErr = errors.New("赛区游戏不存在!")
return
} else {
updateArea.GameID = mGame.ID
}
updateArea.Name = area.Name
updateArea.Area = area.Area
updateArea.Description = area.Description
_, updateErr = util.Engine.Update(&updateArea)
if updateErr != nil {
result = true
}
return
}

View File

@ -1,15 +0,0 @@
package course
import "gitee.com/risewinter/sheep/modules/league"
type Course struct {
RwID int64 `json:"id"`
Name string `json:"name"`
StartTime int64 `json:"start_time"`
EndTime int64 `json:"end_time"`
RwGameID int64 `json:"game_id"`
RwLeagueID int64 `json:"league_id"`
RwAreaID int64 `json:"area_id"`
Description string `json:"description"`
League league.League `json:"league"`
}

View File

@ -0,0 +1,142 @@
package course
import (
"errors"
"gitee.com/risewinter/sheep/models"
"gitee.com/risewinter/sheep/modules/area"
"gitee.com/risewinter/sheep/modules/game"
"gitee.com/risewinter/sheep/modules/league"
"gitee.com/risewinter/sheep/util"
)
type Course struct {
RwID int64 `json:"id"`
Name string `json:"name"`
StartTime int64 `json:"start_time"`
EndTime int64 `json:"end_time"`
RwGameID int64 `json:"game_id"`
RwLeagueID int64 `json:"league_id"`
RwAreaID int64 `json:"area_id"`
Description string `json:"description"`
League league.League `json:"league"`
}
func FindCourseByRwID(rwID int64) (findCourse models.Course, findErr error) {
if rwID <= 0 {
findErr = errors.New("赛事B端ID不能小于或者等于0")
return
}
if has, err := util.Engine.Where("rw_id = ?", rwID).Desc("id").Get(&findCourse); err != nil || !has {
findErr = errors.New("赛事不存在!")
return
}
return
}
func CreateCourse(course Course) (createCourse models.Course, createErr error) {
if course.RwID <= 0 {
createErr = errors.New("赛事B端ID不能小于或者等于0")
return
}
if course.Name == "" {
createErr = errors.New("赛事名称不能为空!")
return
}
if course.StartTime < 0 {
createErr = errors.New("赛事开始时间戳有误!")
return
}
if course.EndTime < 0 {
createErr = errors.New("赛事结束时间戳有误!")
return
}
if mGame, err := game.FindGameByRwID(course.RwGameID); err != nil {
createErr = errors.New("赛事游戏不存在!")
return
} else {
createCourse.GameID = mGame.ID
}
if mLeague, err := league.FindLeagueByRwID(course.RwLeagueID); err != nil {
createErr = errors.New("赛事联赛不存在!")
return
} else {
createCourse.LeagueID = mLeague.ID
}
if mArea, err := area.FindAreaByRwID(course.RwAreaID); err != nil {
createErr = errors.New("赛事赛区不存在!")
return
} else {
createCourse.AreaID = mArea.ID
}
createCourse.RwID = course.RwID
createCourse.Name = course.Name
createCourse.StartTime = course.StartTime
createCourse.EndTime = course.EndTime
createCourse.Description = course.Description
_, createErr = util.Engine.Insert(&createCourse)
return
}
func (course *Course) UpdateCourse() (result bool, updateCourse models.Course, updateErr error) {
if course.Name == "" {
updateErr = errors.New("赛事名称不能为空!")
return
}
if course.StartTime < 0 {
updateErr = errors.New("赛事开始时间戳有误!")
return
}
if course.EndTime < 0 {
updateErr = errors.New("赛事结束时间戳有误!")
return
}
if mGame, err := game.FindGameByRwID(course.RwGameID); err != nil {
updateErr = errors.New("赛事游戏不存在!")
return
} else {
updateCourse.GameID = mGame.ID
}
if mLeague, err := league.FindLeagueByRwID(course.RwLeagueID); err != nil {
updateErr = errors.New("赛事联赛不存在!")
return
} else {
updateCourse.LeagueID = mLeague.ID
}
if mArea, err := area.FindAreaByRwID(course.RwAreaID); err != nil {
updateErr = errors.New("赛事赛区不存在!")
return
} else {
updateCourse.AreaID = mArea.ID
}
updateCourse.RwID = course.RwID
updateCourse.Name = course.Name
updateCourse.StartTime = course.StartTime
updateCourse.EndTime = course.EndTime
updateCourse.Description = course.Description
_, updateErr = util.Engine.Update(&updateCourse)
if updateErr != nil {
result = true
}
return
}

View File

@ -1,12 +0,0 @@
package equipment
type Equipment struct {
RwID int64 `json:"rw_id"`
Name string `json:"name"`
NameEnglish string `json:"name_english"`
RwGameID int64 `json:"game_id"`
Alias string `json:"alias"`
Description string `json:"description"`
Icon string `json:"icon"`
Info string `json:"info"`
}

View File

@ -0,0 +1,141 @@
package equipment
import (
"errors"
"gitee.com/risewinter/sheep/models"
"gitee.com/risewinter/sheep/modules/game"
"gitee.com/risewinter/sheep/util"
)
type Equipment struct {
RwID int64 `json:"rw_id"`
Name string `json:"name"`
NameEnglish string `json:"name_english"`
RwGameID int64 `json:"game_id"`
Alias string `json:"alias"`
Description string `json:"description"`
Icon string `json:"icon"`
Info string `json:"info"`
}
func FindEquipmentByRwID(rwID int64) (findEquipment models.Equipment, findErr error) {
if rwID <= 0 {
findErr = errors.New("装备B端ID不能小于或者等于0")
return
}
if has, err := util.Engine.Where("rw_id = ?", rwID).Desc("id").Get(&findEquipment); err != nil || !has {
findErr = errors.New("装备不存在!")
return
}
return
}
func CreateEquipment(equipment Equipment) (createEquipment models.Equipment, createErr error) {
if equipment.RwID <= 0 {
createErr = errors.New("装备B端ID不能小于或者等于0")
return
}
if equipment.Name == "" {
createErr = errors.New("装备名称不能为空")
return
}
if equipment.NameEnglish == "" {
createErr = errors.New("装备英文名称不能为空")
return
}
if equipment.Alias == "" {
createErr = errors.New("装备别名不能为空")
return
}
if equipment.Description == "" {
createErr = errors.New("装备简介不能为空")
return
}
if equipment.Icon == "" {
createErr = errors.New("装备图标不能为空")
return
}
if equipment.Info == "" {
createErr = errors.New("装备其他信息不能为空")
return
}
if mGame, err := game.FindGameByRwID(equipment.RwGameID); err != nil {
createErr = errors.New("装备游戏不存在!")
return
} else {
createEquipment.GameID = mGame.ID
}
createEquipment.RwID = equipment.RwID
createEquipment.Name = equipment.Name
createEquipment.NameEnglish = equipment.NameEnglish
createEquipment.Alias = equipment.Alias
createEquipment.Description = equipment.Description
createEquipment.Icon = equipment.Icon
_, createErr = util.Engine.Insert(&createEquipment)
return
}
func (equipment *Equipment) UpdateEquipment() (result bool, updateEquipment models.Equipment, updateErr error) {
if equipment.Name == "" {
updateErr = errors.New("装备名称不能为空")
return
}
if equipment.NameEnglish == "" {
updateErr = errors.New("装备英文名称不能为空")
return
}
if equipment.Alias == "" {
updateErr = errors.New("装备别名不能为空")
return
}
if equipment.Description == "" {
updateErr = errors.New("装备简介不能为空")
return
}
if equipment.Icon == "" {
updateErr = errors.New("装备图标不能为空")
return
}
if equipment.Info == "" {
updateErr = errors.New("装备其他信息不能为空")
return
}
if mGame, err := game.FindGameByRwID(equipment.RwGameID); err != nil {
updateErr = errors.New("装备游戏不存在!")
return
} else {
updateEquipment.GameID = mGame.ID
}
updateEquipment.Name = equipment.Name
updateEquipment.NameEnglish = equipment.NameEnglish
updateEquipment.Alias = equipment.Alias
updateEquipment.Description = equipment.Description
updateEquipment.Icon = equipment.Icon
_, updateErr = util.Engine.Update(&updateEquipment)
if updateErr != nil {
result = true
}
return
}

View File

@ -1,41 +0,0 @@
package game
import (
"errors"
"gitee.com/risewinter/sheep/models"
"gitee.com/risewinter/sheep/util"
)
type Game struct {
RwID int64 `json:"id"`
Name string `json:"name"`
ShortName string `json:"short_name"`
Code string `json:"code"`
}
func CreateGame(game Game) (err error) {
if game.RwID <= 0 {
return errors.New("B端ID不能小于或者等于0")
}
if game.Name == "" {
return errors.New("游戏名称不能为空")
}
if game.ShortName == "" {
return errors.New("游戏简称不能为空")
}
if game.Code == "" {
return errors.New("游戏标识不能为空")
}
newGame := new(models.Game)
newGame.RwID = game.RwID
newGame.Name = game.Name
newGame.ShortName = game.ShortName
newGame.Code = game.Code
if _, gameErr := util.Engine.Insert(newGame); gameErr != nil {
err = gameErr
return
}
return
}

54
modules/game/CurdGame.go Normal file
View File

@ -0,0 +1,54 @@
package game
import (
"errors"
"gitee.com/risewinter/sheep/models"
"gitee.com/risewinter/sheep/util"
)
type Game struct {
RwID int64 `json:"id"`
Name string `json:"name"`
ShortName string `json:"short_name"`
Code string `json:"code"`
}
func FindGameByRwID(rwID int64) (findGame models.Game, findErr error) {
if rwID <= 0 {
findErr = errors.New("B端ID不能小于或者等于0")
return
}
if has, err := util.Engine.Where("rw_id = ?", rwID).Desc("id").Get(&findGame); err != nil || !has {
findErr = errors.New("游戏不存在!")
}
return
}
func CreateGame(game Game) (createGame models.Game, createErr error) {
if game.RwID <= 0 {
createErr = errors.New("B端ID不能小于或者等于0")
return
}
if game.Name == "" {
createErr = errors.New("游戏名称不能为空")
return
}
if game.ShortName == "" {
createErr = errors.New("游戏简称不能为空")
return
}
if game.Code == "" {
createErr = errors.New("游戏标识不能为空")
return
}
createGame.RwID = game.RwID
createGame.Name = game.Name
createGame.ShortName = game.ShortName
createGame.Code = game.Code
_, createErr = util.Engine.Insert(&createGame)
return
}

View File

@ -1,20 +0,0 @@
package league
type League struct {
RwID int64 `json:"id"`
Name string `json:"name"`
ShortName string `json:"short_name"`
NameEnglish string `json:"name_english"`
Bonus int64 `json:"bonus"`
BonusType int `json:"bonus_type"`
Alias []string `json:"alias"`
Logo string `json:"logo"`
Organizer string `json:"organizer"`
Level string `json:"level"`
Local string `json:"local"`
RwGameID string `json:"game_id"`
RwAreaID string `json:"area_id"`
GameType string `json:"game_type"`
LimitTeam int `json:"limit_team"`
Description string `json:"description"`
}

View File

@ -0,0 +1,199 @@
package league
import (
"errors"
"gitee.com/risewinter/sheep/models"
"gitee.com/risewinter/sheep/modules/area"
"gitee.com/risewinter/sheep/modules/game"
"gitee.com/risewinter/sheep/util"
)
type League struct {
RwID int64 `json:"id"`
Name string `json:"name"`
ShortName string `json:"short_name"`
NameEnglish string `json:"name_english"`
Bonus int64 `json:"bonus"`
BonusType int `json:"bonus_type"`
Alias []string `json:"alias"`
Logo string `json:"logo"`
Organizer string `json:"organizer"`
Level int `json:"level"`
Local string `json:"local"`
RwGameID int64 `json:"game_id"`
RwAreaID int64 `json:"area_id"`
GameType int `json:"game_type"`
LimitTeam int `json:"limit_team"`
Description string `json:"description"`
}
func FindLeagueByRwID(rwID int64) (findLeague models.League, findErr error) {
if rwID <= 0 {
findErr = errors.New("联赛B端ID不能小于或者等于0")
return
}
if has, err := util.Engine.Where("rw_id = ?", rwID).Desc("id").Get(&findLeague); err != nil || !has {
findErr = errors.New("联赛不存在!")
return
}
return
}
func CreateLeague(league League) (createLeague models.League, createErr error) {
if league.RwID <= 0 {
createErr = errors.New("联赛B端ID不能小于或者等于0")
return
}
if league.Name == "" {
createErr = errors.New("联赛名称不能为空!")
return
}
if league.ShortName == "" {
createErr = errors.New("联赛简称不能为空!")
return
}
if league.Bonus < 0 {
createErr = errors.New("联赛奖金不能小于0")
return
}
if league.BonusType != 1 && league.BonusType != 2 {
createErr = errors.New("联赛奖金单位有误!")
return
}
if league.Logo == "" {
createErr = errors.New("联赛logo不能为空")
return
}
if league.Level < 0 {
createErr = errors.New("联赛等级不能小于0")
return
}
if league.GameType < 0 {
createErr = errors.New("联赛游戏类型不能小于0")
return
}
if league.LimitTeam < 0 {
createErr = errors.New("联赛队伍数量不能小于0")
return
}
if mGame, err := game.FindGameByRwID(league.RwGameID); err != nil {
createErr = errors.New("联赛游戏不存在!")
return
} else {
createLeague.GameID = mGame.ID
}
if mArea, err := area.FindAreaByRwID(league.RwAreaID); err != nil {
createErr = errors.New("联赛赛区不存在!")
return
} else {
createLeague.AreaID = mArea.ID
}
createLeague.RwID = league.RwID
createLeague.Name = league.Name
createLeague.ShortName = league.ShortName
createLeague.Bonus = league.Bonus
createLeague.BonusType = league.BonusType
createLeague.Alias = league.Alias
createLeague.Logo = league.Logo
createLeague.Organizer = league.Organizer
createLeague.Level = league.Level
createLeague.Local = league.Local
createLeague.GameType = league.GameType
createLeague.LimitTeam = league.LimitTeam
createLeague.Description = league.Description
_, createErr = util.Engine.Insert(&createLeague)
return
}
func (league *League) UpdateLeague() (result bool, updateLeague models.League, updateErr error) {
if league.Name == "" {
updateErr = errors.New("联赛名称不能为空!")
return
}
if league.ShortName == "" {
updateErr = errors.New("联赛简称不能为空!")
return
}
if league.Bonus < 0 {
updateErr = errors.New("联赛奖金不能小于0")
return
}
if league.BonusType != 1 && league.BonusType != 2 {
updateErr = errors.New("联赛奖金单位有误!")
return
}
if league.Logo == "" {
updateErr = errors.New("联赛logo不能为空")
return
}
if league.Level < 0 {
updateErr = errors.New("联赛等级不能小于0")
return
}
if league.GameType < 0 {
updateErr = errors.New("联赛游戏类型不能小于0")
return
}
if league.LimitTeam < 0 {
updateErr = errors.New("联赛队伍数量不能小于0")
return
}
if mGame, err := game.FindGameByRwID(league.RwGameID); err != nil {
updateErr = errors.New("联赛游戏不存在!")
return
} else {
updateLeague.GameID = mGame.ID
}
if mArea, err := area.FindAreaByRwID(league.RwAreaID); err != nil {
updateErr = errors.New("联赛赛区不存在!")
return
} else {
updateLeague.AreaID = mArea.ID
}
updateLeague.RwID = league.RwID
updateLeague.Name = league.Name
updateLeague.ShortName = league.ShortName
updateLeague.Bonus = league.Bonus
updateLeague.BonusType = league.BonusType
updateLeague.Alias = league.Alias
updateLeague.Logo = league.Logo
updateLeague.Organizer = league.Organizer
updateLeague.Level = league.Level
updateLeague.Local = league.Local
updateLeague.GameType = league.GameType
updateLeague.LimitTeam = league.LimitTeam
updateLeague.Description = league.Description
_, updateErr = util.Engine.Update(&updateLeague)
if updateErr != nil {
result = true
}
return
}

View File

@ -1,11 +0,0 @@
package role
type Role struct {
RwID int64 `json:"id"`
Name string `json:"name"`
NameEnglish string `json:"name_english"`
Alias string `json:"alias"`
Description string `json:"description"`
Icon string `json:"icon"`
Info string `json:"info"`
}

142
modules/role/CurdRole.go Normal file
View File

@ -0,0 +1,142 @@
package role
import (
"errors"
"gitee.com/risewinter/sheep/models"
"gitee.com/risewinter/sheep/modules/game"
"gitee.com/risewinter/sheep/util"
)
type Role struct {
RwID int64 `json:"id"`
Name string `json:"name"`
NameEnglish string `json:"name_english"`
Alias string `json:"alias"`
RwGameID int64 `json:"game_id"`
Description string `json:"description"`
Icon string `json:"icon"`
Info string `json:"info"`
}
func FindRoleByRwID(rwID int64) (findRole models.Role, findErr error) {
if rwID <= 0 {
findErr = errors.New("B端ID不能小于或者等于0")
return
}
if has, err := util.Engine.Where("rw_id = ?", rwID).Desc("id").Get(&findRole); err != nil || !has {
findErr = errors.New("英雄不存在!")
return
}
return
}
func CreateRole(role Role) (createRole models.Role, createErr error) {
if role.RwID <= 0 {
createErr = errors.New("英雄B端ID不能小于或者等于0")
return
}
if role.Name == "" {
createErr = errors.New("英雄名称不能为空!")
return
}
if role.NameEnglish == "" {
createErr = errors.New("英雄英文名称不能为空!")
return
}
if role.Icon == "" {
createErr = errors.New("英雄头像不能为空!")
return
}
if role.Alias == "" {
createErr = errors.New("英雄别名不能为空!")
return
}
if role.Description == "" {
createErr = errors.New("英雄简介不能为空!")
return
}
if role.Info == "" {
createErr = errors.New("英雄其他信息不能为空!")
return
}
if mGame, err := game.FindGameByRwID(role.RwGameID); err != nil {
createErr = errors.New("英雄游戏不存在!")
return
} else {
createRole.GameID = mGame.ID
}
createRole.RwID = role.RwID
createRole.Name = role.Name
createRole.NameEnglish = role.NameEnglish
createRole.Icon = role.Icon
createRole.Alias = role.Alias
createRole.Description = role.Description
_, createErr = util.Engine.Insert(&createRole)
return
}
func (role *Role) UpdateRole() (result bool, updateRole models.Role, updateErr error) {
if role.Name == "" {
updateErr = errors.New("英雄名称不能为空!")
return
}
if role.NameEnglish == "" {
updateErr = errors.New("英雄英文名称不能为空!")
return
}
if role.Icon == "" {
updateErr = errors.New("英雄头像不能为空!")
return
}
if role.Alias == "" {
updateErr = errors.New("英雄别名不能为空!")
return
}
if role.Description == "" {
updateErr = errors.New("英雄简介不能为空!")
return
}
if role.Info == "" {
updateErr = errors.New("英雄其他信息不能为空!")
return
}
if mGame, err := game.FindGameByRwID(role.RwGameID); err != nil {
updateErr = errors.New("英雄游戏不存在!")
return
} else {
updateRole.GameID = mGame.ID
}
updateRole.RwID = role.RwID
updateRole.Name = role.Name
updateRole.NameEnglish = role.NameEnglish
updateRole.Icon = role.Icon
updateRole.Alias = role.Alias
updateRole.Description = role.Description
_, updateErr = util.Engine.Update(&updateRole)
if updateErr != nil {
result = true
}
return
}

View File

@ -1,13 +0,0 @@
package skill
type Skill struct {
RwID int64 `json:"id"`
Name string `json:"name"`
NameEnglish string `json:"name_english"`
RwGameID int64 `json:"game_id"`
RwRoleID int64 `json:"game_role_id"`
RwEquipmentID int64 `json:"game_equipment_id"`
Alias string `json:"alias"`
Description string `json:"description"`
Icon string `json:"icon"`
}

166
modules/skill/CurdSkill.go Normal file
View File

@ -0,0 +1,166 @@
package skill
import (
"errors"
"gitee.com/risewinter/sheep/models"
"gitee.com/risewinter/sheep/modules/equipment"
"gitee.com/risewinter/sheep/modules/game"
"gitee.com/risewinter/sheep/modules/role"
"gitee.com/risewinter/sheep/util"
)
type Skill struct {
RwID int64 `json:"id"`
Name string `json:"name"`
NameEnglish string `json:"name_english"`
RwGameID int64 `json:"game_id"`
RwRoleID int64 `json:"game_role_id"`
RwEquipmentID int64 `json:"game_equipment_id"`
Alias string `json:"alias"`
Description string `json:"description"`
Icon string `json:"icon"`
}
func FindSkillByRwID(rwID int64) (findSkill models.Skill, findErr error) {
if rwID <= 0 {
findErr = errors.New("B端ID不能小于或者等于0")
return
}
if has, err := util.Engine.Where("rw_id = ?", rwID).Desc("id").Get(&findSkill); err != nil || !has {
findErr = errors.New("技能不存在!")
return
}
return
}
func CreateSkill(skill Skill) (createSkill models.Skill, createErr error) {
if skill.RwID <= 0 {
createErr = errors.New("B端ID不能小于或者等于0")
return
}
if skill.Name == "" {
createErr = errors.New("技能名称不能为空!")
return
}
if skill.NameEnglish == "" {
createErr = errors.New("技能英文名称不能为空!")
return
}
if skill.Alias == "" {
createErr = errors.New("技能别名不能为空!")
return
}
if skill.Description == "" {
createErr = errors.New("技能简介不能为空!")
return
}
if skill.Icon == "" {
createErr = errors.New("技能图标不能为空!")
return
}
if mGame, err := game.FindGameByRwID(skill.RwGameID); err != nil {
createErr = errors.New("技能游戏不存在!")
return
} else {
createSkill.GameID = mGame.ID
}
if skill.RwRoleID > 0 {
if mRole, err := role.FindRoleByRwID(skill.RwRoleID); err != nil {
createErr = errors.New("技能英雄不存在!")
} else {
createSkill.RoleId = mRole.ID
}
}
if skill.RwEquipmentID > 0 {
if mEquipment, err := equipment.FindEquipmentByRwID(skill.RwEquipmentID); err != nil {
createErr = errors.New("技能装备不存在!")
} else {
createSkill.EquipmentId = mEquipment.ID
}
}
createSkill.RwID = skill.RwID
createSkill.Name = skill.Name
createSkill.NameEnglish = skill.NameEnglish
createSkill.Alias = skill.Alias
createSkill.Description = skill.Description
createSkill.Icon = skill.Icon
_, createErr = util.Engine.Insert(&createSkill)
return
}
func (skill *Skill) UpdateSkill() (result bool, updateSkill models.Skill, updateErr error) {
if skill.Name == "" {
updateErr = errors.New("技能名称不能为空!")
return
}
if skill.NameEnglish == "" {
updateErr = errors.New("技能英文名称不能为空!")
return
}
if skill.Alias == "" {
updateErr = errors.New("技能别名不能为空!")
return
}
if skill.Description == "" {
updateErr = errors.New("技能简介不能为空!")
return
}
if skill.Icon == "" {
updateErr = errors.New("技能图标不能为空!")
return
}
if mGame, err := game.FindGameByRwID(skill.RwGameID); err != nil {
updateErr = errors.New("技能游戏不存在!")
return
} else {
updateSkill.GameID = mGame.ID
}
if skill.RwRoleID > 0 {
if mRole, err := role.FindRoleByRwID(skill.RwRoleID); err != nil {
updateErr = errors.New("技能英雄不存在!")
} else {
updateSkill.RoleId = mRole.ID
}
}
if skill.RwEquipmentID > 0 {
if mEquipment, err := equipment.FindEquipmentByRwID(skill.RwEquipmentID); err != nil {
updateErr = errors.New("技能装备不存在!")
} else {
updateSkill.EquipmentId = mEquipment.ID
}
}
updateSkill.Name = skill.Name
updateSkill.NameEnglish = skill.NameEnglish
updateSkill.Alias = skill.Alias
updateSkill.Description = skill.Description
updateSkill.Icon = skill.Icon
_, updateErr = util.Engine.Update(&updateSkill)
if updateErr != nil {
result = true
}
return
}

View File

@ -1,25 +0,0 @@
package team
type Team struct {
RwID int64 `json:"id"`
RwGameID int64 `json:"game_id"`
Name string `json:"name"`
NameEnglish string `json:"name_english"`
ShortName string `json:"short_name"`
Local string `json:"local"`
Country string `json:"country"`
Area string `json:"area"`
Alias []string `json:"alias"`
Logo string `json:"logo"`
Players []Player `json:"players"`
}
type Player struct {
RwID int64 `json:"id"`
Name string `json:"name"`
NameEnglish string `json:"name_english"`
Alias []string `json:"alias"`
Country string `json:"country"`
TeamPlayerPosition string `json:"team_player"`
ExtendInfo string `json:"extend_info"`
}

375
modules/team/CurdTeam.go Normal file
View File

@ -0,0 +1,375 @@
package team
import (
"errors"
"fmt"
"gitee.com/risewinter/sheep/models"
"gitee.com/risewinter/sheep/modules/game"
"gitee.com/risewinter/sheep/util"
)
type Team struct {
RwID int64 `json:"id"`
RwGameID int64 `json:"game_id"`
GameType int `json:"game_type"`
Name string `json:"name"`
NameEnglish string `json:"name_english"`
ShortName string `json:"short_name"`
Local string `json:"local"`
Country string `json:"country"`
Area string `json:"area"`
Alias []string `json:"alias"`
Logo string `json:"logo"`
Players []Player `json:"players"`
}
type Player struct {
RwID int64 `json:"id"`
Name string `json:"name"`
NameEnglish string `json:"name_english"`
Alias []string `json:"alias"`
Country string `json:"country"`
TeamPlayerPosition string `json:"team_player"`
ExtendInfo string `json:"extend_info"`
}
func FindTeamByRwID(rwID int64) (findTeam models.Team, findErr error) {
if rwID <= 0 {
findErr = errors.New("B端ID不能小于或者等于0")
return
}
if has, err := util.Engine.Where("rw_id = ?", rwID).Desc("id").Get(&findTeam); err != nil || !has {
findErr = errors.New("队伍不存在!")
return
}
return
}
func FindPlayerByRwID(rwID int64) (findPlayer models.Player, findErr error) {
if rwID <= 0 {
findErr = errors.New("B端ID不能小于或者等于0")
return
}
if has, err := util.Engine.Where("rw_id = ?", rwID).Desc("id").Get(&findPlayer); err != nil || !has {
findErr = errors.New("队员不存在!")
return
}
return
}
func CreateTeam(team Team) (createTeam models.Team, createErr error) {
if team.RwID <= 0 {
createErr = errors.New("队伍B端ID不能小于或者等于0")
return
}
if team.GameType <= 0 {
createErr = errors.New("队伍游戏类型错误!")
return
}
if team.Name == "" {
createErr = errors.New("队伍名称不能为空!")
return
}
// 暂无
//if team.NameEnglish == "" {
// createErr = errors.New("队伍英文名称不能为空!")
// return
//}
if team.ShortName == "" {
createErr = errors.New("队伍简称不能为空!")
return
}
// 暂无
//if team.Local == "" {
// createErr = errors.New("队伍所属地不能为空!")
// return
//}
if team.Country == "" {
createErr = errors.New("队伍所属国家不能为空!")
return
}
// 暂无
//if team.Area == "" {
// createErr = errors.New("队伍所属地区不能为空!")
// return
//}
if team.Logo == "" {
createErr = errors.New("队伍logo不能为空")
return
}
if mGame, err := game.FindGameByRwID(team.RwGameID); err != nil {
createErr = errors.New("队伍游戏不存在!")
return
} else {
createTeam.GameID = mGame.ID
}
createTeam.RwID = team.RwID
createTeam.GameType = team.GameType
createTeam.Name = team.Name
createTeam.NameEnglish = team.NameEnglish
createTeam.ShortName = team.ShortName
createTeam.Local = team.Local
createTeam.Country = team.Country
createTeam.Area = team.Area
createTeam.Alias = team.Alias
createTeam.Logo = team.Logo
// 开启事务
session := util.Engine.NewSession()
defer session.Close()
if err := session.Begin(); err != nil {
createErr = errors.New("事务开启失败!")
_ = session.Rollback()
return
}
// 创建队伍
if _, err := session.Insert(&createTeam); err != nil {
createErr = errors.New(fmt.Sprintf("队伍创建失败:%v", err))
_ = session.Rollback()
return
}
for _, player := range team.Players {
// 查找该队员是否已经存在
if _, err := FindPlayerByRwID(player.RwID); err == nil {
// 已存在,更新该队员
result, updatePlayer, _ := player.BuildUpdatePlayer()
if result == true {
if i, err := session.Update(&updatePlayer); err != nil || i != 1 {
createErr = errors.New(fmt.Sprintf("rw_id为%d的队员更新失败", player.RwID))
_ = session.Rollback()
return
}
} else {
createErr = errors.New(fmt.Sprintf("rw_id为%d的队员参数错误", player.RwID))
_ = session.Rollback()
return
}
} else {
// 不存在,创建该队员
if mPlayer, err := BuildCreatePlayer(player); err != nil {
createErr = errors.New(fmt.Sprintf("rw_id为%d的队员参数错误%s", player.RwID, err))
return
} else {
if _, err := session.Insert(&mPlayer); err != nil {
createErr = errors.New(fmt.Sprintf("rw_id为%d的队员创建失败", player.RwID))
_ = session.Rollback()
return
}
}
}
}
// 提交事务
if err := session.Commit(); err != nil {
createErr = errors.New("事务commit失败")
return
}
return
}
func (team *Team) UpdateTeam (result bool, updateTeam models.Team, updateErr error) {
if team.GameType <= 0 {
updateErr = errors.New("队伍游戏类型错误!")
return
}
if team.Name == "" {
updateErr = errors.New("队伍名称不能为空!")
return
}
// 暂无
//if team.NameEnglish == "" {
// updateErr = errors.New("队伍英文名称不能为空!")
// return
//}
if team.ShortName == "" {
updateErr = errors.New("队伍简称不能为空!")
return
}
// 暂无
//if team.Local == "" {
// updateErr = errors.New("队伍所属地不能为空!")
// return
//}
if team.Country == "" {
updateErr = errors.New("队伍所属国家不能为空!")
return
}
// 暂无
//if team.Area == "" {
// updateErr = errors.New("队伍所属地区不能为空!")
// return
//}
if team.Logo == "" {
updateErr = errors.New("队伍logo不能为空")
return
}
if mGame, err := game.FindGameByRwID(team.RwGameID); err != nil {
updateErr = errors.New("队伍游戏不存在!")
return
} else {
updateTeam.GameID = mGame.ID
}
updateTeam.GameType = team.GameType
updateTeam.Name = team.Name
updateTeam.NameEnglish = team.NameEnglish
updateTeam.ShortName = team.ShortName
updateTeam.Local = team.Local
updateTeam.Country = team.Country
updateTeam.Area = team.Area
updateTeam.Alias = team.Alias
updateTeam.Logo = team.Logo
// 开启事务
session := util.Engine.NewSession()
defer session.Close()
if err := session.Begin(); err != nil {
updateErr = errors.New("事务开启失败!")
_ = session.Rollback()
return
}
// 创建队伍
if _, err := session.Update(&updateTeam); err != nil {
updateErr = errors.New(fmt.Sprintf("队伍更新失败:%v", err))
_ = session.Rollback()
return
}
for _, player := range team.Players {
// 查找该队员是否已经存在
if _, err := FindPlayerByRwID(player.RwID); err == nil {
// 已存在,更新该队员
result, updatePlayer, _ := player.BuildUpdatePlayer()
if result == true {
if i, err := session.Update(&updatePlayer); err != nil || i != 1 {
updateErr = errors.New(fmt.Sprintf("rw_id为%d的队员更新失败", player.RwID))
_ = session.Rollback()
return
}
} else {
updateErr = errors.New(fmt.Sprintf("rw_id为%d的队员参数错误", player.RwID))
_ = session.Rollback()
return
}
} else {
// 不存在,创建该队员
if mPlayer, err := BuildCreatePlayer(player); err != nil {
updateErr = errors.New(fmt.Sprintf("rw_id为%d的队员参数错误%s", player.RwID, err))
return
} else {
if _, err := session.Insert(&mPlayer); err != nil {
updateErr = errors.New(fmt.Sprintf("rw_id为%d的队员创建失败", player.RwID))
_ = session.Rollback()
return
}
}
}
}
// 提交事务
if err := session.Commit(); err != nil {
updateErr = errors.New("事务commit失败")
return
}
return
}
func BuildCreatePlayer(player Player) (createPlayer models.Player, createErr error) {
if player.RwID <= 0 {
createErr = errors.New("队员B端ID不能小于或者等于0")
return
}
if player.Name == "" {
createErr = errors.New("队员名称不能为空!")
return
}
if player.NameEnglish == "" {
createErr = errors.New("队员英文名称不能为空!")
return
}
if player.Country == "" {
createErr = errors.New("队员所属国家不能为空!")
return
}
if player.TeamPlayerPosition == "" {
createErr = errors.New("队员归属位置不能为空!")
return
}
createPlayer.RwID = player.RwID
createPlayer.Name = player.Name
createPlayer.NameEnglish = player.NameEnglish
createPlayer.Alias = player.Alias
createPlayer.Country = player.Country
createPlayer.TeamPlayerPosition = player.TeamPlayerPosition
createPlayer.ExtendInfo = player.ExtendInfo
return
}
func (player *Player) BuildUpdatePlayer() (result bool, updatePlayer models.Player, updateErr error) {
if player.Name == "" {
updateErr = errors.New("队员名称不能为空!")
return
}
if player.NameEnglish == "" {
updateErr = errors.New("队员英文名称不能为空!")
return
}
if player.Country == "" {
updateErr = errors.New("队员所属国家不能为空!")
return
}
if player.TeamPlayerPosition == "" {
updateErr = errors.New("队员归属位置不能为空!")
return
}
updatePlayer.Name = player.Name
updatePlayer.NameEnglish = player.NameEnglish
updatePlayer.Alias = player.Alias
updatePlayer.Country = player.Country
updatePlayer.TeamPlayerPosition = player.TeamPlayerPosition
updatePlayer.ExtendInfo = player.ExtendInfo
result = true
return
}