type为preSettle和settle的accountOper指向settlement
This commit is contained in:
parent
dba28ebb62
commit
8f6869a0d8
|
|
@ -3,6 +3,7 @@ export const payNotify = {
|
|||
name: '微信支付回调',
|
||||
method: 'post',
|
||||
params: ['payId'],
|
||||
type: 'simple',
|
||||
fn: async (context, params, headers, req, body) => {
|
||||
const { payId } = params;
|
||||
return payNotifyFn(context, body, payId, headers);
|
||||
|
|
@ -12,6 +13,7 @@ export const refundNotify = {
|
|||
name: '微信退款回调',
|
||||
method: 'post',
|
||||
params: ['refundId'],
|
||||
type: 'simple',
|
||||
fn: async (context, params, headers, req, body) => {
|
||||
const { refundId } = params;
|
||||
return refundNotifyFn(context, body, refundId, headers);
|
||||
|
|
|
|||
|
|
@ -3,15 +3,17 @@ import { EntityShape } from 'oak-domain/lib/types/Entity';
|
|||
import { EntityDesc, ActionDef } from 'oak-domain/lib/types';
|
||||
import { Schema as Account } from './Account';
|
||||
import { Schema as Order } from './Order';
|
||||
import { Schema as AccountOper } from './AccountOper';
|
||||
export interface Schema extends EntityShape {
|
||||
account: Account;
|
||||
price: Price;
|
||||
order: Order;
|
||||
opers?: AccountOper[];
|
||||
}
|
||||
type IState = 'unsettled' | 'settled';
|
||||
type IAction = 'settle';
|
||||
export declare const IActionDef: ActionDef<IAction, IState>;
|
||||
type Action = IAction | 'refund' | 'refundFailure';
|
||||
type Action = IAction | 'preSettle' | 'refund' | 'refundFailure';
|
||||
export declare const entityDesc: EntityDesc<Schema, Action, '', {
|
||||
iState: IState;
|
||||
}>;
|
||||
|
|
|
|||
|
|
@ -14,8 +14,10 @@ export const entityDesc = {
|
|||
price: '变化金额',
|
||||
order: '订单',
|
||||
iState: '结算状态',
|
||||
opers: '相关帐户操作',
|
||||
},
|
||||
action: {
|
||||
preSettle: '预结算',
|
||||
settle: '结算',
|
||||
refund: '退款',
|
||||
refundFailure: '退款失败',
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ export const desc = {
|
|||
params: {
|
||||
length: 32
|
||||
},
|
||||
ref: ["deposit", "order", "pay", "refund", "withdraw", "withdrawTransfer"]
|
||||
ref: ["deposit", "order", "pay", "refund", "settlement", "withdraw", "withdrawTransfer"]
|
||||
},
|
||||
entityId: {
|
||||
notNull: true,
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ export type OpSchema = EntityShape & {
|
|||
total: Price;
|
||||
avail: Price;
|
||||
refundable: Price;
|
||||
entity: "deposit" | "order" | "pay" | "refund" | "withdraw" | "withdrawTransfer" | string;
|
||||
entity: "deposit" | "order" | "pay" | "refund" | "settlement" | "withdraw" | "withdrawTransfer" | string;
|
||||
entityId: String<64>;
|
||||
} & {
|
||||
[A in ExpressionKey]?: any;
|
||||
|
|
@ -32,7 +32,7 @@ export type OpFilter = {
|
|||
total: Q_NumberValue;
|
||||
avail: Q_NumberValue;
|
||||
refundable: Q_NumberValue;
|
||||
entity: Q_EnumValue<"deposit" | "order" | "pay" | "refund" | "withdraw" | "withdrawTransfer" | string>;
|
||||
entity: Q_EnumValue<"deposit" | "order" | "pay" | "refund" | "settlement" | "withdraw" | "withdrawTransfer" | string>;
|
||||
entityId: Q_StringValue;
|
||||
} & ExprOp<OpAttr | string>;
|
||||
export type OpProjection = {
|
||||
|
|
|
|||
|
|
@ -3978,6 +3978,7 @@ export type AccountOper = {
|
|||
order?: Order["Schema"];
|
||||
pay?: Pay["Schema"];
|
||||
refund?: Refund["Schema"];
|
||||
settlement?: Settlement["Schema"];
|
||||
withdraw?: Withdraw["Schema"];
|
||||
withdrawTransfer?: WithdrawTransfer["Schema"];
|
||||
};
|
||||
|
|
@ -3987,6 +3988,7 @@ export type AccountOper = {
|
|||
order?: Order["Projection"];
|
||||
pay?: Pay["Projection"];
|
||||
refund?: Refund["Projection"];
|
||||
settlement?: Settlement["Projection"];
|
||||
withdraw?: Withdraw["Projection"];
|
||||
withdrawTransfer?: WithdrawTransfer["Projection"];
|
||||
};
|
||||
|
|
@ -3996,6 +3998,7 @@ export type AccountOper = {
|
|||
order: MakeFilter<Order["FilterUnit"]>;
|
||||
pay: MakeFilter<Pay["FilterUnit"]>;
|
||||
refund: MakeFilter<Refund["FilterUnit"]>;
|
||||
settlement: MakeFilter<Settlement["FilterUnit"]>;
|
||||
withdraw: MakeFilter<Withdraw["FilterUnit"]>;
|
||||
withdrawTransfer: MakeFilter<WithdrawTransfer["FilterUnit"]>;
|
||||
};
|
||||
|
|
@ -4006,6 +4009,7 @@ export type AccountOper = {
|
|||
order: Order["SortAttr"];
|
||||
pay: Pay["SortAttr"];
|
||||
refund: Refund["SortAttr"];
|
||||
settlement: Settlement["SortAttr"];
|
||||
withdraw: Withdraw["SortAttr"];
|
||||
withdrawTransfer: WithdrawTransfer["SortAttr"];
|
||||
}>;
|
||||
|
|
@ -4022,6 +4026,7 @@ export type AccountOper = {
|
|||
order?: OakOperation<"create", Order["CreateOperationData"]> | OakOperation<BaseOrder.OpUpdateAction, Order["UpdateOperationData"], Order["Filter"]>;
|
||||
pay?: OakOperation<"create", Pay["CreateOperationData"]> | OakOperation<BasePay.OpUpdateAction, Pay["UpdateOperationData"], Pay["Filter"]>;
|
||||
refund?: OakOperation<"create", Refund["CreateOperationData"]> | OakOperation<BaseRefund.OpUpdateAction, Refund["UpdateOperationData"], Refund["Filter"]>;
|
||||
settlement?: OakOperation<"create", Settlement["CreateOperationData"]> | OakOperation<BaseSettlement.OpUpdateAction, Settlement["UpdateOperationData"], Settlement["Filter"]>;
|
||||
withdraw?: OakOperation<"create", Withdraw["CreateOperationData"]> | OakOperation<BaseWithdraw.OpUpdateAction, Withdraw["UpdateOperationData"], Withdraw["Filter"]>;
|
||||
withdrawTransfer?: OakOperation<"create", WithdrawTransfer["CreateOperationData"]> | OakOperation<BaseWithdrawTransfer.OpUpdateAction, WithdrawTransfer["UpdateOperationData"], WithdrawTransfer["Filter"]>;
|
||||
}>;
|
||||
|
|
@ -4034,6 +4039,7 @@ export type AccountOper = {
|
|||
order?: OakOperation<"create", Order["CreateOperationData"]> | OakOperation<BaseOrder.OpUpdateAction, Order["UpdateOperationData"], Order["Filter"]> | OakOperation<"remove", Order["RemoveOperationData"], Order["Filter"]>;
|
||||
pay?: OakOperation<"create", Pay["CreateOperationData"]> | OakOperation<BasePay.OpUpdateAction, Pay["UpdateOperationData"], Pay["Filter"]> | OakOperation<"remove", Pay["RemoveOperationData"], Pay["Filter"]>;
|
||||
refund?: OakOperation<"create", Refund["CreateOperationData"]> | OakOperation<BaseRefund.OpUpdateAction, Refund["UpdateOperationData"], Refund["Filter"]> | OakOperation<"remove", Refund["RemoveOperationData"], Refund["Filter"]>;
|
||||
settlement?: OakOperation<"create", Settlement["CreateOperationData"]> | OakOperation<BaseSettlement.OpUpdateAction, Settlement["UpdateOperationData"], Settlement["Filter"]> | OakOperation<"remove", Settlement["RemoveOperationData"], Settlement["Filter"]>;
|
||||
withdraw?: OakOperation<"create", Withdraw["CreateOperationData"]> | OakOperation<BaseWithdraw.OpUpdateAction, Withdraw["UpdateOperationData"], Withdraw["Filter"]> | OakOperation<"remove", Withdraw["RemoveOperationData"], Withdraw["Filter"]>;
|
||||
withdrawTransfer?: OakOperation<"create", WithdrawTransfer["CreateOperationData"]> | OakOperation<BaseWithdrawTransfer.OpUpdateAction, WithdrawTransfer["UpdateOperationData"], WithdrawTransfer["Filter"]> | OakOperation<"remove", WithdrawTransfer["RemoveOperationData"], WithdrawTransfer["Filter"]>;
|
||||
}>;
|
||||
|
|
@ -4459,14 +4465,23 @@ export type Settlement = {
|
|||
Schema: BaseSettlement.OpSchema & {
|
||||
account: Account["Schema"];
|
||||
order: Order["Schema"];
|
||||
accountOper$entity?: Array<Omit<AccountOper["Schema"], "entity">>;
|
||||
accountOper$entity$$aggr?: AggregationResult<Omit<AccountOper["Schema"], "entity">>;
|
||||
};
|
||||
Projection: BaseSettlement.OpProjection & {
|
||||
account?: Account["Projection"];
|
||||
order?: Order["Projection"];
|
||||
accountOper$entity?: OakSelection<"select", Omit<AccountOper["Projection"], "settlement">, Omit<AccountOper["Filter"], "settlement">, AccountOper["Sorter"]> & {
|
||||
$entity: "accountOper";
|
||||
};
|
||||
accountOper$entity$$aggr?: DeduceAggregation<Omit<AccountOper["Projection"], "settlement">, Omit<AccountOper["Filter"], "settlement">, AccountOper["Sorter"]> & {
|
||||
$entity: "accountOper";
|
||||
};
|
||||
};
|
||||
FilterUnit: BaseSettlement.OpFilter & {
|
||||
account: MakeFilter<Account["FilterUnit"]>;
|
||||
order: MakeFilter<Order["FilterUnit"]>;
|
||||
accountOper$entity: MakeFilter<Omit<AccountOper["FilterUnit"], "entity">> & SubQueryPredicateMetadata;
|
||||
};
|
||||
Filter: MakeFilter<Settlement["FilterUnit"]>;
|
||||
SortAttr: Partial<BaseSettlement.OpSortAttr | {
|
||||
|
|
@ -4483,6 +4498,7 @@ export type Settlement = {
|
|||
CreateOperationData: FormCreateData<BaseSettlement.OpSchema & {
|
||||
account?: OakOperation<"create", Account["CreateOperationData"]> | OakOperation<BaseAccount.OpUpdateAction, Account["UpdateOperationData"], Account["Filter"]>;
|
||||
order?: OakOperation<"create", Order["CreateOperationData"]> | OakOperation<BaseOrder.OpUpdateAction, Order["UpdateOperationData"], Order["Filter"]>;
|
||||
accountOper$entity?: OakOperation<"create", Omit<AccountOper["CreateOperationData"], "settlement"> | Omit<AccountOper["CreateOperationData"], "settlement">[]>[];
|
||||
}>;
|
||||
CreateSingle: OakOperation<"create", Settlement["CreateOperationData"]>;
|
||||
CreateMulti: OakOperation<"create", Array<Settlement["CreateOperationData"]>>;
|
||||
|
|
@ -4490,6 +4506,7 @@ export type Settlement = {
|
|||
UpdateOperationData: FormUpdateData<BaseSettlement.OpSchema & {
|
||||
account?: OakOperation<"create", Account["CreateOperationData"]> | OakOperation<BaseAccount.OpUpdateAction, Account["UpdateOperationData"], Account["Filter"]> | OakOperation<"remove", Account["RemoveOperationData"], Account["Filter"]>;
|
||||
order?: OakOperation<"create", Order["CreateOperationData"]> | OakOperation<BaseOrder.OpUpdateAction, Order["UpdateOperationData"], Order["Filter"]> | OakOperation<"remove", Order["RemoveOperationData"], Order["Filter"]>;
|
||||
accountOper$entity?: OakOperation<"create", Omit<AccountOper["CreateOperationData"], "settlement"> | Omit<AccountOper["CreateOperationData"], "settlement">[]>[];
|
||||
}>;
|
||||
Update: OakOperation<BaseSettlement.OpUpdateAction, Settlement["UpdateOperationData"], Settlement["Filter"], Settlement["Sorter"]>;
|
||||
RemoveOperationData: {};
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { GenericAction } from "oak-domain/lib/actions/action";
|
|||
export type IState = 'unsettled' | 'settled' | string;
|
||||
export type IAction = 'settle' | string;
|
||||
export declare const IActionDef: ActionDef<IAction, IState>;
|
||||
export type ParticularAction = IAction | 'refund' | 'refundFailure';
|
||||
export type ParticularAction = IAction | 'preSettle' | 'refund' | 'refundFailure';
|
||||
export declare const actions: string[];
|
||||
export type Action = GenericAction | ParticularAction | string;
|
||||
export declare const actionDefDict: {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ export const IActionDef = {
|
|||
},
|
||||
is: 'unsettled',
|
||||
};
|
||||
export const actions = ["count", "stat", "download", "select", "aggregate", "create", "remove", "update", "settle", "refund", "refundFailure"];
|
||||
export const actions = ["count", "stat", "download", "select", "aggregate", "create", "remove", "update", "settle", "preSettle", "refund", "refundFailure"];
|
||||
export const actionDefDict = {
|
||||
iState: IActionDef
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,9 +4,11 @@
|
|||
"account": "帐号",
|
||||
"price": "变化金额",
|
||||
"order": "订单",
|
||||
"iState": "结算状态"
|
||||
"iState": "结算状态",
|
||||
"opers": "相关帐户操作"
|
||||
},
|
||||
"action": {
|
||||
"preSettle": "预结算",
|
||||
"settle": "结算",
|
||||
"refund": "退款",
|
||||
"refundFailure": "退款失败"
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { DATA_SUBSCRIBER_KEYS } from '../config/constants';
|
|||
import assert from 'assert';
|
||||
const triggers = [
|
||||
{
|
||||
name: '订单全部支付后根据关联的settlement创建type为preSettle的accountOper',
|
||||
name: '订单全部支付后对关联的settlement执行preSettle,更新settlemen关联的ype为preSettle的accountOper',
|
||||
entity: 'order',
|
||||
action: 'payAll',
|
||||
when: 'commit',
|
||||
|
|
@ -26,39 +26,36 @@ const triggers = [
|
|||
forUpdate: true,
|
||||
});
|
||||
assert(settlements && settlements.length > 0);
|
||||
let opers = [];
|
||||
for (const settlement of settlements) {
|
||||
const { price, accountId } = settlement;
|
||||
const { id: settlementId, price, accountId } = settlement;
|
||||
//创建对应的accountOper
|
||||
const oper = [{
|
||||
id: await generateNewIdAsync(),
|
||||
data: {
|
||||
id: await generateNewIdAsync(),
|
||||
totalPlus: price,
|
||||
availPlus: 0,
|
||||
accountId: accountId,
|
||||
type: 'preSettle',
|
||||
},
|
||||
action: 'create',
|
||||
}];
|
||||
opers.push(...oper);
|
||||
await context.operate('settlement', {
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'preSettle',
|
||||
data: {
|
||||
accountOper$entity: [{
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'create',
|
||||
data: {
|
||||
id: await generateNewIdAsync(),
|
||||
totalPlus: price,
|
||||
availPlus: 0,
|
||||
accountId: accountId,
|
||||
type: 'preSettle',
|
||||
}
|
||||
}]
|
||||
},
|
||||
filter: {
|
||||
id: settlementId,
|
||||
}
|
||||
}, {});
|
||||
}
|
||||
await context.operate('order', {
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'update',
|
||||
data: {
|
||||
accountOper$entity: opers,
|
||||
},
|
||||
filter: {
|
||||
id,
|
||||
}
|
||||
}, {});
|
||||
}
|
||||
return;
|
||||
}
|
||||
},
|
||||
{
|
||||
name: '订单执行settle前,对关联的settlement执行settle,创建type为settle的accountOper',
|
||||
name: '订单执行settle前,对关联的settlement执行settle,更新settlemen关联的type为settle的accountOper',
|
||||
entity: 'order',
|
||||
action: 'settle',
|
||||
when: 'before',
|
||||
|
|
@ -90,51 +87,33 @@ const triggers = [
|
|||
dontCollect: true,
|
||||
});
|
||||
for (const order of orders) {
|
||||
const { id, settlement$order: settlements } = order || {};
|
||||
const { settlement$order: settlements } = order || {};
|
||||
assert(settlements && settlements.length > 0);
|
||||
const settlementIds = settlements?.map((ele) => ele.id);
|
||||
if (settlementIds && settlementIds.length > 0) {
|
||||
//将关联的settlement执行settle
|
||||
//将关联的settlement执行settle
|
||||
for (const settlement of settlements) {
|
||||
const { id: settlementId, price, accountId } = settlement;
|
||||
await context.operate('settlement', {
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'settle',
|
||||
data: {},
|
||||
data: {
|
||||
accountOper$entity: [{
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'create',
|
||||
data: {
|
||||
id: await generateNewIdAsync(),
|
||||
totalPlus: 0,
|
||||
availPlus: price,
|
||||
accountId: accountId,
|
||||
type: 'settle',
|
||||
}
|
||||
}]
|
||||
},
|
||||
filter: {
|
||||
id: {
|
||||
$in: settlementIds
|
||||
}
|
||||
id: settlementId,
|
||||
}
|
||||
}, {});
|
||||
cnt++;
|
||||
cnt += settlements.length;
|
||||
}
|
||||
//创建对应的accountOper
|
||||
let opers = [];
|
||||
for (const settlement of settlements) {
|
||||
const { price, accountId } = settlement;
|
||||
const oper = [{
|
||||
id: await generateNewIdAsync(),
|
||||
data: {
|
||||
id: await generateNewIdAsync(),
|
||||
totalPlus: 0,
|
||||
availPlus: price,
|
||||
accountId: accountId,
|
||||
type: 'settle',
|
||||
},
|
||||
action: 'create',
|
||||
}];
|
||||
opers.push(...oper);
|
||||
}
|
||||
await context.operate('order', {
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'update',
|
||||
data: {
|
||||
accountOper$entity: opers,
|
||||
},
|
||||
filter: {
|
||||
id: id,
|
||||
}
|
||||
}, {});
|
||||
cnt++;
|
||||
}
|
||||
return cnt;
|
||||
},
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ exports.payNotify = {
|
|||
name: '微信支付回调',
|
||||
method: 'post',
|
||||
params: ['payId'],
|
||||
type: 'simple',
|
||||
fn: async (context, params, headers, req, body) => {
|
||||
const { payId } = params;
|
||||
return (0, pay_1.payNotify)(context, body, payId, headers);
|
||||
|
|
@ -15,6 +16,7 @@ exports.refundNotify = {
|
|||
name: '微信退款回调',
|
||||
method: 'post',
|
||||
params: ['refundId'],
|
||||
type: 'simple',
|
||||
fn: async (context, params, headers, req, body) => {
|
||||
const { refundId } = params;
|
||||
return (0, pay_1.refundNotify)(context, body, refundId, headers);
|
||||
|
|
|
|||
|
|
@ -3,15 +3,17 @@ import { EntityShape } from 'oak-domain/lib/types/Entity';
|
|||
import { EntityDesc, ActionDef } from 'oak-domain/lib/types';
|
||||
import { Schema as Account } from './Account';
|
||||
import { Schema as Order } from './Order';
|
||||
import { Schema as AccountOper } from './AccountOper';
|
||||
export interface Schema extends EntityShape {
|
||||
account: Account;
|
||||
price: Price;
|
||||
order: Order;
|
||||
opers?: AccountOper[];
|
||||
}
|
||||
type IState = 'unsettled' | 'settled';
|
||||
type IAction = 'settle';
|
||||
export declare const IActionDef: ActionDef<IAction, IState>;
|
||||
type Action = IAction | 'refund' | 'refundFailure';
|
||||
type Action = IAction | 'preSettle' | 'refund' | 'refundFailure';
|
||||
export declare const entityDesc: EntityDesc<Schema, Action, '', {
|
||||
iState: IState;
|
||||
}>;
|
||||
|
|
|
|||
|
|
@ -17,8 +17,10 @@ exports.entityDesc = {
|
|||
price: '变化金额',
|
||||
order: '订单',
|
||||
iState: '结算状态',
|
||||
opers: '相关帐户操作',
|
||||
},
|
||||
action: {
|
||||
preSettle: '预结算',
|
||||
settle: '结算',
|
||||
refund: '退款',
|
||||
refundFailure: '退款失败',
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ exports.desc = {
|
|||
params: {
|
||||
length: 32
|
||||
},
|
||||
ref: ["deposit", "order", "pay", "refund", "withdraw", "withdrawTransfer"]
|
||||
ref: ["deposit", "order", "pay", "refund", "settlement", "withdraw", "withdrawTransfer"]
|
||||
},
|
||||
entityId: {
|
||||
notNull: true,
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ export type OpSchema = EntityShape & {
|
|||
total: Price;
|
||||
avail: Price;
|
||||
refundable: Price;
|
||||
entity: "deposit" | "order" | "pay" | "refund" | "withdraw" | "withdrawTransfer" | string;
|
||||
entity: "deposit" | "order" | "pay" | "refund" | "settlement" | "withdraw" | "withdrawTransfer" | string;
|
||||
entityId: String<64>;
|
||||
} & {
|
||||
[A in ExpressionKey]?: any;
|
||||
|
|
@ -32,7 +32,7 @@ export type OpFilter = {
|
|||
total: Q_NumberValue;
|
||||
avail: Q_NumberValue;
|
||||
refundable: Q_NumberValue;
|
||||
entity: Q_EnumValue<"deposit" | "order" | "pay" | "refund" | "withdraw" | "withdrawTransfer" | string>;
|
||||
entity: Q_EnumValue<"deposit" | "order" | "pay" | "refund" | "settlement" | "withdraw" | "withdrawTransfer" | string>;
|
||||
entityId: Q_StringValue;
|
||||
} & ExprOp<OpAttr | string>;
|
||||
export type OpProjection = {
|
||||
|
|
|
|||
|
|
@ -3978,6 +3978,7 @@ export type AccountOper = {
|
|||
order?: Order["Schema"];
|
||||
pay?: Pay["Schema"];
|
||||
refund?: Refund["Schema"];
|
||||
settlement?: Settlement["Schema"];
|
||||
withdraw?: Withdraw["Schema"];
|
||||
withdrawTransfer?: WithdrawTransfer["Schema"];
|
||||
};
|
||||
|
|
@ -3987,6 +3988,7 @@ export type AccountOper = {
|
|||
order?: Order["Projection"];
|
||||
pay?: Pay["Projection"];
|
||||
refund?: Refund["Projection"];
|
||||
settlement?: Settlement["Projection"];
|
||||
withdraw?: Withdraw["Projection"];
|
||||
withdrawTransfer?: WithdrawTransfer["Projection"];
|
||||
};
|
||||
|
|
@ -3996,6 +3998,7 @@ export type AccountOper = {
|
|||
order: MakeFilter<Order["FilterUnit"]>;
|
||||
pay: MakeFilter<Pay["FilterUnit"]>;
|
||||
refund: MakeFilter<Refund["FilterUnit"]>;
|
||||
settlement: MakeFilter<Settlement["FilterUnit"]>;
|
||||
withdraw: MakeFilter<Withdraw["FilterUnit"]>;
|
||||
withdrawTransfer: MakeFilter<WithdrawTransfer["FilterUnit"]>;
|
||||
};
|
||||
|
|
@ -4006,6 +4009,7 @@ export type AccountOper = {
|
|||
order: Order["SortAttr"];
|
||||
pay: Pay["SortAttr"];
|
||||
refund: Refund["SortAttr"];
|
||||
settlement: Settlement["SortAttr"];
|
||||
withdraw: Withdraw["SortAttr"];
|
||||
withdrawTransfer: WithdrawTransfer["SortAttr"];
|
||||
}>;
|
||||
|
|
@ -4022,6 +4026,7 @@ export type AccountOper = {
|
|||
order?: OakOperation<"create", Order["CreateOperationData"]> | OakOperation<BaseOrder.OpUpdateAction, Order["UpdateOperationData"], Order["Filter"]>;
|
||||
pay?: OakOperation<"create", Pay["CreateOperationData"]> | OakOperation<BasePay.OpUpdateAction, Pay["UpdateOperationData"], Pay["Filter"]>;
|
||||
refund?: OakOperation<"create", Refund["CreateOperationData"]> | OakOperation<BaseRefund.OpUpdateAction, Refund["UpdateOperationData"], Refund["Filter"]>;
|
||||
settlement?: OakOperation<"create", Settlement["CreateOperationData"]> | OakOperation<BaseSettlement.OpUpdateAction, Settlement["UpdateOperationData"], Settlement["Filter"]>;
|
||||
withdraw?: OakOperation<"create", Withdraw["CreateOperationData"]> | OakOperation<BaseWithdraw.OpUpdateAction, Withdraw["UpdateOperationData"], Withdraw["Filter"]>;
|
||||
withdrawTransfer?: OakOperation<"create", WithdrawTransfer["CreateOperationData"]> | OakOperation<BaseWithdrawTransfer.OpUpdateAction, WithdrawTransfer["UpdateOperationData"], WithdrawTransfer["Filter"]>;
|
||||
}>;
|
||||
|
|
@ -4034,6 +4039,7 @@ export type AccountOper = {
|
|||
order?: OakOperation<"create", Order["CreateOperationData"]> | OakOperation<BaseOrder.OpUpdateAction, Order["UpdateOperationData"], Order["Filter"]> | OakOperation<"remove", Order["RemoveOperationData"], Order["Filter"]>;
|
||||
pay?: OakOperation<"create", Pay["CreateOperationData"]> | OakOperation<BasePay.OpUpdateAction, Pay["UpdateOperationData"], Pay["Filter"]> | OakOperation<"remove", Pay["RemoveOperationData"], Pay["Filter"]>;
|
||||
refund?: OakOperation<"create", Refund["CreateOperationData"]> | OakOperation<BaseRefund.OpUpdateAction, Refund["UpdateOperationData"], Refund["Filter"]> | OakOperation<"remove", Refund["RemoveOperationData"], Refund["Filter"]>;
|
||||
settlement?: OakOperation<"create", Settlement["CreateOperationData"]> | OakOperation<BaseSettlement.OpUpdateAction, Settlement["UpdateOperationData"], Settlement["Filter"]> | OakOperation<"remove", Settlement["RemoveOperationData"], Settlement["Filter"]>;
|
||||
withdraw?: OakOperation<"create", Withdraw["CreateOperationData"]> | OakOperation<BaseWithdraw.OpUpdateAction, Withdraw["UpdateOperationData"], Withdraw["Filter"]> | OakOperation<"remove", Withdraw["RemoveOperationData"], Withdraw["Filter"]>;
|
||||
withdrawTransfer?: OakOperation<"create", WithdrawTransfer["CreateOperationData"]> | OakOperation<BaseWithdrawTransfer.OpUpdateAction, WithdrawTransfer["UpdateOperationData"], WithdrawTransfer["Filter"]> | OakOperation<"remove", WithdrawTransfer["RemoveOperationData"], WithdrawTransfer["Filter"]>;
|
||||
}>;
|
||||
|
|
@ -4459,14 +4465,23 @@ export type Settlement = {
|
|||
Schema: BaseSettlement.OpSchema & {
|
||||
account: Account["Schema"];
|
||||
order: Order["Schema"];
|
||||
accountOper$entity?: Array<Omit<AccountOper["Schema"], "entity">>;
|
||||
accountOper$entity$$aggr?: AggregationResult<Omit<AccountOper["Schema"], "entity">>;
|
||||
};
|
||||
Projection: BaseSettlement.OpProjection & {
|
||||
account?: Account["Projection"];
|
||||
order?: Order["Projection"];
|
||||
accountOper$entity?: OakSelection<"select", Omit<AccountOper["Projection"], "settlement">, Omit<AccountOper["Filter"], "settlement">, AccountOper["Sorter"]> & {
|
||||
$entity: "accountOper";
|
||||
};
|
||||
accountOper$entity$$aggr?: DeduceAggregation<Omit<AccountOper["Projection"], "settlement">, Omit<AccountOper["Filter"], "settlement">, AccountOper["Sorter"]> & {
|
||||
$entity: "accountOper";
|
||||
};
|
||||
};
|
||||
FilterUnit: BaseSettlement.OpFilter & {
|
||||
account: MakeFilter<Account["FilterUnit"]>;
|
||||
order: MakeFilter<Order["FilterUnit"]>;
|
||||
accountOper$entity: MakeFilter<Omit<AccountOper["FilterUnit"], "entity">> & SubQueryPredicateMetadata;
|
||||
};
|
||||
Filter: MakeFilter<Settlement["FilterUnit"]>;
|
||||
SortAttr: Partial<BaseSettlement.OpSortAttr | {
|
||||
|
|
@ -4483,6 +4498,7 @@ export type Settlement = {
|
|||
CreateOperationData: FormCreateData<BaseSettlement.OpSchema & {
|
||||
account?: OakOperation<"create", Account["CreateOperationData"]> | OakOperation<BaseAccount.OpUpdateAction, Account["UpdateOperationData"], Account["Filter"]>;
|
||||
order?: OakOperation<"create", Order["CreateOperationData"]> | OakOperation<BaseOrder.OpUpdateAction, Order["UpdateOperationData"], Order["Filter"]>;
|
||||
accountOper$entity?: OakOperation<"create", Omit<AccountOper["CreateOperationData"], "settlement"> | Omit<AccountOper["CreateOperationData"], "settlement">[]>[];
|
||||
}>;
|
||||
CreateSingle: OakOperation<"create", Settlement["CreateOperationData"]>;
|
||||
CreateMulti: OakOperation<"create", Array<Settlement["CreateOperationData"]>>;
|
||||
|
|
@ -4490,6 +4506,7 @@ export type Settlement = {
|
|||
UpdateOperationData: FormUpdateData<BaseSettlement.OpSchema & {
|
||||
account?: OakOperation<"create", Account["CreateOperationData"]> | OakOperation<BaseAccount.OpUpdateAction, Account["UpdateOperationData"], Account["Filter"]> | OakOperation<"remove", Account["RemoveOperationData"], Account["Filter"]>;
|
||||
order?: OakOperation<"create", Order["CreateOperationData"]> | OakOperation<BaseOrder.OpUpdateAction, Order["UpdateOperationData"], Order["Filter"]> | OakOperation<"remove", Order["RemoveOperationData"], Order["Filter"]>;
|
||||
accountOper$entity?: OakOperation<"create", Omit<AccountOper["CreateOperationData"], "settlement"> | Omit<AccountOper["CreateOperationData"], "settlement">[]>[];
|
||||
}>;
|
||||
Update: OakOperation<BaseSettlement.OpUpdateAction, Settlement["UpdateOperationData"], Settlement["Filter"], Settlement["Sorter"]>;
|
||||
RemoveOperationData: {};
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { GenericAction } from "oak-domain/lib/actions/action";
|
|||
export type IState = 'unsettled' | 'settled' | string;
|
||||
export type IAction = 'settle' | string;
|
||||
export declare const IActionDef: ActionDef<IAction, IState>;
|
||||
export type ParticularAction = IAction | 'refund' | 'refundFailure';
|
||||
export type ParticularAction = IAction | 'preSettle' | 'refund' | 'refundFailure';
|
||||
export declare const actions: string[];
|
||||
export type Action = GenericAction | ParticularAction | string;
|
||||
export declare const actionDefDict: {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ exports.IActionDef = {
|
|||
},
|
||||
is: 'unsettled',
|
||||
};
|
||||
exports.actions = ["count", "stat", "download", "select", "aggregate", "create", "remove", "update", "settle", "refund", "refundFailure"];
|
||||
exports.actions = ["count", "stat", "download", "select", "aggregate", "create", "remove", "update", "settle", "preSettle", "refund", "refundFailure"];
|
||||
exports.actionDefDict = {
|
||||
iState: exports.IActionDef
|
||||
};
|
||||
|
|
|
|||
|
|
@ -4,9 +4,11 @@
|
|||
"account": "帐号",
|
||||
"price": "变化金额",
|
||||
"order": "订单",
|
||||
"iState": "结算状态"
|
||||
"iState": "结算状态",
|
||||
"opers": "相关帐户操作"
|
||||
},
|
||||
"action": {
|
||||
"preSettle": "预结算",
|
||||
"settle": "结算",
|
||||
"refund": "退款",
|
||||
"refundFailure": "退款失败"
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ const constants_1 = require("../config/constants");
|
|||
const assert_1 = tslib_1.__importDefault(require("assert"));
|
||||
const triggers = [
|
||||
{
|
||||
name: '订单全部支付后根据关联的settlement创建type为preSettle的accountOper',
|
||||
name: '订单全部支付后对关联的settlement执行preSettle,更新settlemen关联的ype为preSettle的accountOper',
|
||||
entity: 'order',
|
||||
action: 'payAll',
|
||||
when: 'commit',
|
||||
|
|
@ -29,39 +29,36 @@ const triggers = [
|
|||
forUpdate: true,
|
||||
});
|
||||
(0, assert_1.default)(settlements && settlements.length > 0);
|
||||
let opers = [];
|
||||
for (const settlement of settlements) {
|
||||
const { price, accountId } = settlement;
|
||||
const { id: settlementId, price, accountId } = settlement;
|
||||
//创建对应的accountOper
|
||||
const oper = [{
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
data: {
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
totalPlus: price,
|
||||
availPlus: 0,
|
||||
accountId: accountId,
|
||||
type: 'preSettle',
|
||||
},
|
||||
action: 'create',
|
||||
}];
|
||||
opers.push(...oper);
|
||||
await context.operate('settlement', {
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
action: 'preSettle',
|
||||
data: {
|
||||
accountOper$entity: [{
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
action: 'create',
|
||||
data: {
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
totalPlus: price,
|
||||
availPlus: 0,
|
||||
accountId: accountId,
|
||||
type: 'preSettle',
|
||||
}
|
||||
}]
|
||||
},
|
||||
filter: {
|
||||
id: settlementId,
|
||||
}
|
||||
}, {});
|
||||
}
|
||||
await context.operate('order', {
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
action: 'update',
|
||||
data: {
|
||||
accountOper$entity: opers,
|
||||
},
|
||||
filter: {
|
||||
id,
|
||||
}
|
||||
}, {});
|
||||
}
|
||||
return;
|
||||
}
|
||||
},
|
||||
{
|
||||
name: '订单执行settle前,对关联的settlement执行settle,创建type为settle的accountOper',
|
||||
name: '订单执行settle前,对关联的settlement执行settle,更新settlemen关联的type为settle的accountOper',
|
||||
entity: 'order',
|
||||
action: 'settle',
|
||||
when: 'before',
|
||||
|
|
@ -93,51 +90,33 @@ const triggers = [
|
|||
dontCollect: true,
|
||||
});
|
||||
for (const order of orders) {
|
||||
const { id, settlement$order: settlements } = order || {};
|
||||
const { settlement$order: settlements } = order || {};
|
||||
(0, assert_1.default)(settlements && settlements.length > 0);
|
||||
const settlementIds = settlements?.map((ele) => ele.id);
|
||||
if (settlementIds && settlementIds.length > 0) {
|
||||
//将关联的settlement执行settle
|
||||
//将关联的settlement执行settle
|
||||
for (const settlement of settlements) {
|
||||
const { id: settlementId, price, accountId } = settlement;
|
||||
await context.operate('settlement', {
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
action: 'settle',
|
||||
data: {},
|
||||
data: {
|
||||
accountOper$entity: [{
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
action: 'create',
|
||||
data: {
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
totalPlus: 0,
|
||||
availPlus: price,
|
||||
accountId: accountId,
|
||||
type: 'settle',
|
||||
}
|
||||
}]
|
||||
},
|
||||
filter: {
|
||||
id: {
|
||||
$in: settlementIds
|
||||
}
|
||||
id: settlementId,
|
||||
}
|
||||
}, {});
|
||||
cnt++;
|
||||
cnt += settlements.length;
|
||||
}
|
||||
//创建对应的accountOper
|
||||
let opers = [];
|
||||
for (const settlement of settlements) {
|
||||
const { price, accountId } = settlement;
|
||||
const oper = [{
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
data: {
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
totalPlus: 0,
|
||||
availPlus: price,
|
||||
accountId: accountId,
|
||||
type: 'settle',
|
||||
},
|
||||
action: 'create',
|
||||
}];
|
||||
opers.push(...oper);
|
||||
}
|
||||
await context.operate('order', {
|
||||
id: await (0, uuid_1.generateNewIdAsync)(),
|
||||
action: 'update',
|
||||
data: {
|
||||
accountOper$entity: opers,
|
||||
},
|
||||
filter: {
|
||||
id: id,
|
||||
}
|
||||
}, {});
|
||||
cnt++;
|
||||
}
|
||||
return cnt;
|
||||
},
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ export const payNotify: Endpoint<EntityDict, BackendRuntimeContext<EntityDict>>
|
|||
name: '微信支付回调',
|
||||
method: 'post',
|
||||
params: ['payId'],
|
||||
type: 'simple',
|
||||
fn: async (context, params, headers, req, body) => {
|
||||
const { payId } = params;
|
||||
|
||||
|
|
@ -19,6 +20,7 @@ export const refundNotify: Endpoint<EntityDict, BackendRuntimeContext<EntityDict
|
|||
name: '微信退款回调',
|
||||
method: 'post',
|
||||
params: ['refundId'],
|
||||
type: 'simple',
|
||||
fn: async (context, params, headers, req, body) => {
|
||||
const { refundId } = params;
|
||||
|
||||
|
|
|
|||
|
|
@ -9,11 +9,13 @@ import { EntityShape } from 'oak-domain/lib/types/Entity';
|
|||
import { EntityDesc, ActionDef } from 'oak-domain/lib/types';
|
||||
import { Schema as Account } from './Account';
|
||||
import { Schema as Order } from './Order';
|
||||
import { Schema as AccountOper } from './AccountOper';
|
||||
|
||||
export interface Schema extends EntityShape {
|
||||
account: Account;
|
||||
price: Price;
|
||||
order: Order;
|
||||
opers?: AccountOper[];
|
||||
};
|
||||
|
||||
type IState = 'unsettled' | 'settled';
|
||||
|
|
@ -26,7 +28,7 @@ export const IActionDef: ActionDef<IAction, IState> = {
|
|||
is: 'unsettled',
|
||||
};
|
||||
|
||||
type Action = IAction | 'refund' | 'refundFailure';
|
||||
type Action = IAction | 'preSettle' | 'refund' | 'refundFailure';
|
||||
|
||||
export const entityDesc: EntityDesc<Schema, Action, '', {
|
||||
iState: IState,
|
||||
|
|
@ -39,8 +41,10 @@ export const entityDesc: EntityDesc<Schema, Action, '', {
|
|||
price: '变化金额',
|
||||
order: '订单',
|
||||
iState: '结算状态',
|
||||
opers: '相关帐户操作',
|
||||
},
|
||||
action: {
|
||||
preSettle: '预结算',
|
||||
settle: '结算',
|
||||
refund: '退款',
|
||||
refundFailure: '退款失败',
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import assert from 'assert';
|
|||
|
||||
const triggers: Trigger<EntityDict, 'order', BRC>[] = [
|
||||
{
|
||||
name: '订单全部支付后根据关联的settlement创建type为preSettle的accountOper',
|
||||
name: '订单全部支付后对关联的settlement执行preSettle,更新settlemen关联的ype为preSettle的accountOper',
|
||||
entity: 'order',
|
||||
action: 'payAll',
|
||||
when: 'commit',
|
||||
|
|
@ -31,42 +31,36 @@ const triggers: Trigger<EntityDict, 'order', BRC>[] = [
|
|||
});
|
||||
assert(settlements && settlements.length > 0);
|
||||
|
||||
let opers: EntityDict['order']['Update']['data']['accountOper$entity'] = [];
|
||||
for (const settlement of settlements) {
|
||||
const { price, accountId } = settlement;
|
||||
const { id: settlementId, price, accountId } = settlement;
|
||||
//创建对应的accountOper
|
||||
const oper: EntityDict['order']['Update']['data']['accountOper$entity'] = [{
|
||||
await context.operate('settlement', {
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'preSettle',
|
||||
data: {
|
||||
id: await generateNewIdAsync(),
|
||||
totalPlus: price,
|
||||
availPlus: 0,
|
||||
accountId: accountId,
|
||||
type: 'preSettle',
|
||||
},
|
||||
action: 'create',
|
||||
}]
|
||||
opers.push(...oper);
|
||||
}
|
||||
await context.operate('order',
|
||||
{
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'update',
|
||||
data: {
|
||||
accountOper$entity: opers,
|
||||
accountOper$entity: [{
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'create',
|
||||
data: {
|
||||
id: await generateNewIdAsync(),
|
||||
totalPlus: price,
|
||||
availPlus: 0,
|
||||
accountId: accountId,
|
||||
type: 'preSettle',
|
||||
}
|
||||
}]
|
||||
},
|
||||
filter: {
|
||||
id,
|
||||
id: settlementId,
|
||||
}
|
||||
},
|
||||
{}
|
||||
);
|
||||
}, {})
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
},
|
||||
{
|
||||
name: '订单执行settle前,对关联的settlement执行settle,创建type为settle的accountOper',
|
||||
name: '订单执行settle前,对关联的settlement执行settle,更新settlemen关联的type为settle的accountOper',
|
||||
entity: 'order',
|
||||
action: 'settle',
|
||||
when: 'before',
|
||||
|
|
@ -100,58 +94,37 @@ const triggers: Trigger<EntityDict, 'order', BRC>[] = [
|
|||
});
|
||||
|
||||
for (const order of orders) {
|
||||
const { id, settlement$order: settlements } = order || {};
|
||||
const { settlement$order: settlements } = order || {};
|
||||
assert(settlements && settlements.length > 0);
|
||||
const settlementIds = settlements?.map((ele) => ele.id);
|
||||
if (settlementIds && settlementIds.length > 0) {
|
||||
//将关联的settlement执行settle
|
||||
//将关联的settlement执行settle
|
||||
for (const settlement of settlements) {
|
||||
const { id: settlementId, price, accountId } = settlement;
|
||||
|
||||
await context.operate('settlement',
|
||||
{
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'settle',
|
||||
data: {},
|
||||
data: {
|
||||
accountOper$entity: [{
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'create',
|
||||
data: {
|
||||
id: await generateNewIdAsync(),
|
||||
totalPlus: 0,
|
||||
availPlus: price,
|
||||
accountId: accountId,
|
||||
type: 'settle',
|
||||
}
|
||||
}]
|
||||
},
|
||||
filter: {
|
||||
id: {
|
||||
$in: settlementIds
|
||||
}
|
||||
id: settlementId,
|
||||
}
|
||||
},
|
||||
{}
|
||||
);
|
||||
cnt++;
|
||||
cnt += settlements.length;
|
||||
}
|
||||
|
||||
//创建对应的accountOper
|
||||
let opers: EntityDict['order']['Update']['data']['accountOper$entity'] = [];
|
||||
for (const settlement of settlements) {
|
||||
const { price, accountId } = settlement;
|
||||
const oper: EntityDict['order']['Update']['data']['accountOper$entity'] = [{
|
||||
id: await generateNewIdAsync(),
|
||||
data: {
|
||||
id: await generateNewIdAsync(),
|
||||
totalPlus: 0,
|
||||
availPlus: price,
|
||||
accountId: accountId,
|
||||
type: 'settle',
|
||||
},
|
||||
action: 'create',
|
||||
}]
|
||||
opers.push(...oper);
|
||||
}
|
||||
await context.operate('order',
|
||||
{
|
||||
id: await generateNewIdAsync(),
|
||||
action: 'update',
|
||||
data: {
|
||||
accountOper$entity: opers,
|
||||
},
|
||||
filter: {
|
||||
id: id!,
|
||||
}
|
||||
},
|
||||
{}
|
||||
);
|
||||
cnt++;
|
||||
}
|
||||
return cnt;
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue