@@ -0,0 +1,111 @@
|
||||
package adser
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"91porn-server/common"
|
||||
"91porn-server/models/v/adsmod"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
type AdRecord struct {
|
||||
ID primitive.ObjectID `json:"id"` //广告id
|
||||
AdsType adsmod.AdsType `json:"adsType"` //广告类型
|
||||
Cover string `json:"cover"` //广告封面图
|
||||
Size int `json:"size"` //尺寸 B
|
||||
Height int `json:"height"` //高
|
||||
Width int `json:"width"` //宽
|
||||
Title string `json:"title"` //广告标题
|
||||
HrefType adsmod.URLJumpType `json:"hrefType"` //广告链接类型
|
||||
Href string `json:"href"` //广告跳转地址
|
||||
Position adsmod.AdPosition `json:"position"` //广告位置
|
||||
SortCode int `json:"sortCode"` //排序号
|
||||
Active bool `json:"active"` //激活状态 true:激活
|
||||
Click int `json:"click"` //点击次数
|
||||
Remark string `json:"remark"` //备注
|
||||
ReviewID primitive.ObjectID `json:"reviewID,omitempty"` //审核id
|
||||
DistrictCode string `json:"districtCode"` //商区码
|
||||
CreatedAt time.Time `json:"createdAt"` //创建时间
|
||||
Start time.Time `json:"start"` //开始时间
|
||||
End time.Time `json:"end"` //结束时间
|
||||
}
|
||||
|
||||
type AdPage struct {
|
||||
List []AdRecord `json:"list"`
|
||||
Total int64 `json:"total"`
|
||||
}
|
||||
|
||||
// AdPages 获取广告列表
|
||||
func AdPages(skip, limit int64, idMatch adsmod.IDMatch, adsType adsmod.AdsTypeMatch, adsPositionMatch adsmod.AdPositionMatch, districtCodeMatch adsmod.DistrictCodeMatch) (AdPage, error) {
|
||||
mats := []adsmod.Matcher{
|
||||
idMatch.New(),
|
||||
adsType.New(),
|
||||
adsPositionMatch.New(),
|
||||
districtCodeMatch.New(),
|
||||
}
|
||||
list, _ := adsmod.List(adsmod.Sort_createdAt_N1, &skip, &limit, mats...)
|
||||
recordList := make([]AdRecord, len(list))
|
||||
for i, v := range list {
|
||||
recordList[i] = AdRecord{
|
||||
ID: v.ID,
|
||||
AdsType: v.AdsType,
|
||||
Cover: v.Cover,
|
||||
Size: v.Size,
|
||||
Height: v.Height,
|
||||
Width: v.Width,
|
||||
Title: v.Title,
|
||||
HrefType: v.HrefType,
|
||||
Href: v.Href,
|
||||
Position: v.Position,
|
||||
SortCode: v.SortCode,
|
||||
Active: v.Active,
|
||||
Click: v.Click,
|
||||
Remark: v.Remark,
|
||||
ReviewID: v.ReviewID,
|
||||
DistrictCode: v.DistrictCode,
|
||||
CreatedAt: v.CreatedAt,
|
||||
Start: v.Start,
|
||||
End: v.End,
|
||||
}
|
||||
}
|
||||
count, _ := adsmod.Count(mats...)
|
||||
return AdPage{
|
||||
recordList,
|
||||
count,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func IsValidAdPicture(pos adsmod.AdPosition, pictureProp common.PictureProp) error {
|
||||
switch pos {
|
||||
case adsmod.StartupPage: //启动页广告
|
||||
if pictureProp.Height > 1560 || pictureProp.Width > 720 {
|
||||
return ErrImgScale{}
|
||||
}
|
||||
case adsmod.HomeRecoSmall: //首页-推荐小广告
|
||||
if pictureProp.Height > 620 || pictureProp.Width > 560 {
|
||||
return ErrImgScale{}
|
||||
}
|
||||
case adsmod.HomePopupAnnou: //首页-弹窗公告
|
||||
if pictureProp.Height > 1300 || pictureProp.Width > 656 {
|
||||
return ErrImgScale{}
|
||||
}
|
||||
case adsmod.NotifyPage: //消息-界面广告
|
||||
if pictureProp.Height > 260 || pictureProp.Width > 720 {
|
||||
return ErrImgScale{}
|
||||
}
|
||||
case adsmod.LiaoCarousel: //撩吧-轮播广告
|
||||
if pictureProp.Height > 500 || pictureProp.Width > 720 {
|
||||
return ErrImgScale{}
|
||||
}
|
||||
case adsmod.WalletPage: //钱包-轮播广告
|
||||
if pictureProp.Height > 120 || pictureProp.Width > 720 {
|
||||
return ErrImgScale{}
|
||||
}
|
||||
case adsmod.SearchPage: //搜索-轮播广告
|
||||
if pictureProp.Height > 360 || pictureProp.Width > 720 {
|
||||
return ErrImgScale{}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user