user.go 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. }
  37. func PcBindMobile(unionId, mobile string, userId, loginType int) (wxUserId int, err error) {
  38. //loginType 登录方式:1:手机,2:邮箱
  39. sql := ``
  40. if loginType == 1 {
  41. sql = `SELECT * FROM wx_user WHERE mobile = ? `
  42. } else {
  43. sql = "SELECT * FROM wx_user WHERE email = ? "
  44. }
  45. user := new(WxUser)
  46. o := orm.NewOrm()
  47. err = o.Raw(sql, mobile).QueryRow(&user)
  48. if err != nil && err.Error() != utils.ErrNoRow() {
  49. return
  50. }
  51. if user == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  52. msql := ``
  53. if loginType == 1 {
  54. msql = "UPDATE wx_user SET mobile = ?,bind_account = ? WHERE union_id = ? "
  55. } else {
  56. msql = "UPDATE wx_user SET email = ?,bind_account = ? WHERE union_id = ? "
  57. }
  58. _, err = o.Raw(msql, mobile, mobile, unionId).Exec()
  59. wxUserId = userId
  60. } else {
  61. if user.UnionId == "" {
  62. sql = `SELECT * FROM wx_user WHERE union_id = ? `
  63. userInfo := new(WxUser)
  64. o := orm.NewOrm()
  65. err = o.Raw(sql, unionId).QueryRow(&userInfo)
  66. if err != nil {
  67. return
  68. }
  69. var maxRegisterTime time.Time
  70. if user.RegisterTime.Before(userInfo.RegisterTime) {
  71. maxRegisterTime = user.RegisterTime
  72. } else {
  73. maxRegisterTime = userInfo.RegisterTime
  74. }
  75. wxUserId = user.UserId
  76. dsql := ` DELETE FROM wx_user WHERE union_id = ? `
  77. _, err = o.Raw(dsql, unionId).Exec()
  78. if err != nil {
  79. return wxUserId, err
  80. }
  81. msql := ` UPDATE wx_user SET union_id=?,register_time=?,province=?,city=?,country=?,headimgurl=?,unionid=?,sex=? WHERE user_id = ? `
  82. _, err = o.Raw(msql, unionId, maxRegisterTime, userInfo.Province, userInfo.City, userInfo.Country, userInfo.Headimgurl, unionId, userInfo.Sex, user.UserId).Exec()
  83. wxUserId = user.UserId
  84. } else {
  85. sql = `SELECT * FROM wx_user WHERE user_id = ? `
  86. userInfo := new(WxUser)
  87. o := orm.NewOrm()
  88. err = o.Raw(sql, userId).QueryRow(&userInfo)
  89. if err != nil && err.Error() != utils.ErrNoRow() {
  90. return
  91. }
  92. if user.UserId != userId {
  93. dsql := ` DELETE FROM wx_user WHERE user_id = ? `
  94. _, err = o.Raw(dsql, userId).Exec()
  95. if err != nil {
  96. return user.UserId, err
  97. }
  98. }
  99. msql := ` UPDATE wx_user SET union_id=?,province=?,city=?,country=?,headimgurl=?,unionid=?,sex=? WHERE user_id = ? `
  100. _, err = o.Raw(msql, unionId, userInfo.Province, userInfo.City, userInfo.Country, userInfo.Headimgurl, unionId, userInfo.Sex, user.UserId).Exec()
  101. wxUserId = userId
  102. }
  103. }
  104. return
  105. }
  106. type LoginResp struct {
  107. UserId int `description:"用户id"`
  108. Authorization string `description:"Token"`
  109. Headimgurl string `description:"用户头像"`
  110. Mobile string `description:"手机号"`
  111. Email string `description:"邮箱"`
  112. CompanyName string `description:"客户名称"`
  113. Status string `description:"状态"`
  114. EndDate string `description:"到期日期"`
  115. ProductName string `description:"客户类型名称"`
  116. }
  117. type CheckStatusResp struct {
  118. IsBind bool `description:"true:需要绑定手机号或邮箱,false:不需要绑定手机号或邮箱"`
  119. IsAuth bool `description:"true:需要授权,false:不需要授权"`
  120. PermissionName string `description:"拥有权限分类,多个用英文逗号分隔"`
  121. }
  122. func GetArticleUserCollectCount(userId int) (count int, err error) {
  123. sql := `SELECT COUNT(1) AS count FROM cygx_article_collect AS a WHERE a.user_id=? `
  124. err = orm.NewOrm().Raw(sql, userId).QueryRow(&count)
  125. return
  126. }
  127. func GetArticleUserCollectList(startSize, pageSize, userId int) (items []*ArticleCollectList, err error) {
  128. sql := `SELECT a.* FROM cygx_article_collect AS a
  129. WHERE a.user_id=?
  130. ORDER BY a.create_time DESC LIMIT ?,? `
  131. _, err = orm.NewOrm().Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  132. return
  133. }
  134. type ArticleCollectListResp struct {
  135. List []*ArticleCollectList
  136. Paging *paging.PagingItem
  137. }
  138. func GetArticleUserInterviewApplyCount(userId int) (count int, err error) {
  139. sql := `SELECT COUNT(1) AS count FROM cygx_interview_apply AS a WHERE a.user_id=? `
  140. err = orm.NewOrm().Raw(sql, userId).QueryRow(&count)
  141. return
  142. }
  143. func GetArticleUserInterviewApplyList(startSize, pageSize, userId int) (items []*ArticleInterviewApplyList, err error) {
  144. sql := `SELECT a.* FROM cygx_interview_apply AS a
  145. WHERE a.user_id=?
  146. ORDER BY a.status ASC LIMIT ?,? `
  147. _, err = orm.NewOrm().Raw(sql, userId, startSize, pageSize).QueryRows(&items)
  148. return
  149. }
  150. type ArticleInterviewApplyListResp struct {
  151. List []*ArticleInterviewApplyList
  152. Paging *paging.PagingItem
  153. }
  154. func GetArticleUserBrowseHistoryCount(userId int, endDate string) (count int, err error) {
  155. sql := `SELECT COUNT(1) AS count FROM cygx_article_history_record AS a WHERE a.user_id=? AND a.create_time>=? `
  156. err = orm.NewOrm().Raw(sql, userId, endDate).QueryRow(&count)
  157. return
  158. }
  159. func GetArticleUserBrowseHistoryList(startSize, pageSize, userId int, endDate string) (items []*ArticleInterviewApplyList, err error) {
  160. sql := `SELECT a.* FROM cygx_article_history_record AS a
  161. WHERE a.user_id=? AND a.create_time>=? GROUP BY a.article_id
  162. ORDER BY a.id DESC LIMIT ?,? `
  163. _, err = orm.NewOrm().Raw(sql, userId, endDate, startSize, pageSize).QueryRows(&items)
  164. return
  165. }
  166. type ArticleBrowseHistoryListResp struct {
  167. List []*ArticleInterviewApplyList
  168. Paging *paging.PagingItem
  169. }
  170. type ApplyTryReq struct {
  171. BusinessCardUrl string `description:"名片地址"`
  172. RealName string `description:"姓名"`
  173. CompanyName string `description:"公司名称"`
  174. ApplyMethod int `description:"1:已付费客户申请试用,2:非客户申请试用,3:非客户申请试用(ficc下,不需要进行数据校验)"`
  175. }