目录重组:后端按core/domains分领域存放(仅移动与更新引用)
- 50个后端模块用git mv移入core/与domains/<领域>/,入口server.js、launch.js、restore.js及server/原位不动 - 所有require路径由脚本按新旧位置统一换算(后端、server/、测试) - 新增test/app-paths.test.js,锁定默认数据目录、public目录与飞书配置文件的绝对位置 - 维护与部署.md补充目录说明并更新模块路径 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
95c481c74a
commit
9ec37196d4
172 files changed
+458
-384
No files matched your search
@@ -0,0 +1,52 @@
|
||||
'use strict';
|
||||
// 月度业绩只重排原订单与售后利润,不生成结算、转账或新的利润分录。
|
||||
const DailyProfit = require('./daily-profit');
|
||||
const TeamMembers = require('../team/team-members'),
|
||||
ShopSettings = require('../team/shop-settings');
|
||||
function share(profit, percent) {
|
||||
if (profit === null) return null;
|
||||
if (!Number.isSafeInteger(profit) || !Number.isSafeInteger(percent) || percent < 0 || percent > 100)
|
||||
throw new Error('月利润或分成比例无效');
|
||||
const sign = profit < 0 ? -1n : 1n;
|
||||
return Number(sign * ((BigInt(Math.abs(profit)) * BigInt(percent) + 50n) / 100n));
|
||||
}
|
||||
|
||||
function report(ledger, query = {}, actor = ledger.actor, env) {
|
||||
if (actor?.role !== 'owner') env.fail('团队账目仅麦麦账号可查看', 403);
|
||||
const today = env.today(),
|
||||
month = String(query.month ?? today.slice(0, 7));
|
||||
if (!/^\d{4}-(0[1-9]|1[0-2])$/.test(month) || month < '2000-01' || month > today.slice(0, 7))
|
||||
env.fail('请选择2000年1月至本月之间的有效月份');
|
||||
const from = month + '-01',
|
||||
[year, number] = month.split('-').map(Number);
|
||||
const monthEnd = new Date(Date.UTC(year, number, 0)).toISOString().slice(0, 10),
|
||||
date = monthEnd < today ? monthEnd : today;
|
||||
const history = ShopSettings.read(ledger).profitShareHistory ?? [{ month: '2000-01', percent: 30 }];
|
||||
const shareRate =
|
||||
[...history]
|
||||
.filter(row => row.month <= month)
|
||||
.sort((a, b) => a.month.localeCompare(b.month))
|
||||
.at(-1)?.percent ?? 30;
|
||||
return ledger.scope(
|
||||
actor,
|
||||
() => {
|
||||
const book = ledger.orderBook({ from, date, status: 'all' });
|
||||
const rows = TeamMembers.members(ledger)
|
||||
.filter(row => row.member !== 'owner')
|
||||
.map(({ member, label }) => {
|
||||
const summary = DailyProfit.project(ledger, {
|
||||
rows: book.rows,
|
||||
groups: { [member]: { name: label } },
|
||||
from,
|
||||
date,
|
||||
}).summary;
|
||||
const profit = summary.incomplete ? null : summary.profit;
|
||||
return { member, name: label, ...summary, profit, shareRate, estimatedShare: share(profit, shareRate) };
|
||||
});
|
||||
return { basis: 'orderDate', month, from, date, rows };
|
||||
},
|
||||
null,
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = { report };
|
||||
Reference in new issue
Block a user