226 lines
8.1 KiB
JavaScript
226 lines
8.1 KiB
JavaScript
export default OakComponent({
|
|
properties: {
|
|
systemId: '',
|
|
},
|
|
lifetimes: {
|
|
ready() {
|
|
this.refreshData();
|
|
}
|
|
},
|
|
data: {
|
|
refreshing: false,
|
|
},
|
|
methods: {
|
|
async refreshData() {
|
|
this.setState({ refreshing: true });
|
|
let { systemId } = this.props;
|
|
if (!systemId) {
|
|
systemId = this.features.application.getApplication().systemId;
|
|
}
|
|
const schema = this.features.cache.getSchema();
|
|
const { ref } = schema.sysAccountOper.attributes.entity;
|
|
const promises = [];
|
|
try {
|
|
promises.push(...ref.map((entity) => {
|
|
const projection = {
|
|
id: 1,
|
|
$$createAt$$: 1,
|
|
$$updateAt$$: 1,
|
|
};
|
|
Object.keys(schema[entity].attributes).forEach(ele => {
|
|
if (!ele.startsWith('$$')) {
|
|
projection[ele] = 1;
|
|
}
|
|
});
|
|
return this.features.cache.refresh(entity, {
|
|
data: projection,
|
|
filter: {
|
|
systemId,
|
|
}
|
|
});
|
|
}));
|
|
promises.push((async () => {
|
|
const result = await this.features.cache.aggregate('account', {
|
|
data: {
|
|
'#count-1': {
|
|
id: 1,
|
|
},
|
|
'#sum-1': {
|
|
total: 1,
|
|
},
|
|
'#sum-2': {
|
|
avail: 1,
|
|
},
|
|
},
|
|
filter: {
|
|
ofSystemId: systemId,
|
|
}
|
|
});
|
|
const { '#count-1': accountNum, '#sum-1': accountTotalSum, '#sum-2': accountAvailSum } = result[0];
|
|
this.setState({
|
|
accountNum,
|
|
accountTotalSum,
|
|
accountAvailSum,
|
|
});
|
|
})());
|
|
/* (async () => {
|
|
const { data: [account] } = await this.features.cache.refresh('account', {
|
|
data: {
|
|
id: 1,
|
|
total: 1,
|
|
avail: 1,
|
|
},
|
|
filter: {
|
|
entity: 'system',
|
|
entityId: systemId,
|
|
}
|
|
});
|
|
|
|
this.setState({
|
|
systemAccountTotal: account.total!,
|
|
systemAccountAvail: account.avail!,
|
|
});
|
|
})(); */
|
|
promises.push((async () => {
|
|
const result = await this.features.cache.aggregate('refund', {
|
|
data: {
|
|
'#count-1': {
|
|
id: 1,
|
|
},
|
|
'#sum-1': {
|
|
price: 1,
|
|
},
|
|
},
|
|
filter: {
|
|
iState: 'refunding',
|
|
$or: [
|
|
{
|
|
pay: {
|
|
application: {
|
|
systemId,
|
|
}
|
|
}
|
|
},
|
|
{
|
|
withdraw: {
|
|
account: {
|
|
ofSystemId: systemId,
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
});
|
|
const { '#count-1': refundCnt, '#sum-1': refundPriceSum } = result[0];
|
|
this.setState({
|
|
refundCnt,
|
|
refundPriceSum,
|
|
});
|
|
})());
|
|
promises.push((async () => {
|
|
const result = await this.features.cache.aggregate('withdrawTransfer', {
|
|
data: {
|
|
'#count-1': {
|
|
id: 1,
|
|
},
|
|
'#sum-1': {
|
|
price: 1,
|
|
},
|
|
},
|
|
filter: {
|
|
iState: 'transferring',
|
|
withdraw: {
|
|
account: {
|
|
ofSystemId: systemId,
|
|
}
|
|
}
|
|
}
|
|
});
|
|
const { '#count-1': transferCnt, '#sum-1': transferPriceSum } = result[0];
|
|
this.setState({
|
|
transferCnt,
|
|
transferPriceSum,
|
|
});
|
|
})());
|
|
promises.push((async () => {
|
|
const result = await this.features.cache.aggregate('order', {
|
|
data: {
|
|
'#count-1': {
|
|
id: 1,
|
|
},
|
|
'#sum-1': {
|
|
paid: 1,
|
|
},
|
|
'#sum-2': {
|
|
refunded: 1,
|
|
},
|
|
},
|
|
filter: {
|
|
settled: 0,
|
|
price: {
|
|
$gt: 0,
|
|
},
|
|
systemId,
|
|
},
|
|
});
|
|
const { '#count-1': orderCnt, '#sum-1': orderPaidSum, '#sum-2': orderRefundedSum } = result[0];
|
|
this.setState({
|
|
orderCnt,
|
|
orderPaidSum,
|
|
orderRefundedSum,
|
|
});
|
|
})());
|
|
await Promise.all(promises);
|
|
this.setState({ refreshing: false });
|
|
this.reRender();
|
|
}
|
|
catch (e) {
|
|
this.setState({ refreshing: false });
|
|
throw e;
|
|
}
|
|
},
|
|
},
|
|
formData({ features }) {
|
|
let { systemId } = this.props;
|
|
if (!systemId) {
|
|
systemId = this.features.application.getApplication().systemId;
|
|
}
|
|
const schema = features.cache.getSchema();
|
|
const { ref } = schema.sysAccountOper.attributes.entity;
|
|
let total = 0;
|
|
const accounts = ref.map((entity) => {
|
|
const projection = {
|
|
id: 1,
|
|
$$createAt$$: 1,
|
|
$$updateAt$$: 1,
|
|
};
|
|
Object.keys(schema[entity].attributes).forEach(ele => {
|
|
if (!ele.startsWith('$$')) {
|
|
projection[ele] = 1;
|
|
}
|
|
});
|
|
const data = this.features.cache.get(entity, {
|
|
data: projection,
|
|
filter: {
|
|
systemId,
|
|
}
|
|
});
|
|
data.forEach(ele => total += ele.price || 0);
|
|
return data.map((ele) => {
|
|
return {
|
|
entity,
|
|
data: {
|
|
...ele,
|
|
color: entity === 'offlineAccount' && features.style.getColor('offlineAccount', 'type', ele.type),
|
|
}
|
|
};
|
|
});
|
|
}).flat();
|
|
return {
|
|
total,
|
|
accounts,
|
|
systemId,
|
|
};
|
|
},
|
|
});
|