user.go 7.0 KB

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