package system import ( "eta/eta_forum_admin/utils" "fmt" "github.com/beego/beego/v2/client/orm" "strings" "time" ) type LoginReq struct { Username string `description:"账号"` Password string `description:"密码"` IsRemember bool `description:"是否属于受信设备"` } type LoginResp struct { Authorization string AdminName string `description:"系统用户名称"` RealName string `description:"系统用户姓名"` RoleName string `description:"角色名称"` RoleTypeCode string `description:"角色类型编码"` SysRoleTypeCode string `description:"角色类型编码"` AdminId int `description:"系统用户id"` ProductName string `description:"产品名称:admin,ficc,权益"` Authority int `description:"管理权限,0:无,1:部门负责人,2:小组负责人,或者ficc销售主管,4:ficc销售组长"` } type Admin struct { AdminId int `orm:"column(admin_id);pk" description:"系统用户id"` AdminName string `description:"系统用户名称"` AdminAvatar string `description:"用户头像"` RealName string `description:"系统用户姓名"` Password string `json:"-"` LastUpdatedPasswordTime string `json:"-"` Enabled int 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 `description:"部门名称"` GroupId int `description:"分组id"` GroupName string `description:"分组名称"` Authority int `description:"管理权限,0:无,1:部门负责人,2:小组负责人,或者ficc销售主管,3:超级管理员,4:ficc销售组长"` Position string `description:"职位"` DisableTime time.Time `description:"禁用时间"` ChartPermission int8 `description:"图表权限id"` OpenId string `description:"弘则部门公众号的openid"` UnionId string `description:"微信公众平台唯一标识"` EdbPermission int8 `description:"指标库操作权限,0:只能操作 自己的,1:所有指标可操作"` MysteelChemicalPermission int8 `description:"钢联化工指标操作权限,0:只能操作 自己的,1:所有指标可操作"` PredictEdbPermission int8 `description:"预测指标库操作权限,0:只能操作 自己的,1:所有预测指标可操作"` Province string `description:"省"` ProvinceCode string `description:"省编码"` City string `description:"市"` CityCode string `description:"市编码"` EmployeeId string `description:"员工工号(钉钉/每刻报销)"` TelAreaCode string `description:"手机区号"` IsLdap int `description:"是否为域用户:0-系统账户;1-域用户"` BusinessCode string `description:"商家编码"` } // Update 更新用户基础信息 func (item *Admin) Update(cols []string) (err error) { o := orm.NewOrm() _, err = o.Update(item, cols...) return } func GetSysUserById(sysUserId int) (item *Admin, err error) { sql := `SELECT * FROM admin WHERE admin_id=? LIMIT 1` o := orm.NewOrm() err = o.Raw(sql, sysUserId).QueryRow(&item) return } func ModifyPwd(sysUserId int, newPwd string) (err error) { sql := `UPDATE admin SET password=?,last_updated_time=NOW() WHERE admin_id=? ` o := orm.NewOrm() _, err = o.Raw(sql, newPwd, sysUserId).Exec() return } type ModifyPwdReq struct { OldPwd string `description:"旧密码"` NewPwd string `description:"新密码"` } // AdminWxUserRelation 管理员-微信用户关联 type AdminWxUserRelation struct { AdminId int `json:"admin_id"` AdminName string `json:"admin_name"` RealName string `json:"real_name"` UserId int `json:"user_id"` } // GetAdminListByIdList 根据用户id列表获取系统用户列表 func GetAdminListByIdList(idList []int) (items []*Admin, err error) { lenNum := len(idList) if lenNum <= 0 { return } sql := `SELECT * FROM admin WHERE admin_id in (` + utils.GetOrmInReplace(lenNum) + `) and enabled=1 ` o := orm.NewOrm() _, err = o.Raw(sql, idList).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 } func (item *Admin) GetCountByCondition(condition string, pars []interface{}) (count int, err error) { o := orm.NewOrm() sql := fmt.Sprintf(`SELECT COUNT(1) FROM admin WHERE 1=1 %s`, condition) err = o.Raw(sql, pars).QueryRow(&count) return } func (item *Admin) GetItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*Admin, err error) { o := orm.NewOrm() fields := strings.Join(fieldArr, ",") if len(fieldArr) == 0 { fields = `*` } order := `ORDER BY created_time DESC` if orderRule != "" { order = ` ORDER BY ` + orderRule } sql := fmt.Sprintf(`SELECT %s FROM admin WHERE 1=1 %s %s`, fields, condition, order) _, err = o.Raw(sql, pars).QueryRows(&items) return } // GetAdminByAdminName 账号获取用户 func GetAdminByAdminName(adminName string) (item *Admin, err error) { o := orm.NewOrm() sql := `SELECT * FROM admin WHERE admin_name = ? LIMIT 1` err = o.Raw(sql, adminName).QueryRow(&item) return } // GetUserUnexpiredSysSession 获取用户未过期的Token func GetUserUnexpiredSysSession(userName, expiredTime string) (item *SysSession, err error) { o := orm.NewOrm() sql := `SELECT * FROM sys_session WHERE user_name = ? AND expired_time > ? ORDER BY expired_time DESC LIMIT 1` err = o.Raw(sql, userName, expiredTime).QueryRow(&item) return } type AuthCodeLoginReq struct { AuthCode string } type BusinessAdmin struct { AdminId string `description:"系统用户id"` RealName string `description:"用户真实名称"` ChildrenList []*BusinessAdmin `description:"用户列表"` } type BusinessAdminResp struct { List []*BusinessAdmin `description:"用户列表"` } func GetSysAdminById(adminId int) (item *Admin, err error) { sql := `SELECT * FROM admin WHERE admin_id=? ` o := orm.NewOrm() err = o.Raw(sql, adminId).QueryRow(&item) return } func GetSysUserItems(condition string, pars []interface{}) (items []*Admin, err error) { o := orm.NewOrm() sql := `SELECT * FROM admin WHERE 1=1 ` if condition != "" { sql += condition } sql += `ORDER BY last_updated_time DESC ` _, err = o.Raw(sql, pars).QueryRows(&items) return } type HzEtaBusiness struct { BusinessName string `description:"商家名称"` BusinessCode string } func GetSysUserItemsOrderByCreated(condition string, pars []interface{}) (items []*Admin, err error) { o := orm.NewOrm() sql := `SELECT * FROM admin WHERE 1=1 ` if condition != "" { sql += condition } sql += ` ORDER BY created_time DESC ` _, err = o.Raw(sql, pars).QueryRows(&items) return } // GetTeamSysUserList 根据小组id获取系统用户列表 func GetTeamSysUserList(teamId, enabled int) (items []*Admin, err error) { o := orm.NewOrm() sql := `SELECT * FROM admin WHERE group_id=? ` if enabled >= 0 { sql += fmt.Sprint(` AND enabled=`, enabled, ` `) } sql += ` ORDER BY created_time DESC ` _, err = o.Raw(sql, teamId).QueryRows(&items) return } // GetGrooupsysUserList 根据大组id和小组id获取系统用户列表 func GetGrooupsysUserList(groupId int, roleTypeCodes string, enabled int) (items []*Admin, err error) { o := orm.NewOrm() sql := `SELECT * FROM admin WHERE group_id = ? ` if roleTypeCodes != "" { sql += ` and role_type_code in (` + roleTypeCodes + `) ` } if enabled >= 0 { sql += fmt.Sprint(` AND enabled=`, enabled, ` `) } sql += ` ORDER BY created_time asc ` _, err = o.Raw(sql, groupId).QueryRows(&items) return } // GetDepartmentGroupSysUserList 根据部门id和分组id获取系统用户列表 func GetDepartmentGroupSysUserList(departmentId, groupId int, roleTypeCodes string) (items []*Admin, err error) { o := orm.NewOrm() sql := `SELECT * FROM admin WHERE department_id = ? and group_id=? and enabled=1 ` if roleTypeCodes != "" { sql += ` and role_type_code in (` + roleTypeCodes + `) ` } sql += ` ORDER BY created_time asc ` _, err = o.Raw(sql, departmentId, groupId).QueryRows(&items) return } // GetGroupSysUserList 根据分组id获取系统用户列表 func GetGroupSysUserList(groupId int) (items []*Admin, err error) { o := orm.NewOrm() sql := `SELECT * FROM admin WHERE group_id=? ORDER BY created_time DESC ` _, err = o.Raw(sql, groupId).QueryRows(&items) return } type DifferentAdmin struct { AdminId int `description:"系统用户id"` RealName string `description:"用户真实名称"` Mobile string `description:"用户手机号"` CrmAdminId int `description:"crm系统用户id"` CrmRealName string `description:"crm用户真实名称"` CrmMobile string `description:"crm用户手机号"` } // GetDifferentAdmin 获取系统用户和crm系统用户不同的用户 func GetDifferentAdmin() (items []*DifferentAdmin, err error) { sql := `SELECT a.admin_id, a.real_name, a.mobile, c.admin_id as crm_admin_id, c.real_name as crm_real_name, c.mobile as crm_mobile FROM admin as a LEFT JOIN admin_crm c on a.admin_name= c.admin_name WHERE a.admin_id != c.admin_id ` o := orm.NewOrm() _, err = o.Raw(sql).QueryRows(&items) return } // 初始化,把原先crm中的adminId改成社区里的adminId func SetDifferentAdmin(adminId int, adminRealName string, crmAdminId int, crmAdminRealName string, now time.Time, beforeTime string) (err error) { // 事务更新 fmt.Println("开始替换 adminId:", adminId, "adminRealName:", adminRealName, "crmAdminId:", crmAdminId, "crmAdminRealName:", crmAdminRealName, "now:", now, "beforeTime:", beforeTime) o := orm.NewOrm() to, err := o.Begin() if err != nil { return } defer func() { if err != nil { _ = to.Rollback() } else { _ = to.Commit() } }() sql := "UPDATE eta_business SET seller_id = ?, seller_name=?, modify_time=? WHERE seller_id = ? and seller_name = ? and create_time