123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- package http
- import (
- "fmt"
- "go-common/app/admin/main/activity/model"
- "go-common/library/ecode"
- "go-common/library/log"
- bm "go-common/library/net/http/blademaster"
- )
- // addMatch 增加赛程
- func addMatch(c *bm.Context) {
- arg := new(model.ActMatchs)
- if err := c.Bind(arg); err != nil {
- return
- }
- if err := actSrv.DB.Create(arg).Error; err != nil {
- log.Error("addMatch(%v) error(%v)", arg, err)
- c.JSON(nil, err)
- return
- }
- c.JSON(nil, nil)
- }
- // saveMatch 存储赛程
- func saveMatch(c *bm.Context) {
- arg := new(model.ActMatchs)
- if err := c.Bind(arg); err != nil {
- return
- }
- if err := actSrv.DB.Model(&model.ActMatchs{ID: arg.ID}).Update(arg).Error; err != nil {
- log.Error("saveMatch(%v) error(%v)", arg, err)
- c.JSON(nil, err)
- return
- }
- c.JSON(nil, nil)
- }
- // matchInfo 赛程信息
- func matchInfo(c *bm.Context) {
- arg := new(model.ActMatchs)
- if err := c.Bind(arg); err != nil {
- return
- }
- if arg.ID == 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if err := actSrv.DB.First(arg, arg.ID).Error; err != nil {
- log.Error("matcInfo(%d) error(%v)", arg.ID, err)
- c.JSON(nil, err)
- return
- }
- c.JSON(arg, nil)
- }
- // matchList 比赛对象列表
- func matchList(c *bm.Context) {
- var (
- err error
- count int
- list []*model.ActMatchs
- )
- v := new(struct {
- SID int64 `form:"sid" default:"-1"`
- Status int8 `form:"status" default:"-1"`
- Page int `form:"pn" default:"1"`
- Size int `form:"ps" default:"20"`
- })
- if err = c.Bind(v); err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- db := actSrv.DB
- if v.Page == 0 {
- v.Page = 1
- }
- if v.Size == 0 {
- v.Size = 20
- }
- if v.Status != -1 {
- db = db.Where("status = ?", v.Status)
- }
- if v.SID != -1 {
- db = db.Where("sid = ?", v.SID)
- }
- db = db.Where("status = ?", 0)
- if err = db.
- Offset((v.Page - 1) * v.Size).Limit(v.Size).
- Find(&list).Error; err != nil {
- log.Error("businessList(%d,%d) error(%v)", v.Page, v.Size, err)
- c.JSON(nil, err)
- return
- }
- if err = db.Model(&model.ActMatchs{}).Count(&count).Error; err != nil {
- log.Error("businessList count error(%v)", err)
- c.JSON(nil, err)
- return
- }
- data := map[string]interface{}{
- "data": list,
- "pn": v.Page,
- "ps": v.Size,
- "total": count,
- }
- c.JSONMap(data, nil)
- }
- // addMatchObject 比赛对象
- func addMatchObject(c *bm.Context) {
- arg := new(model.ActMatchsObject)
- if err := c.Bind(arg); err != nil {
- return
- }
- if err := actSrv.DB.Create(arg).Error; err != nil {
- log.Error("addMatch(%v) error(%v)", arg, err)
- c.JSON(nil, err)
- return
- }
- c.JSON(nil, nil)
- }
- // saveMatchObject 更新比赛对象
- func saveMatchObject(c *bm.Context) {
- arg := new(model.ActMatchsObject)
- if err := c.Bind(arg); err != nil {
- return
- }
- fmt.Println(arg.AwayName)
- fmt.Println(arg.HomeLogo)
- if err := actSrv.DB.Model(&model.ActMatchsObject{ID: arg.ID}).Update(arg).Error; err != nil {
- log.Error("saveMatch(%v) error(%v)", arg, err)
- c.JSON(nil, err)
- return
- }
- c.JSON(nil, nil)
- }
- // matchObjectInfo 比赛对象信息
- func matchObjectInfo(c *bm.Context) {
- arg := new(model.ActMatchsObject)
- if err := c.Bind(arg); err != nil {
- return
- }
- if arg.ID == 0 {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- if err := actSrv.DB.First(arg, arg.ID).Error; err != nil {
- log.Error("matcInfo(%d) error(%v)", arg.ID, err)
- c.JSON(nil, err)
- return
- }
- c.JSON(arg, nil)
- }
- // matchObjectList 比赛对象列表
- func matchObjectList(c *bm.Context) {
- var (
- err error
- count int
- list []*model.ActMatchsObject
- )
- v := new(struct {
- SID int64 `form:"sid" default:"-1"`
- Status int8 `form:"status" default:"-1"`
- Page int `form:"pn" default:"1"`
- Size int `form:"ps" default:"20"`
- MatchID int `form:"match_id"`
- })
- if err = c.Bind(v); err != nil {
- c.JSON(nil, ecode.RequestErr)
- return
- }
- db := actSrv.DB
- if v.Page == 0 {
- v.Page = 1
- }
- if v.Size == 0 {
- v.Size = 20
- }
- if v.Status != -1 {
- db = db.Where("status = ?", v.Status)
- }
- if v.SID != -1 {
- db = db.Where("sid = ?", v.SID)
- }
- if v.MatchID != 0 {
- db = db.Where("match_id = ?", v.MatchID)
- }
- db = db.Where("status = ?", 0)
- if err = db.
- Offset((v.Page - 1) * v.Size).Limit(v.Size).
- Find(&list).Error; err != nil {
- log.Error("businessList(%d,%d) error(%v)", v.Page, v.Size, err)
- c.JSON(nil, err)
- return
- }
- if err = db.Model(&model.ActMatchsObject{}).Count(&count).Error; err != nil {
- log.Error("businessList count error(%v)", err)
- c.JSON(nil, err)
- return
- }
- data := map[string]interface{}{
- "data": list,
- "pn": v.Page,
- "ps": v.Size,
- "total": count,
- }
- c.JSONMap(data, nil)
- }
|