groupTop.go 1005 Bytes
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
package group_m

import (
	"git.hilo.cn/hilo-common/domain"
	"gorm.io/gorm"
)

type GroupTop struct {
	Id        uint
	ImGroupId string
}

func (g *GroupTop) PutOnTop(model *domain.Model) error {
	err := model.Db.Model(&GroupTop{}).Where("id > 0").Order("id DESC").UpdateColumn("id", gorm.Expr("id + ?", 1)).Error
	if err != nil {
		return err
	}
	g.Id = 1
	return model.Db.Create(g).Error
}

func (g *GroupTop) Delete(model *domain.Model) error {
	return model.Db.Where(g).Delete(&GroupTop{}).Error
}

chenweijian's avatar
chenweijian committed
26
func GroupTopGetAll(model *domain.Model, area int) ([]string, error) {
hujiebin's avatar
hujiebin committed
27
	rows := make([]GroupTop, 0)
chenweijian's avatar
chenweijian committed
28 29 30 31 32
	err := model.DB().Table("group_top").
		Joins("left join group_info gi on group_top.im_group_id = gi.im_group_id "+
			"left join res_country rc on gi.country = rc.name").
		Where("rc.area = ?", area).
		Order("group_top.id").Find(&rows).Error
hujiebin's avatar
hujiebin committed
33 34 35 36 37 38 39 40 41
	if err != nil {
		return nil, err
	}
	result := make([]string, 0)
	for _, i := range rows {
		result = append(result, i.ImGroupId)
	}
	return result, err
}