19 changed files with 554 additions and 3 deletions
@ -0,0 +1,48 @@
|
||||
package game |
||||
|
||||
import ( |
||||
"github.com/gogf/gf/v2/frame/g" |
||||
"tyj_admin/api/v1/common" |
||||
"tyj_admin/internal/model/entity" |
||||
) |
||||
|
||||
type GetActivityConfigsReq struct { |
||||
g.Meta `path:"/gameActivity/list" tags:"gameActivity" method:"get" summary:"获取"` |
||||
common.PageReq |
||||
ServerId int32 `p:"serverId"` |
||||
} |
||||
type GetActivityConfigsRes struct { |
||||
g.Meta `mime:"application/json"` |
||||
List []entity.GameActivityTime `json:"list"` |
||||
common.ListRes |
||||
} |
||||
|
||||
type GetAllGameActivityReq struct { |
||||
g.Meta `path:"/gameActivity/get" tags:"gameActivity" method:"get" summary:"获取"` |
||||
ServerId int32 `p:"serverId"` |
||||
} |
||||
type GetAllGameActivityRes struct { |
||||
g.Meta `mime:"application/json"` |
||||
List []entity.GameActivityTime `json:"list"` |
||||
} |
||||
|
||||
type AddActivityConfigReq struct { |
||||
g.Meta `path:"/gameActivity/add" tags:"gameActivity" method:"get" summary:"添加gameActivity"` |
||||
Id int32 `p:"id"` |
||||
ServerId int32 `p:"serverId"` |
||||
ConfigId int32 `p:"configId"` |
||||
PreviewTime string `p:"previewTime"` |
||||
StartTime string `p:"startTime"` |
||||
EndTime string `p:"endTime"` |
||||
CloseTime string `p:"closeTime"` |
||||
Remark string `p:"remark"` |
||||
} |
||||
type AddActivityConfigRes struct { |
||||
} |
||||
|
||||
type DelActivityConfigReq struct { |
||||
g.Meta `path:"/gameActivity/del" tags:"gameActivity" method:"get" summary:"删除热更地址"` |
||||
Id int32 `p:"id"` |
||||
} |
||||
type DelActivityConfigRes struct { |
||||
} |
||||
@ -0,0 +1,33 @@
|
||||
package controller |
||||
|
||||
import ( |
||||
"context" |
||||
"tyj_admin/api/v1/game" |
||||
"tyj_admin/internal/serviceGame" |
||||
) |
||||
|
||||
var GameActivity = activityController{} |
||||
|
||||
type activityController struct { |
||||
BaseController |
||||
} |
||||
|
||||
func (c *activityController) GetGameActivity(ctx context.Context, req *game.GetActivityConfigsReq) (res *game.GetActivityConfigsRes, err error) { |
||||
res, err = serviceGame.GameActivity().GetGameActivity(ctx, req) |
||||
return |
||||
} |
||||
|
||||
func (c *activityController) AddGameActivity(ctx context.Context, req *game.AddActivityConfigReq) (res *game.AddActivityConfigRes, err error) { |
||||
res, err = serviceGame.GameActivity().AddGameActivity(ctx, req) |
||||
return |
||||
} |
||||
|
||||
func (c *activityController) DelGameActivity(ctx context.Context, req *game.DelActivityConfigReq) (res *game.DelActivityConfigRes, err error) { |
||||
res, err = serviceGame.GameActivity().DelGameActivity(ctx, req) |
||||
return |
||||
} |
||||
|
||||
func (c *serverController) GetAllGameActivity(ctx context.Context, req *game.GetAllGameActivityReq) (res *game.GetAllGameActivityRes, err error) { |
||||
res, err = serviceGame.GameActivity().GetAllGameActivity(ctx, req) |
||||
return |
||||
} |
||||
@ -0,0 +1,27 @@
|
||||
// =================================================================================
|
||||
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||
// =================================================================================
|
||||
|
||||
package dao |
||||
|
||||
import ( |
||||
"tyj_admin/internal/dao/internal" |
||||
) |
||||
|
||||
// internalCsjAdvertisementDao is internal type for wrapping internal DAO implements.
|
||||
type internalCsjAdvertisementDao = *internal.CsjAdvertisementDao |
||||
|
||||
// csjAdvertisementDao is the data access object for table csj_advertisement.
|
||||
// You can define custom methods on it to extend its functionality as you wish.
|
||||
type csjAdvertisementDao struct { |
||||
internalCsjAdvertisementDao |
||||
} |
||||
|
||||
var ( |
||||
// CsjAdvertisement is globally public accessible object for table csj_advertisement operations.
|
||||
CsjAdvertisement = csjAdvertisementDao{ |
||||
internal.NewCsjAdvertisementDao(), |
||||
} |
||||
) |
||||
|
||||
// Fill with you ideas below.
|
||||
@ -0,0 +1,27 @@
|
||||
// =================================================================================
|
||||
// This is auto-generated by GoFrame CLI tool only once. Fill this file as you wish.
|
||||
// =================================================================================
|
||||
|
||||
package dao |
||||
|
||||
import ( |
||||
"tyj_admin/internal/dao/internal" |
||||
) |
||||
|
||||
// internalGameActivityTimeDao is internal type for wrapping internal DAO implements.
|
||||
type internalGameActivityTimeDao = *internal.GameActivityTimeDao |
||||
|
||||
// gameActivityTimeDao is the data access object for table game_activity_time.
|
||||
// You can define custom methods on it to extend its functionality as you wish.
|
||||
type gameActivityTimeDao struct { |
||||
internalGameActivityTimeDao |
||||
} |
||||
|
||||
var ( |
||||
// GameActivityTime is globally public accessible object for table game_activity_time operations.
|
||||
GameActivityTime = gameActivityTimeDao{ |
||||
internal.NewGameActivityTimeDao(), |
||||
} |
||||
) |
||||
|
||||
// Fill with you ideas below.
|
||||
@ -0,0 +1,79 @@
|
||||
// ==========================================================================
|
||||
// Code generated by GoFrame CLI tool. DO NOT EDIT.
|
||||
// ==========================================================================
|
||||
|
||||
package internal |
||||
|
||||
import ( |
||||
"context" |
||||
|
||||
"github.com/gogf/gf/v2/database/gdb" |
||||
"github.com/gogf/gf/v2/frame/g" |
||||
) |
||||
|
||||
// CsjAdvertisementDao is the data access object for table csj_advertisement.
|
||||
type CsjAdvertisementDao struct { |
||||
table string // table is the underlying table name of the DAO.
|
||||
group string // group is the database configuration group name of current DAO.
|
||||
columns CsjAdvertisementColumns // columns contains all the column names of Table for convenient usage.
|
||||
} |
||||
|
||||
// CsjAdvertisementColumns defines and stores column names for table csj_advertisement.
|
||||
type CsjAdvertisementColumns struct { |
||||
Id string //
|
||||
PrimeRit string //
|
||||
MediationRit string //
|
||||
MKey string //
|
||||
} |
||||
|
||||
// csjAdvertisementColumns holds the columns for table csj_advertisement.
|
||||
var csjAdvertisementColumns = CsjAdvertisementColumns{ |
||||
Id: "id", |
||||
PrimeRit: "prime_rit", |
||||
MediationRit: "mediation_rit", |
||||
MKey: "m_key", |
||||
} |
||||
|
||||
// NewCsjAdvertisementDao creates and returns a new DAO object for table data access.
|
||||
func NewCsjAdvertisementDao() *CsjAdvertisementDao { |
||||
return &CsjAdvertisementDao{ |
||||
group: "default", |
||||
table: "csj_advertisement", |
||||
columns: csjAdvertisementColumns, |
||||
} |
||||
} |
||||
|
||||
// DB retrieves and returns the underlying raw database management object of current DAO.
|
||||
func (dao *CsjAdvertisementDao) DB() gdb.DB { |
||||
return g.DB(dao.group) |
||||
} |
||||
|
||||
// Table returns the table name of current dao.
|
||||
func (dao *CsjAdvertisementDao) Table() string { |
||||
return dao.table |
||||
} |
||||
|
||||
// Columns returns all column names of current dao.
|
||||
func (dao *CsjAdvertisementDao) Columns() CsjAdvertisementColumns { |
||||
return dao.columns |
||||
} |
||||
|
||||
// Group returns the configuration group name of database of current dao.
|
||||
func (dao *CsjAdvertisementDao) Group() string { |
||||
return dao.group |
||||
} |
||||
|
||||
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
|
||||
func (dao *CsjAdvertisementDao) Ctx(ctx context.Context) *gdb.Model { |
||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx) |
||||
} |
||||
|
||||
// Transaction wraps the transaction logic using function f.
|
||||
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
|
||||
// It commits the transaction and returns nil if function f returns nil.
|
||||
//
|
||||
// Note that, you should not Commit or Rollback the transaction in function f
|
||||
// as it is automatically handled by this function.
|
||||
func (dao *CsjAdvertisementDao) Transaction(ctx context.Context, f func(ctx context.Context, tx *gdb.TX) error) (err error) { |
||||
return dao.Ctx(ctx).Transaction(ctx, f) |
||||
} |
||||
@ -0,0 +1,87 @@
|
||||
// ==========================================================================
|
||||
// Code generated by GoFrame CLI tool. DO NOT EDIT.
|
||||
// ==========================================================================
|
||||
|
||||
package internal |
||||
|
||||
import ( |
||||
"context" |
||||
|
||||
"github.com/gogf/gf/v2/database/gdb" |
||||
"github.com/gogf/gf/v2/frame/g" |
||||
) |
||||
|
||||
// GameActivityTimeDao is the data access object for table game_activity_time.
|
||||
type GameActivityTimeDao struct { |
||||
table string // table is the underlying table name of the DAO.
|
||||
group string // group is the database configuration group name of current DAO.
|
||||
columns GameActivityTimeColumns // columns contains all the column names of Table for convenient usage.
|
||||
} |
||||
|
||||
// GameActivityTimeColumns defines and stores column names for table game_activity_time.
|
||||
type GameActivityTimeColumns struct { |
||||
Id string //
|
||||
PreviewTime string //
|
||||
StartTime string //
|
||||
EndTime string //
|
||||
CloseTime string //
|
||||
ServerId string //
|
||||
ConfigId string //
|
||||
Remark string //
|
||||
} |
||||
|
||||
// gameActivityTimeColumns holds the columns for table game_activity_time.
|
||||
var gameActivityTimeColumns = GameActivityTimeColumns{ |
||||
Id: "id", |
||||
PreviewTime: "preview_time", |
||||
StartTime: "start_time", |
||||
EndTime: "end_time", |
||||
CloseTime: "close_time", |
||||
ServerId: "server_id", |
||||
ConfigId: "config_id", |
||||
Remark: "remark", |
||||
} |
||||
|
||||
// NewGameActivityTimeDao creates and returns a new DAO object for table data access.
|
||||
func NewGameActivityTimeDao() *GameActivityTimeDao { |
||||
return &GameActivityTimeDao{ |
||||
group: "default", |
||||
table: "game_activity_time", |
||||
columns: gameActivityTimeColumns, |
||||
} |
||||
} |
||||
|
||||
// DB retrieves and returns the underlying raw database management object of current DAO.
|
||||
func (dao *GameActivityTimeDao) DB() gdb.DB { |
||||
return g.DB(dao.group) |
||||
} |
||||
|
||||
// Table returns the table name of current dao.
|
||||
func (dao *GameActivityTimeDao) Table() string { |
||||
return dao.table |
||||
} |
||||
|
||||
// Columns returns all column names of current dao.
|
||||
func (dao *GameActivityTimeDao) Columns() GameActivityTimeColumns { |
||||
return dao.columns |
||||
} |
||||
|
||||
// Group returns the configuration group name of database of current dao.
|
||||
func (dao *GameActivityTimeDao) Group() string { |
||||
return dao.group |
||||
} |
||||
|
||||
// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation.
|
||||
func (dao *GameActivityTimeDao) Ctx(ctx context.Context) *gdb.Model { |
||||
return dao.DB().Model(dao.table).Safe().Ctx(ctx) |
||||
} |
||||
|
||||
// Transaction wraps the transaction logic using function f.
|
||||
// It rollbacks the transaction and returns the error from function f if it returns non-nil error.
|
||||
// It commits the transaction and returns nil if function f returns nil.
|
||||
//
|
||||
// Note that, you should not Commit or Rollback the transaction in function f
|
||||
// as it is automatically handled by this function.
|
||||
func (dao *GameActivityTimeDao) Transaction(ctx context.Context, f func(ctx context.Context, tx *gdb.TX) error) (err error) { |
||||
return dao.Ctx(ctx).Transaction(ctx, f) |
||||
} |
||||
@ -0,0 +1,18 @@
|
||||
// =================================================================================
|
||||
// Code generated by GoFrame CLI tool. DO NOT EDIT.
|
||||
// =================================================================================
|
||||
|
||||
package do |
||||
|
||||
import ( |
||||
"github.com/gogf/gf/v2/frame/g" |
||||
) |
||||
|
||||
// CsjAdvertisement is the golang structure of table csj_advertisement for DAO operations like Where/Data.
|
||||
type CsjAdvertisement struct { |
||||
g.Meta `orm:"table:csj_advertisement, do:true"` |
||||
Id interface{} //
|
||||
PrimeRit interface{} //
|
||||
MediationRit interface{} //
|
||||
MKey interface{} //
|
||||
} |
||||
@ -0,0 +1,23 @@
|
||||
// =================================================================================
|
||||
// Code generated by GoFrame CLI tool. DO NOT EDIT.
|
||||
// =================================================================================
|
||||
|
||||
package do |
||||
|
||||
import ( |
||||
"github.com/gogf/gf/v2/frame/g" |
||||
"github.com/gogf/gf/v2/os/gtime" |
||||
) |
||||
|
||||
// GameActivityTime is the golang structure of table game_activity_time for DAO operations like Where/Data.
|
||||
type GameActivityTime struct { |
||||
g.Meta `orm:"table:game_activity_time, do:true"` |
||||
Id interface{} //
|
||||
PreviewTime *gtime.Time //
|
||||
StartTime *gtime.Time //
|
||||
EndTime *gtime.Time //
|
||||
CloseTime *gtime.Time //
|
||||
ServerId interface{} //
|
||||
ConfigId interface{} //
|
||||
Remark interface{} //
|
||||
} |
||||
@ -0,0 +1,13 @@
|
||||
// =================================================================================
|
||||
// Code generated by GoFrame CLI tool. DO NOT EDIT.
|
||||
// =================================================================================
|
||||
|
||||
package entity |
||||
|
||||
// CsjAdvertisement is the golang structure for table csj_advertisement.
|
||||
type CsjAdvertisement struct { |
||||
Id int `json:"id" description:""` |
||||
PrimeRit string `json:"primeRit" description:""` |
||||
MediationRit string `json:"mediationRit" description:""` |
||||
MKey string `json:"mKey" description:""` |
||||
} |
||||
@ -0,0 +1,21 @@
|
||||
// =================================================================================
|
||||
// Code generated by GoFrame CLI tool. DO NOT EDIT.
|
||||
// =================================================================================
|
||||
|
||||
package entity |
||||
|
||||
import ( |
||||
"github.com/gogf/gf/v2/os/gtime" |
||||
) |
||||
|
||||
// GameActivityTime is the golang structure for table game_activity_time.
|
||||
type GameActivityTime struct { |
||||
Id int `json:"id" description:""` |
||||
PreviewTime *gtime.Time `json:"previewTime" description:""` |
||||
StartTime *gtime.Time `json:"startTime" description:""` |
||||
EndTime *gtime.Time `json:"endTime" description:""` |
||||
CloseTime *gtime.Time `json:"closeTime" description:""` |
||||
ServerId int `json:"serverId" description:""` |
||||
ConfigId int `json:"configId" description:""` |
||||
Remark string `json:"remark" description:""` |
||||
} |
||||
@ -0,0 +1,131 @@
|
||||
package serviceGame |
||||
|
||||
import ( |
||||
"context" |
||||
"github.com/gogf/gf/v2/frame/g" |
||||
"github.com/gogf/gf/v2/os/gtime" |
||||
"tyj_admin/api/v1/game" |
||||
"tyj_admin/internal/dao" |
||||
"tyj_admin/internal/model/do" |
||||
"tyj_admin/internal/model/entity" |
||||
"tyj_admin/library/liberr" |
||||
) |
||||
|
||||
type IGameActivity interface { |
||||
GetGameActivity(ctx context.Context, req *game.GetActivityConfigsReq) (res *game.GetActivityConfigsRes, err error) |
||||
AddGameActivity(ctx context.Context, req *game.AddActivityConfigReq) (res *game.AddActivityConfigRes, err error) |
||||
DelGameActivity(ctx context.Context, req *game.DelActivityConfigReq) (res *game.DelActivityConfigRes, err error) |
||||
GetAllGameActivity(ctx context.Context, req *game.GetAllGameActivityReq) (res *game.GetAllGameActivityRes, err error) |
||||
} |
||||
|
||||
type gameActivityImpl struct { |
||||
} |
||||
|
||||
var gameActivityService = gameActivityImpl{} |
||||
|
||||
func GameActivity() IGameActivity { |
||||
return &gameActivityService |
||||
} |
||||
|
||||
func (c *gameActivityImpl) GetGameActivity(ctx context.Context, req *game.GetActivityConfigsReq) (res *game.GetActivityConfigsRes, err error) { |
||||
g.Try(ctx, func(ctx context.Context) { |
||||
res = new(game.GetActivityConfigsRes) |
||||
model := dao.GameActivityTime.Ctx(ctx) |
||||
res.Total, err = model.Count() |
||||
liberr.ErrIsNil(ctx, err, "mysql err") |
||||
model = model.OrderAsc("config_id").Page(req.PageNum, req.PageSize) |
||||
if req.ServerId != 0 { |
||||
model = model.Where("server_id=?", req.ServerId) |
||||
} |
||||
err = model.Scan(&res.List) |
||||
}) |
||||
return |
||||
} |
||||
|
||||
func (c *gameActivityImpl) AddGameActivity(ctx context.Context, req *game.AddActivityConfigReq) (res *game.AddActivityConfigRes, err error) { |
||||
res = new(game.AddActivityConfigRes) |
||||
err = g.Try(ctx, func(ctx context.Context) { |
||||
server := []entity.GameActivityTime{} |
||||
model := dao.GameActivityTime.Ctx(ctx) |
||||
model.WherePri(req.Id).Scan(&server) |
||||
if len(server) > 0 { |
||||
data := g.Map{ |
||||
dao.GameActivityTime.Columns().Id: req.Id, |
||||
} |
||||
if req.CloseTime != "" { |
||||
data[dao.GameActivityTime.Columns().CloseTime] = req.CloseTime |
||||
} |
||||
if req.EndTime != "" { |
||||
data[dao.GameActivityTime.Columns().EndTime] = req.EndTime |
||||
} |
||||
if req.PreviewTime != "" { |
||||
data[dao.GameActivityTime.Columns().PreviewTime] = req.PreviewTime |
||||
} |
||||
if req.StartTime != "" { |
||||
data[dao.GameActivityTime.Columns().StartTime] = req.StartTime |
||||
} |
||||
if req.Remark != "" { |
||||
data[dao.GameActivityTime.Columns().Remark] = req.Remark |
||||
} |
||||
if req.ConfigId != 0 { |
||||
data[dao.GameActivityTime.Columns().ConfigId] = req.ConfigId |
||||
} |
||||
if req.ServerId != 0 { |
||||
data[dao.GameActivityTime.Columns().ServerId] = req.ServerId |
||||
} |
||||
_, err = model.WherePri(req.Id).Update(data) |
||||
} else { |
||||
_, err = model.Insert(do.GameActivityTime{ |
||||
ServerId: req.ServerId, |
||||
StartTime: gtime.NewFromStr(req.StartTime), |
||||
PreviewTime: gtime.NewFromStr(req.PreviewTime), |
||||
EndTime: gtime.NewFromStr(req.EndTime), |
||||
CloseTime: gtime.NewFromStr(req.CloseTime), |
||||
ConfigId: req.ConfigId, |
||||
Remark: req.Remark, |
||||
}) |
||||
} |
||||
}) |
||||
return |
||||
} |
||||
|
||||
func (c *gameActivityImpl) DelGameActivity(ctx context.Context, req *game.DelActivityConfigReq) (res *game.DelActivityConfigRes, err error) { |
||||
err = g.Try(ctx, func(ctx context.Context) { |
||||
if req.Id == 0 { |
||||
liberr.ErrIsNil(ctx, err, "错误的id") |
||||
} |
||||
_, e := dao.GameActivityTime.Ctx(ctx).Where("id=", req.Id).Delete() |
||||
if e != nil { |
||||
liberr.ErrIsNil(ctx, e, "删除失败") |
||||
} |
||||
}) |
||||
|
||||
return |
||||
} |
||||
|
||||
func (c *gameActivityImpl) GetAllGameActivity(ctx context.Context, req *game.GetAllGameActivityReq) (res *game.GetAllGameActivityRes, err error) { |
||||
g.Try(ctx, func(ctx context.Context) { |
||||
res = new(game.GetAllGameActivityRes) |
||||
|
||||
model := dao.GameActivityTime.Ctx(ctx) |
||||
serverConfigs := []entity.GameActivityTime{} |
||||
err = model.Where("server_id=?", req.ServerId).Scan(&serverConfigs) |
||||
if err != nil { |
||||
return |
||||
} |
||||
err = model.Where("server_id=?", 0).Scan(&res.List) |
||||
if err != nil { |
||||
return |
||||
} |
||||
configs := map[int]entity.GameActivityTime{} |
||||
for _, v := range serverConfigs { |
||||
configs[v.ConfigId] = v |
||||
} |
||||
for k, v := range res.List { |
||||
if configs[v.ConfigId].Id > 0 { |
||||
res.List[k] = configs[v.ConfigId] |
||||
} |
||||
} |
||||
}) |
||||
return |
||||
} |
||||
@ -0,0 +1,31 @@
|
||||
package internal |
||||
|
||||
import ( |
||||
"context" |
||||
"tyj_admin/api/v1/game" |
||||
"tyj_admin/internal/dao" |
||||
"tyj_admin/internal/model/entity" |
||||
) |
||||
|
||||
func GetAllGameActivity(ctx context.Context, req *game.GetAllGameActivityReq) (res *game.GetAllGameActivityRes, err error) { |
||||
res = new(game.GetAllGameActivityRes) |
||||
|
||||
model := dao.GameActivityTime.Ctx(ctx) |
||||
defaultConfigs := []entity.GameActivityTime{} |
||||
_ = model.Where("server_id=?", 0).Scan(&defaultConfigs) |
||||
|
||||
serverConfigs := []entity.GameActivityTime{} |
||||
_ = model.Where("server_id=?", req.ServerId).Scan(&serverConfigs) |
||||
|
||||
configs := map[int]entity.GameActivityTime{} |
||||
for _, v := range serverConfigs { |
||||
configs[v.ConfigId] = v |
||||
} |
||||
for k, v := range defaultConfigs { |
||||
if configs[v.ConfigId].Id > 0 { |
||||
defaultConfigs[k] = configs[v.ConfigId] |
||||
} |
||||
} |
||||
|
||||
return |
||||
} |
||||
Loading…
Reference in new issue