订单增加打印登记,支持多商品销售公式识别预填
This commit is contained in:
1 parent
6cde5e6999
commit
718dbfde2c
13 files changed
+339
-15
No files matched your search
+16
-6
@@ -6,6 +6,7 @@ const crypto=require('node:crypto');
|
||||
const {DatabaseSync,backup}=require('node:sqlite');
|
||||
const TeamMembers=require('./team-members');
|
||||
const ShopSettings=require('./shop-settings');
|
||||
const PrintStatus=require('./print-status');
|
||||
const OrderChanges=require('./order-changes');
|
||||
const OrderNoteTags=require('./order-note-tags');
|
||||
const {inventoryMovementsFile}=require('./inventory-movements-export');
|
||||
@@ -122,6 +123,15 @@ function createApp(options={}){
|
||||
if(!actor)fail('请先登录',401);
|
||||
// 仅校验本次页面的原账号与cookie一致,实际授权仍由登录和成员权限决定。
|
||||
if(req.headers['x-ledger-user']!==undefined&&req.headers['x-ledger-user']!==actor.id){const error=new Error('登录账号已在其他页面切换,请刷新后继续;原操作已暂停。');error.status=409;error.code='ACCOUNT_CHANGED';throw error;}
|
||||
const printStatusMatch=route.match(/^\/api\/print-status\/(order|recovery)\/([a-f0-9-]{36})$/);
|
||||
if(printStatusMatch){
|
||||
const [,kind,id]=printStatusMatch;
|
||||
PrintStatus.access(actorLedger,kind,id,actor);
|
||||
if(!isPost)return send(res,200,PrintStatus.read(actorLedger,kind,id,actor));
|
||||
const body=await read(req);PrintStatus.access(actorLedger,kind,id,actor);
|
||||
const result=actorLedger.transact(req.headers['idempotency-key'],actor,{route,body},()=>PrintStatus.update(actorLedger,kind,id,body,actor),{syncTeamFunds:false});
|
||||
return send(res,200,result);
|
||||
}
|
||||
if(route==='/api/shop-settings'&&!isPost)return send(res,200,ShopSettings.publicSettings(actorLedger,actor));
|
||||
if(isPost&&['/api/shop-settings','/api/printing'].includes(route))owner(actor);
|
||||
if(route==='/api/team-members'&&!isPost)return send(res,200,actorLedger.teamMembers());
|
||||
@@ -146,9 +156,9 @@ function createApp(options={}){
|
||||
const afterSaleMatch=route.match(/^\/api\/after-sales\/([a-f0-9-]{36})(?:\/(update))?$/);
|
||||
if(afterSaleMatch&&!isPost){if(afterSaleMatch[2])fail('地址不存在',404);return send(res,200,actorLedger.afterSale(afterSaleMatch[1],actor));}
|
||||
if(route==='/api/customer-materials'&&!isPost)return send(res,200,actorLedger.customerMaterials(Object.fromEntries(url.searchParams),actor));
|
||||
if(route==='/api/recoveries'&&!isPost)return send(res,200,actorLedger.recoveries(Object.fromEntries(url.searchParams),actor));
|
||||
if(route==='/api/recoveries'&&!isPost){const result=actorLedger.recoveries(Object.fromEntries(url.searchParams),actor);return send(res,200,{...result,rows:result.rows.map(row=>({...row,printStatus:PrintStatus.projection(actorLedger,'recovery',row.id)}))});}
|
||||
const recoveryMatch=route.match(/^\/api\/recoveries\/([a-f0-9-]{36})(?:\/(edit|update|cancel|quote))?$/);
|
||||
if(recoveryMatch&&!isPost){if(recoveryMatch[2]==='edit')return send(res,200,actorLedger.recoveryEdit(recoveryMatch[1],actor));if(recoveryMatch[2])fail('地址不存在',404);return send(res,200,actorLedger.recovery(recoveryMatch[1],actor));}
|
||||
if(recoveryMatch&&!isPost){if(recoveryMatch[2]==='edit'){const result=actorLedger.recoveryEdit(recoveryMatch[1],actor);return send(res,200,{...result,record:{...result.record,printStatus:PrintStatus.projection(actorLedger,'recovery',recoveryMatch[1])}});}if(recoveryMatch[2])fail('地址不存在',404);return send(res,200,{...actorLedger.recovery(recoveryMatch[1],actor),printStatus:PrintStatus.projection(actorLedger,'recovery',recoveryMatch[1])});}
|
||||
if(route==='/api/recovery-changes'&&!isPost)return send(res,200,actorLedger.recoveryChanges(Object.fromEntries(url.searchParams),actor));
|
||||
const recoveryChangeMatch=route.match(/^\/api\/recovery-changes\/([a-f0-9-]{36})(?:\/(approve|reject))?$/);
|
||||
if(recoveryChangeMatch&&!isPost){if(recoveryChangeMatch[2])fail('地址不存在',404);return send(res,200,actorLedger.recoveryChange(recoveryChangeMatch[1],actor));}
|
||||
@@ -200,10 +210,10 @@ function createApp(options={}){
|
||||
const orderAfterSaleMatch=route.match(/^\/api\/orders\/([a-f0-9-]+)\/(after-sale|after-sale-preview)$/);
|
||||
if(orderAfterSaleMatch&&!isPost){if(orderAfterSaleMatch[2]!=='after-sale')fail('地址不存在',404);return send(res,200,actorLedger.orderAfterSale(orderAfterSaleMatch[1],actor));}
|
||||
const match=route.match(/^\/api\/orders\/([a-f0-9-]+)(?:\/([a-z]+))?$/);
|
||||
if(match&&!isPost){if(match[2]==='public')return send(res,200,actorLedger.publicOrder(match[1]));if(match[2]==='edit')return send(res,200,actorLedger.orderEdit(match[1],actor));if(match[2]==='change')return send(res,200,actorLedger.orderChange(match[1],actor));if(match[2]==='ownership')return send(res,200,actorLedger.orderOwnership(match[1],actor));if(match[2]==='cancellation')return send(res,200,actorLedger.orderCancellation(match[1],actor));if(!match[2])return send(res,200,actorLedger.detail(match[1]));fail('地址不存在',404);}
|
||||
if(match&&!isPost){if(match[2]==='public')return send(res,200,actorLedger.publicOrder(match[1]));if(match[2]==='edit')return send(res,200,actorLedger.orderEdit(match[1],actor));if(match[2]==='change')return send(res,200,actorLedger.orderChange(match[1],actor));if(match[2]==='ownership')return send(res,200,actorLedger.orderOwnership(match[1],actor));if(match[2]==='cancellation')return send(res,200,actorLedger.orderCancellation(match[1],actor));if(!match[2])return send(res,200,{...actorLedger.detail(match[1]),printStatus:PrintStatus.projection(actorLedger,'order',match[1])});fail('地址不存在',404);}
|
||||
const recoveryPrintMatch=route.match(/^\/print\/recoveries\/([a-f0-9-]{36})$/);
|
||||
if(recoveryPrintMatch&&!isPost){const dto=actorLedger.publicRecovery(recoveryPrintMatch[1],actor),print=dto.mode==='exchange'?exchangeCustomerPrintDocument:recoveryCustomerPrintDocument;return send(res,200,print(dto,ShopSettings.printingSettings(actorLedger)),'text/html; charset=utf-8');}
|
||||
if(route.startsWith('/print/')&&!isPost){const id=route.slice(7),order=actorLedger.detail(id);if(order.recovery_id){const dto=actorLedger.publicRecovery(order.recovery_id,actor);return send(res,200,exchangeCustomerPrintDocument(dto,ShopSettings.printingSettings(actorLedger)),'text/html; charset=utf-8');}return send(res,200,receipt(actorLedger.publicOrder(id),ShopSettings.printingSettings(actorLedger),url.searchParams.get('mode')),'text/html; charset=utf-8');}
|
||||
if(recoveryPrintMatch&&!isPost){const dto=actorLedger.publicRecovery(recoveryPrintMatch[1],actor),print=dto.mode==='exchange'?exchangeCustomerPrintDocument:recoveryCustomerPrintDocument;return send(res,200,PrintStatus.decorate(print(dto,ShopSettings.printingSettings(actorLedger)),actorLedger,'recovery',recoveryPrintMatch[1],actor),'text/html; charset=utf-8');}
|
||||
if(route.startsWith('/print/')&&!isPost){const id=route.slice(7),order=actorLedger.detail(id);if(order.recovery_id){const dto=actorLedger.publicRecovery(order.recovery_id,actor);return send(res,200,PrintStatus.decorate(exchangeCustomerPrintDocument(dto,ShopSettings.printingSettings(actorLedger)),actorLedger,'order',id,actor),'text/html; charset=utf-8');}return send(res,200,PrintStatus.decorate(receipt(actorLedger.publicOrder(id),ShopSettings.printingSettings(actorLedger),url.searchParams.get('mode')),actorLedger,'order',id,actor),'text/html; charset=utf-8');}
|
||||
if(route==='/api/report'&&!isPost){
|
||||
return send(res,200,actorLedger.reportFor(Object.fromEntries(url.searchParams),actor));
|
||||
}
|
||||
@@ -281,7 +291,7 @@ function createApp(options={}){
|
||||
fail('地址不存在',404);
|
||||
},{syncTeamFunds:!['/api/pockets','/api/shop-settings','/api/printing'].includes(route)&&!pocketMatch});return send(res,200,route==='/api/people-count'?peopleCountResponse(actorLedger,result,actor):result);
|
||||
}
|
||||
const assets={'/':'index.html','/app.js':'app.js','/order-copy.js':'order-copy.js','/order-templates.js':'order-templates.js','/order-templates-ui.js':'order-templates-ui.js','/order-edit-ui.js':'order-edit-ui.js','/order-cancellations-ui.js':'order-cancellations-ui.js','/order-changes-ui.js':'order-changes-ui.js','/order-after-sales-ui.js':'order-after-sales-ui.js','/order-ownership-ui.js':'order-ownership-ui.js','/daily-funds-ui.js':'daily-funds-ui.js','/team-funds-ui.js':'team-funds-ui.js','/cost-funding-ui.js':'cost-funding-ui.js','/price-locks-ui.js':'price-locks-ui.js','/price-lock-changes-ui.js':'price-lock-changes-ui.js','/material-pools-ui.js':'material-pools-ui.js','/recoveries-ui.js':'recoveries-ui.js','/recovery-changes-ui.js':'recovery-changes-ui.js','/inventory-changes-ui.js':'inventory-changes-ui.js','/pockets-ui.js':'pockets-ui.js','/shop-settings-ui.js':'shop-settings-ui.js','/credit-card-fees.js':'credit-card-fees.js','/calculations.js':'calculations.js','/fee-estimates.js':'fee-estimates.js','/order-cost-presets-ui.js':'order-cost-presets-ui.js','/app.css':'app.css','/print.js':'print.js'};const file=assets[route];if(!file||isPost)fail('地址不存在',404);
|
||||
const assets={'/':'index.html','/app.js':'app.js','/order-copy.js':'order-copy.js','/order-templates.js':'order-templates.js','/order-templates-ui.js':'order-templates-ui.js','/order-edit-ui.js':'order-edit-ui.js','/order-cancellations-ui.js':'order-cancellations-ui.js','/order-changes-ui.js':'order-changes-ui.js','/order-after-sales-ui.js':'order-after-sales-ui.js','/order-ownership-ui.js':'order-ownership-ui.js','/daily-funds-ui.js':'daily-funds-ui.js','/team-funds-ui.js':'team-funds-ui.js','/cost-funding-ui.js':'cost-funding-ui.js','/price-locks-ui.js':'price-locks-ui.js','/price-lock-changes-ui.js':'price-lock-changes-ui.js','/material-pools-ui.js':'material-pools-ui.js','/recoveries-ui.js':'recoveries-ui.js','/recovery-changes-ui.js':'recovery-changes-ui.js','/inventory-changes-ui.js':'inventory-changes-ui.js','/pockets-ui.js':'pockets-ui.js','/shop-settings-ui.js':'shop-settings-ui.js','/credit-card-fees.js':'credit-card-fees.js','/calculations.js':'calculations.js','/order-formula.js':'order-formula.js','/fee-estimates.js':'fee-estimates.js','/order-cost-presets-ui.js':'order-cost-presets-ui.js','/app.css':'app.css','/print.js':'print.js'};const file=assets[route];if(!file||isPost)fail('地址不存在',404);
|
||||
send(res,200,fs.readFileSync(path.join(__dirname,'public',file)),file.endsWith('.js')?'application/javascript; charset=utf-8':file.endsWith('.css')?'text/css; charset=utf-8':'text/html; charset=utf-8');
|
||||
}catch(e){if(!res.headersSent)send(res,e.status||400,{error:e.status||e.message?.startsWith('打印')?e.message:(e.code?.startsWith('SQLITE')?'保存失败,请保留操作内容并联系维护者':e.message||'操作失败'),...(e.code==='ACCOUNT_CHANGED'?{code:e.code}:{}),...(e.code==='RECOVERY_MATERIAL_IN_USE'?{code:e.code,blockedUsages:e.blockedUsages}:{})});else res.end();}
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user