customer.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package crm
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "server/dao/crm"
  5. "server/global"
  6. "server/model/common/request"
  7. "server/model/common/response"
  8. "strconv"
  9. )
  10. type CustomerApi struct{}
  11. func (ca *CustomerApi) QueryAllCustomers(c *gin.Context) {
  12. allCustomers, err := customerService.QueryAllCustomers()
  13. if err != nil {
  14. response.FailWithMessage("查询失败", c)
  15. global.GVA_LOG.Error("QueryAllCustomers ====== " + err.Error())
  16. return
  17. }
  18. response.OkWithData(allCustomers, c)
  19. }
  20. func (ca *CustomerApi) QueryCustomerList(c *gin.Context) {
  21. var info request.SearchCustomer
  22. err := c.ShouldBindJSON(&info)
  23. if err != nil {
  24. response.FailWithMessage("参数解析失败", c)
  25. global.GVA_LOG.Error("QueryCustomerList ====== " + err.Error())
  26. return
  27. }
  28. list, total, err := customerService.QueryCustomerList(info)
  29. if err != nil {
  30. response.FailWithMessage("查询失败", c)
  31. global.GVA_LOG.Error("QueryCustomerList ====== " + err.Error())
  32. return
  33. }
  34. response.OkWithDetailed(response.PageResult{
  35. List: list,
  36. Total: total,
  37. Page: info.PageInfo.Page,
  38. PageSize: info.PageInfo.PageSize,
  39. }, "获取成功", c)
  40. }
  41. func (ca *CustomerApi) CreateCustomer(c *gin.Context) {
  42. var customer crm.Customer
  43. err := c.ShouldBindJSON(&customer)
  44. if err != nil {
  45. response.FailWithMessage("参数解析失败", c)
  46. global.GVA_LOG.Error("CreateCustomer ====== " + err.Error())
  47. return
  48. }
  49. err = customerService.CreateCustomer(customer)
  50. if err != nil {
  51. response.FailWithMessage("创建失败", c)
  52. global.GVA_LOG.Error("CreateCustomer ====== " + err.Error())
  53. return
  54. }
  55. response.OkWithMessage("创建成功", c)
  56. }
  57. func (ca *CustomerApi) UpdateCustomer(c *gin.Context) {
  58. var customer crm.Customer
  59. err := c.ShouldBindJSON(&customer)
  60. if err != nil {
  61. response.FailWithMessage("参数解析失败", c)
  62. global.GVA_LOG.Error("UpdateCustomer ====== " + err.Error())
  63. return
  64. }
  65. err = customerService.UpdateCustomer(customer)
  66. if err != nil {
  67. response.FailWithMessage("更新失败", c)
  68. global.GVA_LOG.Error("UpdateCustomer ====== " + err.Error())
  69. return
  70. }
  71. response.OkWithMessage("更新成功", c)
  72. }
  73. func (ca *CustomerApi) DeleteCustomer(c *gin.Context) {
  74. id := c.Query("id")
  75. idInt, _ := strconv.Atoi(id)
  76. err := customerService.DeleteCustomer(idInt)
  77. if err != nil {
  78. response.FailWithMessage("删除失败", c)
  79. global.GVA_LOG.Error("DeleteCustomer ====== " + err.Error())
  80. return
  81. }
  82. response.OkWithMessage("删除成功", c)
  83. }