business.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/admin/main/manager/model"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. // addBusiness .
  9. func addBusiness(c *bm.Context) {
  10. b := &model.Business{}
  11. if err := c.Bind(b); err != nil {
  12. return
  13. }
  14. c.JSON(nil, mngSvc.AddBusiness(c, b))
  15. }
  16. // updateBusiness .
  17. func updateBusiness(c *bm.Context) {
  18. b := &model.Business{}
  19. if err := c.Bind(b); err != nil {
  20. return
  21. }
  22. if b.ID <= 0 {
  23. c.JSON(nil, ecode.RequestErr)
  24. return
  25. }
  26. c.JSON(nil, mngSvc.UpdateBusiness(c, b))
  27. }
  28. // addRole .
  29. func addRole(c *bm.Context) {
  30. br := &model.BusinessRole{}
  31. if err := c.Bind(br); err != nil {
  32. return
  33. }
  34. c.JSON(nil, mngSvc.AddRole(c, br))
  35. }
  36. // updateRole .
  37. func updateRole(c *bm.Context) {
  38. br := &model.BusinessRole{}
  39. if err := c.Bind(br); err != nil {
  40. return
  41. }
  42. if br.ID <= 0 {
  43. c.JSON(nil, ecode.RequestErr)
  44. return
  45. }
  46. c.JSON(nil, mngSvc.UpdateRole(c, br))
  47. }
  48. // addUser .
  49. func addUser(c *bm.Context) {
  50. res := map[string]interface{}{}
  51. bur := &model.BusinessUserRole{}
  52. if err := c.Bind(bur); err != nil {
  53. return
  54. }
  55. if cuid, exists := c.Get("uid"); exists {
  56. bur.CUID = cuid.(int64)
  57. }
  58. if err := mngSvc.AddUser(c, bur); err != nil {
  59. if err == ecode.ManagerUIDNOTExist {
  60. res["message"] = "这个uid是不存在的, 请你不要乱来哦!"
  61. c.JSONMap(res, ecode.ManagerUIDNOTExist)
  62. return
  63. }
  64. c.JSON(nil, err)
  65. return
  66. }
  67. c.JSON(nil, nil)
  68. }
  69. // updateUser .
  70. func updateUser(c *bm.Context) {
  71. bur := &model.BusinessUserRole{}
  72. if err := c.Bind(bur); err != nil {
  73. return
  74. }
  75. if bur.ID <= 0 {
  76. c.JSON(nil, ecode.RequestErr)
  77. return
  78. }
  79. c.JSON(nil, mngSvc.UpdateUser(c, bur))
  80. }
  81. // stateUpdate .
  82. func updateState(c *bm.Context) {
  83. su := &model.StateUpdate{}
  84. res := map[string]interface{}{}
  85. if err := c.Bind(su); err != nil {
  86. return
  87. }
  88. if err := mngSvc.UpdateState(c, su); err != nil {
  89. if err == ecode.ManagerFlowForbidden {
  90. res["message"] = "business flow is forbidden"
  91. c.JSONMap(res, ecode.ManagerFlowForbidden)
  92. return
  93. }
  94. c.JSON(nil, err)
  95. return
  96. }
  97. c.JSON(nil, nil)
  98. }
  99. // businessList .
  100. func businessList(c *bm.Context) {
  101. bp := &model.BusinessListParams{}
  102. if err := c.Bind(bp); err != nil {
  103. return
  104. }
  105. if uid, exists := c.Get("uid"); exists {
  106. bp.UID = uid.(int64)
  107. }
  108. c.JSON(mngSvc.BusinessList(c, bp))
  109. }
  110. // flowList .
  111. func flowList(c *bm.Context) {
  112. bp := &model.BusinessListParams{}
  113. if err := c.Bind(bp); err != nil {
  114. return
  115. }
  116. if uid, exists := c.Get("uid"); exists {
  117. bp.UID = uid.(int64)
  118. }
  119. c.JSON(mngSvc.FlowList(c, bp))
  120. }
  121. // userList .
  122. func userList(c *bm.Context) {
  123. isAdmin := false
  124. u := &model.UserListParams{}
  125. if err := c.Bind(u); err != nil {
  126. return
  127. }
  128. if uid, exists := c.Get("uid"); exists {
  129. isAdmin = mngSvc.IsAdmin(c, u.BID, uid.(int64))
  130. }
  131. data, total, err := mngSvc.UserList(c, u)
  132. if err != nil {
  133. c.JSON(nil, err)
  134. return
  135. }
  136. page := map[string]int64{
  137. "num": u.PN,
  138. "size": u.PS,
  139. "total": total,
  140. }
  141. c.JSON(map[string]interface{}{
  142. "page": page,
  143. "data": data,
  144. "isAdmin": isAdmin,
  145. }, err)
  146. }
  147. // roleList .
  148. func roleList(c *bm.Context) {
  149. br := &model.BusinessRole{}
  150. if err := c.Bind(br); err != nil {
  151. return
  152. }
  153. if uid, exists := c.Get("uid"); exists {
  154. br.UID = uid.(int64)
  155. }
  156. c.JSON(mngSvc.RoleList(c, br))
  157. }
  158. // deleteUser .
  159. func deleteUser(c *bm.Context) {
  160. bur := &model.BusinessUserRole{}
  161. if err := c.Bind(bur); err != nil {
  162. return
  163. }
  164. if bur.ID <= 0 {
  165. c.JSON(nil, ecode.RequestErr)
  166. return
  167. }
  168. c.JSON(nil, mngSvc.DeleteUser(c, bur))
  169. }
  170. // userRole .
  171. func userRole(c *bm.Context) {
  172. brl := &model.BusinessUserRoleList{}
  173. if err := c.Bind(brl); err != nil {
  174. return
  175. }
  176. if brl.BID <= 0 {
  177. c.JSON(nil, ecode.RequestErr)
  178. return
  179. }
  180. if brl.UID <= 0 {
  181. if uid, exists := c.Get("uid"); exists {
  182. uid = uid.(int64)
  183. }
  184. }
  185. c.JSON(mngSvc.UserRole(c, brl))
  186. }
  187. // userRoles .
  188. func userRoles(c *bm.Context) {
  189. uid, _ := strconv.ParseInt(c.Request.Form.Get("uid"), 10, 64)
  190. if uid <= 0 {
  191. c.JSON(nil, ecode.RequestErr)
  192. return
  193. }
  194. c.JSON(mngSvc.UserRoles(c, uid))
  195. }
  196. // userRoles .
  197. func stateUp(c *bm.Context) {
  198. p := &model.UserStateUp{}
  199. if err := c.Bind(p); err != nil {
  200. return
  201. }
  202. c.JSON(nil, mngSvc.StateUp(c, p))
  203. }
  204. // allRoles .
  205. func allRoles(c *bm.Context) {
  206. pid, _ := strconv.ParseInt(c.Request.Form.Get("pid"), 10, 64)
  207. if pid <= 0 {
  208. c.JSON(nil, ecode.RequestErr)
  209. return
  210. }
  211. uid, _ := strconv.ParseInt(c.Request.Form.Get("uid"), 10, 64)
  212. if uid <= 0 {
  213. c.JSON(nil, ecode.RequestErr)
  214. return
  215. }
  216. c.JSON(mngSvc.AllRoles(c, pid, uid))
  217. }