user.go 7.6 KB

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