This commit is contained in:
laodaming 2023-07-21 12:27:37 +08:00
parent eb25e5bfcc
commit 50817d7ae2
4 changed files with 7 additions and 4 deletions

View File

@ -8,7 +8,7 @@ func (d *FsProductModel3dModel) FindOne(ctx context.Context, id int64) (resp *Fs
err = d.db.WithContext(ctx).Model(&FsProductModel3d{}).Where("`id` = ? ", id).First(&resp).Error
return resp, err
}
func (d *FsProductModel3dModel) GetAllByIds(ctx context.Context, ids []int64, fields ...string) (resp []FsProductModel3d, err error) {
func (d *FsProductModel3dModel) GetAllByIds(ctx context.Context, ids []int64, orderBy string, fields ...string) (resp []FsProductModel3d, err error) {
if len(ids) == 0 {
return
}
@ -16,6 +16,9 @@ func (d *FsProductModel3dModel) GetAllByIds(ctx context.Context, ids []int64, fi
if len(fields) > 0 {
db = db.Select(fields[0])
}
if orderBy != "" {
db = db.Order(orderBy)
}
err = db.Find(&resp).Error
return resp, err
}

View File

@ -65,7 +65,7 @@ func (l *GetOrderDetailLogic) GetOrderDetail(req *types.GetOrderDetailReq, useri
}
//获取配件列表
productModel3dModel := gmodel.NewFsProductModel3dModel(l.svcCtx.MysqlConn)
productModel3dList, err := productModel3dModel.GetAllByIds(l.ctx, optionalIds)
productModel3dList, err := productModel3dModel.GetAllByIds(l.ctx, optionalIds, "")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeServiceErr, "failed to get product 3d models")

View File

@ -136,7 +136,7 @@ func (l *GetTemplatevDetailLogic) GetTemplatevDetail(req *types.GetTemplatevDeta
}
//查询使用该选项的模板
if len(partIds) > 0 {
model3dList, err := productModel3dModel.GetAllByIds(l.ctx, partIds, "id,model_info,option_template")
model3dList, err := productModel3dModel.GetAllByIds(l.ctx, partIds, "", "id,model_info,option_template")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get product 3d model list")

View File

@ -73,7 +73,7 @@ func (l *GetFittingByPidLogic) GetFittingByPid(req *types.GetFittingByPidReq, us
partIds = append(partIds, *v.PartId)
}
//获取配件数据
fittingList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByIds(l.ctx, partIds)
fittingList, err := l.svcCtx.AllModels.FsProductModel3d.GetAllByIds(l.ctx, partIds, "price ASC")
if err != nil {
logx.Error(err)
return resp.SetStatusWithMessage(basic.CodeDbSqlErr, "failed to get part list")