package models import ( "eta/eta_forum_admin/utils" "github.com/beego/beego/v2/client/orm" "github.com/rdlucklib/rdluck_tools/paging" "time" ) type User struct { UserId int `orm:"column(user_id);pk"` BusinessCode string EtaBusinessId int UserName string `description:"用户名"` RealName string `description:"姓名"` Mobile string Email string NickName string `description:"昵称"` CountryCode string `description:"区号,86、852、886等"` LastLoginTime time.Time IsFreeLogin int `description:"是否30天免登录,0否,1是"` RegisterTime time.Time LastCollectChartTime string `description:"最近收藏图表时间"` Enabled int DepartmentName string `description:"部门名称"` Position string `description:"岗位"` PositionStatus int `description:"在职状态:1:在职,0:离职"` CreatedTime time.Time LastUpdatedTime time.Time `description:"最近一次更新时间"` } // 用户详情出参 type UserResp struct { Detail *User } func AddUser(item *User) (lastId int64, err error) { o := orm.NewOrm() lastId, err = o.Insert(item) return } func GetUserByMobile(mobile string) (item *User, err error) { o := orm.NewOrm() sql := `SELECT * FROM user WHERE mobile = ? LIMIT 1` err = o.Raw(sql, mobile).QueryRow(&item) return } func GetUserByMobiles(mobiles []string) (items []*User, err error) { o := orm.NewOrm() sql := `SELECT * FROM user WHERE mobile in (` + utils.GetOrmInReplace(len(mobiles)) + `)` _, err = o.Raw(sql, mobiles).QueryRows(&items) return } // GetUserByMobileCountryCode 根据手机号和区号获取用户信息 func GetUserByMobileCountryCode(mobile, countryCode string) (item *User, err error) { o := orm.NewOrm() sql := `SELECT * FROM user WHERE mobile = ? ` sql += ` and country_code =? ` sql += ` LIMIT 1 ` err = o.Raw(sql, mobile, countryCode).QueryRow(&item) return } func GetUserByUserId(userId int) (item *User, err error) { o := orm.NewOrm() sql := `SELECT * FROM user WHERE user_id=? ` err = o.Raw(sql, userId).QueryRow(&item) return } // 更新User信息 func (User *User) Update(cols []string) (err error) { o := orm.NewOrm() _, err = o.Update(User, cols...) return } // 获取该用户数量 func GetUserCountByCondition(condition string, pars []interface{}) (count int, err error) { o := orm.NewOrm() tmpSql := `SELECT * FROM user WHERE 1=1 ` if condition != "" { tmpSql += condition } sql := `SELECT COUNT(1) AS count FROM (` + tmpSql + `) AS c ` err = o.Raw(sql, pars).QueryRow(&count) return } // 获取该用户列表 func GetUserPageListByCondition(condition string, pars []interface{}, order string, startSize, pageSize int) (items []*User, err error) { o := orm.NewOrm() tmpSql := `SELECT * FROM user WHERE 1=1 ` if condition != "" { tmpSql += condition } if order != "" { tmpSql += ` ORDER BY ` + order + ", user_id DESC" } else { tmpSql += ` ORDER BY user_id DESC` } tmpSql += ` Limit ?,?` _, err = o.Raw(tmpSql, pars, startSize, pageSize).QueryRows(&items) return } type BusinessUser struct { UserId int BusinessCode string EtaBusinessId int BusinessName string RealName string `description:"姓名"` Mobile string Email string CountryCode string `description:"区号,86、852、886等"` LastLoginTime string Enabled int DepartmentName string `description:"部门名称"` Position string `description:"岗位"` PositionStatus int `description:"在职状态:1:在职,0:离职"` CreatedTime string LastUpdatedTime string `description:"最近一次更新时间"` } type UserListResp struct { Paging *paging.PagingItem List []*BusinessUser } // 新增用户请求参数 type AddUserReq struct { RealName string `description:"姓名"` CountryCode string `description:"区号,86、852、886等"` Mobile string `description:"手机号"` //Email string `description:"邮箱"` Position string `description:"职位"` PositionStatus int `description:"在职状态:1:在职,0:离职"` EtaBusinessId int DepartmentName string `description:"联系人部门"` } // 删除客户请求参数 type DeleteUserReq struct { UserId int } // 新增客户请求参数 type EditUserReq struct { UserId int RealName string `description:"姓名"` CountryCode string `description:"区号,86、852、886等"` Mobile string `description:"手机号"` //Email string `description:"邮箱"` Position string `description:"职位"` PositionStatus int `description:"在职状态:1:在职,0:离职"` EtaBusinessId int DepartmentName string `description:"联系人部门"` } func DeleteUser(userId int) (err error) { o := orm.NewOrm() sql := ` DELETE FROM user WHERE user_id=? ` _, err = o.Raw(sql, userId).Exec() return } // 联系人导入预览数据返回 type ImportListResp struct { ValidUser []*User `description:"有效客户数据"` RepeatUser []*User `description:"重复客户数据"` } // 联系人导入预览数据返回 type ImportUserReq struct { ValidUser []*ImportUserItem `description:"有效客户数据"` } type ImportUserItem struct { BusinessCode string EtaBusinessId int UserName string `description:"用户名"` RealName string `description:"姓名"` Mobile string NickName string `description:"昵称"` CountryCode string `description:"区号,86、852、886等"` DepartmentName string `description:"部门名称"` Position string `description:"岗位"` PositionStatus int `description:"在职状态:1:在职,0:离职"` } // 新增客户请求参数 type ChangeUserBusinessReq struct { UserId int EtaBusinessId int //BusinessCode string `description:"商家编码"` } // UserEditEnabledReq 用户状态编辑 type UserEditEnabledReq struct { UserId int `description:"系统用户id"` Enabled int `description:"1:有效,0:禁用"` }