oak-pay-business 3.1.2 → 3.1.4

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.
Files changed (35) hide show
  1. package/es/aspects/AspectDict.d.ts +3 -0
  2. package/es/aspects/index.js +2 -1
  3. package/es/aspects/ship.d.ts +6 -0
  4. package/es/aspects/ship.js +40 -0
  5. package/es/components/AbstractComponents.d.ts +3 -8
  6. package/es/components/account/detail/index.js +28 -15
  7. package/es/components/pay/detail/index.js +45 -21
  8. package/es/entities/SettlePlan.d.ts +2 -0
  9. package/es/entities/SettlePlan.js +2 -0
  10. package/es/oak-app-domain/SettlePlan/Storage.js +6 -0
  11. package/es/oak-app-domain/SettlePlan/_baseSchema.d.ts +8 -0
  12. package/es/oak-app-domain/SettlePlan/locales/zh_CN.json +3 -1
  13. package/es/timers/ship.js +19 -18
  14. package/es/triggers/settlePlan.js +142 -100
  15. package/es/triggers/ship.js +24 -51
  16. package/es/triggers/withdraw.d.ts +1 -1
  17. package/es/watchers/settlePlan.js +22 -3
  18. package/es/watchers/ship.js +30 -30
  19. package/lib/aspects/AspectDict.d.ts +3 -0
  20. package/lib/aspects/index.js +1 -0
  21. package/lib/aspects/ship.d.ts +6 -0
  22. package/lib/aspects/ship.js +42 -1
  23. package/lib/entities/SettlePlan.d.ts +2 -0
  24. package/lib/entities/SettlePlan.js +2 -0
  25. package/lib/oak-app-domain/SettlePlan/Storage.js +6 -0
  26. package/lib/oak-app-domain/SettlePlan/_baseSchema.d.ts +8 -0
  27. package/lib/oak-app-domain/SettlePlan/locales/zh_CN.json +3 -1
  28. package/lib/timers/ship.js +19 -18
  29. package/lib/triggers/settlePlan.js +142 -100
  30. package/lib/triggers/ship.js +24 -51
  31. package/lib/triggers/withdraw.d.ts +1 -1
  32. package/lib/watchers/settlePlan.js +22 -3
  33. package/lib/watchers/ship.js +30 -30
  34. package/package.json +1 -1
  35. package/src/entities/SettlePlan.ts +4 -0
@@ -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() {
@@ -6,6 +6,8 @@ export interface Schema extends EntityShape {
6
6
  when?: Datetime;
7
7
  order: Order;
8
8
  price: Price;
9
+ settledAt?: Datetime;
10
+ closedAt?: Datetime;
9
11
  }
10
12
  type IState = 'unsettled' | 'settled' | 'closed';
11
13
  type IAction = 'settle' | 'close';
@@ -15,6 +15,8 @@ export const entityDesc = {
15
15
  order: '订单',
16
16
  price: '结算金额',
17
17
  iState: '结算计划状态',
18
+ settledAt: '结算时间',
19
+ closedAt: '关闭时间'
18
20
  },
19
21
  action: {
20
22
  settle: '结算',
@@ -13,6 +13,12 @@ export const desc = {
13
13
  notNull: true,
14
14
  type: "money"
15
15
  },
16
+ settledAt: {
17
+ type: "datetime"
18
+ },
19
+ closedAt: {
20
+ type: "datetime"
21
+ },
16
22
  iState: {
17
23
  type: "enum",
18
24
  enumeration: ["unsettled", "settled", "closed"]
@@ -7,6 +7,8 @@ export type OpSchema = EntityShape & {
7
7
  when?: Datetime | null;
8
8
  orderId: ForeignKey<"order">;
9
9
  price: Price;
10
+ settledAt?: Datetime | null;
11
+ closedAt?: Datetime | null;
10
12
  iState?: IState | null;
11
13
  } & {
12
14
  [A in ExpressionKey]?: any;
@@ -20,6 +22,8 @@ export type OpFilter = {
20
22
  when: Q_DateValue;
21
23
  orderId: Q_StringValue;
22
24
  price: Q_NumberValue;
25
+ settledAt: Q_DateValue;
26
+ closedAt: Q_DateValue;
23
27
  iState: Q_EnumValue<IState>;
24
28
  } & ExprOp<OpAttr | string>;
25
29
  export type OpProjection = {
@@ -32,6 +36,8 @@ export type OpProjection = {
32
36
  when?: number;
33
37
  orderId?: number;
34
38
  price?: number;
39
+ settledAt?: number;
40
+ closedAt?: number;
35
41
  iState?: number;
36
42
  } & Partial<ExprOp<OpAttr | string>>;
37
43
  export type OpSortAttr = Partial<{
@@ -42,6 +48,8 @@ export type OpSortAttr = Partial<{
42
48
  when: number;
43
49
  orderId: number;
44
50
  price: number;
51
+ settledAt: number;
52
+ closedAt: number;
45
53
  iState: number;
46
54
  [k: string]: any;
47
55
  } | ExprOp<OpAttr | string>>;
@@ -4,7 +4,9 @@
4
4
  "when": "结算时间",
5
5
  "order": "订单",
6
6
  "price": "结算金额",
7
- "iState": "结算计划状态"
7
+ "iState": "结算计划状态",
8
+ "settledAt": "结算时间",
9
+ "closedAt": "关闭时间"
8
10
  },
9
11
  "action": {
10
12
  "settle": "结算",
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;