package system

import (
	"miniapp/global"
	"miniapp/model/common"
	"miniapp/model/common/request"
)

type BannerService struct {
}

// GetBannerList 获取轮播图列表
func (b BannerService) GetBannerList(p request.PageInfo) (list []common.Banner, total int64, err error) {
	err = global.GVA_DB.Scopes(Page(p.Page, p.PageSize)).Find(&list).Limit(-1).Offset(-1).Count(&total).Error
	return
}

// CreateBanner 创建轮播图
func (b BannerService) CreateBanner(banner *common.Banner) (err error) {
	return global.GVA_DB.Create(&banner).Error
}

// UpdateBanner 更新轮播图
func (b BannerService) UpdateBanner(banner *common.Banner) (err error) {
	return global.GVA_DB.Updates(&banner).Error
}

// DeleteBanner 删除轮播图
func (b BannerService) DeleteBanner(banner *common.Banner) (err error) {
	return global.GVA_DB.Delete(&banner).Error
}

// GetBannerById 根据id获取轮播图
func (b BannerService) GetBannerById(id string) (banner *common.Banner, err error) {
	err = global.GVA_DB.Where("id = ?", id).First(&banner).Error
	return
}

// UpdateBannerStatus 更新轮播图状态
func (b BannerService) UpdateBannerStatus(c *common.Banner) (err error) {
	return global.GVA_DB.Model(&c).Update("status", c.Status).Error
}
