格式化:Prettier统一代码风格(仅格式,无逻辑变化)

仅为 npm run format 的输出;黄金对照、旧库兼容、浏览器流程与单元测试全部通过且零差异。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
黄健铭andClaude Opus 5.5 committed 2026-12-04 08:58:53 -08:00
1 parent 3743d687e7
commit 28c64814f0
221 files changed
+116943 -26708

No files matched your search

+46 -25
View File
@@ -1,31 +1,52 @@
'use strict';
// 月度业绩只重排原订单与售后利润,不生成结算、转账或新的利润分录。
const DailyProfit=require('./daily-profit');
const TeamMembers=require('./team-members'),ShopSettings=require('./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));
const DailyProfit = require('./daily-profit');
const TeamMembers = require('./team-members'),
ShopSettings = require('./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);
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};
module.exports = { report };