seller.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. func GetSellerByAdminId(adminId int) (item *AdminItem, err error) {
  46. o := orm.NewOrmUsingDB("weekly_report")
  47. sql := ` SELECT * FROM admin WHERE admin_id=? `
  48. err = o.Raw(sql, adminId).QueryRow(&item)
  49. return
  50. }
  51. // 获取本组的销售ID
  52. func GetSelleridWhichGroup(companyId, productId int) (adminId string, err error) {
  53. o := orm.NewOrmUsingDB("weekly_report")
  54. sql := ` SELECT
  55. GROUP_CONCAT( DISTINCT admin_id SEPARATOR ',' ) AS adminId
  56. FROM
  57. admin
  58. WHERE
  59. group_id IN (
  60. SELECT
  61. a.group_id
  62. FROM
  63. company_product AS a
  64. INNER JOIN admin AS b ON a.seller_id = b.admin_id
  65. WHERE
  66. a.company_id = ?
  67. AND a.product_id = ?
  68. )`
  69. err = o.Raw(sql, companyId, productId).QueryRow(&adminId)
  70. return
  71. }
  72. // 获取权益销售信息
  73. func GetRaiSellerByCompanyId(companyId int) (item *AdminItem, err error) {
  74. o := orm.NewOrmUsingDB("weekly_report")
  75. sql := ` SELECT
  76. a.share_seller_id,
  77. b.admin_id,
  78. b.real_name,
  79. b.mobile
  80. FROM
  81. company_product AS a
  82. INNER JOIN admin AS b ON a.seller_id = b.admin_id
  83. WHERE
  84. a.product_id = 2
  85. AND a.company_id = ?`
  86. err = o.Raw(sql, companyId).QueryRow(&item)
  87. return
  88. }
  89. func GetShareSellerByCompanyIdCheckFicc(companyId, productId int) (item *AdminItem, err error) {
  90. o := orm.NewOrmUsingDB("weekly_report")
  91. sql := ` SELECT b.*,c.open_id,c.user_id,a.company_name FROM company_product AS a
  92. INNER JOIN admin AS b ON a.share_seller_id=b.admin_id
  93. LEFT JOIN wx_user AS c ON b.mobile=c.mobile
  94. WHERE a.company_id=? AND a.product_id=?`
  95. err = o.Raw(sql, companyId, productId).QueryRow(&item)
  96. return
  97. }