123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- package http
- import (
- "fmt"
- "strconv"
- "go-common/app/admin/main/usersuit/model"
- "go-common/library/ecode"
- "go-common/library/log"
- bm "go-common/library/net/http/blademaster"
- )
- // medal.
- func medalList(c *bm.Context) {
- var (
- err error
- res []*model.MedalInfo
- )
- if res, err = svc.Medal(c); err != nil {
- httpCode(c, err)
- return
- }
- httpData(c, res, nil)
- }
- // medalView .
- func medalView(c *bm.Context) {
- arg := new(struct {
- ID int64 `form:"id" validate:"required"`
- })
- if err := c.Bind(arg); err != nil {
- return
- }
- var (
- err error
- np *model.MedalInfo
- )
- if np, err = svc.MedalView(c, arg.ID); err != nil {
- httpCode(c, err)
- return
- }
- np.Image = "http://i0.hdslb.com" + np.Image
- np.ImageSmall = "http://i0.hdslb.com" + np.ImageSmall
- httpData(c, np, nil)
- }
- // medalAdd add medal .
- func medalAdd(c *bm.Context) {
- var (
- err error
- )
- arg := new(model.Medal)
- if err = c.Bind(arg); err != nil {
- return
- }
- if err = svc.AddMedal(c, arg); err != nil {
- httpCode(c, err)
- return
- }
- httpCode(c, nil)
- }
- func medalEdit(c *bm.Context) {
- var (
- err error
- )
- arg := new(model.Medal)
- if err = c.Bind(arg); err != nil {
- return
- }
- if err = svc.UpMedal(c, arg.ID, arg); err != nil {
- httpCode(c, err)
- return
- }
- httpCode(c, nil)
- }
- func medalGroup(c *bm.Context) {
- var (
- err error
- res []*model.MedalGroup
- )
- if res, err = svc.MedalGroupInfo(c); err != nil {
- httpCode(c, err)
- return
- }
- httpData(c, res, nil)
- }
- func medalGroupView(c *bm.Context) {
- arg := new(struct {
- ID int64 `form:"id" validate:"required"`
- })
- if err := c.Bind(arg); err != nil {
- return
- }
- var (
- err error
- res *model.MedalGroup
- )
- if res, err = svc.MedalGroupByGid(c, arg.ID); err != nil {
- httpCode(c, err)
- return
- }
- httpData(c, res, nil)
- }
- func medalGroupParent(c *bm.Context) {
- var (
- err error
- res []*model.MedalGroup
- )
- if res, err = svc.MedalGroupParent(c); err != nil {
- httpCode(c, err)
- return
- }
- httpData(c, res, nil)
- }
- func medalGroupAdd(c *bm.Context) {
- var (
- err error
- )
- arg := new(model.MedalGroup)
- if err = c.Bind(arg); err != nil {
- return
- }
- if err = svc.MedalGroupAdd(c, arg); err != nil {
- httpCode(c, err)
- return
- }
- httpCode(c, nil)
- }
- func medalGroupEdit(c *bm.Context) {
- var (
- err error
- )
- arg := new(model.MedalGroup)
- if err = c.Bind(arg); err != nil {
- return
- }
- if err = svc.MedalGroupUp(c, arg.ID, arg); err != nil {
- httpCode(c, err)
- return
- }
- httpCode(c, nil)
- }
- func medalMemberMID(c *bm.Context) {
- arg := new(struct {
- MID int64 `form:"mid" validate:"required"`
- })
- if err := c.Bind(arg); err != nil {
- return
- }
- var (
- err error
- res []*model.MedalMemberMID
- )
- if res, err = svc.MedalOwner(c, arg.MID); err != nil {
- httpCode(c, err)
- return
- }
- httpData(c, res, nil)
- }
- func medalOwnerUpActivated(c *bm.Context) {
- arg := new(struct {
- ID int64 `form:"id" validate:"required"`
- MID int64 `form:"mid" validate:"required"`
- })
- if err := c.Bind(arg); err != nil {
- return
- }
- var (
- err error
- )
- if err = svc.MedalOwnerUpActivated(c, arg.MID, arg.ID); err != nil {
- httpCode(c, err)
- return
- }
- httpCode(c, nil)
- }
- func medalMemberAddList(c *bm.Context) {
- arg := new(struct {
- MID int64 `form:"mid" validate:"required"`
- })
- if err := c.Bind(arg); err != nil {
- return
- }
- var (
- err error
- res []*model.MedalMemberAddList
- )
- if res, err = svc.MedalOwnerAddList(c, arg.MID); err != nil {
- httpCode(c, err)
- return
- }
- httpData(c, res, nil)
- }
- func medalMemberAdd(c *bm.Context) {
- arg := new(struct {
- MID int64 `form:"mid" validate:"required"`
- NID int64 `form:"nid" validate:"required"`
- Title string `form:"title"`
- Message string `form:"message"`
- OID int64 `form:"oper_id" validate:"required"`
- })
- if err := c.Bind(arg); err != nil {
- return
- }
- var (
- err error
- )
- if err = svc.MedalOwnerAdd(c, arg.MID, arg.NID, arg.Title, arg.Message, arg.OID); err != nil {
- httpCode(c, err)
- return
- }
- httpCode(c, nil)
- }
- func medalMemberDel(c *bm.Context) {
- arg := new(struct {
- MID int64 `form:"mid" validate:"required"`
- NID int64 `form:"nid" validate:"required"`
- IsDel int8 `form:"is_del"`
- Title string `form:"title"`
- Message string `form:"message"`
- })
- if err := c.Bind(arg); err != nil {
- return
- }
- var (
- err error
- )
- if err = svc.MedalOwnerDel(c, arg.MID, arg.NID, arg.IsDel, arg.Title, arg.Message); err != nil {
- httpCode(c, err)
- return
- }
- httpCode(c, nil)
- }
- func medalBatchAdd(c *bm.Context) {
- var (
- err error
- nid int64
- )
- f, h, err := c.Request.FormFile("file")
- if err != nil {
- httpCode(c, ecode.RequestErr)
- return
- }
- defer f.Close()
- params := c.Request.Form
- nidStr := params.Get("nid")
- nid, err = strconv.ParseInt(nidStr, 10, 64)
- if err != nil || nid <= 0 {
- fmt.Printf("nid:%+v\n", nid)
- httpCode(c, ecode.RequestErr)
- return
- }
- msg, err := svc.BatchAdd(c, nid, f, h)
- if err != nil || msg != "" {
- log.Error("svc.BatchAdd error(%v), msg(%v)", err, msg)
- httpCode(c, ecode.ServerErr)
- return
- }
- res := new(struct {
- Message string `form:"message"`
- })
- res.Message = msg
- httpData(c, res, nil)
- }
- func medalOperlog(c *bm.Context) {
- arg := new(struct {
- PN int `form:"pn"`
- PS int `form:"ps"`
- MID int64 `form:"mid" validate:"required"`
- })
- arg.PN, arg.PS = 1, 20
- if err := c.Bind(arg); err != nil {
- return
- }
- opers, pager, err := svc.MedalOperlog(c, arg.MID, arg.PN, arg.PS)
- if err != nil {
- log.Error("svc.MedalOperlog(%+v) err(%v)", arg, err)
- httpCode(c, err)
- return
- }
- if len(opers) == 0 {
- httpData(c, nil, pager)
- return
- }
- httpData(c, opers, pager)
- }
|