This commit is contained in:
laodaming 2023-09-12 17:26:44 +08:00
parent 4a09fc3955
commit ef946ed0e8
5 changed files with 43 additions and 11 deletions

View File

@ -4,8 +4,12 @@ import (
"context"
)
func (d *FsProductModel3dModel) FindOne(ctx context.Context, id int64) (resp *FsProductModel3d, err error) {
err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`id` = ? ", id).First(&resp).Error
func (d *FsProductModel3dModel) FindOne(ctx context.Context, id int64, fields ...string) (resp *FsProductModel3d, err error) {
db := d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`id` = ? ", id)
if len(fields) > 0 {
db = db.Select(fields[0])
}
err = db.Take(&resp).Error
return resp, err
}
func (d *FsProductModel3dModel) GetAllByIds(ctx context.Context, ids []int64, orderBy string, fields ...string) (resp []FsProductModel3d, err error) {

View File

@ -4,8 +4,12 @@ import (
"context"
)
func (s *FsProductSizeModel) FindOne(ctx context.Context, id int64) (resp *FsProductSize, err error) {
err = s.db.WithContext(ctx).Model(&FsProductSize{}).Where("`id` = ? ", id).Take(&resp).Error
func (s *FsProductSizeModel) FindOne(ctx context.Context, id int64, fields ...string) (resp *FsProductSize, err error) {
db := s.db.WithContext(ctx).Model(&FsProductSize{}).Where("`id` = ? ", id)
if len(fields) > 0 {
db = db.Select(fields[0])
}
err = db.Take(&resp).Error
return resp, err
}
func (s *FsProductSizeModel) GetAllByIds(ctx context.Context, ids []int64, sort string) (resp []FsProductSize, err error) {

View File

@ -124,12 +124,17 @@ func (t *FsProductTemplateV2Model) FindOneCloudRenderByProductIdModelIdTemplateT
}
// 获取开启云渲染模板2
func (t *FsProductTemplateV2Model) FindOneCloudRenderByProductIdTemplateTag(ctx context.Context, productId int64, templateTag string) (resp *FsProductTemplateV2, err error) {
err = t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).
func (t *FsProductTemplateV2Model) FindOneCloudRenderByProductIdTemplateTag(ctx context.Context, productId int64, templateTag string, sort string, fields ...string) (resp *FsProductTemplateV2, err error) {
db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).
Where("product_id = ? and template_tag = ? and element_model_id > ? ", productId, templateTag, 0).
Where("status = ? and is_del = ?", 1, 0).
Order("sort ASC").
Take(&resp).Error
Where("status = ? and is_del = ?", 1, 0)
if sort != "" {
db = db.Order(sort)
}
if len(fields) > 0 {
db = db.Select(fields[0])
}
err = db.Take(&resp).Error
return resp, err
}
func (t *FsProductTemplateV2Model) FindAllByModelIdsTemplateTag(ctx context.Context, modelIds []int64, templateTag string, orderBy string, fields ...string) (resp []FsProductTemplateV2, err error) {

View File

@ -50,6 +50,21 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info")
}
//获取跟列表页云渲染一样的默认渲染尺寸(模板->尺寸)
defaultSizeId := int64(0)
defaultTemplate, err := l.svcCtx.AllModels.FsProductTemplateV2.FindOneCloudRenderByProductIdTemplateTag(l.ctx, productInfo.Id, req.TemplateTag, "sort ASC", "model_id")
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get default template ")
} else {
//根据模板找到模型sizeId
defaultModel3d, err := l.svcCtx.AllModels.FsProductModel3d.FindOne(l.ctx, *defaultTemplate.ModelId, "size_id")
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get default model ")
}
defaultSizeId = *defaultModel3d.SizeId
}
//获取产品尺寸列表(需要正序排序)
sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByProductIds(l.ctx, []int64{productInfo.Id}, "is_hot DESC,sort ASC")
if err != nil {
@ -58,9 +73,13 @@ func (l *GetSizeByPidLogic) GetSizeByPid(req *types.GetSizeByPidReq, userinfo *a
}
sizeIds := make([]int64, 0, len(sizeList))
productIds := make([]int64, 0, len(sizeList))
for _, v := range sizeList {
for k, v := range sizeList {
sizeIds = append(sizeIds, v.Id)
productIds = append(productIds, *v.ProductId)
//把默认的排第一
if v.Id == defaultSizeId {
sizeList[0], sizeList[k] = sizeList[k], sizeList[0]
}
}
//获取产品价格列表
productPriceList, err := l.svcCtx.AllModels.FsProductPrice.GetSimplePriceListByProductIds(l.ctx, productIds)

View File

@ -303,7 +303,7 @@ func (w *wsConnectItem) getProductRelateionInfoWithSizeId(renderImageData *webso
func (w *wsConnectItem) getProductRelateionInfoWithNoSizeId(renderImageData *websocket_data.RenderImageReqMsg) (productSize *gmodel.FsProductSize, productTemplate *gmodel.FsProductTemplateV2, model3d *gmodel.FsProductModel3d, err error) {
//指定尺寸(尺寸 -> 模型 ->模板)
//获取模板
productTemplate, err = w.logic.svcCtx.AllModels.FsProductTemplateV2.FindOneCloudRenderByProductIdTemplateTag(w.logic.ctx, renderImageData.RenderData.ProductId, renderImageData.RenderData.TemplateTag)
productTemplate, err = w.logic.svcCtx.AllModels.FsProductTemplateV2.FindOneCloudRenderByProductIdTemplateTag(w.logic.ctx, renderImageData.RenderData.ProductId, renderImageData.RenderData.TemplateTag, "sort ASC")
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
w.renderErrResponse(renderImageData.RenderId, renderImageData.RenderData.TemplateTag, "", "找不到对应开启云渲染模板", renderImageData.RenderData.ProductId, w.userId, w.guestId, 0, 0, 0, 0)