user.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. package models
  2. import (
  3. "eta/eta_forum_hub/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "time"
  7. )
  8. type User struct {
  9. UserId int `orm:"column(user_id);pk"`
  10. BusinessCode string
  11. EtaBusinessId int
  12. RealName string `description:"姓名"`
  13. Mobile string
  14. Email string
  15. UserName string `description:"用户名"`
  16. NickName string `description:"昵称"`
  17. CountryCode string `description:"区号,86、852、886等"`
  18. LastLoginTime time.Time
  19. IsFreeLogin int `description:"是否30天免登录,0否,1是"`
  20. RegisterTime time.Time
  21. LastCollectChartTime string `description:"最近收藏图表时间"`
  22. Enabled int
  23. DepartmentName string `description:"部门名称"`
  24. Position string `description:"岗位"`
  25. PositionStatus int `description:"在职状态:1:在职,0:离职"`
  26. CreatedTime time.Time
  27. LastUpdatedTime time.Time `description:"最近一次更新时间"`
  28. }
  29. // 用户详情出参
  30. type UserResp struct {
  31. Detail *User
  32. }
  33. func GetUserByBusinessCodeAndMobile(businessCode, mobile, countryCode string) (item *User, err error) {
  34. o := orm.NewOrm()
  35. sql := `SELECT * FROM user WHERE business_code=? AND mobile = ? AND country_code =? LIMIT 1`
  36. err = o.Raw(sql, businessCode, mobile, countryCode).QueryRow(&item)
  37. return
  38. }
  39. func GetUserByMobiles(mobiles []string) (items []*User, err error) {
  40. o := orm.NewOrm()
  41. sql := `SELECT * FROM user WHERE mobile in (` + utils.GetOrmInReplace(len(mobiles)) + `)`
  42. _, err = o.Raw(sql, mobiles).QueryRows(&items)
  43. return
  44. }
  45. // GetUserByMobileCountryCode 根据手机号和区号获取用户信息
  46. func GetUserByMobileCountryCode(mobile, countryCode string) (item *User, err error) {
  47. o := orm.NewOrm()
  48. sql := `SELECT * FROM user WHERE mobile = ? `
  49. sql += ` and country_code =? `
  50. sql += ` LIMIT 1 `
  51. err = o.Raw(sql, mobile, countryCode).QueryRow(&item)
  52. return
  53. }
  54. func GetUserByUserId(userId int) (item *User, err error) {
  55. o := orm.NewOrm()
  56. sql := `SELECT * FROM user WHERE user_id=? `
  57. err = o.Raw(sql, userId).QueryRow(&item)
  58. return
  59. }
  60. func GetUserByUserName(userName string) (item *User, err error) {
  61. o := orm.NewOrm()
  62. sql := `SELECT * FROM user WHERE user_name=? `
  63. err = o.Raw(sql, userName).QueryRow(&item)
  64. return
  65. }
  66. // 更新User信息
  67. func (User *User) Update(cols []string) (err error) {
  68. o := orm.NewOrm()
  69. _, err = o.Update(User, cols...)
  70. return
  71. }
  72. // 获取该用户数量
  73. func GetUserCountByCondition(condition string, pars []interface{}) (count int, err error) {
  74. o := orm.NewOrm()
  75. tmpSql := `SELECT *
  76. FROM
  77. user
  78. WHERE
  79. 1=1 `
  80. if condition != "" {
  81. tmpSql += condition
  82. }
  83. sql := `SELECT COUNT(1) AS count FROM (` + tmpSql + `) AS c `
  84. err = o.Raw(sql, pars).QueryRow(&count)
  85. return
  86. }
  87. // 获取该用户列表
  88. func GetUserPageListByCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*User, err error) {
  89. o := orm.NewOrm()
  90. tmpSql := `SELECT *
  91. FROM
  92. user
  93. WHERE
  94. 1=1 `
  95. if condition != "" {
  96. tmpSql += condition
  97. }
  98. tmpSql += ` ORDER BY user_id DESC Limit ?,?`
  99. _, err = o.Raw(tmpSql, pars, startSize, pageSize).QueryRows(&items)
  100. return
  101. }
  102. type BusinessUser struct {
  103. UserId int
  104. BusinessCode string
  105. BusinessName string
  106. RealName string `description:"姓名"`
  107. Mobile string
  108. Email string
  109. CountryCode string `description:"区号,86、852、886等"`
  110. LastLoginTime string
  111. Enabled int
  112. DepartmentName string `description:"部门名称"`
  113. Position string `description:"岗位"`
  114. PositionStatus int `description:"在职状态:1:在职,0:离职"`
  115. CreatedTime string
  116. LastUpdatedTime string `description:"最近一次更新时间"`
  117. }
  118. type UserListResp struct {
  119. Paging *paging.PagingItem
  120. List []*BusinessUser
  121. }
  122. // 新增用户请求参数
  123. type AddUserReq struct {
  124. RealName string `description:"姓名"`
  125. CountryCode string `description:"区号,86、852、886等"`
  126. Mobile string `description:"手机号"`
  127. //Email string `description:"邮箱"`
  128. Position string `description:"职位"`
  129. PositionStatus int `description:"在职状态:1:在职,0:离职"`
  130. BusinessCode string `description:"商家编码"`
  131. DepartmentName string `description:"联系人部门"`
  132. }
  133. // 删除客户请求参数
  134. type DeleteUserReq struct {
  135. UserId int
  136. }
  137. // 新增客户请求参数
  138. type EditUserReq struct {
  139. UserId int
  140. RealName string `description:"姓名"`
  141. CountryCode string `description:"区号,86、852、886等"`
  142. Mobile string `description:"手机号"`
  143. //Email string `description:"邮箱"`
  144. Position string `description:"职位"`
  145. PositionStatus int `description:"在职状态:1:在职,0:离职"`
  146. BusinessCode string `description:"商家编码"`
  147. DepartmentName string `description:"联系人部门"`
  148. }
  149. func DeleteUser(userId int) (err error) {
  150. o := orm.NewOrm()
  151. sql := ` DELETE FROM user WHERE user_id=? `
  152. _, err = o.Raw(sql, userId).Exec()
  153. return
  154. }
  155. // 联系人导入预览数据返回
  156. type ImportListResp struct {
  157. ValidUser []*User `description:"有效客户数据"`
  158. RepeatUser []*User `description:"重复客户数据"`
  159. }
  160. // 新增客户请求参数
  161. type ChangeUserBusinessReq struct {
  162. UserId int
  163. BusinessCode string `description:"商家编码"`
  164. }
  165. // UserEditEnabledReq 用户状态编辑
  166. type UserEditEnabledReq struct {
  167. UserId int `description:"系统用户id"`
  168. Enabled int `description:"1:有效,0:禁用"`
  169. }
  170. type VerifyCodeReq struct {
  171. //VerifyType int `description:"验证方式: 1-手机号; 2-邮箱"`
  172. CaptchaId string `description:"验证码ID"`
  173. CaptchaCode string `description:"图形验证码"`
  174. Mobile string `description:"手机号"`
  175. TelAreaCode string `description:"手机区号"`
  176. //Email string `description:"邮箱"`
  177. //Source int `description:"来源:1-登录;2-异常登录校验;3-忘记密码"`
  178. }
  179. // 入参
  180. type UserLoginReq struct {
  181. //LoginType int `description:"登录方式: 1-账号; 2-手机号; 3-邮箱"`
  182. Username string `description:"账号"`
  183. Password string `description:"密码"`
  184. Mobile string `description:"手机号"`
  185. Email string `description:"邮箱"`
  186. VerifyCode string `description:"验证码"`
  187. IsRemember int `description:"是否60天保持登录,0否,1是"`
  188. ReqTime string `description:"登录时间戳"`
  189. TelAreaCode string `description:"区号"`
  190. }
  191. type LoginResp struct {
  192. Authorization string
  193. RealName string `description:"系统用户姓名"`
  194. Mobile string `description:"手机号"`
  195. UserId int `description:"系统用户id"`
  196. BusinessName string `description:"商家名称"`
  197. BusinessCode string `description:"商家编码"`
  198. DepartmentName string `description:"部门名称"`
  199. Position string `description:"岗位"`
  200. }
  201. type ForgetAccountGetReq struct {
  202. CaptchaId string `description:"验证码ID"`
  203. CaptchaCode string `description:"图形验证码"`
  204. UserName string `description:"用户名"`
  205. }
  206. type ForgetAccountCheckResp struct {
  207. Mobile string `description:"手机号"`
  208. Email string `description:"邮箱"`
  209. TelAreaCode string `description:"手机区号"`
  210. }
  211. type ForgetCodeVerifyReq struct {
  212. FindType int `description:"密码找回方式: 1-手机号; 2-邮箱"`
  213. VerifyCode string `description:"验证码"`
  214. UserName string `description:"用户名"`
  215. Mobile string `description:"手机号"`
  216. Email string `description:"邮箱"`
  217. TelAreaCode string `description:"区号"`
  218. }
  219. type ForgetResetPassReq struct {
  220. UserName string `description:"用户名"`
  221. Password string `description:"密码"`
  222. RePassword string `description:"重复密码"`
  223. }