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.

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