79 lines
2.8 KiB
JavaScript
79 lines
2.8 KiB
JavaScript
import assert from "assert";
|
|
import dayJs from 'dayjs';
|
|
export default class Offline {
|
|
offlineAccount;
|
|
constructor(offlineAccount) {
|
|
this.offlineAccount = offlineAccount;
|
|
// 返回taxLossRatio * refundCompensateRatio / 100
|
|
if (typeof offlineAccount.refundCompensateRatio !== 'number') {
|
|
throw new Error('渠道的refundCompensateRatio未设置');
|
|
}
|
|
if (typeof offlineAccount.taxLossRatio !== 'number') {
|
|
throw new Error('渠道的taxLossRatio未设置');
|
|
}
|
|
}
|
|
getAccountEntity() {
|
|
return ['offlineAccount', this.offlineAccount.id];
|
|
}
|
|
async getAccountAmount(context) {
|
|
const [offlineAccount] = await context.select('offlineAccount', {
|
|
data: {
|
|
id: 1,
|
|
price: 1,
|
|
},
|
|
filter: {
|
|
id: this.offlineAccount.id,
|
|
},
|
|
}, { dontCollect: true });
|
|
return offlineAccount.price;
|
|
}
|
|
calcTransferTax(price) {
|
|
const { allowWithdrawTransfer, withdrawTransferLossRatio } = this.offlineAccount;
|
|
assert(allowWithdrawTransfer);
|
|
if (typeof withdrawTransferLossRatio !== 'number') {
|
|
throw new Error('渠道的withdrawTransferLossRatio未设置');
|
|
}
|
|
return [Math.round(price * withdrawTransferLossRatio / 100), 'offlineAccount', this.offlineAccount.id];
|
|
}
|
|
calcRefundTax(price) {
|
|
const { taxLossRatio, refundCompensateRatio } = this.offlineAccount;
|
|
const value = Math.round(price * taxLossRatio * refundCompensateRatio / 100 / 100);
|
|
return [-value, 'offlineAccount', this.offlineAccount.id];
|
|
}
|
|
calcPayTax(price) {
|
|
const { taxLossRatio } = this.offlineAccount;
|
|
return [taxLossRatio ? Math.round(price * taxLossRatio / 100) : 0, 'offlineAccount', this.offlineAccount.id];
|
|
}
|
|
getRefundableAt(successTime) {
|
|
const { refundGapDays } = this.offlineAccount;
|
|
return refundGapDays ? dayJs(successTime).add(refundGapDays, 'day').subtract(12, 'hour').valueOf() : 0;
|
|
}
|
|
async refund(refund) {
|
|
// 啥也不做
|
|
return;
|
|
}
|
|
async getRefundState(refund) {
|
|
const { iState } = refund;
|
|
assert(iState === 'refunding');
|
|
return [iState, undefined];
|
|
}
|
|
decodePayNotification(params, body) {
|
|
throw new Error("offline类型的pay不需调用此接口");
|
|
}
|
|
decodeRefundNotification(params, body) {
|
|
throw new Error("offline类型的pay不需调用此接口");
|
|
}
|
|
async prepay(pay, data, context) {
|
|
data.phantom3 = Math.ceil(Math.random() * 1000000);
|
|
return;
|
|
}
|
|
async getState(pay) {
|
|
const { iState } = pay;
|
|
assert(iState === 'paying');
|
|
return [iState, {}];
|
|
}
|
|
async close(pay) {
|
|
return;
|
|
}
|
|
}
|