This commit is contained in:
laodaming 2023-08-08 17:03:54 +08:00
parent 584498f556
commit 2f1ef81263
4 changed files with 31 additions and 6 deletions

View File

@ -57,6 +57,9 @@ func (t *FsProductTemplateV2Model) FindAllByModelIds(ctx context.Context, modelI
return return
} }
db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`model_id` in (?) and `is_del` = ? and `status` = ?", modelIds, 0, 1) db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`model_id` in (?) and `is_del` = ? and `status` = ?", modelIds, 0, 1)
if len(fields) != 0 {
db = db.Select(fields[0])
}
switch orderBy { switch orderBy {
case "": case "":
db = db.Order("id DESC") db = db.Order("id DESC")
@ -119,3 +122,20 @@ func (t *FsProductTemplateV2Model) FindOneByProductIdTagIdWithSizeTable(ctx cont
Take(&resp).Error Take(&resp).Error
return resp, err return resp, err
} }
func (t *FsProductTemplateV2Model) FindAllByModelIdsTemplateTag(ctx context.Context, modelIds []int64, templateTag string, orderBy string, fields ...string) (resp []FsProductTemplateV2, err error) {
if len(modelIds) == 0 {
return
}
db := t.db.WithContext(ctx).Model(&FsProductTemplateV2{}).Where("`model_id` in (?) and `tag` = ? and `is_del` = ? and `status` = ?", modelIds, templateTag, 0, 1)
if len(fields) != 0 {
db = db.Select(fields[0])
}
switch orderBy {
case "":
db = db.Order("id DESC")
default:
db = db.Order(orderBy)
}
err = db.Find(&resp).Error
return resp, err
}

View File

@ -42,6 +42,9 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq,
if req.Size > 0 { if req.Size > 0 {
req.Size = image.GetCurrentSize(req.Size) req.Size = image.GetCurrentSize(req.Size)
} }
if req.ProductTemplateTagId <= 0 {
return resp.SetStatusWithMessage(basic.CodeRequestParamsErr, "err param:product_template_tag_id")
}
//获取产品信息(只是获取id) //获取产品信息(只是获取id)
productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Pid, "id") productInfo, err := l.svcCtx.AllModels.FsProduct.FindOneBySn(l.ctx, req.Pid, "id")
if err != nil { if err != nil {
@ -51,7 +54,7 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq,
logx.Error(err) logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info") return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product info")
} }
//获取尺寸ids(只获取) //获取尺寸ids(只获取id)
sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByProductIds(l.ctx, []int64{productInfo.Id}, "id") sizeList, err := l.svcCtx.AllModels.FsProductSize.GetAllByProductIds(l.ctx, []int64{productInfo.Id}, "id")
if err != nil { if err != nil {
logx.Error(err) logx.Error(err)
@ -80,7 +83,7 @@ func (l *GetTemplateByPidLogic) GetTemplateByPid(req *types.GetTemplateByPidReq,
mapModel[v.Id] = k mapModel[v.Id] = k
} }
//获取模板数据 //获取模板数据
productTemplateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByModelIds(l.ctx, modelIds, "sort DESC") productTemplateList, err := l.svcCtx.AllModels.FsProductTemplateV2.FindAllByModelIdsTemplateTag(l.ctx, modelIds, fmt.Sprintf("%d", req.ProductTemplateTagId), "sort DESC")
if err != nil { if err != nil {
logx.Error(err) logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product templates") return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product templates")

View File

@ -342,6 +342,7 @@ type GetSizeByPidRsp struct {
type GetTemplateByPidReq struct { type GetTemplateByPidReq struct {
Pid string `form:"pid"` Pid string `form:"pid"`
Size uint32 `form:"size"` Size uint32 `form:"size"`
ProductTemplateTagId int64 `form:"product_template_tag_id"`
} }
type GetFittingByPidReq struct { type GetFittingByPidReq struct {

View File

@ -387,6 +387,7 @@ type GetSizeByPidRsp {
type GetTemplateByPidReq { type GetTemplateByPidReq {
Pid string `form:"pid"` Pid string `form:"pid"`
Size uint32 `form:"size"` Size uint32 `form:"size"`
ProductTemplateTagId int64 `form:"product_template_tag_id"`
} }
//获取产品配件数据 //获取产品配件数据
type GetFittingByPidReq { type GetFittingByPidReq {