user.go 7.5 KB

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