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.

141 lines
4.5 KiB

  1. package v1
  2. import (
  3. "fmt"
  4. "gin-vue-admin/global"
  5. "gin-vue-admin/model"
  6. "gin-vue-admin/model/request"
  7. "gin-vue-admin/model/response"
  8. "gin-vue-admin/service"
  9. "gin-vue-admin/utils"
  10. "github.com/gin-gonic/gin"
  11. "go.uber.org/zap"
  12. )
  13. // @Tags ExaCustomer
  14. // @Summary 创建客户
  15. // @Security ApiKeyAuth
  16. // @accept application/json
  17. // @Produce application/json
  18. // @Param data body model.ExaCustomer true "客户用户名, 客户手机号码"
  19. // @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
  20. // @Router /customer/customer [post]
  21. func CreateExaCustomer(c *gin.Context) {
  22. var customer model.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 = getUserID(c)
  29. customer.SysUserAuthorityID = getUserAuthorityId(c)
  30. if err := service.CreateExaCustomer(customer); err != nil {
  31. global.GVA_LOG.Error("创建失败!", zap.Any("err", 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 model.ExaCustomer true "客户ID"
  43. // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
  44. // @Router /customer/customer [delete]
  45. func DeleteExaCustomer(c *gin.Context) {
  46. var customer model.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 := service.DeleteExaCustomer(customer); err != nil {
  53. global.GVA_LOG.Error("删除失败!", zap.Any("err", 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 model.ExaCustomer true "客户ID, 客户信息"
  65. // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
  66. // @Router /customer/customer [put]
  67. func UpdateExaCustomer(c *gin.Context) {
  68. var customer model.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 := service.UpdateExaCustomer(&customer); err != nil {
  79. global.GVA_LOG.Error("更新失败!", zap.Any("err", 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 body model.ExaCustomer true "客户ID"
  91. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  92. // @Router /customer/customer [get]
  93. func GetExaCustomer(c *gin.Context) {
  94. var customer model.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 := service.GetExaCustomer(customer.ID)
  101. if err != nil {
  102. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  103. response.FailWithMessage("获取失败", c)
  104. } else {
  105. response.OkWithDetailed(response.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 body request.PageInfo true "页码, 每页大小"
  114. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  115. // @Router /customer/customerList [get]
  116. func 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 := service.GetCustomerInfoList(getUserAuthorityId(c), pageInfo)
  124. if err != nil {
  125. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  126. response.FailWithMessage(fmt.Sprintf("获取失败:%v", err), 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. }