business.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. package http
  2. import (
  3. "strings"
  4. "go-common/app/admin/main/aegis/model/business"
  5. "go-common/app/admin/main/aegis/model/common"
  6. "go-common/library/ecode"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. func preBusinss(b *business.Business) (invalid bool) {
  10. b.Name = common.FilterBusinessName(strings.TrimSpace(b.Name))
  11. b.Desc = strings.TrimSpace(b.Desc)
  12. emails := strings.Split(b.Developer, ",")
  13. if len(emails) > 5 || b.Name == "" || b.Desc == "" || b.TP <= 0 || b.TP > 4 {
  14. invalid = true
  15. return
  16. }
  17. return
  18. }
  19. // addBusiness .
  20. func addBusiness(c *bm.Context) {
  21. b := &business.Business{}
  22. if err := c.Bind(b); err != nil {
  23. return
  24. }
  25. if preBusinss(b) {
  26. c.JSON(nil, ecode.RequestErr)
  27. return
  28. }
  29. b.UID = uid(c)
  30. c.JSON(srv.AddBusiness(c, b))
  31. }
  32. // updateBusiness .
  33. func updateBusiness(c *bm.Context) {
  34. b := &business.Business{}
  35. if err := c.Bind(b); err != nil {
  36. return
  37. }
  38. if b.ID <= 0 || preBusinss(b) {
  39. c.JSON(nil, ecode.RequestErr)
  40. return
  41. }
  42. b.UID = uid(c)
  43. c.JSON(nil, srv.UpdateBusiness(c, b))
  44. }
  45. // setBusiness .
  46. func setBusinessState(c *bm.Context) {
  47. b := &business.Business{}
  48. if err := c.Bind(b); err != nil {
  49. return
  50. }
  51. if b.ID <= 0 {
  52. c.JSON(nil, ecode.RequestErr)
  53. return
  54. }
  55. b.UID = uid(c)
  56. c.JSON(nil, srv.SetBusinessState(c, b))
  57. }
  58. // getBusiness .
  59. func getBusiness(c *bm.Context) {
  60. b := &business.Business{}
  61. if err := c.Bind(b); err != nil {
  62. return
  63. }
  64. if b.ID <= 0 {
  65. c.JSON(nil, ecode.RequestErr)
  66. return
  67. }
  68. res, err := srv.Business(c, b)
  69. if err != nil {
  70. c.JSON(nil, err)
  71. return
  72. }
  73. if res == nil {
  74. c.JSON(nil, ecode.NothingFound)
  75. return
  76. }
  77. c.JSON(res, nil)
  78. }
  79. // getBusinessList .
  80. func getBusinessList(c *bm.Context) {
  81. ids := getAccessBiz(c)
  82. res, err := srv.BusinessList(c, ids, false)
  83. if err != nil {
  84. c.JSON(nil, err)
  85. return
  86. }
  87. if res == nil {
  88. c.JSON(nil, ecode.NothingFound)
  89. return
  90. }
  91. c.JSON(res, nil)
  92. }
  93. // getBusinessList .
  94. func getBusinessEnable(c *bm.Context) {
  95. ids := getAccessBiz(c)
  96. res, err := srv.BusinessList(c, ids, true)
  97. if err != nil {
  98. c.JSON(nil, err)
  99. return
  100. }
  101. c.JSON(res, nil)
  102. }
  103. // addBizCFG
  104. func addBizCFG(c *bm.Context) {
  105. b := &business.BizCFG{}
  106. if err := c.Bind(b); err != nil {
  107. return
  108. }
  109. if b.BusinessID <= 0 {
  110. c.JSON(nil, ecode.RequestErr)
  111. return
  112. }
  113. id, err := srv.AddBizCFG(c, b)
  114. if err != nil {
  115. httpCode(c, err.Error(), ecode.RequestErr)
  116. return
  117. }
  118. c.JSON(id, nil)
  119. }
  120. // updateBizCFG
  121. func updateBizCFG(c *bm.Context) {
  122. b := &business.BizCFG{}
  123. if err := c.Bind(b); err != nil {
  124. return
  125. }
  126. if b.ID <= 0 {
  127. c.JSON(nil, ecode.RequestErr)
  128. return
  129. }
  130. c.JSON(nil, srv.UpdateBizCFG(c, b))
  131. }
  132. // listBizCFGs
  133. func listBizCFGs(c *bm.Context) {
  134. b := &business.BizCFG{}
  135. if err := c.Bind(b); err != nil {
  136. return
  137. }
  138. res, err := srv.ListBizCFGs(c, b.BusinessID)
  139. if err != nil {
  140. c.JSON(nil, err)
  141. return
  142. }
  143. if res == nil {
  144. c.JSON(nil, ecode.NothingFound)
  145. return
  146. }
  147. c.JSON(res, nil)
  148. }
  149. // 保留字配置
  150. func reserveCFG(c *bm.Context) {
  151. opt := new(struct {
  152. BizID int64 `form:"business_id" validate:"required"`
  153. })
  154. if err := c.Bind(opt); err != nil {
  155. return
  156. }
  157. c.JSON(srv.ReserveCFG(c, opt.BizID))
  158. }