123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- package http
- import (
- "fmt"
- "net/http"
- "time"
- "go-common/app/admin/main/growup/model"
- "go-common/library/ecode"
- "go-common/library/log"
- "go-common/library/net/http/blademaster"
- "go-common/library/net/http/blademaster/binding"
- )
- func awardAdd(c *blademaster.Context) {
- username, _, err := checkCookie(c)
- if err != nil {
- c.JSON(nil, err)
- return
- }
- arg := new(model.AddAwardArg)
- if err = c.BindWith(arg, binding.JSON); err != nil {
- return
- }
- awardID, err := svr.AddAward(c, arg, username)
- if err != nil {
- log.Error("svr.AddAward err(%v)", err)
- c.JSON(nil, err)
- return
- }
- c.JSON(awardID, nil)
- }
- func awardUpdate(c *blademaster.Context) {
- arg := new(model.SaveAwardArg)
- if err := c.BindWith(arg, binding.JSON); err != nil {
- return
- }
- err := svr.UpdateAward(c, arg)
- if err != nil {
- log.Error("svr.UpdateAward err(%v)", err)
- c.JSON(nil, err)
- return
- }
- c.JSON(true, nil)
- }
- func awardList(c *blademaster.Context) {
- arg := new(struct {
- From int `form:"from" validate:"min=0" default:"0"`
- Limit int `form:"limit" validate:"min=1" default:"20"`
- })
- if err := c.Bind(arg); err != nil {
- return
- }
- total, list, err := svr.ListAward(c, arg.From, arg.Limit)
- if err != nil {
- log.Error("svr.ListAward err(%v)", err)
- c.JSON(nil, err)
- return
- }
- renderPagRes(list, total, arg.Limit)(c)
- }
- func awardDetail(c *blademaster.Context) {
- arg := new(struct {
- AwardID int64 `form:"award_id" validate:"required"`
- })
- if err := c.Bind(arg); err != nil {
- return
- }
- data, err := svr.DetailAward(c, arg.AwardID)
- if err != nil {
- log.Error("svr.DetailAward err(%v)", err)
- c.JSON(nil, err)
- return
- }
- c.JSON(data, nil)
- }
- func awardWinnerList(c *blademaster.Context) {
- arg := new(model.QueryAwardWinnerArg)
- if err := c.Bind(arg); err != nil {
- return
- }
- total, list, err := svr.ListAwardWinner(c, arg)
- if err != nil {
- log.Error("svr.ListAwardRecord err(%v)", err)
- c.JSON(nil, err)
- return
- }
- renderPagRes(list, total, arg.Limit)(c)
- }
- func awardWinnerExport(c *blademaster.Context) {
- arg := new(model.QueryAwardWinnerArg)
- if err := c.Bind(arg); err != nil {
- return
- }
- content, err := svr.ExportAwardWinner(c, arg)
- if err != nil {
- log.Error("svr.ExportAwardWinner err(%v)", err)
- c.JSON(nil, err)
- return
- }
- c.Render(http.StatusOK, CSV{
- Content: content,
- Title: fmt.Sprintf("%s-%s", time.Now().Format("2006-01-02"), "award_winner"),
- })
- }
- func awardResult(c *blademaster.Context) {
- arg := new(struct {
- AwardID int64 `form:"award_id" validate:"required"`
- })
- if err := c.Bind(arg); err != nil {
- return
- }
- data, err := svr.AwardResult(c, arg.AwardID)
- if err != nil {
- log.Error("svr.AwardResult err(%v)", err)
- c.JSON(nil, err)
- return
- }
- c.JSON(data, nil)
- }
- func awardResultSave(c *blademaster.Context) {
- arg := new(model.AwardResult)
- if err := c.BindWith(arg, binding.JSON); err != nil {
- return
- }
- if arg.AwardID == 0 {
- c.JSON(false, ecode.Error(ecode.RequestErr, "illegal award_id"))
- return
- }
- err := svr.SaveAwardResult(c, arg)
- if err != nil {
- log.Error("svr.SaveAwardResult err(%v)", err)
- c.JSON(false, err)
- return
- }
- c.JSON(true, nil)
- }
- func awardWinnerReplace(c *blademaster.Context) {
- arg := new(struct {
- AwardID int64 `form:"award_id" validate:"required"`
- PrevMID int64 `form:"prev_mid" validate:"required"`
- MID int64 `form:"mid" validate:"required"`
- })
- if err := c.Bind(arg); err != nil {
- return
- }
- err := svr.ReplaceAwardWinner(c, arg.AwardID, arg.PrevMID, arg.MID)
- if err != nil {
- log.Error("svr.ReplaceAwardWinner err(%v)", err)
- c.JSON(false, err)
- return
- }
- c.JSON(true, nil)
- }
|