1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- package crm
- import (
- "fmt"
- "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)
- fmt.Print(list, total, err)
- 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)
- }
|