user.go 6.4 KB

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