合入主线登录和营业时段策略,对齐旧界面与 React 访问流程
This commit is contained in:
commit
42395de23a
113 files changed
+1915
-558
No files matched your search
@@ -0,0 +1,25 @@
|
||||
'use strict';
|
||||
// 北京时间的每日半开区间;跨午夜时,凌晨部分属于前一天开始的营业时段。
|
||||
function accessWindow(hours, now = Date.now()) {
|
||||
if (!hours) return { state: 'unset' };
|
||||
const day = 86400000;
|
||||
const midnight = Math.floor((now + 8 * 3600000) / day) * day - 8 * 3600000;
|
||||
const millis = time => (Number(time.slice(0, 2)) * 60 + Number(time.slice(3))) * 60000;
|
||||
const open = millis(hours.open),
|
||||
close = millis(hours.close),
|
||||
elapsed = now - midnight;
|
||||
const active = open < close ? elapsed >= open && elapsed < close : elapsed >= open || elapsed < close;
|
||||
if (!active)
|
||||
return {
|
||||
state: 'closed',
|
||||
message:
|
||||
'现在是非营业时间。每日开放时段为北京时间 ' +
|
||||
hours.open +
|
||||
' 至 ' +
|
||||
(close < open ? '次日 ' : '') +
|
||||
hours.close +
|
||||
'。',
|
||||
};
|
||||
return { state: 'open', serverTime: now, closesAt: midnight + close + (close < open && elapsed >= open ? day : 0) };
|
||||
}
|
||||
module.exports = { accessWindow };
|
||||
@@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
// 每个账本独立保存店铺配置;成员键、账号ID及历史财务记录不随展示设置改变。
|
||||
const Printing = require('../printing/printing');
|
||||
const { businessHoursError } = require('../../public/ledger-values');
|
||||
const TeamMembers = require('./team-members');
|
||||
const KEY = 'shop-settings-v1';
|
||||
const FeePresets = require('../../public/fee-estimates');
|
||||
@@ -53,6 +54,7 @@ function seed(ledger) {
|
||||
return {
|
||||
version: 1,
|
||||
revision: 0,
|
||||
businessHours: null,
|
||||
storeName: printing.store,
|
||||
receiptSubtitle: printing.subtitle,
|
||||
contact: printing.contact,
|
||||
@@ -78,6 +80,7 @@ function read(ledger) {
|
||||
return {
|
||||
version: 1,
|
||||
revision: raw.revision,
|
||||
businessHours: raw.businessHours ?? null,
|
||||
storeName: raw.storeName,
|
||||
receiptSubtitle: raw.receiptSubtitle,
|
||||
contact: raw.contact,
|
||||
@@ -117,7 +120,7 @@ function aliases(ledger, config = read(ledger)) {
|
||||
function publicSettings(ledger, actor) {
|
||||
const config = read(ledger);
|
||||
if (actor?.role === 'owner') return config;
|
||||
const { profitSharePercent, profitShareEffectiveMonth, profitShareHistory, ...visible } = config;
|
||||
const { businessHours, profitSharePercent, profitShareEffectiveMonth, profitShareHistory, ...visible } = config;
|
||||
visible.members = visible.members.map(({ member, label }) => ({ member, label }));
|
||||
return visible;
|
||||
}
|
||||
@@ -187,6 +190,7 @@ function update(ledger, input, actor = ledger.actor) {
|
||||
'profitShareEffectiveMonth',
|
||||
'feeDefaults',
|
||||
'costPresets',
|
||||
'businessHours',
|
||||
],
|
||||
'店铺配置',
|
||||
);
|
||||
@@ -206,6 +210,16 @@ function update(ledger, input, actor = ledger.actor) {
|
||||
['contact', '店铺联系方式', 80, true],
|
||||
])
|
||||
if (own(input, field)) next[field] = string(input[field], name, max, { empty });
|
||||
if (own(input, 'businessHours')) {
|
||||
if (input.businessHours === null) next.businessHours = null;
|
||||
else {
|
||||
const hours = object(input.businessHours, '营业时间');
|
||||
only(hours, ['open', 'close'], '营业时间');
|
||||
const message = businessHoursError(hours.open, hours.close);
|
||||
if (message) fail(message);
|
||||
next.businessHours = { open: hours.open, close: hours.close };
|
||||
}
|
||||
}
|
||||
if (own(input, 'creditCardRatePermille'))
|
||||
next.creditCardRatePermille = integer(input.creditCardRatePermille, '信用卡手续费率', 0, 1000);
|
||||
if (own(input, 'costPresets')) {
|
||||
|
||||
Reference in new issue
Block a user