| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- package crm
- import (
- "github.com/gin-gonic/gin"
- "server/dao/crm"
- "server/global"
- "server/model/common/request"
- "server/model/common/response"
- "strconv"
- )
- type CustomerApi struct{}
- func (ca *CustomerApi) QueryAllCustomers(c *gin.Context) {
- allCustomers, err := customerService.QueryAllCustomers()
- if err != nil {
- response.FailWithMessage("查询失败", c)
- global.GVA_LOG.Error("QueryAllCustomers ====== " + err.Error())
- return
- }
- response.OkWithData(allCustomers, c)
- }
- func (ca *CustomerApi) QueryCustomerList(c *gin.Context) {
- var info request.SearchCustomer
- err := c.ShouldBindJSON(&info)
- if err != nil {
- response.FailWithMessage("参数解析失败", c)
- global.GVA_LOG.Error("QueryCustomerList ====== " + err.Error())
- return
- }
- list, total, err := customerService.QueryCustomerList(info)
- if err != nil {
- response.FailWithMessage("查询失败", c)
- global.GVA_LOG.Error("QueryCustomerList ====== " + err.Error())
- return
- }
- response.OkWithDetailed(response.PageResult{
- List: list,
- Total: total,
- Page: info.PageInfo.Page,
- PageSize: info.PageInfo.PageSize,
- }, "获取成功", c)
- }
- func (ca *CustomerApi) CreateCustomer(c *gin.Context) {
- var customer crm.Customer
- err := c.ShouldBindJSON(&customer)
- if err != nil {
- response.FailWithMessage("参数解析失败", c)
- global.GVA_LOG.Error("CreateCustomer ====== " + err.Error())
- return
- }
- err = customerService.CreateCustomer(customer)
- if err != nil {
- response.FailWithMessage("创建失败", c)
- global.GVA_LOG.Error("CreateCustomer ====== " + err.Error())
- return
- }
- response.OkWithMessage("创建成功", c)
- }
- func (ca *CustomerApi) UpdateCustomer(c *gin.Context) {
- var customer crm.Customer
- err := c.ShouldBindJSON(&customer)
- if err != nil {
- response.FailWithMessage("参数解析失败", c)
- global.GVA_LOG.Error("UpdateCustomer ====== " + err.Error())
- return
- }
- err = customerService.UpdateCustomer(customer)
- if err != nil {
- response.FailWithMessage("更新失败", c)
- global.GVA_LOG.Error("UpdateCustomer ====== " + err.Error())
- return
- }
- response.OkWithMessage("更新成功", c)
- }
- func (ca *CustomerApi) DeleteCustomer(c *gin.Context) {
- id := c.Query("id")
- idInt, _ := strconv.Atoi(id)
- err := customerService.DeleteCustomer(idInt)
- if err != nil {
- response.FailWithMessage("删除失败", c)
- global.GVA_LOG.Error("DeleteCustomer ====== " + err.Error())
- return
- }
- response.OkWithMessage("删除成功", c)
- }
|