company_seller.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package crm
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/go-playground/validator/v10"
  5. "hongze/fms_api/controller/resp"
  6. "hongze/fms_api/global"
  7. "hongze/fms_api/models/crm"
  8. crmService "hongze/fms_api/services/crm"
  9. )
  10. // CompanySellerController CRM销售
  11. type CompanySellerController struct{}
  12. // List
  13. // @Title 销售列表
  14. // @Description 销售列表
  15. // @Success 200 {object} crm.SellerAdminWithGroupList
  16. // @router /crm/company_seller/list [get]
  17. func (rg *CompanySellerController) List(c *gin.Context) {
  18. // 此处调整为只取销售部门的人员, 而不是原先的根据角色取
  19. list, e := crmService.GetSellerDepartmentList()
  20. if e != nil {
  21. resp.FailData("获取失败", "获取销售列表失败, Err:"+e.Error(), c)
  22. return
  23. }
  24. resp.OkData("获取成功", list, c)
  25. }
  26. // GroupList
  27. // @Title 销售组别列表
  28. // @Description 销售组别列表
  29. // @Success 200 {object} crm.SysGroup
  30. // @router /crm/company_seller/group_list [get]
  31. func (rg *CompanySellerController) GroupList(c *gin.Context) {
  32. var req crm.SysGroupListReq
  33. if e := c.BindQuery(&req); e != nil {
  34. err, ok := e.(validator.ValidationErrors)
  35. if !ok {
  36. resp.FailData("参数解析失败", "Err:"+e.Error(), c)
  37. return
  38. }
  39. resp.FailData("参数解析失败", err.Translate(global.Trans), c)
  40. return
  41. }
  42. var departmentId int
  43. if req.SellerType == 1 {
  44. departmentId = crm.SellerDepartmentId
  45. }else if req.SellerType == 2 {
  46. departmentId = crm.RaiSellerDepartmentId
  47. }else if req.SellerType == 0 {
  48. resp.Fail("请选择销售类型", c)
  49. return
  50. }else {
  51. resp.Fail("请选择正确的销售类型", c)
  52. return
  53. }
  54. groupOB := new(crm.SysGroup)
  55. cond := `department_id = ? AND parent_id = 0`
  56. pars := make([]interface{}, 0)
  57. pars = append(pars, departmentId)
  58. list, e := groupOB.List(cond, pars)
  59. if e != nil {
  60. resp.FailData("获取失败", "获取销售组别列表失败, Err:"+e.Error(), c)
  61. return
  62. }
  63. resp.OkData("获取成功", list, c)
  64. }