package models import ( "eta/eta_mini_crm_ht/utils" "github.com/beego/beego/v2/client/orm" "time" ) const ( unOpen AccountStatus = "unOpen" open AccountStatus = "open" ) var ( accountStatusMap = map[AccountStatus]string{ open: "已开户", unOpen: "未开户", } ) type AccountStatus string // TemplateUsers // @Description: 临时用户表 type TemplateUser struct { Id int `orm:"pk" description:"用户id"` UserName string `description:"姓名"` Mobile string `description:"手机号"` OpenId string `description:"用户openid"` UnionId string `description:"用户unionid"` IsDeleted int `description:"是否已删除"` GzhOpenId string `description:"用户公众号openid"` ReadCount int `description:"阅读次数"` FollowingGzh bool `description:"是否关注公众号"` AccountStatus AccountStatus `description:"账号状态"` LastReadTime time.Time `description:"最近一次阅读时间"` CreatedTime time.Time `description:"创建时间"` UpdatedTime time.Time `description:"变更时间"` } // TemplateUsers // @Description: 临时用户表 type TemplateUsersItem struct { Id int `orm:"pk" description:"用户id"` UserName string `description:"姓名"` Mobile string `description:"手机号"` OpenId string `description:"用户openid"` UnionId string `description:"用户unionid"` GzhOpenId string `description:"用户公众号openid"` ReadCount int `description:"阅读次数"` AccountStatus string `description:"账号状态"` LastReadTime string `description:"最近一次阅读时间"` CreatedTime string `description:"创建时间"` UpdatedTime string `description:"变更时间"` } func (u *TemplateUser) TableName() string { return "template_users" } // GetPageTemplateUserList // @Description: 获取分页用户数据 // @author: Roc // @datetime 2024-08-09 16:45:15 // @param condition string // @param pars []interface{} // @param startSize int // @param pageSize int // @return total int // @return items []*TemplateUsers // @return err error func GetPageTemplateUserList(condition string, pars []interface{}, sortStr string, startSize, pageSize int) (total int, items []*TemplateUser, err error) { o := orm.NewOrm() totalSql := `SELECT count(1) ct FROM template_users AS a WHERE is_deleted = 0 ` if condition != "" { totalSql += condition } err = o.Raw(totalSql, pars).QueryRow(&total) if err != nil { return } sql := `SELECT * FROM template_users AS a WHERE is_deleted = 0 ` if condition != "" { sql += condition } if sortStr != `` { sql += ` ORDER BY ` + sortStr } sql += ` LIMIT ?,? ` _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items) return } func GetTemplateUserList() (items []*TemplateUser, err error) { o := orm.NewOrm() sql := `SELECT * FROM template_users WHERE is_deleted = 0 ` _, err = o.Raw(sql).QueryRows(&items) return } func GetTemplateUserListByCondition(condition string, pars []interface{}, sortStr string) (items []*TemplateUser, err error) { o := orm.NewOrm() sql := `SELECT * FROM template_users AS a WHERE is_deleted = 0 ` if condition != "" { sql += condition } if sortStr != `` { sql += ` ORDER BY ` + sortStr } _, err = o.Raw(sql, pars).QueryRows(&items) return } func GetTemplateUser(id int) (item *TemplateUser, err error) { o := orm.NewOrm() sql := `SELECT * FROM template_users WHERE id=? and is_deleted = 0 ` err = o.Raw(sql, id).QueryRow(&item) return } // ToItem // @Description: 转结构体返回 // @author: Roc // @receiver m // @datetime 2024-08-09 16:50:41 // @return item TemplateUsersItem func (m *TemplateUser) ToItem() (item TemplateUsersItem) { item = TemplateUsersItem{ Id: m.Id, UserName: m.UserName, Mobile: m.Mobile, OpenId: m.OpenId, UnionId: m.UnionId, GzhOpenId: m.GzhOpenId, ReadCount: m.ReadCount, AccountStatus: accountStatusMap[m.AccountStatus], LastReadTime: "", CreatedTime: m.CreatedTime.Format(utils.FormatDateTime), UpdatedTime: m.UpdatedTime.Format(utils.FormatDateTime), } if !m.LastReadTime.IsZero() { item.LastReadTime = m.LastReadTime.Format(utils.FormatDateTime) } return }