admin.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_mfyx/utils"
  5. "time"
  6. )
  7. type AdminMobileResp struct {
  8. Mobile string `description:"手机号"`
  9. }
  10. // 获取销售所能查看到的手机号
  11. func GetAdminByRole() (items []*AdminMobileResp, err error) {
  12. o := orm.NewOrmUsingDB("weekly_report")
  13. sql := ` SELECT mobile FROM admin WHERE role = 'admin' `
  14. _, err = o.Raw(sql).QueryRows(&items)
  15. return
  16. }
  17. type Admin struct {
  18. AdminId int `orm:"column(admin_id);pk" description:"系统用户id"`
  19. AdminName string `description:"系统用户名称"`
  20. AdminAvatar string `description:"用户头像"`
  21. RealName string `description:"系统用户姓名"`
  22. Password string `json:"-"`
  23. LastUpdatedPasswordTime string `json:"-"`
  24. Enabled int
  25. Email string `description:"系统用户邮箱"`
  26. LastLoginTime string
  27. CreatedTime time.Time
  28. LastUpdatedTime string
  29. Role string `description:"系统用户角色"`
  30. Mobile string `description:"手机号"`
  31. RoleType int `description:"角色类型:1需要录入指标,0:不需要"`
  32. RoleId int `description:"角色ID"`
  33. RoleName string `description:"角色名称"`
  34. RoleTypeCode string `description:"角色类型编码"`
  35. DepartmentId int `description:"部门id"`
  36. DepartmentName string `description:"部门名称"`
  37. GroupId int `description:"分组id"`
  38. GroupName string `description:"分组名称"`
  39. Authority int `description:"管理权限,0:无,1:部门负责人,2:小组负责人,或者ficc销售主管,4:ficc销售组长"`
  40. Position string `description:"职位"`
  41. DisableTime time.Time `description:"禁用时间"`
  42. ChartPermission int8 `description:"图表权限id"`
  43. OpenId string `description:"弘则部门公众号的openid"`
  44. UnionId string `description:"微信公众平台唯一标识"`
  45. EdbPermission int8 `description:"指标库操作权限,0:只能操作 自己的,1:所有指标可操作"`
  46. MysteelChemicalPermission int8 `description:"钢联化工指标操作权限,0:只能操作 自己的,1:所有指标可操作"`
  47. PredictEdbPermission int8 `description:"预测指标库操作权限,0:只能操作 自己的,1:所有预测指标可操作"`
  48. Province string `description:"省"`
  49. ProvinceCode string `description:"省编码"`
  50. City string `description:"市"`
  51. CityCode string `description:"市编码"`
  52. }
  53. func GetSysAdminById(adminId int) (item *Admin, err error) {
  54. sql := `SELECT * FROM admin WHERE admin_id=? `
  55. o := orm.NewOrmUsingDB("weekly_report")
  56. err = o.Raw(sql, adminId).QueryRow(&item)
  57. return
  58. }
  59. func GetSysAdminByMobile(mobile string) (item *Admin, err error) {
  60. sql := `SELECT * FROM admin WHERE mobile=? LIMIT 1 `
  61. o := orm.NewOrmUsingDB("weekly_report")
  62. err = o.Raw(sql, mobile).QueryRow(&item)
  63. return
  64. }
  65. // 获取权益内部人员手机号
  66. func GetRaiAdmin() (items []*AdminMobileResp, err error) {
  67. o := orm.NewOrmUsingDB("weekly_report")
  68. sql := ` SELECT
  69. mobile
  70. FROM
  71. admin
  72. WHERE
  73. role_type_code LIKE '%rai%'
  74. AND group_id NOT IN ( 19, 10 )
  75. AND enabled = 1
  76. OR (
  77. department_name = '产品技术部'
  78. AND enabled = 1) `
  79. _, err = o.Raw(sql).QueryRows(&items)
  80. return
  81. }
  82. type GetSellerUserMobileResp struct {
  83. Mobile string `description:"手机号"`
  84. UserId int `description:"用户ID"`
  85. }
  86. // 获取销售所能查看到的手机号
  87. func GetSellerUserMobile(adminId int) (items []*GetSellerUserMobileResp, err error) {
  88. o := orm.NewOrmUsingDB("weekly_report")
  89. sql := ` SELECT mobile FROM user_seller_relation WHERE seller_id = ? `
  90. _, err = o.Raw(sql, adminId).QueryRows(&items)
  91. return
  92. }
  93. // GetUserSellerRelationUserList 获取跟销售绑定了关系的权益用户
  94. func GetUserSellerRelationUserList() (items []*GetSellerUserMobileResp, err error) {
  95. o := orm.NewOrmUsingDB("weekly_report")
  96. sql := ` SELECT
  97. a.user_id
  98. FROM
  99. user_seller_relation AS a
  100. INNER JOIN company_product AS b ON b.company_id = a.company_id
  101. AND b.product_id = 2 `
  102. _, err = o.Raw(sql).QueryRows(&items)
  103. return
  104. }
  105. // 根据多个ID获取管理员列表信息
  106. func GetAdminByAdminIds(adminId []int) (items []*AdminMobileResp, err error) {
  107. lenArr := len(adminId)
  108. if lenArr == 0 {
  109. return
  110. }
  111. o := orm.NewOrmUsingDB("weekly_report")
  112. sql := ` SELECT mobile FROM admin WHERE admin_id IN (` + utils.GetOrmInReplace(lenArr) + `)`
  113. _, err = o.Raw(sql, adminId).QueryRows(&items)
  114. return
  115. }