You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
941 B
41 lines
941 B
package service
|
|
|
|
import (
|
|
"pure/global"
|
|
"pure/model"
|
|
"pure/model/response"
|
|
)
|
|
|
|
func GetBannerList() (err error, list []response.BannerListResponse, total int64) {
|
|
|
|
db := global.MG_DB.Model(&model.Banner{})
|
|
|
|
err = db.Count(&total).Error
|
|
var res []model.Banner
|
|
|
|
err = db.Select("id,title,cover_url,relation_id,relation_type,link_type,link,type,status,sort").
|
|
Where("status = ?", "1").
|
|
Order("sort DESC").Find(&res).Error
|
|
|
|
if err != nil {
|
|
return err, nil, 0
|
|
}
|
|
for i := 0; i < len(res); i++ {
|
|
//精简字段赋值
|
|
vRes := response.BannerListResponse{
|
|
RelationId: res[i].RelationId,
|
|
RelationType: res[i].RelationType,
|
|
Title: res[i].Title,
|
|
CoverUrl: res[i].CoverUrl,
|
|
LinkType: res[i].LinkType,
|
|
Link: res[i].Link,
|
|
Type: res[i].Type,
|
|
Status: res[i].Status,
|
|
}
|
|
vRes.ID = res[i].ID
|
|
vRes.SortIndex = i + 1
|
|
list = append(list, vRes)
|
|
}
|
|
|
|
return err, list, total
|
|
}
|
|
|