订单支付修改
This commit is contained in:
parent
93f7b1b93b
commit
ccdbd41d35
|
|
@ -115,7 +115,7 @@ const checkers = [
|
|||
entity: 'pay',
|
||||
type: 'logical',
|
||||
action: ['continuePaying', 'startPaying'],
|
||||
priority: Trigger_1.CHECKER_MAX_PRIORITY - 1, // 要超过action矩阵定义的赋state值
|
||||
// priority: Trigger_1.CHECKER_MAX_PRIORITY - 1, // 要超过action矩阵定义的赋state值
|
||||
checker: (operation, context) => {
|
||||
const { data, filter } = operation;
|
||||
(0, assert_1.default)(filter && typeof filter.id === 'string');
|
||||
|
|
|
|||
|
|
@ -78,25 +78,27 @@ const triggers = [
|
|||
},
|
||||
}, {});
|
||||
const { price, application, channel } = pay;
|
||||
(0, assert_1.default)(PayConfig_1.PAY_ORG_CHANNELS.includes(channel));
|
||||
const ratio = (0, pay_1.getDepositRatio)(channel, application);
|
||||
let count = 0;
|
||||
if (ratio > 0) {
|
||||
const loss = Math.ceil(price * ratio / 100);
|
||||
await context.operate('accountOper', {
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
action: 'create',
|
||||
data: {
|
||||
if (PayConfig_1.PAY_ORG_CHANNELS.includes(channel)) {
|
||||
// (0, assert_1.default)(PayConfig_1.PAY_ORG_CHANNELS.includes(channel));
|
||||
const ratio = (0, pay_1.getDepositRatio)(channel, application);
|
||||
if (ratio > 0) {
|
||||
const loss = Math.ceil(price * ratio / 100);
|
||||
await context.operate('accountOper', {
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
type: 'loss',
|
||||
totalPlus: -loss,
|
||||
availPlus: -loss,
|
||||
entity,
|
||||
entityId,
|
||||
accountId: data.accountId,
|
||||
}
|
||||
}, {});
|
||||
count++;
|
||||
action: 'create',
|
||||
data: {
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
type: 'loss',
|
||||
totalPlus: -loss,
|
||||
availPlus: -loss,
|
||||
entity,
|
||||
entityId,
|
||||
accountId: data.accountId,
|
||||
}
|
||||
}, {});
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,21 +56,19 @@ async function changeOrderStateByPay(filter, context, option) {
|
|||
}
|
||||
const closeFn = context.openRootMode();
|
||||
try {
|
||||
if (hasPaying) {
|
||||
if (hasPaying && orderIState !== 'paying') {
|
||||
// 一定是在支付状态
|
||||
(0, assert_1.default)(!hasRefunding && payRefunded === 0 && payPaid < orderPrice);
|
||||
if (orderIState !== 'paying' || orderPaid !== payPaid) {
|
||||
await context.operate('order', {
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
action: 'startPaying',
|
||||
data: {
|
||||
paid: payPaid,
|
||||
},
|
||||
filter: {
|
||||
id: orderId,
|
||||
},
|
||||
}, option);
|
||||
}
|
||||
(0, assert_1.default)(!hasRefunding && payRefunded === 0);
|
||||
await context.operate('order', {
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
action: 'startPaying',
|
||||
data: {
|
||||
paid: payPaid,
|
||||
},
|
||||
filter: {
|
||||
id: orderId,
|
||||
},
|
||||
}, option);
|
||||
}
|
||||
else if (hasRefunding) {
|
||||
(0, assert_1.default)(!hasPaying && payPaid === orderPrice && payPaid === orderPaid && payRefunded < orderPrice);
|
||||
|
|
@ -345,5 +343,48 @@ const triggers = [
|
|||
return count;
|
||||
},
|
||||
},
|
||||
{
|
||||
name: '当pay的paid达到price,支付成功',
|
||||
entity: 'pay',
|
||||
action: ['startPaying', 'continuePaying'],
|
||||
check(operation) {
|
||||
return (!!operation.data.paid) && operation.data.paid > 0;
|
||||
},
|
||||
filter: {
|
||||
accountId: {
|
||||
$exists: true,
|
||||
}
|
||||
},
|
||||
when: 'commit',
|
||||
fn: async ({ ids }, context) => {
|
||||
for (const id of ids) {
|
||||
const [row] = await context.select('pay', {
|
||||
data: {
|
||||
id: 1,
|
||||
orderId: 1,
|
||||
accountId: 1,
|
||||
price: 1,
|
||||
paid: 1,
|
||||
},
|
||||
filter: {
|
||||
id,
|
||||
}
|
||||
}, { dontCollect: true });
|
||||
(0, assert_1.default)(row);
|
||||
if (row.accountId && row.paid && row.paid === row.price) {
|
||||
const closeFn = context.openRootMode();
|
||||
await context.operate('pay', {
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
action: 'succeedPaying',
|
||||
data: {},
|
||||
filter: {
|
||||
id,
|
||||
}
|
||||
}, {});
|
||||
closeFn();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
exports.default = triggers;
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ const checkers: Checker<EntityDict, 'pay', RuntimeCxt>[] = [
|
|||
entity: 'pay',
|
||||
type: 'logical',
|
||||
action: ['continuePaying', 'startPaying'],
|
||||
priority: CHECKER_MAX_PRIORITY - 1, // 要超过action矩阵定义的赋state值
|
||||
// priority: CHECKER_MAX_PRIORITY - 1, // 要超过action矩阵定义的赋state值
|
||||
checker: (operation, context) => {
|
||||
const { data, filter } = operation as EntityDict['pay']['Update'];
|
||||
assert(filter && typeof filter.id === 'string');
|
||||
|
|
|
|||
|
|
@ -83,27 +83,28 @@ const triggers: Trigger<EntityDict, 'accountOper', BRC>[] = [
|
|||
}, {});
|
||||
|
||||
const { price, application, channel } = pay;
|
||||
assert(PAY_ORG_CHANNELS.includes(channel!));
|
||||
const ratio = getDepositRatio(channel!, application!);
|
||||
|
||||
let count = 0;
|
||||
if (ratio > 0) {
|
||||
const loss = Math.ceil(price! * ratio / 100);
|
||||
await context.operate('accountOper', {
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'create',
|
||||
data: {
|
||||
if (PAY_ORG_CHANNELS.includes(channel!)) {
|
||||
// assert(PAY_ORG_CHANNELS.includes(channel!));
|
||||
const ratio = getDepositRatio(channel!, application!);
|
||||
if (ratio > 0) {
|
||||
const loss = Math.ceil(price! * ratio / 100);
|
||||
await context.operate('accountOper', {
|
||||
id: await generateNewIdAsync(),
|
||||
type: 'loss',
|
||||
totalPlus: -loss,
|
||||
availPlus: -loss,
|
||||
entity,
|
||||
entityId,
|
||||
accountId: data.accountId!,
|
||||
}
|
||||
}, {});
|
||||
count ++;
|
||||
}
|
||||
action: 'create',
|
||||
data: {
|
||||
id: await generateNewIdAsync(),
|
||||
type: 'loss',
|
||||
totalPlus: -loss,
|
||||
availPlus: -loss,
|
||||
entity,
|
||||
entityId,
|
||||
accountId: data.accountId!,
|
||||
}
|
||||
}, {});
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
} as CreateTriggerInTxn<EntityDict, 'accountOper', BRC>,
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import { getPayClazz } from '@project/utils/payClazz';
|
|||
import { fullPayProjection } from '@project/utils/pay';
|
||||
import { PAY_CHANNEL_ACCOUNT_NAME, PAY_CHANNEL_OFFLINE_NAME } from '@project/types/PayConfig';
|
||||
import { DATA_SUBSCRIBER_KEYS } from '@project/config/constants';
|
||||
import { UpdateOperation } from '@project/oak-app-domain/Pay/Schema';
|
||||
|
||||
async function changeOrderStateByPay(
|
||||
filter: NonNullable<EntityDict['order']['Update']['filter']>,
|
||||
|
|
@ -64,21 +65,19 @@ async function changeOrderStateByPay(
|
|||
|
||||
const closeFn = context.openRootMode();
|
||||
try {
|
||||
if (hasPaying) {
|
||||
if (hasPaying && orderIState !== 'paying') {
|
||||
// 一定是在支付状态
|
||||
assert(!hasRefunding && payRefunded === 0 && payPaid < orderPrice!);
|
||||
if (orderIState !== 'paying' || orderPaid !== payPaid) {
|
||||
await context.operate('order', {
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'startPaying',
|
||||
data: {
|
||||
paid: payPaid,
|
||||
},
|
||||
filter: {
|
||||
id: orderId!,
|
||||
},
|
||||
}, option);
|
||||
}
|
||||
assert(!hasRefunding && payRefunded === 0);
|
||||
await context.operate('order', {
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'startPaying',
|
||||
data: {
|
||||
paid: payPaid,
|
||||
},
|
||||
filter: {
|
||||
id: orderId!,
|
||||
},
|
||||
}, option);
|
||||
}
|
||||
else if (hasRefunding) {
|
||||
assert(!hasPaying && payPaid === orderPrice && payPaid === orderPaid && payRefunded < orderPrice);
|
||||
|
|
@ -369,6 +368,49 @@ const triggers: Trigger<EntityDict, 'pay', BRC>[] = [
|
|||
return count;
|
||||
},
|
||||
} as UpdateTriggerInTxn<EntityDict, 'pay', BRC>,
|
||||
{
|
||||
name: '当pay的paid达到price,支付成功',
|
||||
entity: 'pay',
|
||||
action: ['startPaying', 'continuePaying'],
|
||||
check(operation: UpdateOperation) {
|
||||
return (!!operation.data.paid) && operation.data.paid > 0;
|
||||
},
|
||||
filter: {
|
||||
accountId: {
|
||||
$exists: true,
|
||||
}
|
||||
},
|
||||
when: 'commit',
|
||||
fn: async ({ ids }, context) => {
|
||||
for (const id of ids) {
|
||||
const [row] = await context.select('pay', {
|
||||
data: {
|
||||
id: 1,
|
||||
orderId: 1,
|
||||
accountId: 1,
|
||||
price: 1,
|
||||
paid: 1,
|
||||
},
|
||||
filter: {
|
||||
id,
|
||||
}
|
||||
}, { dontCollect: true });
|
||||
assert(row);
|
||||
if (row.accountId && row.paid && row.paid === row.price) {
|
||||
const closeFn = context.openRootMode();
|
||||
await context.operate('pay', {
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'succeedPaying',
|
||||
data: {},
|
||||
filter: {
|
||||
id,
|
||||
}
|
||||
}, {});
|
||||
closeFn();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
export default triggers;
|
||||
Loading…
Reference in New Issue