新增老板专属私域运营概况与订单新老客户统计
This commit is contained in:
1 parent
000a80af3c
commit
d18089aaf6
21 files changed
+248
-79
No files matched your search
+8
-4
@@ -156,6 +156,9 @@ function createApp(options={}){
|
||||
const pocketMatch=route.match(/^\/api\/pockets\/([^/]+)\/update$/);
|
||||
if(isPost&&(route==='/api/pockets'||pocketMatch))owner(actor);
|
||||
if(route==='/api/team-funds'&&!isPost){owner(actor);return send(res,200,actorLedger.teamFunds(Object.fromEntries(url.searchParams),actor));}
|
||||
if(['/api/private-operations','/api/private-operations/people','/api/people-count','/api/people-count-history'].includes(route))owner(actor);
|
||||
if(route==='/api/private-operations'&&!isPost)return send(res,200,require('./private-operations').report(actorLedger,Object.fromEntries(url.searchParams),actor));
|
||||
if(route==='/api/private-operations/people'&&!isPost)return send(res,200,require('./private-operations').entry(actorLedger,Object.fromEntries(url.searchParams),actor));
|
||||
if(route==='/api/team-profits'&&!isPost){owner(actor);return send(res,200,actorLedger.teamProfits(Object.fromEntries(url.searchParams),actor));}
|
||||
if(['/api/team-funds/transfers','/api/team-funds/transfer'].includes(route))owner(actor);
|
||||
const memberPasswordMatch=route.match(/^\/api\/team-members\/([A-Za-z0-9_-]+)\/password$/);
|
||||
@@ -212,7 +215,7 @@ function createApp(options={}){
|
||||
const inventoryChangeMatch=route.match(/^\/api\/inventory\/changes\/([a-f0-9-]{36})(?:\/(approve|reject))?$/);
|
||||
if(inventoryChangeMatch&&!isPost){if(inventoryChangeMatch[2])fail('地址不存在',404);return send(res,200,actorLedger.inventoryChange(inventoryChangeMatch[1],actor));}
|
||||
if(route==='/api/inventory/snapshots'&&!isPost)return send(res,200,actorLedger.inventorySnapshots(Object.fromEntries(url.searchParams)));
|
||||
if(route==='/api/order-book'&&!isPost)return send(res,200,actorLedger.orderBook(Object.fromEntries(url.searchParams)));
|
||||
if(route==='/api/order-book'&&!isPost){const book=actorLedger.orderBook(Object.fromEntries(url.searchParams));if(actor.role!=='owner')book.peopleCount=null;return send(res,200,book);}
|
||||
if(route==='/api/order-templates'&&!isPost)return send(res,200,actorLedger.orderTemplates(Object.fromEntries(url.searchParams)));
|
||||
const templateMatch=route.match(/^\/api\/order-templates\/([a-f0-9-]{36})(?:\/(update|delete))?$/);
|
||||
if(templateMatch&&!isPost){if(templateMatch[2])fail('地址不存在',404);return send(res,200,actorLedger.orderTemplate(templateMatch[1]));}
|
||||
@@ -232,7 +235,7 @@ function createApp(options={}){
|
||||
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));
|
||||
const report=actorLedger.reportFor(Object.fromEntries(url.searchParams),actor);if(actor.role!=='owner')report.peopleCount=null;return send(res,200,report);
|
||||
}
|
||||
if(route==='/api/export/inventory'&&!isPost){owner(actor);res.setHeader('Content-Disposition','attachment; filename="inventory.csv"');return send(res,200,'\ufeff货盘,账面克重,已占用克重,可用克重,计数单位,账面对数,已占用对数,可用对数\r\n'+actorLedger.inventory().map(r=>[csvText(actorLedger.pocketLabel(r.pocket)),(r.mg/1000).toFixed(3),(r.reserved/1000).toFixed(3),(r.available/1000).toFixed(3),...(r.countUnit==='pair'?['对',r.count??'未登记',r.reservedCount??'未登记',r.availableCount??'未登记']:['','','',''])].join(',')).join('\r\n'),'text/csv; charset=utf-8');}
|
||||
if(route==='/api/backup'&&isPost){owner(actor);await read(req);const b=await doBackup();actorLedger.audit('system','完整备份',actor,{name:b.name});return send(res,200,{name:b.name});}
|
||||
@@ -296,6 +299,7 @@ function createApp(options={}){
|
||||
if(cancellationMatch&&cancellationMatch[2]==='reject')return actorLedger.rejectOrderCancellation(cancellationMatch[1],b,actor);
|
||||
if(match&&match[2]==='cancellation')return actorLedger.requestOrderCancellation(match[1],b,actor);
|
||||
if(match&&match[2]==='canceltoday')return actorLedger.cancelOrderToday(match[1],b,actor);
|
||||
if(route==='/api/private-operations/people')return require('./private-operations').save(actorLedger,b,actor);
|
||||
if(route==='/api/people-count')return actorLedger.savePeopleCount(b,actor);
|
||||
if(match&&match[2]==='edit')return actorLedger.editOrder(match[1],OrderNoteTags.submission(actorLedger,b,actor,match[1]),actor);
|
||||
if(match&&match[2])return actorLedger.action(match[1],match[2],b,actor);
|
||||
@@ -310,9 +314,9 @@ function createApp(options={}){
|
||||
if(route==='/api/printing')return ShopSettings.updatePrinting(actorLedger,b,actor);
|
||||
if(route==='/api/password'){const u=actorLedger.one('SELECT * FROM users WHERE id=?',actor.id);if(derive(String(b.current||''),u.salt)!==u.hash)fail('原密码不正确');if(String(b.password||'').length<12)fail('新密码至少12个字符');const salt=crypto.randomBytes(24).toString('hex');actorLedger.run('UPDATE users SET salt=?,hash=? WHERE id=?',salt,derive(b.password,salt),actor.id);actorLedger.run('UPDATE team_user_members SET password_set=1 WHERE user_id=?',actor.id);actorLedger.run('DELETE FROM sessions WHERE user_id=?',actor.id);return {ok:true};}
|
||||
fail('地址不存在',404);
|
||||
},{syncTeamFunds:!['/api/pockets','/api/shop-settings','/api/printing','/api/employees','/api/password'].includes(route)&&!pocketMatch&&!employeeMatch&&!memberPasswordMatch});return send(res,200,route==='/api/people-count'?peopleCountResponse(actorLedger,result,actor):result);
|
||||
},{syncTeamFunds:!['/api/private-operations/people','/api/pockets','/api/shop-settings','/api/printing','/api/employees','/api/password'].includes(route)&&!pocketMatch&&!employeeMatch&&!memberPasswordMatch});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','/employees-ui.js':'employees-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);
|
||||
const assets={'/':'index.html','/private-operations-ui.js':'private-operations-ui.js','/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','/employees-ui.js':'employees-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==='EMPLOYEE_HAS_BUSINESS'?{code:e.code,businessUsage:e.businessUsage}:{}),...(e.code==='RECOVERY_MATERIAL_IN_USE'?{code:e.code,blockedUsages:e.blockedUsages}:{})});else res.end();}
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user