company_seller.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package company
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hz_crm_api/utils"
  5. )
  6. type CompanySellers struct {
  7. AdminId int `description:"系统用户id"`
  8. AdminName string `description:"系统用户名称"`
  9. RealName string `description:"用户真实名称"`
  10. }
  11. func GetCompanySeller(roleTypeCode string) (items []*CompanySellers, err error) {
  12. o := orm.NewOrm()
  13. sql := ` SELECT a.admin_id,a.admin_name,real_name FROM admin AS a
  14. INNER JOIN sys_role AS b ON a.role_id=b.role_id
  15. WHERE enabled=1 AND b.role_type_code IN(` + roleTypeCode + `) ORDER BY created_time DESC `
  16. _, err = o.Raw(sql).QueryRows(&items)
  17. return
  18. }
  19. type CompanySellerResp struct {
  20. List []*CompanySellers
  21. }
  22. // DepartmentGroupSellersResp 销售列表(根据部门、分组来)
  23. type DepartmentGroupSellersResp struct {
  24. List []DepartmentGroupSellers
  25. }
  26. type DepartmentGroupSellers struct {
  27. AdminId string `description:"系统用户id"`
  28. //AdminName string `description:"系统用户名称"`
  29. RealName string `description:"用户真实名称"`
  30. ChildrenList []DepartmentGroupSellers `description:"销售列表"`
  31. RoleTypeCode string `description:"角色编码"`
  32. Authority int `description:"管理权限,0:无,1:部门负责人,2:小组负责人,或者ficc销售主管,4:ficc销售组长"`
  33. }
  34. func GetCompanyCheckSeller(condition string, pars []interface{}) (items []*CompanySellers, err error) {
  35. o := orm.NewOrm()
  36. sql := ` SELECT a.admin_id,a.admin_name,real_name FROM admin AS a
  37. INNER JOIN sys_role AS b ON a.role_id=b.role_id
  38. WHERE enabled=1 AND b.role_type_code IN(` + utils.ROLE_TYPE_SELLERS + `) `
  39. if condition != "" {
  40. sql += condition
  41. }
  42. sql += `ORDER BY created_time DESC`
  43. _, err = o.Raw(sql, pars).QueryRows(&items)
  44. return
  45. }
  46. // 根据企业id获取对应的销售信息
  47. func GetCompanySellerByCompanyId(companyId int) (items []*CompanySellers, err error) {
  48. o := orm.NewOrm()
  49. sql := ` SELECT a.admin_id,a.admin_name,real_name FROM admin AS a
  50. INNER JOIN sys_role AS b ON a.role_id=b.role_id
  51. INNER JOIN company_product AS c ON a.admin_id=c.seller_id
  52. WHERE enabled=1 AND c.company_id=? ORDER BY created_time DESC `
  53. _, err = o.Raw(sql, companyId).QueryRows(&items)
  54. return
  55. }
  56. // GetCompanySellerByRoleCodes
  57. func GetCompanySellerByRoleCodes(roleTypeCodes []string) (items []*CompanySellers, err error) {
  58. itemsLen := len(roleTypeCodes)
  59. if itemsLen == 0 {
  60. return
  61. }
  62. o := orm.NewOrm()
  63. sql := `SELECT
  64. a.admin_id,
  65. a.admin_name,
  66. real_name
  67. FROM
  68. admin AS a
  69. INNER JOIN sys_role AS b ON a.role_id = b.role_id
  70. WHERE
  71. enabled = 1 AND b.role_type_code IN (` + utils.GetOrmInReplace(itemsLen) + `)
  72. ORDER BY
  73. created_time DESC `
  74. _, err = o.Raw(sql, roleTypeCodes).QueryRows(&items)
  75. return
  76. }