From 50817d7ae231bce98fff93c73bb0af232ca2704d Mon Sep 17 00:00:00 2001 From: laodaming <11058467+laudamine@user.noreply.gitee.com> Date: Fri, 21 Jul 2023 12:27:37 +0800 Subject: [PATCH] fix --- model/gmodel/fs_product_model3d_logic.go | 5 ++++- server/orders/internal/logic/getorderdetaillogic.go | 2 +- .../internal/logic/gettemplatevdetaillogic.go | 2 +- server/product/internal/logic/getfittingbypidlogic.go | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/model/gmodel/fs_product_model3d_logic.go b/model/gmodel/fs_product_model3d_logic.go index 1c86db83..35270c57 100755 --- a/model/gmodel/fs_product_model3d_logic.go +++ b/model/gmodel/fs_product_model3d_logic.go @@ -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 } diff --git a/server/orders/internal/logic/getorderdetaillogic.go b/server/orders/internal/logic/getorderdetaillogic.go index 21c3330e..966decc3 100644 --- a/server/orders/internal/logic/getorderdetaillogic.go +++ b/server/orders/internal/logic/getorderdetaillogic.go @@ -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") diff --git a/server/product-template/internal/logic/gettemplatevdetaillogic.go b/server/product-template/internal/logic/gettemplatevdetaillogic.go index dcce87fb..12324f50 100644 --- a/server/product-template/internal/logic/gettemplatevdetaillogic.go +++ b/server/product-template/internal/logic/gettemplatevdetaillogic.go @@ -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") diff --git a/server/product/internal/logic/getfittingbypidlogic.go b/server/product/internal/logic/getfittingbypidlogic.go index 471d9249..4a62b3e2 100644 --- a/server/product/internal/logic/getfittingbypidlogic.go +++ b/server/product/internal/logic/getfittingbypidlogic.go @@ -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")