订单支付相关修改
This commit is contained in:
parent
4cecec4dfe
commit
c3b82a845c
|
|
@ -61,30 +61,32 @@ const triggers = [
|
|||
}
|
||||
const { price, paid } = pay;
|
||||
const paid2 = Math.min(price - paid, rest);
|
||||
await context.operate('pay', {
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
action: 'continuePaying',
|
||||
data: {
|
||||
paid: paid + paid2,
|
||||
accountOper$entity: [
|
||||
{
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
action: 'create',
|
||||
data: {
|
||||
if(paid2 > 0){
|
||||
await context.operate('pay', {
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
action: 'continuePaying',
|
||||
data: {
|
||||
paid: paid + paid2,
|
||||
accountOper$entity: [
|
||||
{
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
type: 'consume',
|
||||
availPlus: -paid2,
|
||||
totalPlus: -paid2,
|
||||
accountId: filter.id,
|
||||
action: 'create',
|
||||
data: {
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
type: 'consume',
|
||||
availPlus: -paid2,
|
||||
totalPlus: -paid2,
|
||||
accountId: filter.id,
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
filter: {
|
||||
id: pay.id,
|
||||
}
|
||||
}, {});
|
||||
rest = rest - paid2;
|
||||
]
|
||||
},
|
||||
filter: {
|
||||
id: pay.id,
|
||||
}
|
||||
}, {});
|
||||
rest = rest - paid2;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,8 @@ async function changeOrderStateByPay(filter, context, option) {
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (paid) {
|
||||
if (paid && iState === 'paid') {
|
||||
//已支付完成的订单的paid
|
||||
payPaid += paid;
|
||||
}
|
||||
if (refunded) {
|
||||
|
|
@ -56,19 +57,22 @@ async function changeOrderStateByPay(filter, context, option) {
|
|||
}
|
||||
const closeFn = context.openRootMode();
|
||||
try {
|
||||
if (hasPaying && orderIState !== 'paying') {
|
||||
if (hasPaying) {
|
||||
// 一定是在支付状态
|
||||
(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);
|
||||
if (orderIState !== 'paying') {
|
||||
//若订单未开始支付
|
||||
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);
|
||||
|
|
@ -105,6 +109,7 @@ async function changeOrderStateByPay(filter, context, option) {
|
|||
}
|
||||
else if (payPaid) {
|
||||
// 在支付流程当中
|
||||
//存在已完成的pay更新order的paid和iState
|
||||
(0, assert_1.default)(orderRefunded === 0);
|
||||
const iState = payPaid === orderPrice ? 'paid' : 'partiallyPaid';
|
||||
if (orderIState !== iState || orderPaid !== payPaid) {
|
||||
|
|
|
|||
|
|
@ -63,32 +63,33 @@ const triggers: Trigger<EntityDict, 'account', BRC>[] = [
|
|||
}
|
||||
const { price, paid } = pay;
|
||||
const paid2 = Math.min(price! - paid!, rest);
|
||||
|
||||
await context.operate('pay', {
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'continuePaying',
|
||||
data: {
|
||||
paid: paid! + paid2,
|
||||
accountOper$entity: [
|
||||
{
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'create',
|
||||
data: {
|
||||
if(paid2>0){
|
||||
await context.operate('pay', {
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'continuePaying',
|
||||
data: {
|
||||
paid: paid! + paid2,
|
||||
accountOper$entity: [
|
||||
{
|
||||
id: await generateNewIdAsync(),
|
||||
type: 'consume',
|
||||
availPlus: -paid2,
|
||||
totalPlus: -paid2,
|
||||
accountId: filter!.id,
|
||||
action: 'create',
|
||||
data: {
|
||||
id: await generateNewIdAsync(),
|
||||
type: 'consume',
|
||||
availPlus: -paid2,
|
||||
totalPlus: -paid2,
|
||||
accountId: filter!.id,
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
filter: {
|
||||
id: pay!.id!,
|
||||
}
|
||||
}, {});
|
||||
rest = rest - paid2;
|
||||
count ++;
|
||||
]
|
||||
},
|
||||
filter: {
|
||||
id: pay!.id!,
|
||||
}
|
||||
}, {});
|
||||
rest = rest - paid2;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,8 @@ async function changeOrderStateByPay(
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (paid) {
|
||||
if (paid && iState === 'paid') {
|
||||
//已支付完成的订单的paid
|
||||
payPaid += paid;
|
||||
}
|
||||
if (refunded) {
|
||||
|
|
@ -65,19 +66,22 @@ async function changeOrderStateByPay(
|
|||
|
||||
const closeFn = context.openRootMode();
|
||||
try {
|
||||
if (hasPaying && orderIState !== 'paying') {
|
||||
if (hasPaying) {
|
||||
// 一定是在支付状态
|
||||
assert(!hasRefunding && payRefunded === 0);
|
||||
await context.operate('order', {
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'startPaying',
|
||||
data: {
|
||||
paid: payPaid,
|
||||
},
|
||||
filter: {
|
||||
id: orderId!,
|
||||
},
|
||||
}, option);
|
||||
if (orderIState !== 'paying') {
|
||||
//若订单未开始支付
|
||||
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);
|
||||
|
|
@ -114,6 +118,7 @@ async function changeOrderStateByPay(
|
|||
}
|
||||
else if (payPaid) {
|
||||
// 在支付流程当中
|
||||
//存在已完成的pay更新order的paid和iState
|
||||
assert(orderRefunded === 0);
|
||||
const iState = payPaid === orderPrice ? 'paid' : 'partiallyPaid';
|
||||
if (orderIState !== iState || orderPaid !== payPaid) {
|
||||
|
|
@ -224,7 +229,7 @@ const triggers: Trigger<EntityDict, 'pay', BRC>[] = [
|
|||
fn: async ({ operation }, context, option) => {
|
||||
const { filter, action, id } = operation as EntityDict['pay']['Update'];
|
||||
assert(typeof filter!.id === 'string');
|
||||
|
||||
|
||||
const [pay] = await context.select('pay', {
|
||||
data: {
|
||||
id: 1,
|
||||
|
|
@ -279,7 +284,7 @@ const triggers: Trigger<EntityDict, 'pay', BRC>[] = [
|
|||
filter,
|
||||
}, {});
|
||||
assert(pays.length === 1);
|
||||
const [ pay ] = pays;
|
||||
const [pay] = pays;
|
||||
const { applicationId, channel, iState } = pay;
|
||||
assert(iState! === 'unpaid');
|
||||
const payClazz = await getPayClazz(applicationId!, channel!, context);
|
||||
|
|
@ -301,13 +306,13 @@ const triggers: Trigger<EntityDict, 'pay', BRC>[] = [
|
|||
filter,
|
||||
}, {});
|
||||
assert(pays.length === 1);
|
||||
const [ pay ] = pays;
|
||||
const [pay] = pays;
|
||||
const { applicationId, channel, iState, externalId } = pay;
|
||||
assert(iState === 'unpaid' || iState === 'paying');
|
||||
if (iState === 'paying' && externalId && ![PAY_CHANNEL_ACCOUNT_NAME, PAY_CHANNEL_OFFLINE_NAME].includes(channel!)) {
|
||||
const payClazz = await getPayClazz(applicationId!, channel!, context);
|
||||
await payClazz.close(pay as EntityDict['pay']['OpSchema']);
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
|
@ -325,7 +330,7 @@ const triggers: Trigger<EntityDict, 'pay', BRC>[] = [
|
|||
when: 'before',
|
||||
fn: async ({ operation }, context, option) => {
|
||||
const { filter, action, id } = operation as EntityDict['pay']['Update'];
|
||||
|
||||
|
||||
const pays = await context.select('pay', {
|
||||
data: {
|
||||
id: 1,
|
||||
|
|
@ -361,7 +366,7 @@ const triggers: Trigger<EntityDict, 'pay', BRC>[] = [
|
|||
},
|
||||
{}
|
||||
);
|
||||
count ++;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue