对account类型的pay的一些算法改进

This commit is contained in:
Xu Chang 2025-03-05 20:22:06 +08:00
parent c8e4b9c82c
commit 1fe7f220a1
28 changed files with 114 additions and 146 deletions

View File

@ -1,5 +1,4 @@
import { OakAttrNotNullException, OakInputIllegalException } from 'oak-domain/lib/types';
import { pipeline } from 'oak-domain/lib/utils/executor';
import assert from 'assert';
const checkers = [
{
@ -112,32 +111,35 @@ const checkers = [
}
}
},
{
/* {
// 如果在开始支付或者继续支付过程中paid达到了pricepay的状态可以改为paid
entity: 'pay',
type: 'logical',
action: ['continuePaying', 'startPaying'],
// priority: CHECKER_MAX_PRIORITY - 1, // 要超过action矩阵定义的赋state值
checker: (operation, context) => {
const { data, filter } = operation;
const { data, filter } = operation as EntityDict['pay']['Update'];
assert(filter && typeof filter.id === 'string');
const { paid } = data || {};
if (paid) {
return pipeline(() => context.select('pay', {
data: {
id: 1,
paid: 1,
price: 1,
},
}, {}), (pays) => {
const [pay] = pays;
const { paid: payPaid, price } = pay;
if (payPaid + paid === price) {
data.iState === 'paid';
return pipeline(
() => context.select('pay', {
data: {
id: 1,
paid: 1,
price: 1,
},
}, {}),
(pays: EntityDict['pay']['OpSchema'][]) => {
const [pay] = pays;
const { paid: payPaid, price } = pay;
if (payPaid + paid === price) {
data.iState === 'paid';
}
}
});
)
}
}
}
} */
];
export default checkers;

View File

@ -61,14 +61,14 @@ declare const Detail: <T extends keyof EntityDict>(props: ReactComponentProps<En
data: Partial<EntityDict[T]["Schema"]>;
title?: string | undefined;
bordered?: boolean | undefined;
layout?: "vertical" | "horizontal" | undefined;
layout?: "horizontal" | "vertical" | undefined;
}>) => React.ReactElement;
declare const Upsert: <T extends keyof EntityDict>(props: ReactComponentProps<EntityDict, T, false, {
helps: Record<string, string>;
entity: T;
attributes: OakAbsAttrUpsertDef<EntityDict, T, string | number>[];
data: EntityDict[T]["Schema"];
layout: "vertical" | "horizontal";
layout: "horizontal" | "vertical";
mode: "default" | "card";
}>) => React.ReactElement;
export { FilterPanel, List, ListPro, Detail, Upsert, ReactComponentProps, ColumnProps, RowWithActions, OakExtraActionProps, OakAbsAttrDef, onActionFnDef, };

View File

@ -130,7 +130,8 @@ export default OakComponent({
entity: 'account',
entityId: accountId,
price: accountPrice,
autoStart: !!autoStartPay,
// account类型的pay自动开始
autoStart: true,
});
rest = rest - accountPrice;
}

View File

@ -9,9 +9,8 @@ export function registerShipSettingComponent(entity, component) {
assert(!ShipSettingComponentDict[entity]);
ShipSettingComponentDict[entity] = component;
}
function renderShipEntity(props) {
const { oakId, oakFullpath } = props.data;
const { t, execute, clean } = props.methods;
function RenderShipEntity(props) {
const { oakId, oakFullpath, t } = props;
const entities = Object.keys(ShipSettingComponentDict);
if (oakId && oakFullpath && entities.length) {
return (<Tabs className={Styles.container} tabPosition="left" items={entities.map((entity) => {
@ -63,13 +62,12 @@ function renderShipEntity(props) {
export default function render(props) {
const { oakFullpath, oakId } = props.data;
const { t } = props.methods;
const E = renderShipEntity(props);
if (oakFullpath && oakId) {
return (<Tabs items={[
{
key: '1',
label: t('shipEntity'),
children: E,
children: <RenderShipEntity oakFullpath={oakFullpath} oakId={oakId} t={t}/>,
},
{
key: '2',

View File

@ -1,7 +1,7 @@
{
"appName": "关联小程序",
"help": {
"intro": "小程序关联物流的优先级最高,只要通过该小程序下单就会默认启用"
"intro": "小程序物流能力参见文档https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/express/business/introduction.html必须有相应的小程序方可启用"
},
"warning": {
"disabled": "注意,小程序要求大部分支付必须与物流进行绑定,若是关闭,可能会造成资金无法正常结转",

View File

@ -10,7 +10,6 @@ export default OakComponent({
name: 1,
},
},
bizId: 1,
sort: 1,
},
isList: false,

View File

@ -10,7 +10,7 @@ export default function render(props) {
update({
wpProductId: value,
});
}}/> : <Input disabled={true} value={wechatMpShip.wpProduct.application.name}/>}
}}/> : <Input disabled={true} value={wechatMpShip.wpProduct?.application?.name}/>}
</Form.Item>
<Form.Item label={t('wechatMpShip:attr.disabled')} help={t('help.disabled')}>
<Switch value={!!wechatMpShip.disabled} onChange={(v) => {

View File

@ -6,6 +6,7 @@ export const selectFreeEntities = [
'withdrawChannel',
'wpAccount',
'shipCompany',
'shipService',
];
export const updateFreeDict = {};
export default {

View File

@ -318,7 +318,7 @@ const i18ns = [
data: {
"appName": "关联小程序",
"help": {
"intro": "小程序关联物流的优先级最高,只要通过该小程序下单就会默认启用"
"intro": "小程序物流能力参见文档https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/express/business/introduction.html必须有相应的小程序方可启用"
},
"warning": {
"disabled": "注意,小程序要求大部分支付必须与物流进行绑定,若是关闭,可能会造成资金无法正常结转",

View File

@ -2,7 +2,7 @@
export const entityDesc = {
locales: {
zh_CN: {
name: '微信小程序快递帐号',
name: '微信小程序物流接口',
attr: {
sort: '排序',
phatom1: '备用属性一',

View File

@ -290,7 +290,7 @@ const triggers = [
{
name: '当pay的状态发生变化时修改相应的order的状态或者deposit的状态同时尝试向订阅者推送',
entity: 'pay',
action: ['startPaying', 'succeedPaying', 'continuePaying', 'close', 'startRefunding',
action: ['startPaying', 'succeedPaying', 'close', 'startRefunding',
'refundAll', 'refundPartially'],
when: 'after',
asRoot: true,
@ -644,9 +644,17 @@ const triggers = [
{
entity: 'pay',
name: '当有pay支付成功时尝试将account类型的pay完成',
action: ['startPaying', 'continuePaying', 'succeedPaying'],
action: ['startPaying', 'succeedPaying'],
attributes: ['paid'],
/**
* 只有account类型的pay在startPaying的时候就会修改paid因此这里的触发情况实际上是
* 1account类型的pay进行startPaying
* 2) 非account类型的pay进行succeedPaying
*
* by Xc 2025/03/05
*/
when: 'after',
priority: 99,
fn: async ({ operation }, context, option) => {
const { filter } = operation;
const ids = getRelevantIds(filter);
@ -711,26 +719,3 @@ const triggers = [
} as SelectTriggerAfter<EntityDict, 'pay', BRC>, */
];
export default triggers;
// export const optionalTriggers: Trigger<EntityDict, 'pay', BRC>[] = [
// {
// name: '当生成pay后自动开始支付流程',
// entity: 'pay',
// action: 'create',
// when: 'commit',
// asRoot: true,
// fn: async ({ ids }, context, option) => {
// assert(ids.length === 1);
// const [id] = ids;
// await context.operate('pay', {
// id: await generateNewIdAsync(),
// action: 'startPaying',
// data: {
// },
// filter: {
// id,
// }
// }, option);
// return;
// },
// }
// ]

View File

@ -6,6 +6,6 @@ import { BRC } from '../types/RuntimeCxt';
* @param context
* @param refunds
*/
export declare function updateWithdrawState(context: BRC, id: string): Promise<1 | 0>;
export declare function updateWithdrawState(context: BRC, id: string): Promise<0 | 1>;
declare const triggers: Trigger<EntityDict, 'withdraw', BRC>[];
export default triggers;

View File

@ -7,12 +7,15 @@ export const fullShipProjection = {
id: 1,
type: 1,
iState: 1,
shipCompanyId: 1,
shipCompany: {
shipService: {
id: 1,
name: 1,
abbr: 1,
wechatMpName: 1,
shipCompany: {
id: 1,
name: 1,
abbr: 1,
wechatMpName: 1,
}
},
serial: 1,
deposit$ship: {

View File

@ -2,7 +2,6 @@
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const types_1 = require("oak-domain/lib/types");
const executor_1 = require("oak-domain/lib/utils/executor");
const assert_1 = tslib_1.__importDefault(require("assert"));
const checkers = [
{
@ -115,32 +114,35 @@ const checkers = [
}
}
},
{
/* {
// 如果在开始支付或者继续支付过程中paid达到了pricepay的状态可以改为paid
entity: 'pay',
type: 'logical',
action: ['continuePaying', 'startPaying'],
// priority: CHECKER_MAX_PRIORITY - 1, // 要超过action矩阵定义的赋state值
checker: (operation, context) => {
const { data, filter } = operation;
(0, assert_1.default)(filter && typeof filter.id === 'string');
const { data, filter } = operation as EntityDict['pay']['Update'];
assert(filter && typeof filter.id === 'string');
const { paid } = data || {};
if (paid) {
return (0, executor_1.pipeline)(() => context.select('pay', {
data: {
id: 1,
paid: 1,
price: 1,
},
}, {}), (pays) => {
const [pay] = pays;
const { paid: payPaid, price } = pay;
if (payPaid + paid === price) {
data.iState === 'paid';
return pipeline(
() => context.select('pay', {
data: {
id: 1,
paid: 1,
price: 1,
},
}, {}),
(pays: EntityDict['pay']['OpSchema'][]) => {
const [pay] = pays;
const { paid: payPaid, price } = pay;
if (payPaid + paid === price) {
data.iState === 'paid';
}
}
});
)
}
}
}
} */
];
exports.default = checkers;

View File

@ -9,6 +9,7 @@ exports.selectFreeEntities = [
'withdrawChannel',
'wpAccount',
'shipCompany',
'shipService',
];
exports.updateFreeDict = {};
exports.default = {

View File

@ -320,7 +320,7 @@ const i18ns = [
data: {
"appName": "关联小程序",
"help": {
"intro": "小程序关联物流的优先级最高,只要通过该小程序下单就会默认启用"
"intro": "小程序物流能力参见文档https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/express/business/introduction.html必须有相应的小程序方可启用"
},
"warning": {
"disabled": "注意,小程序要求大部分支付必须与物流进行绑定,若是关闭,可能会造成资金无法正常结转",

View File

@ -5,7 +5,7 @@ exports.entityDesc = void 0;
exports.entityDesc = {
locales: {
zh_CN: {
name: '微信小程序快递帐号',
name: '微信小程序物流接口',
attr: {
sort: '排序',
phatom1: '备用属性一',

View File

@ -293,7 +293,7 @@ const triggers = [
{
name: '当pay的状态发生变化时修改相应的order的状态或者deposit的状态同时尝试向订阅者推送',
entity: 'pay',
action: ['startPaying', 'succeedPaying', 'continuePaying', 'close', 'startRefunding',
action: ['startPaying', 'succeedPaying', 'close', 'startRefunding',
'refundAll', 'refundPartially'],
when: 'after',
asRoot: true,
@ -647,9 +647,17 @@ const triggers = [
{
entity: 'pay',
name: '当有pay支付成功时尝试将account类型的pay完成',
action: ['startPaying', 'continuePaying', 'succeedPaying'],
action: ['startPaying', 'succeedPaying'],
attributes: ['paid'],
/**
* 只有account类型的pay在startPaying的时候就会修改paid因此这里的触发情况实际上是
* 1account类型的pay进行startPaying
* 2) 非account类型的pay进行succeedPaying
*
* by Xc 2025/03/05
*/
when: 'after',
priority: 99,
fn: async ({ operation }, context, option) => {
const { filter } = operation;
const ids = (0, filter_1.getRelevantIds)(filter);
@ -714,26 +722,3 @@ const triggers = [
} as SelectTriggerAfter<EntityDict, 'pay', BRC>, */
];
exports.default = triggers;
// export const optionalTriggers: Trigger<EntityDict, 'pay', BRC>[] = [
// {
// name: '当生成pay后自动开始支付流程',
// entity: 'pay',
// action: 'create',
// when: 'commit',
// asRoot: true,
// fn: async ({ ids }, context, option) => {
// assert(ids.length === 1);
// const [id] = ids;
// await context.operate('pay', {
// id: await generateNewIdAsync(),
// action: 'startPaying',
// data: {
// },
// filter: {
// id,
// }
// }, option);
// return;
// },
// }
// ]

View File

@ -6,6 +6,6 @@ import { BRC } from '../types/RuntimeCxt';
* @param context
* @param refunds
*/
export declare function updateWithdrawState(context: BRC, id: string): Promise<1 | 0>;
export declare function updateWithdrawState(context: BRC, id: string): Promise<0 | 1>;
declare const triggers: Trigger<EntityDict, 'withdraw', BRC>[];
export default triggers;

View File

@ -11,12 +11,15 @@ exports.fullShipProjection = {
id: 1,
type: 1,
iState: 1,
shipCompanyId: 1,
shipCompany: {
shipService: {
id: 1,
name: 1,
abbr: 1,
wechatMpName: 1,
shipCompany: {
id: 1,
name: 1,
abbr: 1,
wechatMpName: 1,
}
},
serial: 1,
deposit$ship: {

View File

@ -125,7 +125,7 @@ const checkers: Checker<EntityDict, 'pay', RuntimeCxt>[] = [
}
}
},
{
/* {
// 如果在开始支付或者继续支付过程中paid达到了pricepay的状态可以改为paid
entity: 'pay',
type: 'logical',
@ -154,7 +154,7 @@ const checkers: Checker<EntityDict, 'pay', RuntimeCxt>[] = [
)
}
}
}
} */
];
export default checkers;

View File

@ -134,7 +134,8 @@ export default OakComponent({
entity: 'account',
entityId: accountId,
price: accountPrice,
autoStart: !!autoStartPay,
// account类型的pay自动开始
autoStart: true,
});
rest = rest - accountPrice;
}

View File

@ -1,7 +1,7 @@
{
"appName": "关联小程序",
"help": {
"intro": "小程序关联物流的优先级最高,只要通过该小程序下单就会默认启用"
"intro": "小程序物流能力参见文档https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/express/business/introduction.html必须有相应的小程序方可启用"
},
"warning": {
"disabled": "注意,小程序要求大部分支付必须与物流进行绑定,若是关闭,可能会造成资金无法正常结转",

View File

@ -11,6 +11,7 @@ export const selectFreeEntities = [
'withdrawChannel',
'wpAccount',
'shipCompany',
'shipService',
];
export const updateFreeDict: UpdateFreeDict<EntityDict> = {

View File

@ -320,7 +320,7 @@ const i18ns: I18n[] = [
data: {
"appName": "关联小程序",
"help": {
"intro": "小程序关联物流的优先级最高,只要通过该小程序下单就会默认启用"
"intro": "小程序物流能力参见文档https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/express/business/introduction.html必须有相应的小程序方可启用"
},
"warning": {
"disabled": "注意,小程序要求大部分支付必须与物流进行绑定,若是关闭,可能会造成资金无法正常结转",

View File

@ -18,7 +18,7 @@ export interface Schema extends AbstractShipAccount {
export const entityDesc: EntityDesc<Schema> = {
locales: {
zh_CN: {
name: '微信小程序快递帐号',
name: '微信小程序物流接口',
attr: {
sort: '排序',
phatom1: '备用属性一',

View File

@ -315,7 +315,7 @@ const triggers: Trigger<EntityDict, 'pay', BRC>[] = [
{
name: '当pay的状态发生变化时修改相应的order的状态或者deposit的状态同时尝试向订阅者推送',
entity: 'pay',
action: ['startPaying', 'succeedPaying', 'continuePaying', 'close', 'startRefunding',
action: ['startPaying', 'succeedPaying', 'close', 'startRefunding',
'refundAll', 'refundPartially'],
when: 'after',
asRoot: true,
@ -702,9 +702,17 @@ const triggers: Trigger<EntityDict, 'pay', BRC>[] = [
{
entity: 'pay',
name: '当有pay支付成功时尝试将account类型的pay完成',
action: ['startPaying', 'continuePaying', 'succeedPaying'],
action: ['startPaying', 'succeedPaying'],
attributes: ['paid'],
/**
* account类型的pay在startPaying的时候就会修改paid
* 1account类型的pay进行startPaying
* 2) account类型的pay进行succeedPaying
*
* by Xc 2025/03/05
*/
when: 'after',
priority: 99,
fn: async ({ operation }, context, option) => {
const { filter } = operation;
const ids = getRelevantIds(filter!);
@ -773,29 +781,4 @@ const triggers: Trigger<EntityDict, 'pay', BRC>[] = [
} as SelectTriggerAfter<EntityDict, 'pay', BRC>, */
];
export default triggers;
// export const optionalTriggers: Trigger<EntityDict, 'pay', BRC>[] = [
// {
// name: '当生成pay后自动开始支付流程',
// entity: 'pay',
// action: 'create',
// when: 'commit',
// asRoot: true,
// fn: async ({ ids }, context, option) => {
// assert(ids.length === 1);
// const [id] = ids;
// await context.operate('pay', {
// id: await generateNewIdAsync(),
// action: 'startPaying',
// data: {
// },
// filter: {
// id,
// }
// }, option);
// return;
// },
// }
// ]
export default triggers;

View File

@ -12,12 +12,15 @@ export const fullShipProjection: EntityDict['ship']['Projection'] = {
id: 1,
type: 1,
iState: 1,
shipCompanyId: 1,
shipCompany: {
shipService: {
id: 1,
name: 1,
abbr: 1,
wechatMpName: 1,
shipCompany: {
id: 1,
name: 1,
abbr: 1,
wechatMpName: 1,
}
},
serial: 1,
deposit$ship: {