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.7 KiB

  1. package v1
  2. import (
  3. "fmt"
  4. "gin-vue-admin/global/response"
  5. "gin-vue-admin/model"
  6. "gin-vue-admin/model/request"
  7. resp "gin-vue-admin/model/response"
  8. "gin-vue-admin/service"
  9. "gin-vue-admin/utils"
  10. "github.com/gin-gonic/gin"
  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 cu model.ExaCustomer
  22. _ = c.ShouldBindJSON(&cu)
  23. CustomerVerify := utils.Rules{
  24. "CustomerName": {utils.NotEmpty()},
  25. "CustomerPhoneData": {utils.NotEmpty()},
  26. }
  27. if CustomerVerifyErr := utils.Verify(cu, CustomerVerify); CustomerVerifyErr != nil {
  28. response.FailWithMessage(CustomerVerifyErr.Error(), c)
  29. return
  30. }
  31. cu.SysUserID = getUserID(c)
  32. cu.SysUserAuthorityID = getUserAuthorityId(c)
  33. if err := service.CreateExaCustomer(cu); err != nil {
  34. response.FailWithMessage(fmt.Sprintf("删除失败:%v", err), c)
  35. } else {
  36. response.OkWithMessage("创建成功", c)
  37. }
  38. }
  39. // @Tags ExaCustomer
  40. // @Summary 删除客户
  41. // @Security ApiKeyAuth
  42. // @accept application/json
  43. // @Produce application/json
  44. // @Param data body model.ExaCustomer true "客户ID"
  45. // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
  46. // @Router /customer/customer [delete]
  47. func DeleteExaCustomer(c *gin.Context) {
  48. var cu model.ExaCustomer
  49. _ = c.ShouldBindJSON(&cu)
  50. if CustomerVerifyErr := utils.Verify(cu.GVA_MODEL, utils.Rules{"ID": {utils.NotEmpty()}}); CustomerVerifyErr != nil {
  51. response.FailWithMessage(CustomerVerifyErr.Error(), c)
  52. return
  53. }
  54. if err := service.DeleteExaCustomer(cu); err != nil {
  55. response.FailWithMessage(fmt.Sprintf("删除失败:%v", err), 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 model.ExaCustomer true "客户ID, 客户信息"
  66. // @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
  67. // @Router /customer/customer [put]
  68. func UpdateExaCustomer(c *gin.Context) {
  69. var cu model.ExaCustomer
  70. _ = c.ShouldBindJSON(&cu)
  71. if IdCustomerVerifyErr := utils.Verify(cu.GVA_MODEL, utils.Rules{"ID": {utils.NotEmpty()}}); IdCustomerVerifyErr != nil {
  72. response.FailWithMessage(IdCustomerVerifyErr.Error(), c)
  73. return
  74. }
  75. CustomerVerify := utils.Rules{
  76. "CustomerName": {utils.NotEmpty()},
  77. "CustomerPhoneData": {utils.NotEmpty()},
  78. }
  79. if CustomerVerifyErr := utils.Verify(cu, CustomerVerify); CustomerVerifyErr != nil {
  80. response.FailWithMessage(CustomerVerifyErr.Error(), c)
  81. return
  82. }
  83. if err := service.UpdateExaCustomer(&cu); err != nil {
  84. response.FailWithMessage(fmt.Sprintf("更新失败:%v", err), c)
  85. } else {
  86. response.OkWithMessage("更新成功", c)
  87. }
  88. }
  89. // @Tags ExaCustomer
  90. // @Summary 获取单一客户信息
  91. // @Security ApiKeyAuth
  92. // @accept application/json
  93. // @Produce application/json
  94. // @Param data body model.ExaCustomer true "客户ID"
  95. // @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
  96. // @Router /customer/customer [get]
  97. func GetExaCustomer(c *gin.Context) {
  98. var cu model.ExaCustomer
  99. _ = c.ShouldBindQuery(&cu)
  100. if IdCustomerVerifyErr := utils.Verify(cu.GVA_MODEL, utils.Rules{"ID": {utils.NotEmpty()}}); IdCustomerVerifyErr != nil {
  101. response.FailWithMessage(IdCustomerVerifyErr.Error(), c)
  102. return
  103. }
  104. err, customer := service.GetExaCustomer(cu.ID)
  105. if err != nil {
  106. response.FailWithMessage(fmt.Sprintf("获取失败:%v", err), c)
  107. } else {
  108. response.OkWithData(resp.ExaCustomerResponse{Customer: customer}, c)
  109. }
  110. }
  111. // @Tags ExaCustomer
  112. // @Summary 获取权限客户列表
  113. // @Security ApiKeyAuth
  114. // @accept application/json
  115. // @Produce application/json
  116. // @Param data body request.PageInfo true "页码, 每页大小"
  117. // @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
  118. // @Router /customer/customerList [get]
  119. func GetExaCustomerList(c *gin.Context) {
  120. var pageInfo request.PageInfo
  121. _ = c.ShouldBindQuery(&pageInfo)
  122. if PageVerifyErr := utils.Verify(pageInfo, utils.CustomizeMap["PageVerify"]); PageVerifyErr != nil {
  123. response.FailWithMessage(PageVerifyErr.Error(), c)
  124. return
  125. }
  126. err, customerList, total := service.GetCustomerInfoList(getUserAuthorityId(c), pageInfo)
  127. if err != nil {
  128. response.FailWithMessage(fmt.Sprintf("获取失败:%v", err), c)
  129. } else {
  130. response.OkWithData(resp.PageResult{
  131. List: customerList,
  132. Total: total,
  133. Page: pageInfo.Page,
  134. PageSize: pageInfo.PageSize,
  135. }, c)
  136. }
  137. }