feat: product items info
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"lone-services/pkg/modelbase"
|
||||
"lone-services/pkg/utils"
|
||||
"lone-services/pkg/validate"
|
||||
product "lone-services/rpc/product/pb"
|
||||
"lone-services/services/product/internal/dao"
|
||||
"lone-services/services/product/internal/model"
|
||||
"lone-services/services/product/internal/svc"
|
||||
"lone-services/services/product/validator"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type ApiItemsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewApiItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiItemsLogic {
|
||||
return &ApiItemsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ApiItemsLogic) ApiItems(in *product.ApiItemsReq) (*product.Response, error) {
|
||||
var req validator.ApiProductItemsValidator
|
||||
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return outResponse(utils.ErrorParams, msg), nil
|
||||
}
|
||||
|
||||
userInfo := utils.GetUserFromCtx(l.ctx)
|
||||
if !userInfo.Valid || userInfo.ID < utils.NumberOne {
|
||||
return failResponse(utils.ErrorNoLoginInfo), nil
|
||||
}
|
||||
|
||||
w := modelbase.Params{
|
||||
Eq: map[string]string{
|
||||
"status": utils.StringStatusOk,
|
||||
"sales_model": strconv.Itoa(dao.ProductSalesModelOffline),
|
||||
},
|
||||
Other: map[string]string{
|
||||
"publish_time < ? ": utils.Now().String(),
|
||||
},
|
||||
Order: "sort DESC, id DESC",
|
||||
}
|
||||
if len(req.Name) > utils.NumberZero {
|
||||
w.Like = map[string]string{
|
||||
"name LIKE ? ": "%%" + req.Name + "%%",
|
||||
}
|
||||
}
|
||||
|
||||
var rows []dao.WebInfo
|
||||
err := model.ProductModel{}.Init().Items(w, &rows)
|
||||
if err != nil {
|
||||
l.Errorf("api product items: %v", err)
|
||||
return failResponse(utils.Fail), nil
|
||||
}
|
||||
|
||||
items := make([]*product.ApiItem, 0, len(rows))
|
||||
for _, row := range rows {
|
||||
items = append(items, toApiItem(row))
|
||||
}
|
||||
return okResponse(items), nil
|
||||
}
|
||||
Reference in New Issue
Block a user