feat: 更新订单分组区块,重量/金额实现方式 feat #600 (#604)

Reviewed-on: daoyoucloud/tachycode#604
Co-authored-by: hello@lv <2256334253@qq.com>
Co-committed-by: hello@lv <2256334253@qq.com>
This commit is contained in:
hello@lv 2024-04-07 20:14:51 +08:00 committed by sealday
parent 511f282b8c
commit bed28c72ac
2 changed files with 49 additions and 7 deletions

View File

@ -0,0 +1,5 @@
---
"@hera/plugin-rental": patch
---
重新订单分组统计区块重量总金额写法

View File

@ -93,16 +93,34 @@ export class RecordPreviewController {
@Action('allweight')
async groupWeight(ctx: Context) {
const { filter } = ctx.action.params.values;
const collectionName = 'records';
const collection = ctx.db.getCollection(collectionName);
const fields = collection.fields;
const filterParser = new FilterParser(filter, {
collection,
});
const { sequelize } = ctx.db;
const records = await ctx.db.getRepository('records').find({
filter,
const { where, include } = filterParser.toSequelizeParams();
const parsedFilterInclude =
include?.map((item) => {
if (fields.get(item.association)?.type === 'belongsToMany') {
item.through = { attributes: [] };
}
return item;
}) || [];
const query = {
where: where || {},
attributes: [
[sequelize.fn('sum', sequelize.col('records.weight')), 'weight'],
[sequelize.col('records.movement'), 'movement'],
],
group: [sequelize.col('records.movement')],
});
include: [...parsedFilterInclude],
order: [],
subQuery: false,
raw: true,
} as any;
const records = await ctx.db.getModel('records').findAll(query);
const inNum = records.find((item) => item.movement === Movement.in)?.weight ?? 0;
const outNum = records.find((item) => item.movement === Movement.out)?.weight ?? 0;
const data = {
@ -114,15 +132,34 @@ export class RecordPreviewController {
@Action('allprice')
async groupPrice(ctx: Context) {
const { filter } = ctx.action.params.values;
const collectionName = 'records';
const collection = ctx.db.getCollection(collectionName);
const fields = collection.fields;
const filterParser = new FilterParser(filter, {
collection,
});
const { sequelize } = ctx.db;
const records = await ctx.db.getRepository('records').find({
filter,
const { where, include } = filterParser.toSequelizeParams();
const parsedFilterInclude =
include?.map((item) => {
if (fields.get(item.association)?.type === 'belongsToMany') {
item.through = { attributes: [] };
}
return item;
}) || [];
const query = {
where: where || {},
attributes: [
[sequelize.fn('sum', sequelize.col('records.all_price')), 'all_price'],
[sequelize.col('records.movement'), 'movement'],
],
group: [sequelize.col('records.movement')],
});
include: [...parsedFilterInclude],
order: [],
subQuery: false,
raw: true,
} as any;
const records = await ctx.db.getModel('records').findAll(query);
const inNum = records.find((item) => item.movement === Movement.in)?.all_price ?? 0;
const outNum = records.find((item) => item.movement === Movement.out)?.all_price ?? 0;