user.go 5.3 KB

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