user.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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{}, order string, 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. if order != "" {
  98. tmpSql += ` ORDER BY ` + order + ", user_id DESC"
  99. } else {
  100. tmpSql += ` ORDER BY user_id DESC`
  101. }
  102. tmpSql += ` Limit ?,?`
  103. _, err = o.Raw(tmpSql, pars, startSize, pageSize).QueryRows(&items)
  104. return
  105. }
  106. type BusinessUser struct {
  107. UserId int
  108. BusinessCode string
  109. EtaBusinessId int
  110. BusinessName string
  111. RealName string `description:"姓名"`
  112. Mobile string
  113. Email string
  114. CountryCode string `description:"区号,86、852、886等"`
  115. LastLoginTime string
  116. Enabled int
  117. DepartmentName string `description:"部门名称"`
  118. Position string `description:"岗位"`
  119. PositionStatus int `description:"在职状态:1:在职,0:离职"`
  120. CreatedTime string
  121. LastUpdatedTime string `description:"最近一次更新时间"`
  122. }
  123. type UserListResp struct {
  124. Paging *paging.PagingItem
  125. List []*BusinessUser
  126. }
  127. // 新增用户请求参数
  128. type AddUserReq struct {
  129. RealName string `description:"姓名"`
  130. CountryCode string `description:"区号,86、852、886等"`
  131. Mobile string `description:"手机号"`
  132. //Email string `description:"邮箱"`
  133. Position string `description:"职位"`
  134. PositionStatus int `description:"在职状态:1:在职,0:离职"`
  135. EtaBusinessId int
  136. DepartmentName string `description:"联系人部门"`
  137. }
  138. // 删除客户请求参数
  139. type DeleteUserReq struct {
  140. UserId int
  141. }
  142. // 新增客户请求参数
  143. type EditUserReq struct {
  144. UserId int
  145. RealName string `description:"姓名"`
  146. CountryCode string `description:"区号,86、852、886等"`
  147. Mobile string `description:"手机号"`
  148. //Email string `description:"邮箱"`
  149. Position string `description:"职位"`
  150. PositionStatus int `description:"在职状态:1:在职,0:离职"`
  151. EtaBusinessId int
  152. DepartmentName string `description:"联系人部门"`
  153. }
  154. func DeleteUser(userId int) (err error) {
  155. o := orm.NewOrm()
  156. sql := ` DELETE FROM user WHERE user_id=? `
  157. _, err = o.Raw(sql, userId).Exec()
  158. return
  159. }
  160. // 联系人导入预览数据返回
  161. type ImportListResp struct {
  162. ValidUser []*User `description:"有效客户数据"`
  163. RepeatUser []*User `description:"重复客户数据"`
  164. }
  165. // 联系人导入预览数据返回
  166. type ImportUserReq struct {
  167. ValidUser []*ImportUserItem `description:"有效客户数据"`
  168. }
  169. type ImportUserItem struct {
  170. BusinessCode string
  171. EtaBusinessId int
  172. UserName string `description:"用户名"`
  173. RealName string `description:"姓名"`
  174. Mobile string
  175. NickName string `description:"昵称"`
  176. CountryCode string `description:"区号,86、852、886等"`
  177. DepartmentName string `description:"部门名称"`
  178. Position string `description:"岗位"`
  179. PositionStatus int `description:"在职状态:1:在职,0:离职"`
  180. }
  181. // 新增客户请求参数
  182. type ChangeUserBusinessReq struct {
  183. UserId int
  184. EtaBusinessId int
  185. //BusinessCode string `description:"商家编码"`
  186. }
  187. // UserEditEnabledReq 用户状态编辑
  188. type UserEditEnabledReq struct {
  189. UserId int `description:"系统用户id"`
  190. Enabled int `description:"1:有效,0:禁用"`
  191. }