feat: ad manager
This commit is contained in:
@@ -18,3 +18,13 @@ func toAdItem(row dao.AdInfo) *ad.Item {
|
||||
CreateTime: row.CreateTime,
|
||||
}
|
||||
}
|
||||
|
||||
func toAdWebItem(row dao.AdWebInfo) *ad.WebItem {
|
||||
return &ad.WebItem{
|
||||
Id: int64(row.Id),
|
||||
Type: uint32(row.Type),
|
||||
Image: row.Image,
|
||||
Content: row.Content,
|
||||
Url: row.Url,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,7 @@ package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"lone-services/pkg/log"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
ad "lone-services/rpc/ad/pb"
|
||||
@@ -50,9 +48,9 @@ func (l *CreateLogic) Create(in *ad.CreateReq) (*ad.Response, error) {
|
||||
AdminName: adminInfo.Name,
|
||||
}
|
||||
if err := (model.AdModel{}.Init().Create(&data)); err != nil {
|
||||
log.Errorf("create ad: %v", err)
|
||||
l.Errorf("create ad: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
return okResponse(strconv.Itoa(data.Id)), nil
|
||||
return okResponse(utils.StringEmpty), nil
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"lone-services/pkg/log"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
@@ -46,7 +45,7 @@ func (l *EditLogic) Edit(in *ad.EditReq) (*ad.Response, error) {
|
||||
var info dao.AdCreate
|
||||
m := model.AdModel{}.Init()
|
||||
if err := m.GetOne(w, &info); err != nil {
|
||||
log.Errorf("edit ad get: %v", err)
|
||||
l.Errorf("edit ad get: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
if info.Id < utils.NumberOne {
|
||||
@@ -61,7 +60,7 @@ func (l *EditLogic) Edit(in *ad.EditReq) (*ad.Response, error) {
|
||||
info.AdminName = adminInfo.Name
|
||||
|
||||
if _, err := m.Edit(w, &info); err != nil {
|
||||
log.Errorf("edit ad: %v", err)
|
||||
l.Errorf("edit ad: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package logic
|
||||
import (
|
||||
"context"
|
||||
|
||||
"lone-services/pkg/log"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
@@ -54,7 +53,7 @@ func (l *ItemsLogic) Items(in *ad.ItemsReq) (*ad.Response, error) {
|
||||
var info []dao.AdInfo
|
||||
result, err := model.AdModel{}.Init().Page(w, &info)
|
||||
if err != nil {
|
||||
log.Errorf("ad items: %v", err)
|
||||
l.Errorf("ad items: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"lone-services/pkg/log"
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
@@ -41,7 +40,7 @@ func (l *StatusLogic) Status(in *ad.StatusReq) (*ad.Response, error) {
|
||||
var info dao.AdStatus
|
||||
m := model.AdModel{}.Init()
|
||||
if err := m.GetOne(w, &info); err != nil {
|
||||
log.Errorf("ad status get: %v", err)
|
||||
l.Errorf("ad status get: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
if info.Id < utils.NumberOne {
|
||||
@@ -59,7 +58,7 @@ func (l *StatusLogic) Status(in *ad.StatusReq) (*ad.Response, error) {
|
||||
info.AdminName = adminInfo.Name
|
||||
|
||||
if _, err := m.Edit(w, &info); err != nil {
|
||||
log.Errorf("ad status edit: %v", err)
|
||||
l.Errorf("ad status edit: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
ad "lone-services/rpc/ad/pb"
|
||||
"lone-services/services/ad/internal/dao"
|
||||
"lone-services/services/ad/internal/model"
|
||||
"lone-services/services/ad/internal/svc"
|
||||
"lone-services/services/ad/validator"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type WebItemsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewWebItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WebItemsLogic {
|
||||
return &WebItemsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *WebItemsLogic) WebItems(in *ad.WebItemsReq) (*ad.Response, error) {
|
||||
var req validator.AdWebItemsValidator
|
||||
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return outResponse(utils.ErrorParams, msg), nil
|
||||
}
|
||||
|
||||
types := make([]string, 0)
|
||||
for _, t := range strings.Split(req.Type, utils.DecollatorComma) {
|
||||
t = strings.TrimSpace(t)
|
||||
if t != "" {
|
||||
types = append(types, t)
|
||||
}
|
||||
}
|
||||
if len(types) < 1 {
|
||||
return outResponse(utils.ErrorParams, "请选择类型"), nil
|
||||
}
|
||||
|
||||
w := modelbase.Params{
|
||||
Order: "type asc",
|
||||
In: map[string][]string{"type": types},
|
||||
Eq: map[string]string{"status": utils.StringStatusOk},
|
||||
}
|
||||
|
||||
var info []dao.AdWebInfo
|
||||
if err := (model.AdModel{}.Init().Items(w, &info)); err != nil {
|
||||
l.Errorf("ad web items: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
items := make([]*ad.WebItem, 0, len(info))
|
||||
for _, row := range info {
|
||||
items = append(items, toAdWebItem(row))
|
||||
}
|
||||
|
||||
return okResponse(utils.StructToJson(items)), nil
|
||||
}
|
||||
Reference in New Issue
Block a user