1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- package bizhi
- import orm "duoduo/database"
- type Collection struct {
- ID int `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"` // 主键
- OpenID string `gorm:"column:open_id;type:varchar(255)" json:"openId"`
- BizhiID int `gorm:"column:bizhi_id;type:bigint(20)" json:"bizhiId"` // 壁纸id
- Url string `gorm:"column:url;type:varchar(255)" json:"url"` // 壁纸url
- CreateTime string `gorm:"column:create_time;type:datetime" json:"createTime"` // 创建时间
- }
- type CollectionBiZhi struct {
- ID int `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"` // 主键
- OpenID string `gorm:"column:open_id;type:varchar(255)" json:"openId"`
- BizhiID int `gorm:"column:bizhi_id;type:bigint(20)" json:"bizhiId"` // 壁纸id
- Url string `gorm:"column:url;type:varchar(255)" json:"url"` // 壁纸url
- CreateTime string `gorm:"column:create_time;type:datetime" json:"createTime"` // 创建时间
- Label string `gorm:"column:label;type:varchar(255)" json:"label"` // 标签
- }
- func (m *Collection) TableName() string {
- return "collection"
- }
- func (m *Collection) Insert() error {
- result := orm.BzMysql.Table(m.TableName()).Create(&m)
- if result.Error != nil {
- err := result.Error
- return err
- }
- return nil
- }
- func (m *Collection) Del() error {
- result := orm.BzMysql.Table(m.TableName()).Where("bizhi_id = ? and open_id = ?", m.BizhiID, m.OpenID).Delete(nil)
- if result.Error != nil {
- err := result.Error
- return err
- }
- return nil
- }
- //list 接口使用
- func (m *Collection) GetOpenIdList(pageSize int, pageIndex int) ([]CollectionBiZhi, int, error) {
- var doc []CollectionBiZhi
- table := orm.BzMysql.Table("collection c LEFT JOIN bizhi b ON b.id = c.bizhi_id")
- table = table.Where("open_id = ? ", m.OpenID)
- //SELECT c.*,b.label FROM collection c LEFT JOIN bizhi b ON b.id = c.bizhi_id;
- var count int
- if err := table.Select("c.*,b.label").Order("id desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
- return nil, 0, err
- }
- table.Count(&count)
- return doc, count, nil
- }
- //list 接口使用
- func (m *Collection) GetOpenIdDownList(pageSize int, pageIndex int) ([]CollectionBiZhi, int, error) {
- var doc []CollectionBiZhi
- table := orm.BzMysql.Table("download c LEFT JOIN bizhi b ON b.id = c.bizhi_id")
- table = table.Where("open_id = ? ", m.OpenID)
- //SELECT c.*,b.label FROM collection c LEFT JOIN bizhi b ON b.id = c.bizhi_id;
- var count int
- if err := table.Select("c.*,b.label").Order("id desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
- return nil, 0, err
- }
- table.Count(&count)
- return doc, count, nil
- }
|