feat: product item
This commit is contained in:
@@ -147,3 +147,43 @@ type ProductEditBase struct {
|
||||
AdminName string `gorm:"column:admin_name"`
|
||||
AdminId int `gorm:"column:admin_id"`
|
||||
}
|
||||
|
||||
// ProductInfo 列表/详情查询投影
|
||||
type ProductInfo struct {
|
||||
Id int `gorm:"column:id"`
|
||||
Name string `gorm:"column:name"`
|
||||
Subhead string `gorm:"column:subhead"`
|
||||
Content string `gorm:"column:content"`
|
||||
ModelCode string `gorm:"column:model_code"`
|
||||
Price float32 `gorm:"column:price"`
|
||||
StorePrice float32 `gorm:"column:store_price"`
|
||||
SalePrice float32 `gorm:"column:sale_price"`
|
||||
SharePrice float32 `gorm:"column:share_price"`
|
||||
AgentPrice float32 `gorm:"column:agent_price"`
|
||||
SaleReward string `gorm:"column:sale_reward"`
|
||||
SalesModel uint8 `gorm:"column:sales_model"`
|
||||
Waybill string `gorm:"column:waybill"`
|
||||
Status uint8 `gorm:"column:status"`
|
||||
Weight float32 `gorm:"column:weight"`
|
||||
IsIndex uint8 `gorm:"column:is_index"`
|
||||
IndexImage string `gorm:"column:index_image"`
|
||||
Cubage string `gorm:"column:cubage"`
|
||||
Label string `gorm:"column:label"`
|
||||
Images string `gorm:"column:images"`
|
||||
IsBuy uint8 `gorm:"column:is_buy"`
|
||||
PeriodValidity int16 `gorm:"column:period_validity"`
|
||||
PublishTime time.Time `gorm:"column:publish_time"`
|
||||
Type uint8 `gorm:"column:type"`
|
||||
NormsNumber uint8 `gorm:"column:norms_number"`
|
||||
BoxNumber float64 `gorm:"column:box_number"`
|
||||
Sort uint16 `gorm:"column:sort"`
|
||||
Number uint `gorm:"column:number"`
|
||||
VerifyStatus uint8 `gorm:"column:verify_status"`
|
||||
VerifyId int `gorm:"column:verify_id"`
|
||||
VerifyName string `gorm:"column:verify_name"`
|
||||
VerifySecondId int `gorm:"column:verify_second_id"`
|
||||
VerifySecondName string `gorm:"column:verify_second_name"`
|
||||
Reason string `gorm:"column:reason"`
|
||||
AdminName string `gorm:"column:admin_name"`
|
||||
Edit uint8 `gorm:"-"`
|
||||
}
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"product/internal/dao"
|
||||
"product/internal/model"
|
||||
"product/internal/svc"
|
||||
"product/product"
|
||||
"product/validator"
|
||||
|
||||
"pkg.local/log"
|
||||
"pkg.local/modelbase"
|
||||
"pkg.local/utils"
|
||||
validateService "pkg.local/validate"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
type ItemsLogic struct {
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
logx.Logger
|
||||
}
|
||||
|
||||
func NewItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ItemsLogic {
|
||||
return &ItemsLogic{
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
Logger: logx.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ItemsLogic) Items(in *product.ItemsReq) (*product.ItemsResp, error) {
|
||||
var req validator.ProductItemsValidator
|
||||
if msg := validateService.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||
return nil, status.Error(codes.InvalidArgument, msg)
|
||||
}
|
||||
|
||||
page := int(req.Page)
|
||||
size := int(req.PageSize)
|
||||
if page < modelbase.DefaultPage {
|
||||
page = modelbase.DefaultPage
|
||||
}
|
||||
if size < modelbase.DefaultPage {
|
||||
size = modelbase.DefaultSize
|
||||
}
|
||||
|
||||
w := modelbase.Params{
|
||||
Page: page,
|
||||
Size: size,
|
||||
Order: "sort DESC, id DESC",
|
||||
}
|
||||
if len(req.Name) > utils.NumberZero {
|
||||
w.Like = map[string]string{
|
||||
"name LIKE ? ": "%%" + req.Name + "%%",
|
||||
}
|
||||
}
|
||||
|
||||
var info []dao.ProductInfo
|
||||
result, err := model.ProductModel{}.Init().Page(w, &info)
|
||||
if err != nil {
|
||||
log.Errorf("product items: %v", err)
|
||||
return nil, status.Error(codes.Internal, "查询失败")
|
||||
}
|
||||
|
||||
items := make([]*product.Item, 0, len(info))
|
||||
for _, row := range info {
|
||||
items = append(items, toProductItem(row))
|
||||
}
|
||||
|
||||
return &product.ItemsResp{
|
||||
Count: result.Count,
|
||||
Items: items,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func toProductItem(row dao.ProductInfo) *product.Item {
|
||||
publishTime := ""
|
||||
if !row.PublishTime.IsZero() {
|
||||
publishTime = row.PublishTime.Format(time.DateTime)
|
||||
}
|
||||
return &product.Item{
|
||||
Id: int64(row.Id),
|
||||
Name: row.Name,
|
||||
Subhead: row.Subhead,
|
||||
Content: row.Content,
|
||||
ModelCode: row.ModelCode,
|
||||
Price: float64(row.Price),
|
||||
StorePrice: float64(row.StorePrice),
|
||||
SalePrice: float64(row.SalePrice),
|
||||
SharePrice: float64(row.SharePrice),
|
||||
AgentPrice: float64(row.AgentPrice),
|
||||
SaleReward: row.SaleReward,
|
||||
SalesModel: uint32(row.SalesModel),
|
||||
Waybill: row.Waybill,
|
||||
Status: uint32(row.Status),
|
||||
Weight: float64(row.Weight),
|
||||
IsIndex: uint32(row.IsIndex),
|
||||
IndexImage: row.IndexImage,
|
||||
Cubage: row.Cubage,
|
||||
Label: row.Label,
|
||||
Images: row.Images,
|
||||
IsBuy: uint32(row.IsBuy),
|
||||
PeriodValidity: int32(row.PeriodValidity),
|
||||
PublishTime: publishTime,
|
||||
Type: uint32(row.Type),
|
||||
NormsNumber: uint32(row.NormsNumber),
|
||||
BoxNumber: row.BoxNumber,
|
||||
Sort: uint32(row.Sort),
|
||||
Number: uint32(row.Number),
|
||||
VerifyStatus: uint32(row.VerifyStatus),
|
||||
VerifyId: int64(row.VerifyId),
|
||||
VerifyName: row.VerifyName,
|
||||
VerifySecondId: int64(row.VerifySecondId),
|
||||
VerifySecondName: row.VerifySecondName,
|
||||
Reason: row.Reason,
|
||||
AdminName: row.AdminName,
|
||||
Edit: uint32(row.Edit),
|
||||
}
|
||||
}
|
||||
@@ -32,3 +32,8 @@ func (s *ProductServer) Edit(ctx context.Context, in *product.EditReq) (*product
|
||||
l := logic.NewEditLogic(ctx, s.svcCtx)
|
||||
return l.Edit(in)
|
||||
}
|
||||
|
||||
func (s *ProductServer) Items(ctx context.Context, in *product.ItemsReq) (*product.ItemsResp, error) {
|
||||
l := logic.NewItemsLogic(ctx, s.svcCtx)
|
||||
return l.Items(in)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user