seller.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. package models
  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. ShareSellerId int `description:"共享销售ID"`
  20. }
  21. func GetSellerByCompanyId(companyId int) (item *AdminItem, err error) {
  22. o := orm.NewOrmUsingDB("weekly_report")
  23. sql := ` SELECT b.*,c.open_id,c.user_id,a.company_name FROM company_product AS a
  24. INNER JOIN admin AS b ON a.seller_id=b.admin_id
  25. LEFT JOIN wx_user AS c ON b.mobile=c.mobile
  26. WHERE a.company_id=? AND role_type_code LIKE '%rai%'`
  27. err = o.Raw(sql, companyId).QueryRow(&item)
  28. return
  29. }
  30. func GetSellerByCompanyIdCheckFicc(companyId, productId int) (item *AdminItem, err error) {
  31. o := orm.NewOrmUsingDB("weekly_report")
  32. sql := ` SELECT b.*,c.open_id,c.user_id,a.company_name FROM company_product AS a
  33. INNER JOIN admin AS b ON a.seller_id=b.admin_id
  34. LEFT JOIN wx_user AS c ON b.mobile=c.mobile
  35. WHERE a.company_id=? AND a.product_id=?`
  36. err = o.Raw(sql, companyId, productId).QueryRow(&item)
  37. return
  38. }
  39. func GetSellerByName(userName string) (item *AdminItem, err error) {
  40. o := orm.NewOrmUsingDB("weekly_report")
  41. sql := ` SELECT * FROM admin WHERE real_name=? `
  42. err = o.Raw(sql, userName).QueryRow(&item)
  43. return
  44. }
  45. // 获取本组的销售ID
  46. func GetSelleridWhichGroup(companyId, productId int) (adminId string, err error) {
  47. o := orm.NewOrmUsingDB("weekly_report")
  48. sql := ` SELECT
  49. GROUP_CONCAT( DISTINCT admin_id SEPARATOR ',' ) AS adminId
  50. FROM
  51. admin
  52. WHERE
  53. group_id IN (
  54. SELECT
  55. a.group_id
  56. FROM
  57. company_product AS a
  58. INNER JOIN admin AS b ON a.seller_id = b.admin_id
  59. WHERE
  60. a.company_id = ?
  61. AND a.product_id = ?
  62. )`
  63. err = o.Raw(sql, companyId, productId).QueryRow(&adminId)
  64. return
  65. }
  66. func GetSellerByAdminId(adminId int) (item *AdminItem, err error) {
  67. o := orm.NewOrmUsingDB("weekly_report")
  68. sql := ` SELECT * FROM admin WHERE admin_id=? `
  69. err = o.Raw(sql, adminId).QueryRow(&item)
  70. return
  71. }
  72. func GetSellerByAdminMobile(mobile string) (item *AdminItem, err error) {
  73. o := orm.NewOrmUsingDB("weekly_report")
  74. sql := ` SELECT * FROM admin WHERE mobile=? `
  75. err = o.Raw(sql, mobile).QueryRow(&item)
  76. return
  77. }
  78. // GetAdminListByGroupId 根据分组id获取系统用户列表
  79. func GetAdminListByGroupId(groupId int) (items []*Admin, err error) {
  80. sql := `SELECT * FROM admin WHERE group_id=? and enabled=1 `
  81. o := orm.NewOrmUsingDB("weekly_report")
  82. _, err = o.Raw(sql, groupId).QueryRows(&items)
  83. return
  84. }
  85. // 获取权益销售信息
  86. func GetRaiSellerByCompanyId(companyId int) (item *AdminItem, err error) {
  87. o := orm.NewOrmUsingDB("weekly_report")
  88. sql := ` SELECT
  89. a.share_seller_id,
  90. b.admin_id,
  91. b.real_name,
  92. b.mobile
  93. FROM
  94. company_product AS a
  95. INNER JOIN admin AS b ON a.seller_id = b.admin_id
  96. WHERE
  97. a.product_id = 2
  98. AND a.company_id = ?`
  99. err = o.Raw(sql, companyId).QueryRow(&item)
  100. return
  101. }