user.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. EtaBusinessId int
  12. UserName string `description:"用户名"`
  13. RealName string `description:"姓名"`
  14. Mobile string
  15. Email string
  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 AddUser(item *User) (lastId int64, err error) {
  34. o := orm.NewOrm()
  35. lastId, err = o.Insert(item)
  36. return
  37. }
  38. func GetUserByMobile(mobile string) (item *User, err error) {
  39. o := orm.NewOrm()
  40. sql := `SELECT * FROM user WHERE mobile = ? LIMIT 1`
  41. err = o.Raw(sql, mobile).QueryRow(&item)
  42. return
  43. }
  44. func GetUserByMobiles(mobiles []string) (items []*User, err error) {
  45. o := orm.NewOrm()
  46. sql := `SELECT * FROM user WHERE mobile in (` + utils.GetOrmInReplace(len(mobiles)) + `)`
  47. _, err = o.Raw(sql, mobiles).QueryRows(&items)
  48. return
  49. }
  50. // GetUserByMobileCountryCode 根据手机号和区号获取用户信息
  51. func GetUserByMobileCountryCode(mobile, countryCode string) (item *User, err error) {
  52. o := orm.NewOrm()
  53. sql := `SELECT * FROM user WHERE mobile = ? `
  54. sql += ` and country_code =? `
  55. sql += ` LIMIT 1 `
  56. err = o.Raw(sql, mobile, countryCode).QueryRow(&item)
  57. return
  58. }
  59. func GetUserByUserId(userId int) (item *User, err error) {
  60. o := orm.NewOrm()
  61. sql := `SELECT * FROM user WHERE user_id=? `
  62. err = o.Raw(sql, userId).QueryRow(&item)
  63. return
  64. }
  65. // 更新User信息
  66. func (User *User) Update(cols []string) (err error) {
  67. o := orm.NewOrm()
  68. _, err = o.Update(User, cols...)
  69. return
  70. }
  71. // 获取该用户数量
  72. func GetUserCountByCondition(condition string, pars []interface{}) (count int, err error) {
  73. o := orm.NewOrm()
  74. tmpSql := `SELECT *
  75. FROM
  76. user
  77. WHERE
  78. 1=1 `
  79. if condition != "" {
  80. tmpSql += condition
  81. }
  82. sql := `SELECT COUNT(1) AS count FROM (` + tmpSql + `) AS c `
  83. err = o.Raw(sql, pars).QueryRow(&count)
  84. return
  85. }
  86. // 获取该用户列表
  87. func GetUserPageListByCondition(condition string, pars []interface{}, startSize, pageSize int) (items []*User, err error) {
  88. o := orm.NewOrm()
  89. tmpSql := `SELECT *
  90. FROM
  91. user
  92. WHERE
  93. 1=1 `
  94. if condition != "" {
  95. tmpSql += condition
  96. }
  97. tmpSql += ` ORDER BY user_id DESC Limit ?,?`
  98. _, err = o.Raw(tmpSql, pars, startSize, pageSize).QueryRows(&items)
  99. return
  100. }
  101. type BusinessUser struct {
  102. UserId int
  103. BusinessCode string
  104. EtaBusinessId int
  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 ImportUserReq struct {
  162. ValidUser []*User `description:"有效客户数据"`
  163. }
  164. // 新增客户请求参数
  165. type ChangeUserBusinessReq struct {
  166. UserId int
  167. BusinessCode string `description:"商家编码"`
  168. }
  169. // UserEditEnabledReq 用户状态编辑
  170. type UserEditEnabledReq struct {
  171. UserId int `description:"系统用户id"`
  172. Enabled int `description:"1:有效,0:禁用"`
  173. }