user.go 7.6 KB

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