user.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. RealName string `description:"姓名"`
  33. Mobile string `description:"手机号码"`
  34. FollowingGzh bool
  35. LastReadTime string
  36. ReadCount int
  37. AccountStatus AccountStatus `description:"账号状态"`
  38. CreatedTime string
  39. }
  40. func GetPageOfficialUserList(condition string, pars []interface{}, sortStr string, startSize int, pageSize int) (total int, userList []*UserView, err error) {
  41. o := orm.NewOrm()
  42. totalSql := `SELECT distinct template_user_id FROM users`
  43. var officialIds []int
  44. _, err = o.Raw(totalSql).QueryRows(&officialIds)
  45. if err != nil {
  46. return
  47. }
  48. total = len(officialIds)
  49. idCondition := " and tus.id in (" + utils.GetOrmReplaceHolder(len(officialIds)) + ")"
  50. sql := `SELECT us.id as 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`
  51. sql = sql + idCondition
  52. if condition != "" {
  53. sql += condition
  54. }
  55. if sortStr != `` {
  56. sql += ` ORDER BY ` + sortStr
  57. }
  58. sql += ` LIMIT ?,? `
  59. _, err = o.Raw(sql, officialIds, pars, startSize, pageSize).QueryRows(&userList)
  60. if userList == nil {
  61. userList = []*UserView{}
  62. }
  63. return
  64. }