128 lines
6.8 KiB
JavaScript
128 lines
6.8 KiB
JavaScript
"use strict";
|
||
Object.defineProperty(exports, "__esModule", { value: true });
|
||
const tslib_1 = require("tslib");
|
||
const assert_1 = tslib_1.__importDefault(require("assert"));
|
||
const types_1 = require("oak-domain/lib/types");
|
||
const checkers = [
|
||
{
|
||
entity: 'accountOper',
|
||
action: 'create',
|
||
type: 'row',
|
||
filter: {
|
||
account: {
|
||
ableState: 'enabled',
|
||
},
|
||
},
|
||
errMsg: 'account.update.accountDisabled',
|
||
},
|
||
{
|
||
entity: 'accountOper',
|
||
action: 'create',
|
||
type: 'data',
|
||
checker(data, context) {
|
||
(0, assert_1.default)(!(data instanceof Array));
|
||
const { type, totalPlus, availPlus, refundablePlus } = data;
|
||
if (typeof totalPlus !== 'number') {
|
||
throw new types_1.OakInputIllegalException('accountOper', ['totalPlus'], 'accountOper中的totalPlus不是数字');
|
||
}
|
||
if (typeof availPlus !== 'number') {
|
||
throw new types_1.OakInputIllegalException('accountOper', ['availPlus'], 'accountOper中的availPlus不是数字');
|
||
}
|
||
switch (type) {
|
||
case 'consume': {
|
||
if (totalPlus > 0 || availPlus > 0 || totalPlus > availPlus) {
|
||
throw new types_1.OakInputIllegalException('accountOper', ['availPlus'], 'accountOper为consume时,其totalPlus/availPlus必须为0或负数,且totalPlus的绝对值要更大');
|
||
}
|
||
break;
|
||
}
|
||
case 'deposit': {
|
||
if (totalPlus < 0 || availPlus < 0 || totalPlus !== availPlus ||
|
||
typeof refundablePlus === 'number' && refundablePlus < 0) {
|
||
throw new types_1.OakInputIllegalException('accountOper', ['availPlus'], 'accountOper为deposit时,其totalPlus/availPlus必须为正数且相等, refundable必须为空或者正数');
|
||
}
|
||
break;
|
||
}
|
||
case 'loan': {
|
||
if (totalPlus !== 0 || availPlus >= 0) {
|
||
throw new types_1.OakInputIllegalException('accountOper', ['availPlus'], 'accountOper为loan时,其totalPlus必须为0,且availPlus必须为负数');
|
||
}
|
||
break;
|
||
}
|
||
case 'repay': {
|
||
if (totalPlus !== 0 || availPlus <= 0) {
|
||
throw new types_1.OakInputIllegalException('accountOper', ['availPlus'], 'accountOper为repay时,其totalPlus必须为0,且availPlus必须为正数');
|
||
}
|
||
break;
|
||
}
|
||
case 'refund':
|
||
//当订单未完成分账时,仅减少total,此时totalPlus与availPlus不相等
|
||
if (totalPlus > 0 || availPlus > 0) {
|
||
throw new types_1.OakInputIllegalException('accountOper', ['totalPlus', 'availPlus'], `accountOper为${type}时,其totalPlus必须为非正数`);
|
||
}
|
||
break;
|
||
case 'withdraw': {
|
||
if (totalPlus >= 0 || availPlus >= 0 || totalPlus !== availPlus) {
|
||
throw new types_1.OakInputIllegalException('accountOper', ['availPlus'], `accountOper为${type}时,其totalPlus和availPlus必须为相等的负数`);
|
||
}
|
||
break;
|
||
}
|
||
case 'refundFailure':
|
||
if (totalPlus < 0 || availPlus < 0) {
|
||
throw new types_1.OakInputIllegalException('accountOper', ['availPlus'], `accountOper为${type}时,其totalPlus和availPlus必须为非负数`);
|
||
}
|
||
break;
|
||
case 'withdrawBack':
|
||
case 'consumeBack': {
|
||
if (totalPlus < 0 || availPlus < 0 || totalPlus !== availPlus) {
|
||
throw new types_1.OakInputIllegalException('accountOper', ['availPlus'], `accountOper为${type}时,其totalPlus和availPlus必须为相等的非负数数`);
|
||
}
|
||
break;
|
||
}
|
||
case 'earn': {
|
||
if (totalPlus <= 0 || availPlus < 0) {
|
||
throw new types_1.OakInputIllegalException('accountOper', ['availPlus'], 'accountOper为earn时,其totalPlus必须为正数、availPlus必须为非负数');
|
||
}
|
||
break;
|
||
}
|
||
case 'cutoffRefundable': {
|
||
if (totalPlus !== 0 || availPlus !== 0 || typeof refundablePlus !== 'number' || refundablePlus >= 0) {
|
||
throw new types_1.OakInputIllegalException('accountOper', ['refundablePlus'], 'accountOper为cutoffRefundable时,其totalPlus/availPlus必须为0,且refundablePlus必须为负数');
|
||
}
|
||
break;
|
||
}
|
||
case 'tax': {
|
||
if (totalPlus >= 0 || availPlus >= 0 || totalPlus !== availPlus) {
|
||
throw new types_1.OakInputIllegalException('accountOper', ['totalPlus', 'availPlus'], 'accountOper为tax时,其totalPlus/availPlus必须为负且相等');
|
||
}
|
||
break;
|
||
}
|
||
case 'taxRefund': {
|
||
if (totalPlus <= 0 || availPlus <= 0 || totalPlus !== availPlus) {
|
||
throw new types_1.OakInputIllegalException('accountOper', ['totalPlus', 'availPlus'], 'accountOper为taxRefund时,其totalPlus/availPlus必须为正且相等');
|
||
}
|
||
break;
|
||
}
|
||
// case 'preSettle': {
|
||
// //预分账时账户total增加,avail不变,refundable不变
|
||
// if (totalPlus < 0 || availPlus !== 0 || (refundablePlus && refundablePlus !== 0)) {
|
||
// throw new OakInputIllegalException('accountOper', ['totalPlus', 'availPlus', 'refundablePlus'], 'accountOper为preSettle时,其totalPlus必须为非负数、availPlus必须为0,refundable必须为空或者0');
|
||
// }
|
||
// break;
|
||
// }
|
||
case 'settle': {
|
||
//分账时账户total增加,avail增加,refundable不变
|
||
if (totalPlus < 0 || availPlus < 0 || (refundablePlus && refundablePlus !== 0)) {
|
||
throw new types_1.OakInputIllegalException('accountOper', ['totalPlus', 'refundablePlus'], 'accountOper为settle时,其totalPlus、availPlus必须为非负数,refundable必须为空或者0');
|
||
}
|
||
break;
|
||
}
|
||
default: {
|
||
// assert(false);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
];
|
||
exports.default = checkers;
|