demand.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package crm
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "server/dao/crm"
  5. "server/global"
  6. "server/model/common/response"
  7. "strconv"
  8. )
  9. type DemandApi struct{}
  10. func (da *DemandApi) QueryDemandsByCustomerId(c *gin.Context) {
  11. id := c.Query("id")
  12. customerId, err := strconv.Atoi(id)
  13. demands, err := demandService.QueryDemandsByCustomerId(customerId)
  14. if err != nil {
  15. response.FailWithMessage("查询失败", c)
  16. global.GVA_LOG.Error("QueryDemandsByCustomerId ====== " + err.Error())
  17. return
  18. }
  19. response.OkWithData(demands, c)
  20. }
  21. func (da *DemandApi) CreateDemand(c *gin.Context) {
  22. var demand crm.Demand
  23. err := c.ShouldBindJSON(&demand)
  24. if err != nil {
  25. response.FailWithMessage("参数错误", c)
  26. global.GVA_LOG.Error("CreateDemand ====== " + err.Error())
  27. return
  28. }
  29. err = demandService.CreateDemand(demand)
  30. if err != nil {
  31. response.FailWithMessage("创建失败", c)
  32. global.GVA_LOG.Error("CreateDemand ====== " + err.Error())
  33. return
  34. }
  35. response.OkWithMessage("创建成功", c)
  36. }
  37. func (da *DemandApi) UpdateDemand(c *gin.Context) {
  38. var demand crm.Demand
  39. err := c.ShouldBindJSON(&demand)
  40. if err != nil {
  41. response.FailWithMessage("参数错误", c)
  42. global.GVA_LOG.Error("UpdateDemand ====== " + err.Error())
  43. return
  44. }
  45. err = demandService.UpdateDemand(demand)
  46. if err != nil {
  47. response.FailWithMessage("更新失败", c)
  48. global.GVA_LOG.Error("UpdateDemand ====== " + err.Error())
  49. return
  50. }
  51. response.OkWithMessage("更新成功", c)
  52. }
  53. func (da *DemandApi) DeleteDemand(c *gin.Context) {
  54. id := c.Query("id")
  55. demandId, _ := strconv.Atoi(id)
  56. err := demandService.DeleteDemand(demandId)
  57. if err != nil {
  58. response.FailWithMessage("删除失败", c)
  59. global.GVA_LOG.Error("DeleteDemand ====== " + err.Error())
  60. return
  61. }
  62. response.OkWithMessage("删除成功", c)
  63. }