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.

165 lines
4.9 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 SysApi
  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. CustomerVerifyErr := utils.Verify(cu, CustomerVerify)
  28. if CustomerVerifyErr != nil {
  29. response.FailWithMessage(CustomerVerifyErr.Error(), c)
  30. return
  31. }
  32. claims, _ := c.Get("claims")
  33. waitUse := claims.(*request.CustomClaims)
  34. cu.SysUserID = waitUse.ID
  35. cu.SysUserAuthorityID = waitUse.AuthorityId
  36. err := service.CreateExaCustomer(cu)
  37. if err != nil {
  38. response.FailWithMessage(fmt.Sprintf("删除失败:%v", err), c)
  39. } else {
  40. response.OkWithMessage("创建成功", c)
  41. }
  42. }
  43. // @Tags SysApi
  44. // @Summary 删除客户
  45. // @Security ApiKeyAuth
  46. // @accept application/json
  47. // @Produce application/json
  48. // @Param data body model.ExaCustomer true "删除客户"
  49. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  50. // @Router /customer/customer [delete]
  51. func DeleteExaCustomer(c *gin.Context) {
  52. var cu model.ExaCustomer
  53. _ = c.ShouldBindJSON(&cu)
  54. CustomerVerify := utils.Rules{
  55. "ID": {utils.NotEmpty()},
  56. }
  57. CustomerVerifyErr := utils.Verify(cu.GVA_MODEL, CustomerVerify)
  58. if CustomerVerifyErr != nil {
  59. response.FailWithMessage(CustomerVerifyErr.Error(), c)
  60. return
  61. }
  62. err := service.DeleteExaCustomer(cu)
  63. if err != nil {
  64. response.FailWithMessage(fmt.Sprintf("删除失败:%v", err), c)
  65. } else {
  66. response.OkWithMessage("删除成功", c)
  67. }
  68. }
  69. // @Tags SysApi
  70. // @Summary 更新客户信息
  71. // @Security ApiKeyAuth
  72. // @accept application/json
  73. // @Produce application/json
  74. // @Param data body model.ExaCustomer true "创建客户"
  75. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  76. // @Router /customer/customer [put]
  77. func UpdateExaCustomer(c *gin.Context) {
  78. var cu model.ExaCustomer
  79. _ = c.ShouldBindJSON(&cu)
  80. IdCustomerVerify := utils.Rules{
  81. "ID": {utils.NotEmpty()},
  82. }
  83. IdCustomerVerifyErr := utils.Verify(cu.GVA_MODEL, IdCustomerVerify)
  84. if IdCustomerVerifyErr != nil {
  85. response.FailWithMessage(IdCustomerVerifyErr.Error(), c)
  86. return
  87. }
  88. CustomerVerify := utils.Rules{
  89. "CustomerName": {utils.NotEmpty()},
  90. "CustomerPhoneData": {utils.NotEmpty()},
  91. }
  92. CustomerVerifyErr := utils.Verify(cu, CustomerVerify)
  93. if CustomerVerifyErr != nil {
  94. response.FailWithMessage(CustomerVerifyErr.Error(), c)
  95. return
  96. }
  97. err := service.UpdateExaCustomer(&cu)
  98. if err != nil {
  99. response.FailWithMessage(fmt.Sprintf("更新失败:%v", err), c)
  100. } else {
  101. response.OkWithMessage("更新成功", c)
  102. }
  103. }
  104. // @Tags SysApi
  105. // @Summary 获取单一客户信息
  106. // @Security ApiKeyAuth
  107. // @accept application/json
  108. // @Produce application/json
  109. // @Param data body model.ExaCustomer true "获取单一客户信息"
  110. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  111. // @Router /customer/customer [get]
  112. func GetExaCustomer(c *gin.Context) {
  113. var cu model.ExaCustomer
  114. _ = c.ShouldBindQuery(&cu)
  115. IdCustomerVerify := utils.Rules{
  116. "ID": {utils.NotEmpty()},
  117. }
  118. IdCustomerVerifyErr := utils.Verify(cu.GVA_MODEL, IdCustomerVerify)
  119. if IdCustomerVerifyErr != nil {
  120. response.FailWithMessage(IdCustomerVerifyErr.Error(), c)
  121. return
  122. }
  123. err, customer := service.GetExaCustomer(cu.ID)
  124. if err != nil {
  125. response.FailWithMessage(fmt.Sprintf("获取失败:%v", err), c)
  126. } else {
  127. response.OkWithData(resp.ExaCustomerResponse{Customer: customer}, c)
  128. }
  129. }
  130. // @Tags SysApi
  131. // @Summary 获取权限客户列表
  132. // @Security ApiKeyAuth
  133. // @accept application/json
  134. // @Produce application/json
  135. // @Param data body request.PageInfo true "获取权限客户列表"
  136. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  137. // @Router /customer/customerList [get]
  138. func GetExaCustomerList(c *gin.Context) {
  139. claims, _ := c.Get("claims")
  140. waitUse := claims.(*request.CustomClaims)
  141. var pageInfo request.PageInfo
  142. _ = c.ShouldBindQuery(&pageInfo)
  143. PageVerifyErr := utils.Verify(pageInfo, utils.CustomizeMap["PageVerify"])
  144. if PageVerifyErr != nil {
  145. response.FailWithMessage(PageVerifyErr.Error(), c)
  146. return
  147. }
  148. err, customerList, total := service.GetCustomerInfoList(waitUse.AuthorityId, pageInfo)
  149. if err != nil {
  150. response.FailWithMessage(fmt.Sprintf("获取失败:%v", err), c)
  151. } else {
  152. response.OkWithData(resp.PageResult{
  153. List: customerList,
  154. Total: total,
  155. Page: pageInfo.Page,
  156. PageSize: pageInfo.PageSize,
  157. }, c)
  158. }
  159. }