user.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. package models
  2. import (
  3. "hongze/hongze_cygx/utils"
  4. "rdluck_tools/orm"
  5. "rdluck_tools/paging"
  6. "time"
  7. )
  8. type UserDetail struct {
  9. Headimgurl string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
  10. Mobile string `description:"手机号码"`
  11. Email string `description:"邮箱"`
  12. NickName string `description:"用户昵称"`
  13. RealName string `description:"用户实际名称"`
  14. CompanyName string `description:"公司名称"`
  15. PermissionName string `description:"拥有权限分类,多个用英文逗号分隔"`
  16. HasPermission int `description:"1:无该行业权限,不存在权益客户下,2:潜在客户,未提交过申请,3:潜在客户,已提交过申请"`
  17. SellerMobile string `description:"销售手机号"`
  18. SellerName string `description:"销售名称"`
  19. Note string `json:"-" description:"申请提交时,公司名称"`
  20. }
  21. func GetUserDetailByUserId(userId int) (item *UserDetail, err error) {
  22. o := orm.NewOrm()
  23. sql := `SELECT * FROM wx_user WHERE user_id = ? `
  24. err = o.Raw(sql, userId).QueryRow(&item)
  25. return
  26. }
  27. type UserPermission struct {
  28. CompanyName string `description:"公司名称"`
  29. ChartPermissionName string `description:"权限"`
  30. }
  31. type LoginReq struct {
  32. LoginType int `description:"登录方式:1:微信手机,2:邮箱,3:自定义手机登录"`
  33. Mobile string `description:"手机号"`
  34. Email string `description:"邮箱"`
  35. VCode string `description:"验证码"`
  36. CountryCode string `description:"区号"`
  37. }
  38. func PcBindMobile(unionId, mobile string, userId, loginType int) (wxUserId int, err error) {
  39. //loginType 登录方式:1:手机,2:邮箱
  40. sql := ``
  41. if loginType == 1 {
  42. sql = `SELECT * FROM wx_user WHERE mobile = ? `
  43. } else {
  44. sql = "SELECT * FROM wx_user WHERE email = ? "
  45. }
  46. user := new(WxUser)
  47. o := orm.NewOrm()
  48. err = o.Raw(sql, mobile).QueryRow(&user)
  49. if err != nil && err.Error() != utils.ErrNoRow() {
  50. return
  51. }
  52. if user == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  53. msql := ``
  54. if loginType == 1 {
  55. msql = "UPDATE wx_user SET mobile = ?,bind_account = ? WHERE union_id = ? "
  56. } else {
  57. msql = "UPDATE wx_user SET email = ?,bind_account = ? WHERE union_id = ? "
  58. }
  59. _, err = o.Raw(msql, mobile, mobile, unionId).Exec()
  60. wxUserId = userId
  61. } else {
  62. if user.UnionId == "" {
  63. sql = `SELECT * FROM wx_user WHERE union_id = ? `
  64. userInfo := new(WxUser)
  65. o := orm.NewOrm()
  66. err = o.Raw(sql, unionId).QueryRow(&userInfo)
  67. if err != nil {
  68. return
  69. }
  70. var maxRegisterTime time.Time
  71. if user.RegisterTime.Before(userInfo.RegisterTime) {
  72. maxRegisterTime = user.RegisterTime
  73. } else {
  74. maxRegisterTime = userInfo.RegisterTime
  75. }
  76. wxUserId = user.UserId
  77. dsql := ` DELETE FROM wx_user WHERE union_id = ? `
  78. _, err = o.Raw(dsql, unionId).Exec()
  79. if err != nil {
  80. return wxUserId, err
  81. }
  82. msql := ` UPDATE wx_user SET union_id=?,register_time=?,province=?,city=?,country=?,headimgurl=?,unionid=?,sex=? WHERE user_id = ? `
  83. _, err = o.Raw(msql, unionId, maxRegisterTime, userInfo.Province, userInfo.City, userInfo.Country, userInfo.Headimgurl, unionId, userInfo.Sex, user.UserId).Exec()
  84. wxUserId = user.UserId
  85. } else {
  86. sql = `SELECT * FROM wx_user WHERE user_id = ? `
  87. userInfo := new(WxUser)
  88. o := orm.NewOrm()
  89. err = o.Raw(sql, userId).QueryRow(&userInfo)
  90. if err != nil && err.Error() != utils.ErrNoRow() {
  91. return
  92. }
  93. if user.UserId != userId {
  94. dsql := ` DELETE FROM wx_user WHERE user_id = ? `
  95. _, err = o.Raw(dsql, userId).Exec()
  96. if err != nil {
  97. return user.UserId, err
  98. }
  99. }
  100. msql := ` UPDATE wx_user SET union_id=?,province=?,city=?,country=?,headimgurl=?,unionid=?,sex=? WHERE user_id = ? `
  101. _, err = o.Raw(msql, unionId, userInfo.Province, userInfo.City, userInfo.Country, userInfo.Headimgurl, unionId, userInfo.Sex, user.UserId).Exec()
  102. wxUserId = userId
  103. }
  104. }
  105. return
  106. }
  107. type LoginResp struct {
  108. UserId int `description:"用户id"`
  109. Authorization string `description:"Token"`
  110. Headimgurl string `description:"用户头像"`
  111. Mobile string `description:"手机号"`
  112. Email string `description:"邮箱"`
  113. CompanyName string `description:"客户名称"`
  114. Status string `description:"状态"`
  115. EndDate string `description:"到期日期"`
  116. ProductName string `description:"客户类型名称"`
  117. }
  118. type CheckStatusResp struct {
  119. IsBind bool `description:"true:需要绑定手机号或邮箱,false:不需要绑定手机号或邮箱"`
  120. IsAuth bool `description:"true:需要授权,false:不需要授权"`
  121. PermissionName string `description:"拥有权限分类,多个用英文逗号分隔"`
  122. }
  123. func GetArticleUserCollectCount(userId int) (count int, err error) {
  124. sql := `SELECT COUNT(1) AS count FROM cygx_article_collect AS a WHERE a.user_id=? `
  125. err = orm.NewOrm().Raw(sql, userId).QueryRow(&count)
  126. return
  127. }
  128. func GetArticleUserCollectList(startSize, pageSize, userId int) (items []*ArticleCollectList, err error) {
  129. sql := `SELECT a.* FROM cygx_article_collect AS a
  130. WHERE a.user_id=?
  131. ORDER BY a.create_time DESC LIMIT ?,? `
  132. _, err = orm.NewOrm().Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  133. return
  134. }
  135. type ArticleCollectListResp struct {
  136. List []*ArticleCollectList
  137. Paging *paging.PagingItem
  138. }
  139. func GetArticleUserInterviewApplyCount(userId int) (count int, err error) {
  140. sql := `SELECT COUNT(1) AS count FROM cygx_interview_apply AS a WHERE a.user_id=? `
  141. err = orm.NewOrm().Raw(sql, userId).QueryRow(&count)
  142. return
  143. }
  144. func GetArticleUserInterviewApplyList(startSize, pageSize, userId int) (items []*ArticleInterviewApplyList, err error) {
  145. sql := `SELECT a.* FROM cygx_interview_apply AS a
  146. WHERE a.user_id=?
  147. ORDER BY a.status ASC LIMIT ?,? `
  148. _, err = orm.NewOrm().Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  149. return
  150. }
  151. type ArticleInterviewApplyListResp struct {
  152. List []*ArticleInterviewApplyList
  153. Paging *paging.PagingItem
  154. }
  155. func GetArticleUserBrowseHistoryCount(userId int, endDate string) (count int, err error) {
  156. sql := `SELECT COUNT(1) AS count FROM cygx_article_history_record AS a WHERE a.user_id=? AND a.create_time>=? `
  157. err = orm.NewOrm().Raw(sql, userId, endDate).QueryRow(&count)
  158. return
  159. }
  160. func GetArticleUserBrowseHistoryList(startSize, pageSize, userId int, endDate string) (items []*ArticleInterviewApplyList, err error) {
  161. sql := `SELECT a.* FROM cygx_article_history_record AS a
  162. WHERE a.user_id=? AND a.create_time>=? GROUP BY a.article_id
  163. ORDER BY a.id DESC LIMIT ?,? `
  164. _, err = orm.NewOrm().Raw(sql, userId, endDate, startSize, pageSize).QueryRows(&items)
  165. return
  166. }
  167. type ArticleBrowseHistoryListResp struct {
  168. List []*ArticleInterviewApplyList
  169. Paging *paging.PagingItem
  170. }
  171. type ApplyTryReq struct {
  172. BusinessCardUrl string `description:"名片地址"`
  173. RealName string `description:"姓名"`
  174. CompanyName string `description:"公司名称"`
  175. ApplyMethod int `description:"1:已付费客户申请试用,2:非客户申请试用,3:非客户申请试用(ficc下,不需要进行数据校验)"`
  176. }