123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- package models
- import (
- "eta/eta_mini_crm_ht/utils"
- "github.com/beego/beego/v2/client/orm"
- "time"
- )
- type User struct {
- Id int `orm:"pk" description:"用户id"`
- TemplateUserId int `description:"临时用户ID"`
- RealName string `description:"姓名"`
- IdNo string `description:"证件号"`
- IdKind int `description:"证件类型"`
- IdBeginDate time.Time `description:"证件开始日期"`
- IdEndDate time.Time `description:"证件结束日期"`
- AccountStatus AccountStatus `description:"账号状态"`
- CreatedTime time.Time `description:"创建时间"`
- UpdatedTime time.Time `description:"更新时间"`
- }
- func (u User) FillUserInfo(user *TemplateUser) UserView {
- return UserView{
- RealName: u.RealName,
- AccountStatus: u.AccountStatus,
- LastReadTime: user.LastReadTime.Format(time.DateTime),
- FollowingGzh: user.FollowingGzh,
- ReadCount: user.ReadCount,
- Mobile: user.Mobile,
- CreatedTime: u.CreatedTime.Format(time.DateTime),
- }
- }
- type UserView struct {
- Id int
- TemplateUserId int
- CompanyName string
- RealName string `description:"姓名"`
- Mobile string `description:"手机号码"`
- FollowingGzh bool
- FollowingGzhStr string
- LastReadTime string
- ReadCount int
- AccountStatus AccountStatus `description:"账号状态"`
- CreatedTime string
- }
- func GetPageOfficialUserList(condition string, pars []interface{}, sortStr string, startSize int, pageSize int) (total int, userList []*UserView, err error) {
- o := orm.NewOrm()
- totalSql := `SELECT distinct template_user_id FROM users`
- var officialIds []int
- _, err = o.Raw(totalSql).QueryRows(&officialIds)
- if err != nil {
- return
- }
- total = len(officialIds)
- idCondition := " and tus.id in (" + utils.GetOrmReplaceHolder(len(officialIds)) + ")"
- 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`
- sql = sql + idCondition
- if condition != "" {
- sql += condition
- }
- if sortStr != `` {
- sql += ` ORDER BY ` + sortStr
- }
- sql += ` LIMIT ?,? `
- _, err = o.Raw(sql, officialIds, pars, startSize, pageSize).QueryRows(&userList)
- if userList == nil {
- userList = []*UserView{}
- }
- return
- }
- func GetPageOfficialUserByCondition(condition string, pars []interface{}, sortStr string) (userList []UserView, err error) {
- o := orm.NewOrm()
- totalSql := `SELECT distinct template_user_id FROM users`
- var officialIds []int
- _, err = o.Raw(totalSql).QueryRows(&officialIds)
- if err != nil {
- return
- }
- idCondition := " and tus.id in (" + utils.GetOrmReplaceHolder(len(officialIds)) + ")"
- 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`
- sql = sql + idCondition
- if condition != "" {
- sql += condition
- }
- if sortStr != `` {
- sql += ` ORDER BY ` + sortStr
- }
- _, err = o.Raw(sql, officialIds, pars).QueryRows(&userList)
- if userList == nil {
- userList = []UserView{}
- return
- }
- for i := 0; i < len(userList); i++ {
- if userList[i].FollowingGzh {
- userList[i].FollowingGzhStr = "是"
- } else {
- userList[i].FollowingGzhStr = "否"
- }
- }
- return
- }
|