customer.go 2.4 KB

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