You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
4.9 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. package example
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
  5. "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
  6. "github.com/flipped-aurora/gin-vue-admin/server/model/example"
  7. exampleRes "github.com/flipped-aurora/gin-vue-admin/server/model/example/response"
  8. "github.com/flipped-aurora/gin-vue-admin/server/utils"
  9. "github.com/gin-gonic/gin"
  10. "go.uber.org/zap"
  11. )
  12. type CustomerApi struct {
  13. }
  14. // @Tags ExaCustomer
  15. // @Summary 创建客户
  16. // @Security ApiKeyAuth
  17. // @accept application/json
  18. // @Produce application/json
  19. // @Param data body example.ExaCustomer true "客户用户名, 客户手机号码"
  20. // @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
  21. // @Router /customer/customer [post]
  22. func (e *CustomerApi) CreateExaCustomer(c *gin.Context) {
  23. var customer example.ExaCustomer
  24. _ = c.ShouldBindJSON(&customer)
  25. if err := utils.Verify(customer, utils.CustomerVerify); err != nil {
  26. response.FailWithMessage(err.Error(), c)
  27. return
  28. }
  29. customer.SysUserID = utils.GetUserID(c)
  30. customer.SysUserAuthorityID = utils.GetUserAuthorityId(c)
  31. if err := customerService.CreateExaCustomer(customer); err != nil {
  32. global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
  33. response.FailWithMessage("创建失败", c)
  34. } else {
  35. response.OkWithMessage("创建成功", c)
  36. }
  37. }
  38. // @Tags ExaCustomer
  39. // @Summary 删除客户
  40. // @Security ApiKeyAuth
  41. // @accept application/json
  42. // @Produce application/json
  43. // @Param data body example.ExaCustomer true "客户ID"
  44. // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
  45. // @Router /customer/customer [delete]
  46. func (e *CustomerApi) DeleteExaCustomer(c *gin.Context) {
  47. var customer example.ExaCustomer
  48. _ = c.ShouldBindJSON(&customer)
  49. if err := utils.Verify(customer.GVA_MODEL, utils.IdVerify); err != nil {
  50. response.FailWithMessage(err.Error(), c)
  51. return
  52. }
  53. if err := customerService.DeleteExaCustomer(customer); err != nil {
  54. global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
  55. response.FailWithMessage("删除失败", c)
  56. } else {
  57. response.OkWithMessage("删除成功", c)
  58. }
  59. }
  60. // @Tags ExaCustomer
  61. // @Summary 更新客户信息
  62. // @Security ApiKeyAuth
  63. // @accept application/json
  64. // @Produce application/json
  65. // @Param data body example.ExaCustomer true "客户ID, 客户信息"
  66. // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
  67. // @Router /customer/customer [put]
  68. func (e *CustomerApi) UpdateExaCustomer(c *gin.Context) {
  69. var customer example.ExaCustomer
  70. _ = c.ShouldBindJSON(&customer)
  71. if err := utils.Verify(customer.GVA_MODEL, utils.IdVerify); err != nil {
  72. response.FailWithMessage(err.Error(), c)
  73. return
  74. }
  75. if err := utils.Verify(customer, utils.CustomerVerify); err != nil {
  76. response.FailWithMessage(err.Error(), c)
  77. return
  78. }
  79. if err := customerService.UpdateExaCustomer(&customer); err != nil {
  80. global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
  81. response.FailWithMessage("更新失败", c)
  82. } else {
  83. response.OkWithMessage("更新成功", c)
  84. }
  85. }
  86. // @Tags ExaCustomer
  87. // @Summary 获取单一客户信息
  88. // @Security ApiKeyAuth
  89. // @accept application/json
  90. // @Produce application/json
  91. // @Param data query example.ExaCustomer true "客户ID"
  92. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  93. // @Router /customer/customer [get]
  94. func (e *CustomerApi) GetExaCustomer(c *gin.Context) {
  95. var customer example.ExaCustomer
  96. _ = c.ShouldBindQuery(&customer)
  97. if err := utils.Verify(customer.GVA_MODEL, utils.IdVerify); err != nil {
  98. response.FailWithMessage(err.Error(), c)
  99. return
  100. }
  101. err, data := customerService.GetExaCustomer(customer.ID)
  102. if err != nil {
  103. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  104. response.FailWithMessage("获取失败", c)
  105. } else {
  106. response.OkWithDetailed(exampleRes.ExaCustomerResponse{Customer: data}, "获取成功", c)
  107. }
  108. }
  109. // @Tags ExaCustomer
  110. // @Summary 分页获取权限客户列表
  111. // @Security ApiKeyAuth
  112. // @accept application/json
  113. // @Produce application/json
  114. // @Param data query request.PageInfo true "页码, 每页大小"
  115. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  116. // @Router /customer/customerList [get]
  117. func (e *CustomerApi) GetExaCustomerList(c *gin.Context) {
  118. var pageInfo request.PageInfo
  119. _ = c.ShouldBindQuery(&pageInfo)
  120. if err := utils.Verify(pageInfo, utils.PageInfoVerify); err != nil {
  121. response.FailWithMessage(err.Error(), c)
  122. return
  123. }
  124. err, customerList, total := customerService.GetCustomerInfoList(utils.GetUserAuthorityId(c), pageInfo)
  125. if err != nil {
  126. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  127. response.FailWithMessage("获取失败"+err.Error(), c)
  128. } else {
  129. response.OkWithDetailed(response.PageResult{
  130. List: customerList,
  131. Total: total,
  132. Page: pageInfo.Page,
  133. PageSize: pageInfo.PageSize,
  134. }, "获取成功", c)
  135. }
  136. }