seller.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. package cygx
  2. import "github.com/beego/beego/v2/client/orm"
  3. type AdminItem struct {
  4. AdminId int `description:"系统用户id"`
  5. RealName string `description:"系统用户姓名"`
  6. Mobile string `description:"手机号"`
  7. RoleType int `description:"角色类型:1需要录入指标,0:不需要"`
  8. RoleId int `description:"角色id"`
  9. RoleName string `description:"角色名称"`
  10. RoleTypeCode string `description:"角色编码"`
  11. DepartmentId int `description:"部门id"`
  12. DepartmentName string `json:"-" description:"部门名称"`
  13. GroupId int `description:"分组id"`
  14. GroupName string `json:"-" description:"分组名称"`
  15. Authority int `description:"管理权限,0:无,1:部门负责人,2:小组负责人"`
  16. OpenId string `description:"openId"`
  17. CompanyName string `description:"客户名称"`
  18. UserId int `description:"联系人id"`
  19. }
  20. func GetSellerByCompanyId(companyId int) (item *AdminItem, err error) {
  21. o := orm.NewOrm()
  22. sql := ` SELECT b.*,c.open_id,c.user_id,a.company_name FROM company_product AS a
  23. INNER JOIN admin AS b ON a.seller_id=b.admin_id
  24. LEFT JOIN wx_user AS c ON b.mobile=c.mobile
  25. WHERE a.company_id=? AND role_type_code LIKE '%rai%'`
  26. err = o.Raw(sql, companyId).QueryRow(&item)
  27. return
  28. }
  29. func GetSellerByCompanyIdCheckFicc(companyId, productId int) (item *AdminItem, err error) {
  30. o := orm.NewOrm()
  31. sql := ` SELECT b.*,c.open_id,c.user_id,a.company_name FROM company_product AS a
  32. INNER JOIN admin AS b ON a.seller_id=b.admin_id
  33. LEFT JOIN wx_user AS c ON b.mobile=c.mobile
  34. WHERE a.company_id=? AND a.product_id=?`
  35. err = o.Raw(sql, companyId, productId).QueryRow(&item)
  36. return
  37. }
  38. func GetSellerByName(userName string) (item *AdminItem, err error) {
  39. o := orm.NewOrm()
  40. sql := ` SELECT * FROM admin WHERE real_name=? `
  41. err = o.Raw(sql, userName).QueryRow(&item)
  42. return
  43. }
  44. func GetSellerByAdminId(adminId int) (item *AdminItem, err error) {
  45. o := orm.NewOrm()
  46. sql := ` SELECT * FROM admin WHERE admin_id=? `
  47. err = o.Raw(sql, adminId).QueryRow(&item)
  48. return
  49. }
  50. // 获取本组的销售ID
  51. func GetSelleridWhichGroup(companyId, productId int) (adminId string, err error) {
  52. o := orm.NewOrm()
  53. sql := ` SELECT
  54. GROUP_CONCAT( DISTINCT admin_id SEPARATOR ',' ) AS adminId
  55. FROM
  56. admin
  57. WHERE
  58. group_id IN (
  59. SELECT
  60. a.group_id
  61. FROM
  62. company_product AS a
  63. INNER JOIN admin AS b ON a.seller_id = b.admin_id
  64. WHERE
  65. a.company_id = ?
  66. AND a.product_id = ?
  67. )`
  68. err = o.Raw(sql, companyId, productId).QueryRow(&adminId)
  69. return
  70. }
  71. type CompanyProductDetial struct {
  72. IsSuspend int `description:"1:暂停,0:启用"`
  73. Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。多个用, 隔开"`
  74. }
  75. // 获取对应销售以及销售的手机号
  76. func GetCompanyProductDetail(companyId, productId int) (item *CompanyProductDetial, err error) {
  77. sql := ` SELECT * FROM company_product WHERE company_id = ? AND product_id = ?; `
  78. o := orm.NewOrm()
  79. err = o.Raw(sql, companyId, productId).QueryRow(&item)
  80. return
  81. }
  82. func GetCompanyDetailById(companyId int) (item *CompanyDetail, err error) {
  83. sql := ` SELECT a.company_id,a.company_name,b.status,b.seller_id,b.seller_name,c.mobile,p.product_id
  84. FROM company AS a
  85. INNER JOIN company_product AS b ON a.company_id=b.company_id
  86. INNER JOIN company_report_permission AS p ON p.company_id = a.company_id
  87. INNER JOIN chart_permission AS cp ON cp.chart_permission_id=p.chart_permission_id
  88. LEFT JOIN admin AS c ON b.seller_id=c.admin_id
  89. WHERE a.company_id=? AND cp.cygx_auth=1
  90. OR (a.company_id = ? AND cp.permission_name = '策略' ) ORDER BY b.product_id DESC LIMIT 1` // 兼容永续状态
  91. o := orm.NewOrm()
  92. err = o.Raw(sql, companyId, companyId).QueryRow(&item)
  93. return
  94. }