package models import ( "hongze/hongze_cygx/utils" "rdluck_tools/orm" "rdluck_tools/paging" "time" ) type UserDetail struct { Headimgurl string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"` Mobile string `description:"手机号码"` Email string `description:"邮箱"` NickName string `description:"用户昵称"` RealName string `description:"用户实际名称"` CompanyName string `description:"公司名称"` PermissionName string `description:"拥有权限分类,多个用英文逗号分隔"` HasPermission int `description:"1:无该行业权限,不存在权益客户下,2:潜在客户,未提交过申请,3:潜在客户,已提交过申请"` SellerMobile string `description:"销售手机号"` SellerName string `description:"销售名称"` Note string `json:"-" description:"申请提交时,公司名称"` } func GetUserDetailByUserId(userId int) (item *UserDetail, err error) { o := orm.NewOrm() sql := `SELECT * FROM wx_user WHERE user_id = ? ` err = o.Raw(sql, userId).QueryRow(&item) return } type UserPermission struct { CompanyName string `description:"公司名称"` ChartPermissionName string `description:"权限"` } type LoginReq struct { LoginType int `description:"登录方式:1:微信手机,2:邮箱,3:自定义手机登录"` Mobile string `description:"手机号"` Email string `description:"邮箱"` VCode string `description:"验证码"` } func PcBindMobile(unionId, mobile string, userId, loginType int) (wxUserId int, err error) { //loginType 登录方式:1:手机,2:邮箱 sql := `` if loginType == 1 { sql = `SELECT * FROM wx_user WHERE mobile = ? ` } else { sql = "SELECT * FROM wx_user WHERE email = ? " } user := new(WxUser) o := orm.NewOrm() err = o.Raw(sql, mobile).QueryRow(&user) if err != nil && err.Error() != utils.ErrNoRow() { return } if user == nil || (err != nil && err.Error() == utils.ErrNoRow()) { msql := `` if loginType == 1 { msql = "UPDATE wx_user SET mobile = ?,bind_account = ? WHERE union_id = ? " } else { msql = "UPDATE wx_user SET email = ?,bind_account = ? WHERE union_id = ? " } _, err = o.Raw(msql, mobile, mobile, unionId).Exec() wxUserId = userId } else { if user.UnionId == "" { sql = `SELECT * FROM wx_user WHERE union_id = ? ` userInfo := new(WxUser) o := orm.NewOrm() err = o.Raw(sql, unionId).QueryRow(&userInfo) if err != nil { return } var maxRegisterTime time.Time if user.RegisterTime.Before(userInfo.RegisterTime) { maxRegisterTime = user.RegisterTime } else { maxRegisterTime = userInfo.RegisterTime } wxUserId = user.UserId dsql := ` DELETE FROM wx_user WHERE union_id = ? ` _, err = o.Raw(dsql, unionId).Exec() if err != nil { return wxUserId, err } msql := ` UPDATE wx_user SET union_id=?,register_time=?,province=?,city=?,country=?,headimgurl=?,unionid=?,sex=? WHERE user_id = ? ` _, err = o.Raw(msql, unionId, maxRegisterTime, userInfo.Province, userInfo.City, userInfo.Country, userInfo.Headimgurl, unionId, userInfo.Sex, user.UserId).Exec() wxUserId = user.UserId } else { sql = `SELECT * FROM wx_user WHERE user_id = ? ` userInfo := new(WxUser) o := orm.NewOrm() err = o.Raw(sql, userId).QueryRow(&userInfo) if err != nil && err.Error() != utils.ErrNoRow() { return } if user.UserId != userId { dsql := ` DELETE FROM wx_user WHERE user_id = ? ` _, err = o.Raw(dsql, userId).Exec() if err != nil { return user.UserId, err } } msql := ` UPDATE wx_user SET union_id=?,province=?,city=?,country=?,headimgurl=?,unionid=?,sex=? WHERE user_id = ? ` _, err = o.Raw(msql, unionId, userInfo.Province, userInfo.City, userInfo.Country, userInfo.Headimgurl, unionId, userInfo.Sex, user.UserId).Exec() wxUserId = userId } } return } type LoginResp struct { UserId int `description:"用户id"` Authorization string `description:"Token"` Headimgurl string `description:"用户头像"` Mobile string `description:"手机号"` Email string `description:"邮箱"` CompanyName string `description:"客户名称"` Status string `description:"状态"` EndDate string `description:"到期日期"` ProductName string `description:"客户类型名称"` } type CheckStatusResp struct { IsBind bool `description:"true:需要绑定手机号或邮箱,false:不需要绑定手机号或邮箱"` IsAuth bool `description:"true:需要授权,false:不需要授权"` PermissionName string `description:"拥有权限分类,多个用英文逗号分隔"` } func GetArticleUserCollectCount(userId int) (count int, err error) { sql := `SELECT COUNT(1) AS count FROM cygx_article_collect AS a WHERE a.user_id=? ` err = orm.NewOrm().Raw(sql, userId).QueryRow(&count) return } func GetArticleUserCollectList(startSize, pageSize, userId int) (items []*ArticleCollectList, err error) { sql := `SELECT a.* FROM cygx_article_collect AS a WHERE a.user_id=? ORDER BY a.create_time DESC LIMIT ?,? ` _, err = orm.NewOrm().Raw(sql, userId, startSize, pageSize).QueryRows(&items) return } type ArticleCollectListResp struct { List []*ArticleCollectList Paging *paging.PagingItem } func GetArticleUserInterviewApplyCount(userId int) (count int, err error) { sql := `SELECT COUNT(1) AS count FROM cygx_interview_apply AS a WHERE a.user_id=? ` err = orm.NewOrm().Raw(sql, userId).QueryRow(&count) return } func GetArticleUserInterviewApplyList(startSize, pageSize, userId int) (items []*ArticleInterviewApplyList, err error) { sql := `SELECT a.* FROM cygx_interview_apply AS a WHERE a.user_id=? ORDER BY a.status ASC LIMIT ?,? ` _, err = orm.NewOrm().Raw(sql, userId, startSize, pageSize).QueryRows(&items) return } type ArticleInterviewApplyListResp struct { List []*ArticleInterviewApplyList Paging *paging.PagingItem } func GetArticleUserBrowseHistoryCount(userId int, endDate string) (count int, err error) { sql := `SELECT COUNT(1) AS count FROM cygx_article_history_record AS a WHERE a.user_id=? AND a.create_time>=? ` err = orm.NewOrm().Raw(sql, userId, endDate).QueryRow(&count) return } func GetArticleUserBrowseHistoryList(startSize, pageSize, userId int, endDate string) (items []*ArticleInterviewApplyList, err error) { sql := `SELECT a.* FROM cygx_article_history_record AS a WHERE a.user_id=? AND a.create_time>=? GROUP BY a.article_id ORDER BY a.id DESC LIMIT ?,? ` _, err = orm.NewOrm().Raw(sql, userId, endDate, startSize, pageSize).QueryRows(&items) return } type ArticleBrowseHistoryListResp struct { List []*ArticleInterviewApplyList Paging *paging.PagingItem } type ApplyTryReq struct { BusinessCardUrl string `description:"名片地址"` RealName string `description:"姓名"` CompanyName string `description:"公司名称"` ApplyMethod int `description:"1:已付费客户申请试用,2:非客户申请试用,3:非客户申请试用(ficc下,不需要进行数据校验)"` }