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.

140 lines
4.5 KiB

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