123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- package models
- import (
- "time"
- "github.com/beego/beego/v2/client/orm"
- )
- type User struct {
- UserId int `orm:"pk" description:"用户id"`
- OpenId string `description:"openid"`
- UnionId string `description:"unionid"`
- NickName string `description:"用户昵称"`
- RealName string `description:"姓名"`
- Phone string `description:"手机号"`
- AreaCode string `description:"区号"`
- Email string `description:"邮箱"`
- SellerId int `description:"销售id(SysUserId)"`
- SellerDepartmentId int `description:"营业部门id"`
- SellerDepartmentName string `description:"营业部门名称"`
- Company string `description:"所属公司"`
- ValidStartTime time.Time `description:"有效期开始时间"`
- ValidEndTime time.Time `description:"有效期结束时间"`
- Status int `description:"用户类型: 0表示禁用,1表示潜在客户,2表示正式客户"`
- ApplyStatus int `description:"申请状态: 0表示未申请,1表示已申请"`
- CreateTime time.Time `description:"系统中首次新增用户的时间"`
- ModifyTime time.Time `description:"系统中用户信息变更的时间"`
- RegisterTime time.Time `description:"用户首次登录小程序的时间"`
- ApplyTime time.Time `description:"用户提交申请的时间"`
- IsSubscribed bool `description:"是否关注公众号: 0表示没有关注,1表示关注"`
- IsRegistered bool `description:"是否注册: 0表示没有注册,1表示注册"`
- AccessToken string `description:"用户token"`
- Headimgurl string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
- }
- func (u *User) Insert() (insertId int64, err error) {
- o := orm.NewOrm()
- insertId, err = o.Insert(u)
- return
- }
- func (u *User) Update(cols []string) (err error) {
- o := orm.NewOrm()
- _, err = o.Update(u, cols...)
- return
- }
- type UserView struct {
- Headimgurl string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
- RealName string `description:"用户实际名称"`
- Phone string `description:"手机号码"`
- AreaCode string `description:"区号"`
- SellerDepartmentName string `description:"营业部名称"`
- SellerDepartmentPhone []string `description:"营业部电话"`
- Email string `description:"邮箱"`
- Componey string `description:"所属公司"`
- HasPermission string `description:"拥有权限"`
- ValidEndTime string `description:"服务截至时间"`
- IsRegistered bool `description:"是否注册:1:已注册,0:未注册"`
- Status int `description:"用户类型: 0表示禁用,1表示潜在客户,2表示正式客户"`
- ApplyStatus int `description:"申请状态: 0表示未申请,1表示已申请"`
- }
- func GetUserByToken(token string) (item *User, err error) {
- sql := `SELECT * FROM user WHERE access_token=? `
- o := orm.NewOrm()
- err = o.Raw(sql, token).QueryRow(&item)
- return
- }
- // 根据openid获取用户关系
- func GetUserByOpenId(openId string) (item *User, err error) {
- sql := `SELECT * FROM user WHERE open_id=? `
- o := orm.NewOrm()
- err = o.Raw(sql, openId).QueryRow(&item)
- return
- }
- // 根据unionid获取用户关系
- func GetUserByUnionId(unionId string) (item *User, err error) {
- sql := `SELECT * FROM user WHERE union_id=? `
- o := orm.NewOrm()
- err = o.Raw(sql, unionId).QueryRow(&item)
- return
- }
- // 变更联系人是否已注册状态
- func ModifyUserRegisterStatus(userId int, status bool, registerTime, modifyTime time.Time) (err error) {
- o := orm.NewOrm()
- sql := `UPDATE user SET is_registered=?, register_time=?, modify_time=? WHERE user_id = ? `
- _, err = o.Raw(sql, status, registerTime, modifyTime, userId).Exec()
- return
- }
- func GetUserById(userId int) (item *User, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM user WHERE user_id=? `
- err = o.Raw(sql, userId).QueryRow(&item)
- return
- }
- func GetUserList(condition string, pars []interface{}) (items []*User, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM user WHERE 1=1 `
- if condition != "" {
- sql += condition
- }
- _, err = o.Raw(sql, pars...).QueryRows(&items)
- return
- }
- func GetUserByPhone(phone string) (item *User, err error) {
- o := orm.NewOrm()
- sql := `SELECT * FROM user WHERE phone=? `
- err = o.Raw(sql, phone).QueryRow(&item)
- return
- }
- func GetUserByEmail(email string) (item *User, err error) {
- sql := `SELECT * FROM user WHERE email=? `
- err = orm.NewOrm().Raw(sql, email).QueryRow(&item)
- return
- }
|