123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- package admin
- import (
- //_ "github.com/go-sql-driver/mysql"
- "github.com/beego/beego/v2/client/orm"
- "hongze/hongze_mobile_admin/models/custom"
- "hongze/hongze_mobile_admin/utils"
- "time"
- )
- type Admin struct {
- AdminId int `orm:"column(admin_id);pk" json:"admin_id"`
- AdminName string `orm:"column(admin_name);" json:"admin_name"`
- AdminAvatar string `description:"用户头像"`
- RealName string `orm:"column(real_name);" json:"real_name"`
- Password string `orm:"column(password);" json:"password"`
- LastUpdatedPasswordTime string `orm:"column(last_updated_password_time);" json:"last_updated_password_time"`
- Enabled int `orm:"column(enabled);" json:"enabled"` // 1:有效,0:禁用
- Email string `orm:"column(email);" json:"email"`
- LastLoginTime string `orm:"column(last_login_time);" json:"last_login_time"` // 最近登陆时间
- CreatedTime string `orm:"column(created_time);" json:"created_time"` // 创建时间
- LastUpdatedTime string `orm:"column(last_updated_time);" json:"last_updated_time"`
- Role string `orm:"column(role);" json:"role"` // 用户角色
- Mobile string `orm:"column(mobile);" json:"mobile"` // 手机号
- RoleType int `orm:"column(role_type);" json:"role_type"` // 角色类型:1需要录入指标,0:不需要
- RoleId int `orm:"column(role_id);" json:"role_id"` // 角色id
- RoleName string `orm:"column(role_name);" json:"role_name"` // 角色名称
- RoleTypeCode string `orm:"column(role_type_code);" json:"role_type_code"` // 角色编码
- DepartmentId int `orm:"column(department_id);" json:"department_id"` // 部门id
- DepartmentName string `orm:"column(department_name);" json:"department_name"` // 部门名称
- GroupId int `orm:"column(group_id);" json:"group_id"` // 分组id
- GroupName string `orm:"column(group_name);" json:"group_name"` // 分组名称
- Authority int `orm:"column(authority);" json:"authority"` // 管理权限,0:无,1:部门负责人,2:小组负责人,3:超级管理员
- Position string `orm:"column(position);" json:"position"` // 职位
- OpenId string `orm:"column(open_id);" json:"open_id"` //弘则部门公众号的openid
- UnionId string `orm:"column(union_id);" json:"union_id"` //微信公众平台唯一标识
- }
- // 账号密码校验
- func CheckAdmin(userName, password string) (item *Admin, err error) {
- sql := ` SELECT a.*,b.role_type_code FROM admin AS a
- INNER JOIN sys_role AS b ON a.role_id=b.role_id WHERE a.admin_name=? AND a.password=? LIMIT 1`
- o := orm.NewOrm()
- err = o.Raw(sql, userName, password).QueryRow(&item)
- return
- }
- // 根据管理员id获取管理员信息
- func GetAdminById(adminId int) (item *Admin, err error) {
- sql := `SELECT * FROM admin WHERE admin_id=? LIMIT 1`
- o := orm.NewOrm()
- err = o.Raw(sql, adminId).QueryRow(&item)
- return
- }
- // 根据权限code获取系统用户列表
- func GetAdminListByRoleCode(roleTypeCode string) (items []*Admin, err error) {
- sql := `SELECT * FROM admin WHERE role_type_code=? and enabled=1 `
- o := orm.NewOrm()
- _, err = o.Raw(sql, roleTypeCode).QueryRows(&items)
- return
- }
- // 根据权限id获取系统用户列表
- func GetAdminListByRoleId(roleId string) (items []*Admin, err error) {
- sql := `SELECT * FROM admin WHERE role_id=? and enabled=1 `
- o := orm.NewOrm()
- _, err = o.Raw(sql, roleId).QueryRows(&items)
- return
- }
- // 根据用户id字符串获取系统用户列表
- func GetAdminListByIds(ids string) (items []*Admin, err error) {
- sql := `SELECT * FROM admin WHERE admin_id in (` + ids + `) and enabled=1 `
- o := orm.NewOrm()
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // 根据管理员id获取管理员信息(包含微信、第三方信息)
- func GetAdminWxById(adminId int) (item *custom.AdminWx, err error) {
- sql := `SELECT * FROM admin WHERE admin_id=? LIMIT 1`
- o := orm.NewOrm()
- err = o.Raw(sql, adminId).QueryRow(&item)
- return
- }
- func GetSysuserList(condition string, pars []interface{}, startSize, pageSize int) (items []*AdminItem, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM admin WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- sql += `ORDER BY created_time DESC LIMIT ?,?`
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
- return
- }
- // AdminItem 管理后台的adminInfo,没有使用json格式化,路演这边需要用到,没办法
- type AdminItem struct {
- AdminId int `description:"系统用户id"`
- AdminName string `description:"系统用户名称"`
- RealName string `description:"系统用户姓名"`
- Password string
- LastUpdatedPasswordTime string `json:"-"`
- Enabled int `description:"1:有效,0:禁用"`
- Email string `description:"系统用户邮箱"`
- LastLoginTime string
- CreatedTime time.Time
- LastUpdatedTime string
- Role string `description:"系统用户角色"`
- Mobile string `description:"手机号"`
- RoleType int `description:"角色类型:1需要录入指标,0:不需要"`
- RoleId int `description:"角色id"`
- RoleName string `description:"角色名称"`
- RoleTypeCode string `description:"角色编码"`
- DepartmentId int `description:"部门id"`
- DepartmentName string `json:"-" description:"部门名称"`
- TeamId int `description:"三级id"`
- GroupId int `description:"分组id"`
- GroupName string `json:"-" description:"分组名称"`
- Authority int `description:"管理权限,0:无,1:部门负责人,2:小组负责人,或者ficc销售主管,4:ficc销售组长"`
- Position string `description:"职位"`
- DepartmentGroup string `description:"部门分组"`
- LabelVal int `description:"标签:1:超级管理员,2:管理员,3:部门经理,4:组长,5:ficc销售主管"`
- }
- type SmsCodeReq struct {
- Mobile string
- Token string
- AreaNum string
- }
- type BindMobileReq struct {
- Mobile string
- Token string
- Code string
- }
- type WxLoginResp struct {
- BindToken string
- BindFlag bool
- }
- type WxSmsResp struct {
- SmsFlag bool
- BindFlag bool
- }
- // GetAdminWxByAdminOpenId 根据openId 获取管理员信息
- func GetAdminWxByAdminOpenId(openId string) (item *Admin, err error) {
- sql := `SELECT * FROM admin WHERE open_id=? LIMIT 1`
- o := orm.NewOrm()
- err = o.Raw(sql, openId).QueryRow(&item)
- return
- }
- // GetAdminByMobile 根据手机号 获取管理员信息
- func GetAdminByMobile(mobile string) (item *Admin, err error) {
- sql := `SELECT * FROM admin WHERE mobile=? LIMIT 1`
- o := orm.NewOrm()
- err = o.Raw(sql, mobile).QueryRow(&item)
- return
- }
- // UpdateAdminOpenIdUnionId 更新openId
- func UpdateAdminOpenIdUnionId(adminId int, openId, unionId string) (err error) {
- o := orm.NewOrm()
- sql := `UPDATE admin
- SET
- last_updated_time = NOW(),open_id=?,union_id=? WHERE admin_id = ? `
- _, err = o.Raw(sql, openId, unionId, adminId).Exec()
- return
- }
- type OpenIdList struct {
- OpenId string
- AdminId int
- }
- // GetOpenIdListByMobile 根据手机号获取用户的openid列表
- func GetOpenIdListByMobile(mobile, openIdStr string) (items []*OpenIdList, err error) {
- sql := `SELECT admin_id, open_id FROM admin
- WHERE open_id != "" and mobile=? `
- if openIdStr != "" {
- sql += ` AND open_id in (` + openIdStr + `) `
- }
- _, err = orm.NewOrm().Raw(sql, mobile).QueryRows(&items)
- return
- }
- func GetAdminWxByIdS(adminIdStr string) (items []*custom.AdminWx, err error) {
- sql := `SELECT * FROM admin WHERE admin_id IN(` + adminIdStr + `)`
- o := orm.NewOrm()
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // GetSysuserRaiList 获取权益销售
- func GetSysuserRaiList() (items []*AdminItem, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- real_name,
- mobile,
- group_name
- FROM
- admin
- WHERE
- role_type_code IN ('rai_group','rai_seller')
- AND group_id NOT IN ( 19, 10, 17 )
- AND enabled = 1
- OR real_name IN ( '沈涛', '张传星' ) ` // 先写死,看情况要不要改
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // GetAdminListByIdList 根据用户id列表获取系统用户列表
- func GetAdminListByIdListWithoutEnable(idList []int) (items []*Admin, err error) {
- lenNum := len(idList)
- if lenNum <= 0 {
- return
- }
- sql := `SELECT * FROM admin WHERE admin_id in (` + utils.GetOrmInReplace(lenNum) + `) `
- o := orm.NewOrm()
- _, err = o.Raw(sql, idList).QueryRows(&items)
- return
- }
- // GetSysUserByAdminName 账号获取用户
- func GetSysUserByAdminName(adminName string) (item *Admin, err error) {
- o := orm.NewOrm()
- sql := `SELECT
- a.*, b.role_type_code
- FROM
- admin AS a
- INNER JOIN sys_role AS b ON a.role_id = b.role_id
- WHERE
- a.admin_name = ?
- LIMIT 1`
- err = o.Raw(sql, adminName).QueryRow(&item)
- return
- }
|