user.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. package models
  2. import (
  3. "eta/eta_forum_admin/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. RealName string `description:"姓名"`
  12. Mobile string
  13. Email string
  14. NickName string `description:"昵称"`
  15. CountryCode string `description:"区号,86、852、886等"`
  16. LastLoginTime time.Time
  17. IsFreeLogin int `description:"是否30天免登录,0否,1是"`
  18. RegisterTime time.Time
  19. LastCollectChartTime string `description:"最近收藏图表时间"`
  20. Enabled int
  21. DepartmentName string `description:"部门名称"`
  22. Position string `description:"岗位"`
  23. PositionStatus int `description:"在职状态:1:在职,0:离职"`
  24. CreatedTime time.Time
  25. LastUpdatedTime time.Time `description:"最近一次更新时间"`
  26. }
  27. // 用户详情出参
  28. type UserResp struct {
  29. Detail *User
  30. }
  31. func AddUser(item *User) (lastId int64, err error) {
  32. o := orm.NewOrm()
  33. lastId, err = o.Insert(item)
  34. return
  35. }
  36. func GetUserByMobile(mobile string) (item *User, err error) {
  37. o := orm.NewOrm()
  38. sql := `SELECT * FROM user WHERE mobile = ? LIMIT 1`
  39. err = o.Raw(sql, mobile).QueryRow(&item)
  40. return
  41. }
  42. func GetUserByMobiles(mobiles []string) (items []*User, err error) {
  43. o := orm.NewOrm()
  44. sql := `SELECT * FROM user WHERE mobile in (` + utils.GetOrmInReplace(len(mobiles)) + `)`
  45. _, err = o.Raw(sql, mobiles).QueryRows(&items)
  46. return
  47. }
  48. // GetUserByMobileCountryCode 根据手机号和区号获取用户信息
  49. func GetUserByMobileCountryCode(mobile, countryCode string) (item *User, err error) {
  50. o := orm.NewOrm()
  51. sql := `SELECT * FROM user WHERE mobile = ? `
  52. sql += ` and country_code =? `
  53. sql += ` LIMIT 1 `
  54. err = o.Raw(sql, mobile, countryCode).QueryRow(&item)
  55. return
  56. }
  57. func GetUserByUserId(userId int) (item *User, err error) {
  58. o := orm.NewOrm()
  59. sql := `SELECT * FROM user WHERE user_id=? `
  60. err = o.Raw(sql, userId).QueryRow(&item)
  61. return
  62. }
  63. // 更新User信息
  64. func (User *User) Update(cols []string) (err error) {
  65. o := orm.NewOrm()
  66. _, err = o.Update(User, cols...)
  67. return
  68. }
  69. // 获取该用户数量
  70. func GetUserCountByCondition(condition string, pars []interface{}) (count int, err error) {
  71. o := orm.NewOrm()
  72. tmpSql := `SELECT *
  73. FROM
  74. user
  75. WHERE
  76. 1=1 `
  77. if condition != "" {
  78. tmpSql += condition
  79. }
  80. sql := `SELECT COUNT(1) AS count FROM (` + tmpSql + `) AS c `
  81. err = o.Raw(sql, pars).QueryRow(&count)
  82. return
  83. }
  84. // 获取该用户列表
  85. func GetUserPageListByCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*User, err error) {
  86. o := orm.NewOrm()
  87. tmpSql := `SELECT *
  88. FROM
  89. user
  90. WHERE
  91. 1=1 `
  92. if condition != "" {
  93. tmpSql += condition
  94. }
  95. tmpSql += ` ORDER BY user_id DESC Limit ?,?`
  96. _, err = o.Raw(tmpSql, pars, startSize, pageSize).QueryRows(&items)
  97. return
  98. }
  99. type BusinessUser struct {
  100. UserId int
  101. BusinessCode string
  102. BusinessName string
  103. RealName string `description:"姓名"`
  104. Mobile string
  105. Email string
  106. CountryCode string `description:"区号,86、852、886等"`
  107. LastLoginTime string
  108. Enabled int
  109. DepartmentName string `description:"部门名称"`
  110. Position string `description:"岗位"`
  111. PositionStatus int `description:"在职状态:1:在职,0:离职"`
  112. CreatedTime string
  113. LastUpdatedTime string `description:"最近一次更新时间"`
  114. }
  115. type UserListResp struct {
  116. Paging *paging.PagingItem
  117. List []*BusinessUser
  118. }
  119. // 新增用户请求参数
  120. type AddUserReq struct {
  121. RealName string `description:"姓名"`
  122. CountryCode string `description:"区号,86、852、886等"`
  123. Mobile string `description:"手机号"`
  124. //Email string `description:"邮箱"`
  125. Position string `description:"职位"`
  126. PositionStatus int `description:"在职状态:1:在职,0:离职"`
  127. BusinessCode string `description:"商家编码"`
  128. DepartmentName string `description:"联系人部门"`
  129. }
  130. // 删除客户请求参数
  131. type DeleteUserReq struct {
  132. UserId int
  133. }
  134. // 新增客户请求参数
  135. type EditUserReq struct {
  136. UserId int
  137. RealName string `description:"姓名"`
  138. CountryCode string `description:"区号,86、852、886等"`
  139. Mobile string `description:"手机号"`
  140. //Email string `description:"邮箱"`
  141. Position string `description:"职位"`
  142. PositionStatus int `description:"在职状态:1:在职,0:离职"`
  143. BusinessCode string `description:"商家编码"`
  144. DepartmentName string `description:"联系人部门"`
  145. }
  146. func DeleteUser(userId int) (err error) {
  147. o := orm.NewOrm()
  148. sql := ` DELETE FROM user WHERE user_id=? `
  149. _, err = o.Raw(sql, userId).Exec()
  150. return
  151. }
  152. // 联系人导入预览数据返回
  153. type ImportListResp struct {
  154. ValidUser []*User `description:"有效客户数据"`
  155. RepeatUser []*User `description:"重复客户数据"`
  156. }
  157. // 新增客户请求参数
  158. type ChangeUserBusinessReq struct {
  159. UserId int
  160. BusinessCode string `description:"商家编码"`
  161. }
  162. // UserEditEnabledReq 用户状态编辑
  163. type UserEditEnabledReq struct {
  164. UserId int `description:"系统用户id"`
  165. Enabled int `description:"1:有效,0:禁用"`
  166. }