package models import ( "fmt" "github.com/beego/beego/v2/client/orm" "hongze/hongze_web_mfyx/utils" "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:"申请提交时,公司名称"` CountryCode string `description:"区号"` OutboundMobile string `description:"外呼手机号"` OutboundCountryCode string `description:"外呼手机号区号"` } func GetUserDetailByUserId(userId int) (item *UserDetail, err error) { o := orm.NewOrmUsingDB("weekly_report") sql := `SELECT * FROM wx_user WHERE user_id = ? ` err = o.Raw(sql, userId).QueryRow(&item) return } func GetUserDetailByMobile(mobile string) (item *UserDetail, err error) { o := orm.NewOrmUsingDB("weekly_report") sql := `SELECT * FROM wx_user WHERE mobile = ? ` err = o.Raw(sql, mobile).QueryRow(&item) return } type UserPermission struct { CompanyName string `description:"公司名称"` ChartPermissionName string `description:"权限"` } type LoginReq struct { Mobile string `description:"手机号"` VCode string `description:"验证码"` Token string `description:"微信扫码登录之后返回的Token"` InviteShareCode string `description:"销售账号邀请码"` Password string `comment:"密码"` LoginType string `comment:"登录方式 2 密码登录,其他不用传"` } type WxBindMobileReq struct { Mobile string `description:"手机号"` VCode string `description:"验证码"` //Token string `description:"Token"` } 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.NewOrmUsingDB("weekly_report") 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:"客户名称"` LoginErrCode int `description:"错误状态自定义,1:是专栏作者,但是还没设置登录密码"` } type UserDetailResp struct { UserId int `description:"用户id"` UserName string `description:"用户名称"` Headimgurl string `description:"用户头像"` Mobile string `description:"手机号"` Email string `description:"邮箱"` CompanyName string `description:"客户名称"` OutboundMobile string `description:"外呼手机号"` OutboundCountryCode string `description:"外呼手机号区号"` PermissionName []string `description:"拥有权限分类"` PermissionStatus string `description:"状态"` StartDate string `description:"开始日期"` EndDate string `description:"结束日期"` CompanyPointsNum float64 `description:"公司剩余点数"` HasPermission int `description:"1:有该行业权限,正常展示"` IsAuthor bool `description:"是否开通了研选专栏"` SpecialColumnId int // 专栏栏目ID IsImproveInformation bool `description:"作者信息是否完善"` InviteShareCode string `description:"销售账号邀请码"` UserCardType int `description:"权益卡类型,0:未开通、1日卡、2月卡"` UserCardEndDate string `description:"权益卡有效期"` IsShowWxPaySet bool `description:"是否展示微信支付全局设置"` // 配合前端支付进入详情页使用 IsSetPassword bool `description:"是否设置了登录密码"` } type CheckStatusResp struct { IsBind bool `description:"true:需要绑定手机号或邮箱,false:不需要绑定手机号或邮箱"` IsAuth bool `description:"true:需要授权,false:不需要授权"` PermissionName string `description:"拥有权限分类,多个用英文逗号分隔"` } type ApplyTryReq struct { BusinessCardUrl string `description:"名片地址"` RealName string `description:"姓名"` CompanyName string `description:"公司名称"` ApplyMethod int `description:"1:已付费客户申请试用,2:非客户申请试用,3:非客户申请试用(ficc下,不需要进行数据校验)"` TryType string `description:"提交类型,Article:文章、Activity:活动、MicroAudio:微路演音频、MicroVideo:微路演视频、Researchsummary:本周研究汇总、Minutessummary:上周纪要汇总、ReportSelection:报告精选、ProductInterior:产品内测"` DetailId int `description:"详情ID"` } type CountryCode struct { IsNeedAddCountryCode bool `description:"是否需要填写区号:需要填写,false:不需要填写"` } type OutboundMobile struct { IsNeedAddOutboundMobile bool `description:"是否需要填写外呼手机号:需要填写,false:不需要填写"` } type CountryCodeItem struct { CountryCode string `description:"区号"` } // 修改外呼手机号 type OutboundMobileItem struct { OutboundMobile string `description:"外呼手机号"` OutboundCountryCode string `description:"外呼手机号区号"` } type UserWhiteList struct { Mobile string `description:"手机号码"` RealName string `description:"用户实际名称"` CompanyName string `description:"公司名称"` Permission string `description:"拥有权限分类,多个用英文逗号分隔"` CountryCode string `description:"区号"` SellerName string `description:"销售姓名"` CreatedTime time.Time Status string `description:"客户状态'试用','永续','冻结','流失','正式','潜在'"` } type UserWhiteListRep struct { List []*UserWhiteList } type UserDetailByUserLogin struct { Headimgurl string `description:"头像"` Mobile string `description:"手机号码"` RealName string `description:"用户实际名称"` CompanyName string `description:"公司名称"` Permission string `description:"拥有权限分类,多个用英文逗号分隔"` HasPermission int `description:"1:有该行业权限,正常展示,2:无权限,非潜在客户,3:潜在客户"` Token string `description:"Token"` } func GetCompanyPermission(companyId int) (permission string, err error) { sql := ` SELECT GROUP_CONCAT(DISTINCT b.remark ORDER BY b.sort ASC SEPARATOR ',') AS permission FROM company_report_permission AS a INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id WHERE a.company_id=? AND c.is_suspend=0 AND b.cygx_auth=1 AND c.status IN('正式','试用','永续') AND a.status IN('正式','试用','永续') ` o := orm.NewOrmUsingDB("weekly_report") err = o.Raw(sql, companyId).QueryRow(&permission) return } func GetCompanyPermissionName(companyId int) (permission string, err error) { sql := ` SELECT GROUP_CONCAT(DISTINCT b.chart_permission_name ORDER BY b.sort ASC SEPARATOR ',') AS permission FROM company_report_permission AS a INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id WHERE a.company_id=? AND c.is_suspend=0 AND b.cygx_auth=1 AND c.status IN('正式','试用','永续') AND a.status IN('正式','试用','永续') ` o := orm.NewOrmUsingDB("weekly_report") err = o.Raw(sql, companyId).QueryRow(&permission) return } func GetCompanyPermissionId(companyId int) (permissionId string, err error) { sql := ` SELECT GROUP_CONCAT(DISTINCT b.chart_permission_id ORDER BY b.sort ASC SEPARATOR ',') AS permissionId FROM company_report_permission AS a INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id WHERE a.company_id=? AND c.is_suspend=0 AND b.cygx_auth=1 AND c.status IN('正式','试用','永续') AND a.status IN('正式','试用','永续') ` o := orm.NewOrmUsingDB("weekly_report") err = o.Raw(sql, companyId).QueryRow(&permissionId) return } // 用户绑定手机号时同时绑定外呼手机号 func BindUserOutboundMobile(mobile, countryCode string, userId int) (err error) { o := orm.NewOrmUsingDB("weekly_report") sql := `UPDATE wx_user SET outbound_mobile=? ,outbound_country_code = ?, country_code= ? WHERE user_id=? ` _, err = o.Raw(sql, mobile, countryCode, countryCode, userId).Exec() return } type UserPermissionAuthInfo struct { HasPermission int `description:"是否有权限:1-有权限; 2-无权限; 3-潜在客户未提交申请; 4-潜在客户已提交申请 5-仅有FICC权限"` SellerMobile string `description:"销售手机号"` SellerName string `description:"销售名称"` OperationMode string `description:"操作方式:Apply-立即申请; Call-拨号"` PopupMsg string `description:"权限弹窗信息"` } // 修改用户是否绑定外呼手机号弹窗 func ModifyWxUserIsMsgOutboundMobile(userId int) (err error) { o := orm.NewOrmUsingDB("weekly_report") sql := `UPDATE wx_user SET is_msg_outbound_mobile=1 WHERE user_id=? ` _, err = o.Raw(sql, userId).Exec() return } // 已经绑定手机号,没有绑定外呼手机号的的用户,预约外呼的时候,将外呼手机号同步成手机号 func BindUserOutboundMobileByMobile(mobile, countryCode string, userId int) (err error) { o := orm.NewOrmUsingDB("weekly_report") sql := `UPDATE wx_user SET outbound_mobile=? ,outbound_country_code = ? WHERE user_id=? ` _, err = o.Raw(sql, mobile, countryCode, userId).Exec() return } // GetWxUserByMobiles 根据用户手机号获取用户详情 func GetWxUserByMobiles(mobiles []string) (items []*WxUser, err error) { lenmobiles := len(mobiles) if lenmobiles == 0 { return } sql := `SELECT* FROM wx_user WHERE mobile in (` + utils.GetOrmInReplace(lenmobiles) + `) ` o := orm.NewOrmUsingDB("weekly_report") _, err = o.Raw(sql, mobiles).QueryRows(&items) return } func GetUserCompanyPermissionSand(companyId int) (items []*ChartPermissionResp, err error) { sql := ` SELECT b.* FROM company_report_permission AS a INNER JOIN chart_permission AS b ON a.chart_permission_id=b.chart_permission_id INNER JOIN company_product AS c ON a.company_id=c.company_id AND a.product_id=c.product_id WHERE a.company_id=? AND a.product_id=2 AND c.is_suspend=0 AND b.cygx_auth=1 AND b.is_other=0 AND c.status IN('正式','试用','永续') AND a.status IN('正式','试用','永续') AND b.chart_permission_name != '专家' GROUP BY b.chart_permission_name ORDER BY b.sort ASC ` o := orm.NewOrmUsingDB("weekly_report") _, err = o.Raw(sql, companyId).QueryRows(&items) return } func AddOutboundMobile(item *OutboundMobileItem, userId int) (err error) { o, err := orm.NewOrmUsingDB("weekly_report").Begin() if err != nil { return } defer func() { fmt.Println(err) if err == nil { o.Commit() } else { o.Rollback() } }() sql := `UPDATE wx_user SET outbound_mobile=? ,outbound_country_code = ?, is_msg_outbound_mobile= 1 WHERE user_id=? ` _, err = o.Raw(sql, item.OutboundMobile, item.OutboundCountryCode, userId).Exec() if err != nil { return } //if item.ActivityId > 0 { // sql = `UPDATE cygx_activity_signup SET outbound_mobile=? ,country_code = ? WHERE user_id=? AND activity_id = ?` // _, err = o.Raw(sql, item.OutboundMobile, item.OutboundCountryCode, userId, item.ActivityId).Exec() //} return } type Headimgurl struct { Headimgurl string `description:"用户头像"` } // 更改用户头像 func UpdateUserHeadimgurl(headimgurl string, userId int) (err error) { o := orm.NewOrmUsingDB("weekly_report") sql := `UPDATE wx_user SET headimgurl = ? WHERE user_id=? ` _, err = o.Raw(sql, headimgurl, userId).Exec() return } // 更改用户邮箱号 func UpdateUserEmail(email string, userId int) (err error) { o := orm.NewOrmUsingDB("weekly_report") sql := `UPDATE wx_user SET email = ? WHERE user_id=? ` _, err = o.Raw(sql, email, userId).Exec() return } func GetArticleUserCollectCount(userId int) (count int, err error) { sql := `SELECT SUM(count) AS count FROM ( SELECT COUNT(1) AS count FROM cygx_article_collect AS a INNER JOIN cygx_article as art ON art.article_id = a.article_id WHERE a.user_id=? AND art.publish_status = 1 AND art.article_type_id > 0 UNION ALL SELECT COUNT(1) AS count FROM cygx_yanxuan_special_collect AS a INNER JOIN cygx_yanxuan_special as b ON b.id = a.yanxuan_special_id WHERE a.user_id=? AND b.status = 3) AS c ` err = orm.NewOrm().Raw(sql, userId, userId).QueryRow(&count) return } //art.article_id, //art.article_type_id, //art.title, //art.publish_date, //'' AS company_tags, //'' AS industry_tags, //art.department_id, //d.nick_name, //0 AS is_special, //0 as pv, //0 as collect_num, //a.create_time //FROM //cygx_article AS art //INNER JOIN cygx_article_history_record_newpv AS a ON art.article_id = a.article_id //INNER JOIN cygx_article_department AS d ON d.department_id = art.department_id //WHERE //a.user_id = ? //AND a.create_time >= ? //AND art.article_type_id > 0 //GROUP BY //art.article_id UNION ALL //SELECT //art.id AS article_id, //- 1 AS article_type_id, //art.title, //art.publish_time AS publish_date, //art.company_tags AS company_tags, //art.industry_tags AS industry_tags, //d.id AS department_id, //d.nick_name, //1 AS is_special, //art.pv, //art.article_collect_num as collect_num, //a.create_time func GetArticleUserCollectList(startSize, pageSize, userId int) (items []*ArticleListResp, err error) { sql := `SELECT art.article_id, art.article_type_id, art.title, art.publish_date, '' AS company_tags, '' AS industry_tags, art.department_id, d.nick_name, 0 AS is_special, 0 as pv, 0 as collect_num, a.create_time FROM cygx_article AS art INNER JOIN cygx_article_collect as a ON art.article_id = a.article_id INNER JOIN cygx_article_department AS d ON d.department_id = art.department_id WHERE a.user_id=? AND art.article_type_id > 0 UNION ALL SELECT art.id AS article_id, - 1 AS article_type_id, art.title, art.publish_time AS publish_date, art.company_tags AS company_tags, art.industry_tags AS industry_tags, b.id AS department_id, b.nick_name, 1 AS is_special, art.pv, art.article_collect_num as collect_num, c.create_time FROM cygx_yanxuan_special AS art JOIN cygx_yanxuan_special_author AS b ON art.user_id = b.user_id JOIN cygx_yanxuan_special_collect AS c ON art.id = c.yanxuan_special_id WHERE 1 = 1 AND art.status = 3 AND c.user_id=? ORDER BY create_time DESC LIMIT ?,? ` _, err = orm.NewOrm().Raw(sql, userId, userId, startSize, pageSize).QueryRows(&items) return } func GetArticleUserBrowseHistoryCount(userId int, endDate string) (count int, err error) { sql := `SELECT COUNT( 1 ) as count FROM ( SELECT count(*) FROM cygx_article as art INNER JOIN cygx_article_history_record_newpv AS a ON art.article_id = a.article_id AND article_type_id > 0 WHERE a.user_id = ? AND a.create_time >= ? GROUP BY a.article_id ) b ` err = orm.NewOrm().Raw(sql, userId, endDate).QueryRow(&count) return } //func GetArticleUserBrowseHistoryList(startSize, pageSize, userId int, endDate string) (items []*ArticleReportBillboardResp, err error) { // sql := `SELECT a.* , MAX( a.id ) AS mid FROM cygx_article as art INNER JOIN cygx_article_history_record_newpv AS a ON art.article_id = a.article_id AND article_type_id > 0 // WHERE a.user_id=? AND a.create_time>=? GROUP BY a.article_id // ORDER BY mid DESC LIMIT ?,? ` // _, err = orm.NewOrm().Raw(sql, userId, endDate, startSize, pageSize).QueryRows(&items) // return //} func GetArticleUserBrowseHistoryList(startSize, pageSize, userId int, endDate string) (items []*ArticleListResp, err error) { sql := `SELECT art.article_id, art.article_type_id, art.title, art.publish_date, '' AS company_tags, '' AS industry_tags, art.department_id, d.nick_name, 0 AS is_special, 0 as pv, 0 as collect_num, a.create_time FROM cygx_article AS art INNER JOIN cygx_article_history_record_newpv AS a ON art.article_id = a.article_id INNER JOIN cygx_article_department AS d ON d.department_id = art.department_id WHERE a.user_id = ? AND a.create_time >= ? AND art.article_type_id > 0 GROUP BY art.article_id UNION ALL SELECT art.id AS article_id, - 1 AS article_type_id, art.title, art.publish_time AS publish_date, art.company_tags AS company_tags, art.industry_tags AS industry_tags, d.id AS department_id, d.nick_name, 1 AS is_special, art.pv, art.article_collect_num as collect_num, a.create_time FROM cygx_yanxuan_special AS art INNER JOIN cygx_yanxuan_special_record AS a ON art.id = a.yanxuan_special_id INNER JOIN cygx_yanxuan_special_author AS d ON d.user_id = art.user_id WHERE a.user_id = ? AND a.create_time >= ? GROUP BY art.id ORDER BY create_time DESC LIMIT ?,? ` _, err = orm.NewOrm().Raw(sql, userId, endDate, userId, endDate, startSize, pageSize).QueryRows(&items) return } func GetUserMicroRoadshowCollectList(userId int) (items []*CygxArticleCollect, err error) { sql := `SELECT a.* FROM cygx_article_collect AS a WHERE a.user_id=? AND a.article_id =0 ORDER BY a.create_time DESC ` _, err = orm.NewOrm().Raw(sql, userId).QueryRows(&items) return } type UserEmail struct { Email string `description:"邮箱号"` }