oak-pay-business 3.1.3 → 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.
- package/es/aspects/AspectDict.d.ts +3 -0
- package/es/aspects/index.js +2 -1
- package/es/aspects/ship.d.ts +6 -0
- package/es/aspects/ship.js +40 -0
- package/es/components/AbstractComponents.d.ts +3 -8
- package/es/components/account/detail/index.js +28 -15
- package/es/components/pay/detail/index.js +45 -21
- package/es/timers/ship.js +19 -18
- package/es/triggers/ship.js +24 -51
- package/es/triggers/withdraw.d.ts +1 -1
- package/es/watchers/ship.js +30 -30
- package/lib/aspects/AspectDict.d.ts +3 -0
- package/lib/aspects/index.js +1 -0
- package/lib/aspects/ship.d.ts +6 -0
- package/lib/aspects/ship.js +42 -1
- package/lib/timers/ship.js +19 -18
- package/lib/triggers/ship.js +24 -51
- package/lib/triggers/withdraw.d.ts +1 -1
- package/lib/watchers/ship.js +30 -30
- package/package.json +1 -1
package/es/aspects/index.js
CHANGED
|
@@ -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;
|
package/es/aspects/ship.d.ts
CHANGED
package/es/aspects/ship.js
CHANGED
|
@@ -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" | "
|
|
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" | "
|
|
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 (
|
|
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 (
|
|
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
|
-
|
|
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() {
|
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
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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;
|
package/es/triggers/ship.js
CHANGED
|
@@ -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.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
},
|
|
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<
|
|
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/watchers/ship.js
CHANGED
|
@@ -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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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;
|
package/lib/aspects/index.js
CHANGED
package/lib/aspects/ship.d.ts
CHANGED
package/lib/aspects/ship.js
CHANGED
|
@@ -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;
|
package/lib/timers/ship.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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;
|
package/lib/triggers/ship.js
CHANGED
|
@@ -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.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
},
|
|
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<
|
|
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/watchers/ship.js
CHANGED
|
@@ -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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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;
|