user.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package models
  2. import (
  3. "eta/eta_mini_crm_ht/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "time"
  6. )
  7. type User struct {
  8. Id int `orm:"pk" description:"用户id"`
  9. TemplateUserId int `description:"临时用户ID"`
  10. RealName string `description:"姓名"`
  11. IdNo string `description:"证件号"`
  12. IdKind int `description:"证件类型"`
  13. IdBeginDate time.Time `description:"证件开始日期"`
  14. IdEndDate time.Time `description:"证件结束日期"`
  15. AccountStatus AccountStatus `description:"账号状态"`
  16. CreatedTime time.Time `description:"创建时间"`
  17. UpdatedTime time.Time `description:"更新时间"`
  18. }
  19. func (u User) FillUserInfo(user *TemplateUser) UserView {
  20. return UserView{
  21. RealName: u.RealName,
  22. AccountStatus: u.AccountStatus,
  23. LastReadTime: user.LastReadTime.Format(time.DateTime),
  24. FollowingGzh: user.FollowingGzh,
  25. ReadCount: user.ReadCount,
  26. Mobile: user.Mobile,
  27. CreatedTime: u.CreatedTime.Format(time.DateTime),
  28. }
  29. }
  30. type UserView struct {
  31. Id int
  32. TemplateUserId int
  33. RealName string `description:"姓名"`
  34. Mobile string `description:"手机号码"`
  35. FollowingGzh bool
  36. LastReadTime string
  37. ReadCount int
  38. AccountStatus AccountStatus `description:"账号状态"`
  39. CreatedTime string
  40. }
  41. func GetPageOfficialUserList(condition string, pars []interface{}, sortStr string, startSize int, pageSize int) (total int, userList []*UserView, err error) {
  42. o := orm.NewOrm()
  43. totalSql := `SELECT distinct template_user_id FROM users`
  44. var officialIds []int
  45. _, err = o.Raw(totalSql).QueryRows(&officialIds)
  46. if err != nil {
  47. return
  48. }
  49. total = len(officialIds)
  50. idCondition := " and tus.id in (" + utils.GetOrmReplaceHolder(len(officialIds)) + ")"
  51. sql := `SELECT us.id as id,us.template_user_id as template_user_id, us.real_name as real_name, tus.mobile,tus.following_gzh,tus.created_time,tus.read_count,tus.last_read_time,tus.account_status FROM template_users tus LEFT JOIN (select id, real_name,template_user_id from users) us on us.template_user_id=tus.id WHERE 1=1`
  52. sql = sql + idCondition
  53. if condition != "" {
  54. sql += condition
  55. }
  56. if sortStr != `` {
  57. sql += ` ORDER BY ` + sortStr
  58. }
  59. sql += ` LIMIT ?,? `
  60. _, err = o.Raw(sql, officialIds, pars, startSize, pageSize).QueryRows(&userList)
  61. if userList == nil {
  62. userList = []*UserView{}
  63. }
  64. return
  65. }