51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package ads
|
|
|
|
import (
|
|
"context"
|
|
|
|
"bsm/full/module/ec/mall/internal/impl"
|
|
"bsm/full/module/ec/mall/internal/models"
|
|
pb "bsm/full/module/ec/mall/pb"
|
|
"git.apinb.com/bsm-sdk/core/errcode"
|
|
"git.apinb.com/bsm-sdk/core/printer"
|
|
)
|
|
|
|
// 广告列表
|
|
func Fetch(ctx context.Context, in *pb.FetchRequest) (reply *pb.AdsListReply, err error) {
|
|
if in.GetStoreIdentity() == "" {
|
|
return nil, errcode.ErrInvalidArgument
|
|
}
|
|
|
|
var (
|
|
cnt int64 = 0
|
|
pageNo int64 = in.GetPageNo()
|
|
pageSize int64 = in.GetPageSize()
|
|
offset int64 = (pageNo - 1) * pageSize
|
|
params = map[string]string{
|
|
"store_identity": in.GetStoreIdentity(),
|
|
}
|
|
)
|
|
|
|
// vlidate request page_no,page_size.
|
|
if pageNo < 1 {
|
|
pageNo = 1
|
|
offset = 0
|
|
}
|
|
if pageSize < 50 {
|
|
pageSize = 50
|
|
offset = (pageNo - 1) * pageSize
|
|
}
|
|
|
|
var data []*models.MallAds
|
|
if err := impl.DBService.Model(&models.MallAds{}).Where(params).Order("created_at desc").Count(&cnt).Offset(int(offset)).
|
|
Limit(int(pageSize)).Find(&data).Error; err != nil {
|
|
printer.Error(err.Error())
|
|
return nil, errcode.ErrDB
|
|
}
|
|
|
|
return &pb.AdsListReply{
|
|
Count: cnt,
|
|
Data: ref(data),
|
|
}, nil
|
|
}
|