package cygx

import (
	"github.com/beego/beego/v2/client/orm"
	"github.com/rdlucklib/rdluck_tools/paging"
)

type CygxBannerImgResp struct {
	ImgId      int    `orm:"column(img_id);pk"`
	IndexImg   string `description:"小程序封面图"`
	Img1       string `description:"图片1"`
	Img2       string `description:"图片2"`
	Img3       string `description:"图片3"`
	Img4       string `description:"图片4"`
	CreateTime string `description:"创建时间"`
	ModifyTime string `description:"更改时间"`
}

type CygxBannerImgListResp struct {
	Paging *paging.PagingItem `description:"分页数据"`
	List   []*CygxBannerImgResp
}

// 获取数量
func GetCygxBannerImgCount(condition string, pars []interface{}) (count int, err error) {
	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_banner_img as art WHERE 1= 1  `
	if condition != "" {
		sqlCount += condition
	}
	o := orm.NewOrmUsingDB("hz_cygx")
	err = o.Raw(sqlCount, pars).QueryRow(&count)
	return
}

// 列表
func GetCygxBannerImgList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxBannerImgResp, err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := `SELECT * FROM cygx_banner_img as art WHERE 1= 1 `
	if condition != "" {
		sql += condition
	}
	sql += ` LIMIT ?,?  `
	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
	return
}

// 通过ID获取详情
func GetCygxBannerImgDetail(imgId int) (item *CygxBannerImgResp, err error) {
	o := orm.NewOrmUsingDB("hz_cygx")
	sql := `SELECT * FROM cygx_banner_img  WHERE img_id=? `
	err = o.Raw(sql, imgId).QueryRow(&item)
	return
}
