oak-pay-business 3.1.3 → 3.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,4 +15,7 @@ export type AspectDict<ED extends EntityDict> = {
15
15
  type: "html";
16
16
  data: string;
17
17
  }>;
18
+ shipConfirmSuccess: (params: {
19
+ shipId: string;
20
+ }, context: BackendRuntimeContext<ED>) => Promise<Boolean>;
18
21
  };
@@ -1,8 +1,9 @@
1
1
  import { getWithdrawCreateData } from './withdraw';
2
- import { getExpressPrintInfo, getMpShipState } from './ship';
2
+ import { getExpressPrintInfo, getMpShipState, shipConfirmSuccess } from './ship';
3
3
  const aspectDict = {
4
4
  getMpShipState,
5
5
  getWithdrawCreateData,
6
6
  getExpressPrintInfo,
7
+ shipConfirmSuccess,
7
8
  };
8
9
  export default aspectDict;
@@ -16,3 +16,9 @@ export declare function getExpressPrintInfo(params: {
16
16
  type: "html";
17
17
  data: string;
18
18
  }>;
19
+ /**
20
+ * 小程序确认收货组件成功后更新ship状态
21
+ */
22
+ export declare function shipConfirmSuccess(params: {
23
+ shipId: string;
24
+ }, context: BRC): Promise<boolean>;
@@ -1,6 +1,7 @@
1
1
  import { OakPreConditionUnsetException } from 'oak-domain/lib/types';
2
2
  import { getOrderShipState } from '../utils/ship';
3
3
  import { getShipClazz } from '../utils/shipClazz';
4
+ import { generateNewIdAsync } from 'oak-domain/lib/utils/uuid';
4
5
  /**
5
6
  * 获取小程序订单发货状态
6
7
  * @param params
@@ -39,3 +40,42 @@ export async function getExpressPrintInfo(params, context) {
39
40
  const clazz = await getShipClazz(entity, entityId, context);
40
41
  return await clazz.getPrintInfo(shipId, context);
41
42
  }
43
+ /**
44
+ * 小程序确认收货组件成功后更新ship状态
45
+ */
46
+ export async function shipConfirmSuccess(params, context) {
47
+ const application = context.getApplication();
48
+ const { type, } = application;
49
+ if (type === 'wechatMp') {
50
+ try {
51
+ const { shipId } = params;
52
+ const shipState = await getOrderShipState(context, shipId);
53
+ if (shipState === 'received') {
54
+ //微信端已确认收货
55
+ const [ship] = await context.select('ship', {
56
+ data: {
57
+ id: 1,
58
+ iState: 1,
59
+ }, filter: {
60
+ id: shipId,
61
+ }
62
+ }, { forUpdate: true });
63
+ if (ship.iState === 'receiving') {
64
+ await context.operate('ship', {
65
+ id: await generateNewIdAsync(),
66
+ action: 'succeedReceiving',
67
+ data: {},
68
+ filter: {
69
+ id: shipId,
70
+ },
71
+ }, {});
72
+ return true;
73
+ }
74
+ }
75
+ }
76
+ catch (err) {
77
+ return false;
78
+ }
79
+ }
80
+ return false;
81
+ }
@@ -21,13 +21,8 @@ declare const List: <T extends keyof EntityDict>(props: ReactComponentProps<Enti
21
21
  rowSelection?: any;
22
22
  hideHeader?: boolean | undefined;
23
23
  disableSerialNumber?: boolean | undefined;
24
- size?: "small" | "middle" | "large" | undefined;
25
- scroll?: ({
26
- x?: string | number | true | undefined;
27
- y?: string | number | undefined;
28
- } & {
29
- scrollToFirstRowOnChange?: boolean | undefined;
30
- }) | undefined;
24
+ size?: "small" | "large" | "middle" | undefined;
25
+ scroll?: any;
31
26
  empty?: React.ReactNode;
32
27
  opWidth?: number | undefined;
33
28
  ellipsis?: boolean | undefined;
@@ -48,7 +43,7 @@ declare const ListPro: <T extends keyof EntityDict>(props: {
48
43
  tablePagination?: any;
49
44
  rowSelection?: any;
50
45
  disableSerialNumber?: boolean | undefined;
51
- size?: "small" | "middle" | "large" | undefined;
46
+ size?: "small" | "large" | "middle" | undefined;
52
47
  scroll?: any;
53
48
  empty?: any;
54
49
  opWidth?: number | undefined;
@@ -347,30 +347,43 @@ export default OakComponent({
347
347
  },
348
348
  success: async () => {
349
349
  console.log('success');
350
- const { result: mpShipState } = await this.features.cache.exec('getMpShipState', {
350
+ // const { result: mpShipState } = await this.features.cache.exec('getMpShipState', {
351
+ // shipId: ship.id,
352
+ // })
353
+ // if (mpShipState === 'received') {
354
+ // await this.features.cache.operate('ship',
355
+ // [{
356
+ // id: await generateNewIdAsync(),
357
+ // action: 'succeedReceiving',
358
+ // data: {},
359
+ // filter: {
360
+ // id: ship.id,
361
+ // },
362
+ // }]
363
+ // );
364
+ // this.setMessage({
365
+ // type: 'success',
366
+ // content: this.t('ship.success')
367
+ // });
368
+ // } else {
369
+ // console.log(mpShipState);
370
+ // this.reRender();
371
+ // // this.setMessage({
372
+ // // type: 'warning',
373
+ // // content: this.t('ship.wait'),
374
+ // // })
375
+ // }
376
+ const { result } = await this.features.cache.exec('shipConfirmSuccess', {
351
377
  shipId: ship.id,
352
378
  });
353
- if (mpShipState === 'received') {
354
- await this.features.cache.operate('ship', [{
355
- id: await generateNewIdAsync(),
356
- action: 'succeedReceiving',
357
- data: {},
358
- filter: {
359
- id: ship.id,
360
- },
361
- }]);
379
+ if (result) {
362
380
  this.setMessage({
363
381
  type: 'success',
364
382
  content: this.t('ship.success')
365
383
  });
366
384
  }
367
385
  else {
368
- console.log(mpShipState);
369
386
  this.reRender();
370
- // this.setMessage({
371
- // type: 'warning',
372
- // content: this.t('ship.wait'),
373
- // })
374
387
  }
375
388
  },
376
389
  fail: () => {
@@ -360,30 +360,43 @@ export default OakComponent({
360
360
  },
361
361
  success: async () => {
362
362
  console.log('success');
363
- const { result: mpShipState } = await this.features.cache.exec('getMpShipState', {
363
+ // const { result: mpShipState } = await this.features.cache.exec('getMpShipState', {
364
+ // shipId,
365
+ // })
366
+ // if (mpShipState === 'received') {
367
+ // await this.features.cache.operate('ship',
368
+ // [{
369
+ // id: await generateNewIdAsync(),
370
+ // action: 'succeedReceiving',
371
+ // data: {},
372
+ // filter: {
373
+ // id: shipId,
374
+ // },
375
+ // }]
376
+ // );
377
+ // this.reRender();
378
+ // this.setMessage({
379
+ // type: 'success',
380
+ // content: this.t('ship.success')
381
+ // });
382
+ // } else {
383
+ // console.log(mpShipState);
384
+ // // this.setMessage({
385
+ // // type: 'warning',
386
+ // // content: this.t('ship.wait'),
387
+ // // })
388
+ // this.reRender();
389
+ // }
390
+ const { result } = await this.features.cache.exec('shipConfirmSuccess', {
364
391
  shipId,
365
392
  });
366
- if (mpShipState === 'received') {
367
- await this.features.cache.operate('ship', [{
368
- id: await generateNewIdAsync(),
369
- action: 'succeedReceiving',
370
- data: {},
371
- filter: {
372
- id: shipId,
373
- },
374
- }]);
375
- this.reRender();
393
+ if (result) {
376
394
  this.setMessage({
377
395
  type: 'success',
378
396
  content: this.t('ship.success')
379
397
  });
380
398
  }
381
399
  else {
382
- console.log(mpShipState);
383
- // this.setMessage({
384
- // type: 'warning',
385
- // content: this.t('ship.wait'),
386
- // })
387
400
  this.reRender();
388
401
  }
389
402
  },
@@ -422,16 +435,27 @@ export default OakComponent({
422
435
  const unsub = await this.subDataEvents([
423
436
  `${DATA_SUBSCRIBER_KEYS.payStateChanged}-${oakId}`,
424
437
  `${DATA_SUBSCRIBER_KEYS.depositStateChanged}-${oakId}`
425
- ]);
438
+ ], async (event, opRecords) => {
439
+ for (const record of opRecords) {
440
+ console.log(record);
441
+ if (record.e === 'pay' || record.e === 'deposit') {
442
+ const { f } = record;
443
+ const [pay] = this.features.cache.get('pay', {
444
+ data: baseProjection,
445
+ filter: f,
446
+ });
447
+ console.log(JSON.stringify(pay));
448
+ }
449
+ }
450
+ });
451
+ let depositUnsub = undefined;
426
452
  const { depositId } = this.state;
427
453
  if (depositId) {
428
- const depositUnsub = await this.subDataEvents([`${DATA_SUBSCRIBER_KEYS.shipStateChanged}-${depositId}`]);
429
- this.setState({
430
- depositUnsub,
431
- });
454
+ depositUnsub = await this.subDataEvents([`${DATA_SUBSCRIBER_KEYS.shipStateChanged}-${depositId}`]);
432
455
  }
433
456
  this.setState({
434
457
  unsub,
458
+ depositUnsub,
435
459
  });
436
460
  },
437
461
  async mature() {
@@ -44,6 +44,10 @@ export const desc = {
44
44
  type: "enum",
45
45
  enumeration: ["login", "changePassword", "confirm"]
46
46
  },
47
+ applicationId: {
48
+ type: "ref",
49
+ ref: "application"
50
+ },
47
51
  iState: {
48
52
  type: "enum",
49
53
  enumeration: ["unsent", "sending", "sent", "failure"]
@@ -1,3 +1,4 @@
1
+ import { ForeignKey } from "oak-domain/lib/types/DataType";
1
2
  import { Q_DateValue, Q_BooleanValue, Q_NumberValue, Q_StringValue, Q_EnumValue, NodeId, ExprOp, ExpressionKey } from "oak-domain/lib/types/Demand";
2
3
  import { MakeAction as OakMakeAction, EntityShape } from "oak-domain/lib/types/Entity";
3
4
  import { Action, ParticularAction, IState } from "./Action";
@@ -12,6 +13,7 @@ export type OpSchema = EntityShape & {
12
13
  expired: Boolean;
13
14
  expiresAt: Datetime;
14
15
  type: "login" | "changePassword" | "confirm";
16
+ applicationId?: ForeignKey<"application"> | null;
15
17
  iState?: IState | null;
16
18
  } & {
17
19
  [A in ExpressionKey]?: any;
@@ -31,6 +33,7 @@ export type OpFilter = {
31
33
  expired: Q_BooleanValue;
32
34
  expiresAt: Q_DateValue;
33
35
  type: Q_EnumValue<"login" | "changePassword" | "confirm">;
36
+ applicationId: Q_StringValue;
34
37
  iState: Q_EnumValue<IState>;
35
38
  } & ExprOp<OpAttr | string>;
36
39
  export type OpProjection = {
@@ -49,6 +52,7 @@ export type OpProjection = {
49
52
  expired?: number;
50
53
  expiresAt?: number;
51
54
  type?: number;
55
+ applicationId?: number;
52
56
  iState?: number;
53
57
  } & Partial<ExprOp<OpAttr | string>>;
54
58
  export type OpSortAttr = Partial<{
@@ -64,6 +68,7 @@ export type OpSortAttr = Partial<{
64
68
  expired: number;
65
69
  expiresAt: number;
66
70
  type: number;
71
+ applicationId: number;
67
72
  iState: number;
68
73
  [k: string]: any;
69
74
  } | ExprOp<OpAttr | string>>;
@@ -10,7 +10,8 @@
10
10
  "expired": "是否过期",
11
11
  "expiresAt": "过期时间",
12
12
  "iState": "状态",
13
- "type": "类型"
13
+ "type": "类型",
14
+ "application": "应用"
14
15
  },
15
16
  "action": {
16
17
  "send": "发送",
@@ -1211,6 +1211,7 @@ export type Application = {
1211
1211
  system: System["Schema"];
1212
1212
  domain?: Domain["Schema"];
1213
1213
  applicationPassport$application?: Array<Omit<ApplicationPassport["Schema"], "application">>;
1214
+ captcha$application?: Array<Omit<Captcha["Schema"], "application">>;
1214
1215
  extraFile$application?: Array<Omit<ExtraFile["Schema"], "application">>;
1215
1216
  notification$application?: Array<Omit<Notification["Schema"], "application">>;
1216
1217
  sessionMessage$application?: Array<Omit<SessionMessage["Schema"], "application">>;
@@ -1228,6 +1229,7 @@ export type Application = {
1228
1229
  wpProduct$application?: Array<Omit<WpProduct["Schema"], "application">>;
1229
1230
  session$entity?: Array<Omit<Session["Schema"], "entity">>;
1230
1231
  applicationPassport$application$$aggr?: AggregationResult<Omit<ApplicationPassport["Schema"], "application">>;
1232
+ captcha$application$$aggr?: AggregationResult<Omit<Captcha["Schema"], "application">>;
1231
1233
  extraFile$application$$aggr?: AggregationResult<Omit<ExtraFile["Schema"], "application">>;
1232
1234
  notification$application$$aggr?: AggregationResult<Omit<Notification["Schema"], "application">>;
1233
1235
  sessionMessage$application$$aggr?: AggregationResult<Omit<SessionMessage["Schema"], "application">>;
@@ -1254,6 +1256,12 @@ export type Application = {
1254
1256
  applicationPassport$application$$aggr?: DeduceAggregation<Omit<ApplicationPassport["Projection"], "application">, Omit<ApplicationPassport["Filter"], "application">, ApplicationPassport["Sorter"]> & {
1255
1257
  $entity: "applicationPassport";
1256
1258
  };
1259
+ captcha$application?: OakSelection<"select", Omit<Captcha["Projection"], "application">, Omit<Captcha["Filter"], "application">, Captcha["Sorter"]> & {
1260
+ $entity: "captcha";
1261
+ };
1262
+ captcha$application$$aggr?: DeduceAggregation<Omit<Captcha["Projection"], "application">, Omit<Captcha["Filter"], "application">, Captcha["Sorter"]> & {
1263
+ $entity: "captcha";
1264
+ };
1257
1265
  extraFile$application?: OakSelection<"select", Omit<ExtraFile["Projection"], "application">, Omit<ExtraFile["Filter"], "application">, ExtraFile["Sorter"]> & {
1258
1266
  $entity: "extraFile";
1259
1267
  };
@@ -1355,6 +1363,7 @@ export type Application = {
1355
1363
  system: MakeFilter<System["FilterUnit"]>;
1356
1364
  domain: MakeFilter<Domain["FilterUnit"]>;
1357
1365
  applicationPassport$application: MakeFilter<Omit<ApplicationPassport["FilterUnit"], "application">> & SubQueryPredicateMetadata;
1366
+ captcha$application: MakeFilter<Omit<Captcha["FilterUnit"], "application">> & SubQueryPredicateMetadata;
1358
1367
  extraFile$application: MakeFilter<Omit<ExtraFile["FilterUnit"], "application">> & SubQueryPredicateMetadata;
1359
1368
  notification$application: MakeFilter<Omit<Notification["FilterUnit"], "application">> & SubQueryPredicateMetadata;
1360
1369
  sessionMessage$application: MakeFilter<Omit<SessionMessage["FilterUnit"], "application">> & SubQueryPredicateMetadata;
@@ -1388,6 +1397,7 @@ export type Application = {
1388
1397
  system?: OakOperation<"create", System["CreateOperationData"]> | OakOperation<BaseSystem.OpUpdateAction, System["UpdateOperationData"], System["Filter"]>;
1389
1398
  domain?: OakOperation<"create", Domain["CreateOperationData"]> | OakOperation<BaseDomain.OpUpdateAction, Domain["UpdateOperationData"], Domain["Filter"]>;
1390
1399
  applicationPassport$application?: (OakOperation<"create", Omit<ApplicationPassport["CreateOperationData"], "application"> | Omit<ApplicationPassport["CreateOperationData"], "application">[]> | OakOperation<BaseApplicationPassport.OpUpdateAction, Omit<ApplicationPassport["UpdateOperationData"], "application">, ApplicationPassport["Filter"]>)[];
1400
+ captcha$application?: (OakOperation<"create", Omit<Captcha["CreateOperationData"], "application"> | Omit<Captcha["CreateOperationData"], "application">[]> | OakOperation<BaseCaptcha.OpUpdateAction, Omit<Captcha["UpdateOperationData"], "application">, Captcha["Filter"]>)[];
1391
1401
  extraFile$application?: (OakOperation<"create", Omit<ExtraFile["CreateOperationData"], "application"> | Omit<ExtraFile["CreateOperationData"], "application">[]> | OakOperation<BaseExtraFile.OpUpdateAction, Omit<ExtraFile["UpdateOperationData"], "application">, ExtraFile["Filter"]>)[];
1392
1402
  notification$application?: (OakOperation<"create", Omit<Notification["CreateOperationData"], "application"> | Omit<Notification["CreateOperationData"], "application">[]> | OakOperation<BaseNotification.OpUpdateAction, Omit<Notification["UpdateOperationData"], "application">, Notification["Filter"]>)[];
1393
1403
  sessionMessage$application?: (OakOperation<"create", Omit<SessionMessage["CreateOperationData"], "application"> | Omit<SessionMessage["CreateOperationData"], "application">[]> | OakOperation<BaseSessionMessage.OpUpdateAction, Omit<SessionMessage["UpdateOperationData"], "application">, SessionMessage["Filter"]>)[];
@@ -1412,6 +1422,7 @@ export type Application = {
1412
1422
  system?: OakOperation<"create", System["CreateOperationData"]> | OakOperation<BaseSystem.OpUpdateAction, System["UpdateOperationData"], System["Filter"]> | OakOperation<"remove", System["RemoveOperationData"], System["Filter"]>;
1413
1423
  domain?: OakOperation<"create", Domain["CreateOperationData"]> | OakOperation<BaseDomain.OpUpdateAction, Domain["UpdateOperationData"], Domain["Filter"]> | OakOperation<"remove", Domain["RemoveOperationData"], Domain["Filter"]>;
1414
1424
  applicationPassport$application?: (OakOperation<"create", Omit<ApplicationPassport["CreateOperationData"], "application"> | Omit<ApplicationPassport["CreateOperationData"], "application">[]> | OakOperation<BaseApplicationPassport.OpUpdateAction, Omit<ApplicationPassport["UpdateOperationData"], "application">, ApplicationPassport["Filter"]> | OakOperation<"remove", ApplicationPassport["RemoveOperationData"], ApplicationPassport["Filter"]>)[];
1425
+ captcha$application?: (OakOperation<"create", Omit<Captcha["CreateOperationData"], "application"> | Omit<Captcha["CreateOperationData"], "application">[]> | OakOperation<BaseCaptcha.OpUpdateAction, Omit<Captcha["UpdateOperationData"], "application">, Captcha["Filter"]> | OakOperation<"remove", Captcha["RemoveOperationData"], Captcha["Filter"]>)[];
1415
1426
  extraFile$application?: (OakOperation<"create", Omit<ExtraFile["CreateOperationData"], "application"> | Omit<ExtraFile["CreateOperationData"], "application">[]> | OakOperation<BaseExtraFile.OpUpdateAction, Omit<ExtraFile["UpdateOperationData"], "application">, ExtraFile["Filter"]> | OakOperation<"remove", ExtraFile["RemoveOperationData"], ExtraFile["Filter"]>)[];
1416
1427
  notification$application?: (OakOperation<"create", Omit<Notification["CreateOperationData"], "application"> | Omit<Notification["CreateOperationData"], "application">[]> | OakOperation<BaseNotification.OpUpdateAction, Omit<Notification["UpdateOperationData"], "application">, Notification["Filter"]> | OakOperation<"remove", Notification["RemoveOperationData"], Notification["Filter"]>)[];
1417
1428
  sessionMessage$application?: (OakOperation<"create", Omit<SessionMessage["CreateOperationData"], "application"> | Omit<SessionMessage["CreateOperationData"], "application">[]> | OakOperation<BaseSessionMessage.OpUpdateAction, Omit<SessionMessage["UpdateOperationData"], "application">, SessionMessage["Filter"]> | OakOperation<"remove", SessionMessage["RemoveOperationData"], SessionMessage["Filter"]>)[];
@@ -1675,11 +1686,19 @@ export type ArticleMenu = {
1675
1686
  export type Captcha = {
1676
1687
  OpSchema: BaseCaptcha.OpSchema;
1677
1688
  Action: BaseCaptcha.OpAction;
1678
- Schema: BaseCaptcha.OpSchema & {};
1679
- Projection: BaseCaptcha.OpProjection & {};
1680
- FilterUnit: BaseCaptcha.OpFilter & {};
1689
+ Schema: BaseCaptcha.OpSchema & {
1690
+ application?: Application["Schema"];
1691
+ };
1692
+ Projection: BaseCaptcha.OpProjection & {
1693
+ application?: Application["Projection"];
1694
+ };
1695
+ FilterUnit: BaseCaptcha.OpFilter & {
1696
+ application: MakeFilter<Application["FilterUnit"]>;
1697
+ };
1681
1698
  Filter: MakeFilter<Captcha["FilterUnit"]>;
1682
- SortAttr: Partial<BaseCaptcha.OpSortAttr | {}>;
1699
+ SortAttr: Partial<BaseCaptcha.OpSortAttr | {
1700
+ application: Application["SortAttr"];
1701
+ }>;
1683
1702
  SortNode: {
1684
1703
  $attr: Captcha["SortAttr"];
1685
1704
  $direction?: "asc" | "desc";
@@ -1687,11 +1706,15 @@ export type Captcha = {
1687
1706
  Sorter: Captcha["SortNode"][];
1688
1707
  Selection: OakSelection<"select", Captcha["Projection"], Captcha["Filter"], Captcha["Sorter"]>;
1689
1708
  Aggregation: DeduceAggregation<Captcha["Projection"], Captcha["Filter"], Captcha["Sorter"]>;
1690
- CreateOperationData: FormCreateData<BaseCaptcha.OpSchema>;
1709
+ CreateOperationData: FormCreateData<BaseCaptcha.OpSchema & {
1710
+ application?: OakOperation<"create", Application["CreateOperationData"]> | OakOperation<BaseApplication.OpUpdateAction, Application["UpdateOperationData"], Application["Filter"]>;
1711
+ }>;
1691
1712
  CreateSingle: OakOperation<"create", Captcha["CreateOperationData"]>;
1692
1713
  CreateMulti: OakOperation<"create", Array<Captcha["CreateOperationData"]>>;
1693
1714
  Create: Captcha["CreateSingle"] | Captcha["CreateMulti"];
1694
- UpdateOperationData: FormUpdateData<BaseCaptcha.OpSchema>;
1715
+ UpdateOperationData: FormUpdateData<BaseCaptcha.OpSchema & {
1716
+ application?: OakOperation<"create", Application["CreateOperationData"]> | OakOperation<BaseApplication.OpUpdateAction, Application["UpdateOperationData"], Application["Filter"]> | OakOperation<"remove", Application["RemoveOperationData"], Application["Filter"]>;
1717
+ }>;
1695
1718
  Update: OakOperation<BaseCaptcha.OpUpdateAction, Captcha["UpdateOperationData"], Captcha["Filter"], Captcha["Sorter"]>;
1696
1719
  RemoveOperationData: {};
1697
1720
  Remove: OakOperation<"remove", Captcha["RemoveOperationData"], Captcha["Filter"], Captcha["Sorter"]>;
package/es/timers/ship.js CHANGED
@@ -8,7 +8,7 @@ const timers = [
8
8
  filter: {
9
9
  type: 'express',
10
10
  iState: {
11
- $nin: ['received', 'cancelled', 'rejected', 'receiving'],
11
+ $nin: ['received', 'cancelled', 'rejected', 'receiving', 'unshipped'],
12
12
  },
13
13
  entity: {
14
14
  $exists: true
@@ -41,7 +41,7 @@ const timers = [
41
41
  },
42
42
  {
43
43
  name: '同步微信小程序虚拟、自提ship状态',
44
- cron: '0 0/2 * * * ?',
44
+ cron: '0 * * * * ?',
45
45
  entity: 'ship',
46
46
  filter: {
47
47
  type: {
@@ -53,6 +53,7 @@ const timers = [
53
53
  },
54
54
  projection: {
55
55
  id: 1,
56
+ iState: 1,
56
57
  },
57
58
  fn: async (context, data) => {
58
59
  const results = [];
@@ -68,21 +69,21 @@ const timers = [
68
69
  return results.reduce((prev, cur) => mergeOperationResult(prev, cur));
69
70
  },
70
71
  },
71
- {
72
- name: '对虚拟或自提类型的ship自动发货',
73
- cron: '0 * * * * ?',
74
- entity: 'ship',
75
- filter: {
76
- type: {
77
- $in: ['virtual', 'pickup'],
78
- },
79
- iState: 'unshipped',
80
- },
81
- projection: {
82
- id: 1,
83
- },
84
- action: 'ship',
85
- actionData: {},
86
- },
72
+ // {
73
+ // name: '对虚拟或自提类型的ship自动发货',
74
+ // cron: '0 * * * * ?',
75
+ // entity: 'ship',
76
+ // filter: {
77
+ // type: {
78
+ // $in: ['virtual', 'pickup'],
79
+ // },
80
+ // iState: 'unshipped',
81
+ // },
82
+ // projection: {
83
+ // id: 1,
84
+ // },
85
+ // action: 'ship',
86
+ // actionData: {},
87
+ // },
87
88
  ];
88
89
  export default timers;
@@ -3,6 +3,7 @@ import { DATA_SUBSCRIBER_KEYS } from '../config/constants';
3
3
  import assert from 'assert';
4
4
  import { getShipClazz, getShipEntity } from '../utils/shipClazz';
5
5
  import { notifyConfirmReceive, uploadShippingInfo } from '../utils/ship';
6
+ import { promisify } from 'util';
6
7
  const triggers = [
7
8
  {
8
9
  name: '当虚拟或自提类型的ship创建后自动发货',
@@ -14,14 +15,27 @@ const triggers = [
14
15
  check: (operation) => ['virtual', 'pickup'].includes(operation.data.type),
15
16
  fn: async ({ ids }, context, option) => {
16
17
  for (const id of ids) {
17
- await context.operate('ship', {
18
- id: await generateNewIdAsync(),
19
- action: 'ship',
20
- data: {},
18
+ const [ship] = await context.select('ship', {
19
+ data: {
20
+ id: 1,
21
+ iState: 1,
22
+ type: 1,
23
+ },
21
24
  filter: {
22
- id,
25
+ id
23
26
  }
24
- }, option);
27
+ }, { dontCollect: true, forUpdate: true });
28
+ const { iState, type } = ship;
29
+ if (iState && ['unshipped', 'unknown'].includes(iState) && type && ['virtual', 'pickup'].includes(type)) {
30
+ await context.operate('ship', {
31
+ id: await generateNewIdAsync(),
32
+ action: 'ship',
33
+ data: {},
34
+ filter: {
35
+ id,
36
+ }
37
+ }, option);
38
+ }
25
39
  }
26
40
  return;
27
41
  },
@@ -48,7 +62,7 @@ const triggers = [
48
62
  id
49
63
  }
50
64
  }, { dontCollect: true, forUpdate: true });
51
- const { entity, entityId } = ship;
65
+ const { entity, entityId } = ship || {};
52
66
  if (entity && entityId) {
53
67
  const shipClazz = await getShipClazz(entity, entityId, context);
54
68
  const extraShipId = await shipClazz.eOrder(id, context);
@@ -116,6 +130,9 @@ const triggers = [
116
130
  const { id: shipId, type, deposit$ship: deposits, shipOrder$ship, shipServiceId, entity, entityId, wechatMpShip } = ship || {};
117
131
  if (deposits && deposits.length > 0) {
118
132
  //充值 (此时该充值必定为受发货限制的小程序上的充值)
133
+ //等待5秒以避免小程序订单号查询不到
134
+ const sleep = promisify(setTimeout);
135
+ await sleep(5 * 1000);
119
136
  await uploadShippingInfo(shipId, context);
120
137
  cnt++;
121
138
  }
@@ -448,49 +465,5 @@ const triggers = [
448
465
  return count;
449
466
  },
450
467
  },
451
- {
452
- name: '当虚拟ship自动确认收货后更新deposit状态',
453
- entity: 'ship',
454
- action: 'update',
455
- when: 'after',
456
- asRoot: true,
457
- fn: async ({ operation }, context, option) => {
458
- const { filter, id, data } = operation;
459
- const ships = await context.select('ship', {
460
- data: {
461
- id: 1,
462
- iState: 1,
463
- type: 1,
464
- deposit$ship: {
465
- $entity: 'deposit',
466
- data: {
467
- id: 1,
468
- iState: 1,
469
- }
470
- }
471
- },
472
- filter,
473
- }, { forUpdate: true });
474
- let count = 0;
475
- const virtualShips = ships?.filter((ele) => ele.type === 'virtual');
476
- if (virtualShips && virtualShips.length > 0) {
477
- for (const ship of virtualShips) {
478
- const deposit = ship.deposit$ship?.[0];
479
- if (deposit && deposit.iState === 'shipped') {
480
- await context.operate('deposit', {
481
- id: await generateNewIdAsync(),
482
- action: 'succeed',
483
- data: {},
484
- filter: {
485
- id: deposit.id,
486
- }
487
- }, option);
488
- count++;
489
- }
490
- }
491
- }
492
- return count;
493
- }
494
- },
495
468
  ];
496
469
  export default triggers;
@@ -6,6 +6,6 @@ import { BRC } from '../types/RuntimeCxt';
6
6
  * @param context
7
7
  * @param refunds
8
8
  */
9
- export declare function updateWithdrawState(context: BRC, id: string): Promise<0 | 1>;
9
+ export declare function updateWithdrawState(context: BRC, id: string): Promise<1 | 0>;
10
10
  declare const triggers: Trigger<EntityDict, 'withdraw', BRC>[];
11
11
  export default triggers;
package/es/utils/ship.js CHANGED
@@ -58,6 +58,7 @@ export const shipProjection = {
58
58
  order: {
59
59
  id: 1,
60
60
  iState: 1,
61
+ desc: 1,
61
62
  pay$order: {
62
63
  $entity: 'pay',
63
64
  data: {
@@ -197,14 +198,14 @@ export async function uploadShippingInfo(shipId, context) {
197
198
  //订单 每笔微信支付调用一次接口
198
199
  //当已发货的订单再次调用小程序发货信息录入接口视为重新发货(仅可重新发货一次)
199
200
  const orders = shipOrder$ship.map((ele) => ele.order);
200
- const fromPhoneStr = maskPhone(from.phone);
201
- const toPhoneStr = maskPhone(to.phone);
202
201
  for (const order of orders) {
203
202
  const { pay$order, desc } = order;
204
203
  const wechatPay = pay$order.find((ele) => ele.entity === 'wpProduct');
205
204
  const meta = wechatPay?.meta;
206
205
  let shippingList = [];
207
206
  if (shipType === 'express') {
207
+ const fromPhoneStr = maskPhone(from.phone);
208
+ const toPhoneStr = maskPhone(to.phone);
208
209
  shippingList = [
209
210
  {
210
211
  tracking_no: extraShipId,
@@ -1,34 +1,34 @@
1
- import { mergeOperationResult } from 'oak-domain/lib/utils/operationResult';
2
- import { shipProjection, refreshShipState } from '../utils/ship';
3
1
  const QUERY_PAYING_STATE_GAP = process.env.NODE_ENV === 'production' ? 3600 * 1000 : 60 * 1000;
4
2
  const watchers = [
5
- {
6
- name: '对shipping状态的物流,同步其真实状态',
7
- entity: 'ship',
8
- filter: async () => {
9
- const now = Date.now();
10
- return {
11
- type: 'express',
12
- iState: 'shipping',
13
- $$updateAt$$: {
14
- $lte: now - QUERY_PAYING_STATE_GAP,
15
- },
16
- };
17
- },
18
- projection: shipProjection,
19
- fn: async (context, data) => {
20
- const results = [];
21
- for (const ship of data) {
22
- const result = await refreshShipState(ship.id, context);
23
- if (result) {
24
- results.push(result);
25
- }
26
- }
27
- if (results.length === 0) {
28
- return {};
29
- }
30
- return results.reduce((prev, cur) => mergeOperationResult(prev, cur));
31
- }
32
- }
3
+ // {
4
+ // name: '对shipping状态的物流,同步其真实状态',
5
+ // entity: 'ship',
6
+ // filter: async () => {
7
+ // const now = Date.now();
8
+ // return {
9
+ // type: 'express',
10
+ // iState: 'shipping',
11
+ // $$updateAt$$: {
12
+ // $lte: now - QUERY_PAYING_STATE_GAP,
13
+ // },
14
+ // };
15
+ // },
16
+ // projection: shipProjection,
17
+ // fn: async (context, data) => {
18
+ // const results = [] as OperationResult<EntityDict>[];
19
+ // for (const ship of data) {
20
+ // const result = await refreshShipState(ship.id!, context);
21
+ // if (result) {
22
+ // results.push(result);
23
+ // }
24
+ // }
25
+ // if (results.length === 0) {
26
+ // return {};
27
+ // }
28
+ // return results.reduce(
29
+ // (prev, cur) => mergeOperationResult(prev, cur)
30
+ // );
31
+ // }
32
+ // }
33
33
  ];
34
34
  export default watchers;
@@ -15,4 +15,7 @@ export type AspectDict<ED extends EntityDict> = {
15
15
  type: "html";
16
16
  data: string;
17
17
  }>;
18
+ shipConfirmSuccess: (params: {
19
+ shipId: string;
20
+ }, context: BackendRuntimeContext<ED>) => Promise<Boolean>;
18
21
  };
@@ -6,5 +6,6 @@ const aspectDict = {
6
6
  getMpShipState: ship_1.getMpShipState,
7
7
  getWithdrawCreateData: withdraw_1.getWithdrawCreateData,
8
8
  getExpressPrintInfo: ship_1.getExpressPrintInfo,
9
+ shipConfirmSuccess: ship_1.shipConfirmSuccess,
9
10
  };
10
11
  exports.default = aspectDict;
@@ -16,3 +16,9 @@ export declare function getExpressPrintInfo(params: {
16
16
  type: "html";
17
17
  data: string;
18
18
  }>;
19
+ /**
20
+ * 小程序确认收货组件成功后更新ship状态
21
+ */
22
+ export declare function shipConfirmSuccess(params: {
23
+ shipId: string;
24
+ }, context: BRC): Promise<boolean>;
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getExpressPrintInfo = exports.getMpShipState = void 0;
3
+ exports.shipConfirmSuccess = exports.getExpressPrintInfo = exports.getMpShipState = void 0;
4
4
  const types_1 = require("oak-domain/lib/types");
5
5
  const ship_1 = require("../utils/ship");
6
6
  const shipClazz_1 = require("../utils/shipClazz");
7
+ const uuid_1 = require("oak-domain/lib/utils/uuid");
7
8
  /**
8
9
  * 获取小程序订单发货状态
9
10
  * @param params
@@ -44,3 +45,43 @@ async function getExpressPrintInfo(params, context) {
44
45
  return await clazz.getPrintInfo(shipId, context);
45
46
  }
46
47
  exports.getExpressPrintInfo = getExpressPrintInfo;
48
+ /**
49
+ * 小程序确认收货组件成功后更新ship状态
50
+ */
51
+ async function shipConfirmSuccess(params, context) {
52
+ const application = context.getApplication();
53
+ const { type, } = application;
54
+ if (type === 'wechatMp') {
55
+ try {
56
+ const { shipId } = params;
57
+ const shipState = await (0, ship_1.getOrderShipState)(context, shipId);
58
+ if (shipState === 'received') {
59
+ //微信端已确认收货
60
+ const [ship] = await context.select('ship', {
61
+ data: {
62
+ id: 1,
63
+ iState: 1,
64
+ }, filter: {
65
+ id: shipId,
66
+ }
67
+ }, { forUpdate: true });
68
+ if (ship.iState === 'receiving') {
69
+ await context.operate('ship', {
70
+ id: await (0, uuid_1.generateNewIdAsync)(),
71
+ action: 'succeedReceiving',
72
+ data: {},
73
+ filter: {
74
+ id: shipId,
75
+ },
76
+ }, {});
77
+ return true;
78
+ }
79
+ }
80
+ }
81
+ catch (err) {
82
+ return false;
83
+ }
84
+ }
85
+ return false;
86
+ }
87
+ exports.shipConfirmSuccess = shipConfirmSuccess;
@@ -47,6 +47,10 @@ exports.desc = {
47
47
  type: "enum",
48
48
  enumeration: ["login", "changePassword", "confirm"]
49
49
  },
50
+ applicationId: {
51
+ type: "ref",
52
+ ref: "application"
53
+ },
50
54
  iState: {
51
55
  type: "enum",
52
56
  enumeration: ["unsent", "sending", "sent", "failure"]
@@ -1,3 +1,4 @@
1
+ import { ForeignKey } from "oak-domain/lib/types/DataType";
1
2
  import { Q_DateValue, Q_BooleanValue, Q_NumberValue, Q_StringValue, Q_EnumValue, NodeId, ExprOp, ExpressionKey } from "oak-domain/lib/types/Demand";
2
3
  import { MakeAction as OakMakeAction, EntityShape } from "oak-domain/lib/types/Entity";
3
4
  import { Action, ParticularAction, IState } from "./Action";
@@ -12,6 +13,7 @@ export type OpSchema = EntityShape & {
12
13
  expired: Boolean;
13
14
  expiresAt: Datetime;
14
15
  type: "login" | "changePassword" | "confirm";
16
+ applicationId?: ForeignKey<"application"> | null;
15
17
  iState?: IState | null;
16
18
  } & {
17
19
  [A in ExpressionKey]?: any;
@@ -31,6 +33,7 @@ export type OpFilter = {
31
33
  expired: Q_BooleanValue;
32
34
  expiresAt: Q_DateValue;
33
35
  type: Q_EnumValue<"login" | "changePassword" | "confirm">;
36
+ applicationId: Q_StringValue;
34
37
  iState: Q_EnumValue<IState>;
35
38
  } & ExprOp<OpAttr | string>;
36
39
  export type OpProjection = {
@@ -49,6 +52,7 @@ export type OpProjection = {
49
52
  expired?: number;
50
53
  expiresAt?: number;
51
54
  type?: number;
55
+ applicationId?: number;
52
56
  iState?: number;
53
57
  } & Partial<ExprOp<OpAttr | string>>;
54
58
  export type OpSortAttr = Partial<{
@@ -64,6 +68,7 @@ export type OpSortAttr = Partial<{
64
68
  expired: number;
65
69
  expiresAt: number;
66
70
  type: number;
71
+ applicationId: number;
67
72
  iState: number;
68
73
  [k: string]: any;
69
74
  } | ExprOp<OpAttr | string>>;
@@ -10,7 +10,8 @@
10
10
  "expired": "是否过期",
11
11
  "expiresAt": "过期时间",
12
12
  "iState": "状态",
13
- "type": "类型"
13
+ "type": "类型",
14
+ "application": "应用"
14
15
  },
15
16
  "action": {
16
17
  "send": "发送",
@@ -1211,6 +1211,7 @@ export type Application = {
1211
1211
  system: System["Schema"];
1212
1212
  domain?: Domain["Schema"];
1213
1213
  applicationPassport$application?: Array<Omit<ApplicationPassport["Schema"], "application">>;
1214
+ captcha$application?: Array<Omit<Captcha["Schema"], "application">>;
1214
1215
  extraFile$application?: Array<Omit<ExtraFile["Schema"], "application">>;
1215
1216
  notification$application?: Array<Omit<Notification["Schema"], "application">>;
1216
1217
  sessionMessage$application?: Array<Omit<SessionMessage["Schema"], "application">>;
@@ -1228,6 +1229,7 @@ export type Application = {
1228
1229
  wpProduct$application?: Array<Omit<WpProduct["Schema"], "application">>;
1229
1230
  session$entity?: Array<Omit<Session["Schema"], "entity">>;
1230
1231
  applicationPassport$application$$aggr?: AggregationResult<Omit<ApplicationPassport["Schema"], "application">>;
1232
+ captcha$application$$aggr?: AggregationResult<Omit<Captcha["Schema"], "application">>;
1231
1233
  extraFile$application$$aggr?: AggregationResult<Omit<ExtraFile["Schema"], "application">>;
1232
1234
  notification$application$$aggr?: AggregationResult<Omit<Notification["Schema"], "application">>;
1233
1235
  sessionMessage$application$$aggr?: AggregationResult<Omit<SessionMessage["Schema"], "application">>;
@@ -1254,6 +1256,12 @@ export type Application = {
1254
1256
  applicationPassport$application$$aggr?: DeduceAggregation<Omit<ApplicationPassport["Projection"], "application">, Omit<ApplicationPassport["Filter"], "application">, ApplicationPassport["Sorter"]> & {
1255
1257
  $entity: "applicationPassport";
1256
1258
  };
1259
+ captcha$application?: OakSelection<"select", Omit<Captcha["Projection"], "application">, Omit<Captcha["Filter"], "application">, Captcha["Sorter"]> & {
1260
+ $entity: "captcha";
1261
+ };
1262
+ captcha$application$$aggr?: DeduceAggregation<Omit<Captcha["Projection"], "application">, Omit<Captcha["Filter"], "application">, Captcha["Sorter"]> & {
1263
+ $entity: "captcha";
1264
+ };
1257
1265
  extraFile$application?: OakSelection<"select", Omit<ExtraFile["Projection"], "application">, Omit<ExtraFile["Filter"], "application">, ExtraFile["Sorter"]> & {
1258
1266
  $entity: "extraFile";
1259
1267
  };
@@ -1355,6 +1363,7 @@ export type Application = {
1355
1363
  system: MakeFilter<System["FilterUnit"]>;
1356
1364
  domain: MakeFilter<Domain["FilterUnit"]>;
1357
1365
  applicationPassport$application: MakeFilter<Omit<ApplicationPassport["FilterUnit"], "application">> & SubQueryPredicateMetadata;
1366
+ captcha$application: MakeFilter<Omit<Captcha["FilterUnit"], "application">> & SubQueryPredicateMetadata;
1358
1367
  extraFile$application: MakeFilter<Omit<ExtraFile["FilterUnit"], "application">> & SubQueryPredicateMetadata;
1359
1368
  notification$application: MakeFilter<Omit<Notification["FilterUnit"], "application">> & SubQueryPredicateMetadata;
1360
1369
  sessionMessage$application: MakeFilter<Omit<SessionMessage["FilterUnit"], "application">> & SubQueryPredicateMetadata;
@@ -1388,6 +1397,7 @@ export type Application = {
1388
1397
  system?: OakOperation<"create", System["CreateOperationData"]> | OakOperation<BaseSystem.OpUpdateAction, System["UpdateOperationData"], System["Filter"]>;
1389
1398
  domain?: OakOperation<"create", Domain["CreateOperationData"]> | OakOperation<BaseDomain.OpUpdateAction, Domain["UpdateOperationData"], Domain["Filter"]>;
1390
1399
  applicationPassport$application?: (OakOperation<"create", Omit<ApplicationPassport["CreateOperationData"], "application"> | Omit<ApplicationPassport["CreateOperationData"], "application">[]> | OakOperation<BaseApplicationPassport.OpUpdateAction, Omit<ApplicationPassport["UpdateOperationData"], "application">, ApplicationPassport["Filter"]>)[];
1400
+ captcha$application?: (OakOperation<"create", Omit<Captcha["CreateOperationData"], "application"> | Omit<Captcha["CreateOperationData"], "application">[]> | OakOperation<BaseCaptcha.OpUpdateAction, Omit<Captcha["UpdateOperationData"], "application">, Captcha["Filter"]>)[];
1391
1401
  extraFile$application?: (OakOperation<"create", Omit<ExtraFile["CreateOperationData"], "application"> | Omit<ExtraFile["CreateOperationData"], "application">[]> | OakOperation<BaseExtraFile.OpUpdateAction, Omit<ExtraFile["UpdateOperationData"], "application">, ExtraFile["Filter"]>)[];
1392
1402
  notification$application?: (OakOperation<"create", Omit<Notification["CreateOperationData"], "application"> | Omit<Notification["CreateOperationData"], "application">[]> | OakOperation<BaseNotification.OpUpdateAction, Omit<Notification["UpdateOperationData"], "application">, Notification["Filter"]>)[];
1393
1403
  sessionMessage$application?: (OakOperation<"create", Omit<SessionMessage["CreateOperationData"], "application"> | Omit<SessionMessage["CreateOperationData"], "application">[]> | OakOperation<BaseSessionMessage.OpUpdateAction, Omit<SessionMessage["UpdateOperationData"], "application">, SessionMessage["Filter"]>)[];
@@ -1412,6 +1422,7 @@ export type Application = {
1412
1422
  system?: OakOperation<"create", System["CreateOperationData"]> | OakOperation<BaseSystem.OpUpdateAction, System["UpdateOperationData"], System["Filter"]> | OakOperation<"remove", System["RemoveOperationData"], System["Filter"]>;
1413
1423
  domain?: OakOperation<"create", Domain["CreateOperationData"]> | OakOperation<BaseDomain.OpUpdateAction, Domain["UpdateOperationData"], Domain["Filter"]> | OakOperation<"remove", Domain["RemoveOperationData"], Domain["Filter"]>;
1414
1424
  applicationPassport$application?: (OakOperation<"create", Omit<ApplicationPassport["CreateOperationData"], "application"> | Omit<ApplicationPassport["CreateOperationData"], "application">[]> | OakOperation<BaseApplicationPassport.OpUpdateAction, Omit<ApplicationPassport["UpdateOperationData"], "application">, ApplicationPassport["Filter"]> | OakOperation<"remove", ApplicationPassport["RemoveOperationData"], ApplicationPassport["Filter"]>)[];
1425
+ captcha$application?: (OakOperation<"create", Omit<Captcha["CreateOperationData"], "application"> | Omit<Captcha["CreateOperationData"], "application">[]> | OakOperation<BaseCaptcha.OpUpdateAction, Omit<Captcha["UpdateOperationData"], "application">, Captcha["Filter"]> | OakOperation<"remove", Captcha["RemoveOperationData"], Captcha["Filter"]>)[];
1415
1426
  extraFile$application?: (OakOperation<"create", Omit<ExtraFile["CreateOperationData"], "application"> | Omit<ExtraFile["CreateOperationData"], "application">[]> | OakOperation<BaseExtraFile.OpUpdateAction, Omit<ExtraFile["UpdateOperationData"], "application">, ExtraFile["Filter"]> | OakOperation<"remove", ExtraFile["RemoveOperationData"], ExtraFile["Filter"]>)[];
1416
1427
  notification$application?: (OakOperation<"create", Omit<Notification["CreateOperationData"], "application"> | Omit<Notification["CreateOperationData"], "application">[]> | OakOperation<BaseNotification.OpUpdateAction, Omit<Notification["UpdateOperationData"], "application">, Notification["Filter"]> | OakOperation<"remove", Notification["RemoveOperationData"], Notification["Filter"]>)[];
1417
1428
  sessionMessage$application?: (OakOperation<"create", Omit<SessionMessage["CreateOperationData"], "application"> | Omit<SessionMessage["CreateOperationData"], "application">[]> | OakOperation<BaseSessionMessage.OpUpdateAction, Omit<SessionMessage["UpdateOperationData"], "application">, SessionMessage["Filter"]> | OakOperation<"remove", SessionMessage["RemoveOperationData"], SessionMessage["Filter"]>)[];
@@ -1675,11 +1686,19 @@ export type ArticleMenu = {
1675
1686
  export type Captcha = {
1676
1687
  OpSchema: BaseCaptcha.OpSchema;
1677
1688
  Action: BaseCaptcha.OpAction;
1678
- Schema: BaseCaptcha.OpSchema & {};
1679
- Projection: BaseCaptcha.OpProjection & {};
1680
- FilterUnit: BaseCaptcha.OpFilter & {};
1689
+ Schema: BaseCaptcha.OpSchema & {
1690
+ application?: Application["Schema"];
1691
+ };
1692
+ Projection: BaseCaptcha.OpProjection & {
1693
+ application?: Application["Projection"];
1694
+ };
1695
+ FilterUnit: BaseCaptcha.OpFilter & {
1696
+ application: MakeFilter<Application["FilterUnit"]>;
1697
+ };
1681
1698
  Filter: MakeFilter<Captcha["FilterUnit"]>;
1682
- SortAttr: Partial<BaseCaptcha.OpSortAttr | {}>;
1699
+ SortAttr: Partial<BaseCaptcha.OpSortAttr | {
1700
+ application: Application["SortAttr"];
1701
+ }>;
1683
1702
  SortNode: {
1684
1703
  $attr: Captcha["SortAttr"];
1685
1704
  $direction?: "asc" | "desc";
@@ -1687,11 +1706,15 @@ export type Captcha = {
1687
1706
  Sorter: Captcha["SortNode"][];
1688
1707
  Selection: OakSelection<"select", Captcha["Projection"], Captcha["Filter"], Captcha["Sorter"]>;
1689
1708
  Aggregation: DeduceAggregation<Captcha["Projection"], Captcha["Filter"], Captcha["Sorter"]>;
1690
- CreateOperationData: FormCreateData<BaseCaptcha.OpSchema>;
1709
+ CreateOperationData: FormCreateData<BaseCaptcha.OpSchema & {
1710
+ application?: OakOperation<"create", Application["CreateOperationData"]> | OakOperation<BaseApplication.OpUpdateAction, Application["UpdateOperationData"], Application["Filter"]>;
1711
+ }>;
1691
1712
  CreateSingle: OakOperation<"create", Captcha["CreateOperationData"]>;
1692
1713
  CreateMulti: OakOperation<"create", Array<Captcha["CreateOperationData"]>>;
1693
1714
  Create: Captcha["CreateSingle"] | Captcha["CreateMulti"];
1694
- UpdateOperationData: FormUpdateData<BaseCaptcha.OpSchema>;
1715
+ UpdateOperationData: FormUpdateData<BaseCaptcha.OpSchema & {
1716
+ application?: OakOperation<"create", Application["CreateOperationData"]> | OakOperation<BaseApplication.OpUpdateAction, Application["UpdateOperationData"], Application["Filter"]> | OakOperation<"remove", Application["RemoveOperationData"], Application["Filter"]>;
1717
+ }>;
1695
1718
  Update: OakOperation<BaseCaptcha.OpUpdateAction, Captcha["UpdateOperationData"], Captcha["Filter"], Captcha["Sorter"]>;
1696
1719
  RemoveOperationData: {};
1697
1720
  Remove: OakOperation<"remove", Captcha["RemoveOperationData"], Captcha["Filter"], Captcha["Sorter"]>;
@@ -10,7 +10,7 @@ const timers = [
10
10
  filter: {
11
11
  type: 'express',
12
12
  iState: {
13
- $nin: ['received', 'cancelled', 'rejected', 'receiving'],
13
+ $nin: ['received', 'cancelled', 'rejected', 'receiving', 'unshipped'],
14
14
  },
15
15
  entity: {
16
16
  $exists: true
@@ -43,7 +43,7 @@ const timers = [
43
43
  },
44
44
  {
45
45
  name: '同步微信小程序虚拟、自提ship状态',
46
- cron: '0 0/2 * * * ?',
46
+ cron: '0 * * * * ?',
47
47
  entity: 'ship',
48
48
  filter: {
49
49
  type: {
@@ -55,6 +55,7 @@ const timers = [
55
55
  },
56
56
  projection: {
57
57
  id: 1,
58
+ iState: 1,
58
59
  },
59
60
  fn: async (context, data) => {
60
61
  const results = [];
@@ -70,21 +71,21 @@ const timers = [
70
71
  return results.reduce((prev, cur) => (0, operationResult_1.mergeOperationResult)(prev, cur));
71
72
  },
72
73
  },
73
- {
74
- name: '对虚拟或自提类型的ship自动发货',
75
- cron: '0 * * * * ?',
76
- entity: 'ship',
77
- filter: {
78
- type: {
79
- $in: ['virtual', 'pickup'],
80
- },
81
- iState: 'unshipped',
82
- },
83
- projection: {
84
- id: 1,
85
- },
86
- action: 'ship',
87
- actionData: {},
88
- },
74
+ // {
75
+ // name: '对虚拟或自提类型的ship自动发货',
76
+ // cron: '0 * * * * ?',
77
+ // entity: 'ship',
78
+ // filter: {
79
+ // type: {
80
+ // $in: ['virtual', 'pickup'],
81
+ // },
82
+ // iState: 'unshipped',
83
+ // },
84
+ // projection: {
85
+ // id: 1,
86
+ // },
87
+ // action: 'ship',
88
+ // actionData: {},
89
+ // },
89
90
  ];
90
91
  exports.default = timers;
@@ -6,6 +6,7 @@ const constants_1 = require("../config/constants");
6
6
  const assert_1 = tslib_1.__importDefault(require("assert"));
7
7
  const shipClazz_1 = require("../utils/shipClazz");
8
8
  const ship_1 = require("../utils/ship");
9
+ const util_1 = require("util");
9
10
  const triggers = [
10
11
  {
11
12
  name: '当虚拟或自提类型的ship创建后自动发货',
@@ -17,14 +18,27 @@ const triggers = [
17
18
  check: (operation) => ['virtual', 'pickup'].includes(operation.data.type),
18
19
  fn: async ({ ids }, context, option) => {
19
20
  for (const id of ids) {
20
- await context.operate('ship', {
21
- id: await (0, uuid_1.generateNewIdAsync)(),
22
- action: 'ship',
23
- data: {},
21
+ const [ship] = await context.select('ship', {
22
+ data: {
23
+ id: 1,
24
+ iState: 1,
25
+ type: 1,
26
+ },
24
27
  filter: {
25
- id,
28
+ id
26
29
  }
27
- }, option);
30
+ }, { dontCollect: true, forUpdate: true });
31
+ const { iState, type } = ship;
32
+ if (iState && ['unshipped', 'unknown'].includes(iState) && type && ['virtual', 'pickup'].includes(type)) {
33
+ await context.operate('ship', {
34
+ id: await (0, uuid_1.generateNewIdAsync)(),
35
+ action: 'ship',
36
+ data: {},
37
+ filter: {
38
+ id,
39
+ }
40
+ }, option);
41
+ }
28
42
  }
29
43
  return;
30
44
  },
@@ -51,7 +65,7 @@ const triggers = [
51
65
  id
52
66
  }
53
67
  }, { dontCollect: true, forUpdate: true });
54
- const { entity, entityId } = ship;
68
+ const { entity, entityId } = ship || {};
55
69
  if (entity && entityId) {
56
70
  const shipClazz = await (0, shipClazz_1.getShipClazz)(entity, entityId, context);
57
71
  const extraShipId = await shipClazz.eOrder(id, context);
@@ -119,6 +133,9 @@ const triggers = [
119
133
  const { id: shipId, type, deposit$ship: deposits, shipOrder$ship, shipServiceId, entity, entityId, wechatMpShip } = ship || {};
120
134
  if (deposits && deposits.length > 0) {
121
135
  //充值 (此时该充值必定为受发货限制的小程序上的充值)
136
+ //等待5秒以避免小程序订单号查询不到
137
+ const sleep = (0, util_1.promisify)(setTimeout);
138
+ await sleep(5 * 1000);
122
139
  await (0, ship_1.uploadShippingInfo)(shipId, context);
123
140
  cnt++;
124
141
  }
@@ -451,49 +468,5 @@ const triggers = [
451
468
  return count;
452
469
  },
453
470
  },
454
- {
455
- name: '当虚拟ship自动确认收货后更新deposit状态',
456
- entity: 'ship',
457
- action: 'update',
458
- when: 'after',
459
- asRoot: true,
460
- fn: async ({ operation }, context, option) => {
461
- const { filter, id, data } = operation;
462
- const ships = await context.select('ship', {
463
- data: {
464
- id: 1,
465
- iState: 1,
466
- type: 1,
467
- deposit$ship: {
468
- $entity: 'deposit',
469
- data: {
470
- id: 1,
471
- iState: 1,
472
- }
473
- }
474
- },
475
- filter,
476
- }, { forUpdate: true });
477
- let count = 0;
478
- const virtualShips = ships?.filter((ele) => ele.type === 'virtual');
479
- if (virtualShips && virtualShips.length > 0) {
480
- for (const ship of virtualShips) {
481
- const deposit = ship.deposit$ship?.[0];
482
- if (deposit && deposit.iState === 'shipped') {
483
- await context.operate('deposit', {
484
- id: await (0, uuid_1.generateNewIdAsync)(),
485
- action: 'succeed',
486
- data: {},
487
- filter: {
488
- id: deposit.id,
489
- }
490
- }, option);
491
- count++;
492
- }
493
- }
494
- }
495
- return count;
496
- }
497
- },
498
471
  ];
499
472
  exports.default = triggers;
@@ -6,6 +6,6 @@ import { BRC } from '../types/RuntimeCxt';
6
6
  * @param context
7
7
  * @param refunds
8
8
  */
9
- export declare function updateWithdrawState(context: BRC, id: string): Promise<0 | 1>;
9
+ export declare function updateWithdrawState(context: BRC, id: string): Promise<1 | 0>;
10
10
  declare const triggers: Trigger<EntityDict, 'withdraw', BRC>[];
11
11
  export default triggers;
package/lib/utils/ship.js CHANGED
@@ -61,6 +61,7 @@ exports.shipProjection = {
61
61
  order: {
62
62
  id: 1,
63
63
  iState: 1,
64
+ desc: 1,
64
65
  pay$order: {
65
66
  $entity: 'pay',
66
67
  data: {
@@ -201,14 +202,14 @@ async function uploadShippingInfo(shipId, context) {
201
202
  //订单 每笔微信支付调用一次接口
202
203
  //当已发货的订单再次调用小程序发货信息录入接口视为重新发货(仅可重新发货一次)
203
204
  const orders = shipOrder$ship.map((ele) => ele.order);
204
- const fromPhoneStr = maskPhone(from.phone);
205
- const toPhoneStr = maskPhone(to.phone);
206
205
  for (const order of orders) {
207
206
  const { pay$order, desc } = order;
208
207
  const wechatPay = pay$order.find((ele) => ele.entity === 'wpProduct');
209
208
  const meta = wechatPay?.meta;
210
209
  let shippingList = [];
211
210
  if (shipType === 'express') {
211
+ const fromPhoneStr = maskPhone(from.phone);
212
+ const toPhoneStr = maskPhone(to.phone);
212
213
  shippingList = [
213
214
  {
214
215
  tracking_no: extraShipId,
@@ -1,36 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const operationResult_1 = require("oak-domain/lib/utils/operationResult");
4
- const ship_1 = require("../utils/ship");
5
3
  const QUERY_PAYING_STATE_GAP = process.env.NODE_ENV === 'production' ? 3600 * 1000 : 60 * 1000;
6
4
  const watchers = [
7
- {
8
- name: '对shipping状态的物流,同步其真实状态',
9
- entity: 'ship',
10
- filter: async () => {
11
- const now = Date.now();
12
- return {
13
- type: 'express',
14
- iState: 'shipping',
15
- $$updateAt$$: {
16
- $lte: now - QUERY_PAYING_STATE_GAP,
17
- },
18
- };
19
- },
20
- projection: ship_1.shipProjection,
21
- fn: async (context, data) => {
22
- const results = [];
23
- for (const ship of data) {
24
- const result = await (0, ship_1.refreshShipState)(ship.id, context);
25
- if (result) {
26
- results.push(result);
27
- }
28
- }
29
- if (results.length === 0) {
30
- return {};
31
- }
32
- return results.reduce((prev, cur) => (0, operationResult_1.mergeOperationResult)(prev, cur));
33
- }
34
- }
5
+ // {
6
+ // name: '对shipping状态的物流,同步其真实状态',
7
+ // entity: 'ship',
8
+ // filter: async () => {
9
+ // const now = Date.now();
10
+ // return {
11
+ // type: 'express',
12
+ // iState: 'shipping',
13
+ // $$updateAt$$: {
14
+ // $lte: now - QUERY_PAYING_STATE_GAP,
15
+ // },
16
+ // };
17
+ // },
18
+ // projection: shipProjection,
19
+ // fn: async (context, data) => {
20
+ // const results = [] as OperationResult<EntityDict>[];
21
+ // for (const ship of data) {
22
+ // const result = await refreshShipState(ship.id!, context);
23
+ // if (result) {
24
+ // results.push(result);
25
+ // }
26
+ // }
27
+ // if (results.length === 0) {
28
+ // return {};
29
+ // }
30
+ // return results.reduce(
31
+ // (prev, cur) => mergeOperationResult(prev, cur)
32
+ // );
33
+ // }
34
+ // }
35
35
  ];
36
36
  exports.default = watchers;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oak-pay-business",
3
- "version": "3.1.3",
3
+ "version": "3.1.5",
4
4
  "description": "",
5
5
  "files": [
6
6
  "lib/**/*",
@@ -33,8 +33,8 @@
33
33
  "dayjs": "^1.11.5",
34
34
  "oak-domain": "^5.1.27",
35
35
  "oak-external-sdk": "^2.3.10",
36
- "oak-frontend-base": "^5.3.34",
37
- "oak-general-business": "~5.7.8",
36
+ "oak-frontend-base": "^5.3.35",
37
+ "oak-general-business": "~5.7.9",
38
38
  "react-markdown": "^9.0.3",
39
39
  "wechat-pay-nodejs": "^0.2.3"
40
40
  },