package crm import ( "fmt" "github.com/gin-gonic/gin" "server/dao/crm" "server/global" "server/model/common/response" "strconv" ) type DemandApi struct{} func (da *DemandApi) QueryDemandsByCustomerId(c *gin.Context) { id := c.Query("id") customerId, err := strconv.Atoi(id) fmt.Print("customerId:", customerId) demands, err := demandService.QueryDemandsByCustomerId(customerId) if err != nil { response.FailWithMessage("查询失败", c) global.GVA_LOG.Error("QueryDemandsByCustomerId ====== " + err.Error()) return } response.OkWithData(demands, c) } func (da *DemandApi) CreateDemand(c *gin.Context) { var demand crm.Demand err := c.ShouldBindJSON(&demand) if err != nil { response.FailWithMessage("参数错误", c) global.GVA_LOG.Error("CreateDemand ====== " + err.Error()) return } err = demandService.CreateDemand(demand) if err != nil { response.FailWithMessage("创建失败", c) global.GVA_LOG.Error("CreateDemand ====== " + err.Error()) return } response.OkWithMessage("创建成功", c) } func (da *DemandApi) UpdateDemand(c *gin.Context) { var demand crm.Demand err := c.ShouldBindJSON(&demand) fmt.Println(demand) if err != nil { response.FailWithMessage("参数错误", c) global.GVA_LOG.Error("UpdateDemand ====== " + err.Error()) return } err = demandService.UpdateDemand(demand) if err != nil { response.FailWithMessage("更新失败", c) global.GVA_LOG.Error("UpdateDemand ====== " + err.Error()) return } response.OkWithMessage("更新成功", c) } func (da *DemandApi) DeleteDemand(c *gin.Context) { id := c.Query("id") demandId, _ := strconv.Atoi(id) err := demandService.DeleteDemand(demandId) if err != nil { response.FailWithMessage("删除失败", c) global.GVA_LOG.Error("DeleteDemand ====== " + err.Error()) return } response.OkWithMessage("删除成功", c) }