business.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package http
  2. import (
  3. "go-common/app/admin/main/vip/model"
  4. "go-common/library/ecode"
  5. bm "go-common/library/net/http/blademaster"
  6. )
  7. const (
  8. _defpn = 1
  9. _defps = 10
  10. )
  11. func business(c *bm.Context) {
  12. var (
  13. err error
  14. r *model.VipBusinessInfo
  15. )
  16. arg := new(model.ArgID)
  17. if err = c.Bind(arg); err != nil {
  18. return
  19. }
  20. if r, err = vipSvc.BusinessInfo(c, int(arg.ID)); err != nil {
  21. c.JSON(nil, err)
  22. return
  23. }
  24. c.JSON(r, nil)
  25. }
  26. func updateBusiness(c *bm.Context) {
  27. var (
  28. err error
  29. arg = new(model.VipBusinessInfo)
  30. )
  31. if err = c.Bind(arg); err != nil {
  32. return
  33. }
  34. if arg.ID == 0 {
  35. c.JSON(nil, ecode.RequestErr)
  36. return
  37. }
  38. c.JSON(nil, vipSvc.UpdateBusinessInfo(c, arg))
  39. }
  40. func addBusiness(c *bm.Context) {
  41. var (
  42. err error
  43. arg = new(model.VipBusinessInfo)
  44. )
  45. if err = c.Bind(arg); err != nil {
  46. return
  47. }
  48. c.JSON(nil, vipSvc.AddBusinessInfo(c, arg))
  49. }
  50. func businessList(c *bm.Context) {
  51. var (
  52. infos []*model.VipBusinessInfo
  53. total int64
  54. err error
  55. arg = new(model.ArgPage)
  56. )
  57. if err = c.Bind(arg); err != nil {
  58. return
  59. }
  60. if arg.Pn == 0 {
  61. arg.Pn = _defpn
  62. }
  63. if arg.Ps == 0 {
  64. arg.Ps = _defps
  65. }
  66. if infos, total, err = vipSvc.BusinessList(c, arg.Pn, arg.Ps, arg.Status); err != nil {
  67. c.JSON(nil, err)
  68. return
  69. }
  70. res := new(struct {
  71. Data []*model.VipBusinessInfo `json:"data"`
  72. Total int64 `json:"total"`
  73. })
  74. res.Data = infos
  75. res.Total = total
  76. c.JSON(res, nil)
  77. }