oak-pay-business 3.0.1 → 3.0.3

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.
@@ -1,3 +1,7 @@
1
+ /**
2
+ * 抽象组件在业务层根据EntityDict的重新声明
3
+ * by Xc 20230807
4
+ */
1
5
  import AbsFilterPanel from 'oak-frontend-base/es/components/filterPanel';
2
6
  import AbsList from 'oak-frontend-base/es/components/list';
3
7
  import AbsListPro from 'oak-frontend-base/es/components/listPro';
@@ -16,6 +16,7 @@ export default OakComponent({
16
16
  $entity: 'deposit',
17
17
  data: {
18
18
  id: 1,
19
+ iState: 1,
19
20
  pay$deposit: {
20
21
  $entity: 'pay',
21
22
  data: {
@@ -64,9 +65,36 @@ export default OakComponent({
64
65
  preWithdraw: () => true,
65
66
  onGoToHistory: () => undefined,
66
67
  },
67
- formData({ data }) {
68
- const unfinishedDepositId = data?.deposit$account?.filter((ele) => ele.iState === 'depositing')?.[0]?.id; //未完成支付的充值
69
- const unreceivedDepositId = data?.deposit$account?.filter((ele) => ele.iState === 'shipped')?.[0]?.id; //未确认收货的充值
68
+ formData({ data, features }) {
69
+ let unfinishedDepositId = data?.deposit$account?.filter((ele) => ele.iState === 'depositing')?.[0]?.id; //未完成支付的充值
70
+ let unreceivedDepositId = data?.deposit$account?.filter((ele) => ele.iState === 'shipped')?.[0]?.id; //未确认收货的充值
71
+ if (data?.id) {
72
+ const deposits = features.cache.get('deposit', {
73
+ data: {
74
+ id: 1,
75
+ iState: 1,
76
+ pay$deposit: {
77
+ $entity: 'pay',
78
+ data: {
79
+ id: 1,
80
+ },
81
+ filter: {
82
+ iState: 'paying',
83
+ },
84
+ },
85
+ },
86
+ filter: {
87
+ iState: {
88
+ $in: ['depositing', 'shipped'],
89
+ },
90
+ accountId: data?.id,
91
+ }
92
+ });
93
+ if (deposits && deposits.length > 0) {
94
+ unfinishedDepositId = deposits?.filter((ele) => ele.iState === 'depositing')?.[0]?.id; //未完成支付的充值
95
+ unreceivedDepositId = deposits?.filter((ele) => ele.iState === 'shipped')?.[0]?.id; //未确认收货的充值
96
+ }
97
+ }
70
98
  return {
71
99
  account: data,
72
100
  availStr: data?.avail && CentToString(data.avail, 2),
@@ -186,7 +214,8 @@ export default OakComponent({
186
214
  this.setState({ depPrice }, () => this.setDepositLoss());
187
215
  },
188
216
  setDepositChannel(depositChannel) {
189
- this.setState({ depositChannel }, () => this.setDepositLoss());
217
+ const channel = depositChannel ? depositChannel : null;
218
+ this.setState({ depositChannel: channel }, () => this.setDepositLoss());
190
219
  },
191
220
  setDepositLoss() {
192
221
  const { depPrice, depositChannel } = this.state;
@@ -302,6 +331,15 @@ export default OakComponent({
302
331
  id: ship.id,
303
332
  },
304
333
  }]);
334
+ await this.features.cache.refresh('deposit', {
335
+ data: {
336
+ id: 1,
337
+ iState: 1,
338
+ },
339
+ filter: {
340
+ id: unreceivedDepositId,
341
+ }
342
+ });
305
343
  this.setMessage({
306
344
  type: 'success',
307
345
  content: this.t('ship.success')
@@ -336,10 +374,11 @@ export default OakComponent({
336
374
  }
337
375
  else {
338
376
  console.log(mpShipState);
339
- this.setMessage({
340
- type: 'warning',
341
- content: this.t('ship.wait'),
342
- });
377
+ this.reRender();
378
+ // this.setMessage({
379
+ // type: 'warning',
380
+ // content: this.t('ship.wait'),
381
+ // })
343
382
  }
344
383
  },
345
384
  fail() {
@@ -371,12 +410,13 @@ export default OakComponent({
371
410
  }
372
411
  }
373
412
  else {
374
- if (!noMessage) {
375
- this.setMessage({
376
- content: this.t('ship.wait'),
377
- type: 'warning',
378
- });
379
- }
413
+ // if (!noMessage) {
414
+ // this.setMessage({
415
+ // content: this.t('ship.wait'),
416
+ // type: 'warning',
417
+ // })
418
+ // }
419
+ this.reRender();
380
420
  }
381
421
  }
382
422
  }
@@ -398,47 +438,7 @@ export default OakComponent({
398
438
  async ready() {
399
439
  const { oakId } = this.props;
400
440
  assert(typeof oakId === 'string');
401
- const unsub = await this.subDataEvents([`${DATA_SUBSCRIBER_KEYS.accountNumberChanged}-${oakId}`, `${DATA_SUBSCRIBER_KEYS.depositStateChanged}-${oakId}`], async (event, opRecords) => {
402
- for (const record of opRecords) {
403
- if (record.a === 'succeed') {
404
- const { e, d } = record;
405
- if (e === 'deposit') {
406
- await this.features.cache.refresh('deposit', {
407
- data: {
408
- id: 1,
409
- accountId: 1,
410
- iState: 1,
411
- pay$deposit: {
412
- $entity: 'pay',
413
- data: {
414
- id: 1,
415
- meta: 1,
416
- iState: 1,
417
- entity: 1,
418
- entityId: 1,
419
- },
420
- filter: {
421
- entity: 'wpProduct',
422
- iState: 'paid',
423
- }
424
- },
425
- shipId: 1,
426
- ship: {
427
- id: 1,
428
- iState: 1,
429
- }
430
- },
431
- filter: {
432
- accountId: oakId,
433
- iState: {
434
- $in: ['depositing', 'shipped'],
435
- },
436
- }
437
- });
438
- }
439
- }
440
- }
441
- });
441
+ const unsub = await this.subDataEvents([`${DATA_SUBSCRIBER_KEYS.accountNumberChanged}-${oakId}`, `${DATA_SUBSCRIBER_KEYS.depositStateChanged}-${oakId}`]);
442
442
  this.setState({
443
443
  unsub,
444
444
  });
@@ -4,7 +4,7 @@ declare const _default: (props: import("oak-frontend-base").ReactComponentProps<
4
4
  depositMinCent: number;
5
5
  depositMaxCent: number;
6
6
  price: number | null;
7
- channel: PayChannel | null;
7
+ channel: PayChannel | undefined;
8
8
  onSetPrice: (price: null | number) => void;
9
9
  onSetChannel: (channel: PayChannel) => void;
10
10
  loss: [number, string, any];
@@ -5,7 +5,7 @@ export default OakComponent({
5
5
  depositMinCent: 0,
6
6
  depositMaxCent: 1000000,
7
7
  price: 0,
8
- channel: {},
8
+ channel: undefined,
9
9
  onSetPrice: (price) => undefined,
10
10
  onSetChannel: (channel) => undefined,
11
11
  loss: [0, '', {}],
@@ -30,11 +30,19 @@ export default OakComponent({
30
30
  },
31
31
  lifetimes: {
32
32
  ready() {
33
- const { depositMinCent } = this.props;
33
+ const { depositMinCent, channel, onSetChannel } = this.props;
34
34
  if (depositMinCent) {
35
35
  this.onPriceChange(ToYuan(depositMinCent), true);
36
36
  }
37
- }
37
+ if (!channel && process.env.OAK_PLATFORM === 'wechatMp') {
38
+ //小程序环境下默认选择微信支付
39
+ const { payChannels } = this.state;
40
+ const wpProduct = payChannels?.find((ele) => ele.entity === 'wpProduct');
41
+ if (wpProduct) {
42
+ onSetChannel && onSetChannel(wpProduct);
43
+ }
44
+ }
45
+ },
38
46
  },
39
47
  listeners: {
40
48
  price() {
@@ -87,9 +95,9 @@ export default OakComponent({
87
95
  this.onPriceChange(value);
88
96
  }
89
97
  else {
90
- const price2 = parseInt(value);
98
+ const price2 = Number(value);
91
99
  if (!isNaN(price2)) {
92
- this.onPriceChange(price2);
100
+ this.onPriceChange(Math.round(price2 * 100) / 100);
93
101
  }
94
102
  }
95
103
  },
@@ -24,10 +24,10 @@ export default OakComponent({
24
24
  },
25
25
  isList: false,
26
26
  properties: {
27
- accountId: '',
28
- accountAvailMax: 0,
27
+ accountId: '', // 是否可以使用帐户中的余额抵扣
28
+ accountAvailMax: 0, // 本次交易可以使用的帐户中的Avail max值,调用者自己保证此数值的一致性,不要扣成负数
29
29
  onSetPays: (pays) => undefined,
30
- accountTips: '',
30
+ accountTips: '', // 使用余额支付的提示说明
31
31
  autoStartPay: false,
32
32
  },
33
33
  formData({ data }) {
@@ -129,16 +129,18 @@ export default OakComponent({
129
129
  showCloseConfirmMp: false,
130
130
  showChannelSelectMp: false,
131
131
  unsub: undefined,
132
- unsubShip: undefined,
132
+ depositUnsub: undefined,
133
133
  },
134
134
  formData({ data, props }) {
135
135
  const application = this.features.application.getApplication();
136
136
  const iState = data?.iState;
137
137
  let iStateStr = this.t(`pay:v.iState.${iState}`);
138
138
  let iStateColor = iState && this.features.style.getColor('pay', 'iState', iState);
139
+ let showDepositConfirm = false;
139
140
  if (data?.depositId && data?.deposit?.shipId && data?.deposit?.iState === 'shipped') {
140
141
  iStateStr = this.t('ship.shipped');
141
142
  iStateColor = this.features.style.getColor('deposit', 'iState', data?.deposit?.iState);
143
+ showDepositConfirm = true;
142
144
  }
143
145
  const startPayable = iState === 'paying' && !['account', 'offlineAccount'].includes(data.entity) && (PayRoutineDict[data.entity] && PayRoutineDict[data.entity].judgeCanPay(data, this.features));
144
146
  const { mode } = this.props;
@@ -180,6 +182,7 @@ export default OakComponent({
180
182
  shipId: data?.deposit?.shipId,
181
183
  ship: data?.deposit?.ship,
182
184
  depositId: data?.depositId,
185
+ showDepositConfirm,
183
186
  };
184
187
  },
185
188
  features: [{
@@ -323,10 +326,12 @@ export default OakComponent({
323
326
  externalId: null,
324
327
  });
325
328
  },
326
- async confirmShipMp(shipId, shipState) {
329
+ async confirmShipMp() {
327
330
  //小程序唤起确认收货组件
331
+ const { pay, ship, depositId } = this.state;
328
332
  if (process.env.OAK_PLATFORM === 'wechatMp') {
329
- const { pay, } = this.state;
333
+ const shipId = ship.id;
334
+ const shipState = ship.iState;
330
335
  if (shipId && shipState === 'receiving') {
331
336
  if (process.env.NODE_ENV === 'development') {
332
337
  await this.features.cache.operate('ship', [{
@@ -337,6 +342,15 @@ export default OakComponent({
337
342
  id: shipId,
338
343
  },
339
344
  }]);
345
+ await this.features.cache.refresh('deposit', {
346
+ data: {
347
+ id: 1,
348
+ iState: 1,
349
+ },
350
+ filter: {
351
+ id: depositId,
352
+ }
353
+ });
340
354
  this.setMessage({
341
355
  type: 'success',
342
356
  content: this.t('ship.success')
@@ -364,6 +378,7 @@ export default OakComponent({
364
378
  id: shipId,
365
379
  },
366
380
  }]);
381
+ this.reRender();
367
382
  this.setMessage({
368
383
  type: 'success',
369
384
  content: this.t('ship.success')
@@ -371,10 +386,11 @@ export default OakComponent({
371
386
  }
372
387
  else {
373
388
  console.log(mpShipState);
374
- this.setMessage({
375
- type: 'warning',
376
- content: this.t('ship.wait'),
377
- });
389
+ // this.setMessage({
390
+ // type: 'warning',
391
+ // content: this.t('ship.wait'),
392
+ // })
393
+ this.reRender();
378
394
  }
379
395
  },
380
396
  fail() {
@@ -404,10 +420,7 @@ export default OakComponent({
404
420
  }
405
421
  }
406
422
  else {
407
- this.setMessage({
408
- type: 'warning',
409
- content: this.t('ship.wait'),
410
- });
423
+ this.reRender();
411
424
  }
412
425
  }
413
426
  }
@@ -416,21 +429,17 @@ export default OakComponent({
416
429
  async ready() {
417
430
  const { oakId } = this.props;
418
431
  assert(typeof oakId === 'string');
419
- const unsub = await this.subDataEvents([`${DATA_SUBSCRIBER_KEYS.payStateChanged}-${oakId}`], async (event, opRecords) => {
420
- for (const record of opRecords) {
421
- if (record.a === 'succeedPaying') {
422
- const { e, d } = record;
423
- if (e === 'pay' && d.iState === 'paid') {
424
- await this.features.cache.refresh('pay', {
425
- data: baseProjection,
426
- filter: {
427
- id: oakId,
428
- }
429
- });
430
- }
431
- }
432
- }
433
- });
432
+ const unsub = await this.subDataEvents([
433
+ `${DATA_SUBSCRIBER_KEYS.payStateChanged}-${oakId}`,
434
+ `${DATA_SUBSCRIBER_KEYS.depositStateChanged}-${oakId}`
435
+ ]);
436
+ const { depositId } = this.state;
437
+ if (depositId) {
438
+ const depositUnsub = await this.subDataEvents([`${DATA_SUBSCRIBER_KEYS.shipStateChanged}-${depositId}`]);
439
+ this.setState({
440
+ depositUnsub,
441
+ });
442
+ }
434
443
  this.setState({
435
444
  unsub,
436
445
  });
@@ -438,13 +447,13 @@ export default OakComponent({
438
447
  async mature() {
439
448
  const { ship } = this.state;
440
449
  if (ship?.id && ship?.iState === 'receiving') {
441
- await this.confirmShipMp(ship.id, ship.iState);
450
+ await this.confirmShipMp();
442
451
  }
443
452
  },
444
453
  detached() {
445
- const { unsub, unsubShip } = this.state;
454
+ const { unsub, depositUnsub } = this.state;
446
455
  unsub && unsub();
447
- unsubShip && unsubShip();
456
+ depositUnsub && depositUnsub();
448
457
  },
449
458
  },
450
459
  listeners: {
@@ -458,30 +467,5 @@ export default OakComponent({
458
467
  this.refreshOfflineAccounts();
459
468
  }
460
469
  },
461
- async shipId(prev, next) {
462
- const { depositId } = this.state;
463
- if (depositId && prev.shipId !== next.shipId && next.shipId) {
464
- if (prev.shipId) {
465
- const { unsubShip } = this.state;
466
- unsubShip && unsubShip();
467
- }
468
- const unsubShip = await this.subDataEvents([`${DATA_SUBSCRIBER_KEYS.shipStateChanged}-${next.shipId}`], async (event, opRecords) => {
469
- if (process.env.OAK_PLATFORM === 'wechatMp') {
470
- //在充值虚拟发货成功后,小程序唤起确认收货组件
471
- for (const record of opRecords) {
472
- if (record.a === 'startReceiving') {
473
- const { e, d } = record;
474
- if (e === 'ship' && d.iState === 'receiving') {
475
- await this.confirmShipMp(next.shipId, d.iState);
476
- }
477
- }
478
- }
479
- }
480
- });
481
- this.setState({
482
- unsubShip,
483
- });
484
- }
485
- }
486
470
  },
487
471
  });
@@ -46,7 +46,7 @@
46
46
  }
47
47
 
48
48
  .meta {
49
- margin-top: 40px;
49
+ margin-top: 18px;
50
50
  display: flex;
51
51
  flex-direction: column;
52
52
  align-items: center;
@@ -166,7 +166,7 @@
166
166
  flex-direction: column;
167
167
  align-items: center;
168
168
  padding: 24rpx;
169
- margin-top: 90rpx;
169
+ margin-top: 50rpx;
170
170
 
171
171
  text {
172
172
  margin-top: 40rpx;
@@ -197,4 +197,23 @@
197
197
  grid-template-columns: 1fr 1fr;
198
198
  gap: 32rpx;
199
199
  flex: 1;
200
+ }
201
+
202
+ .depositConfrimBox {
203
+ display: flex;
204
+ flex-direction: column;
205
+ align-items: center;
206
+ justify-content: center;
207
+ row-gap: 32rpx;
208
+ padding: 12rpx;
209
+ box-sizing: border-box;
210
+ margin-top: 24rpx;
211
+ background-color: #fff;
212
+ border-radius: 16rpx;
213
+
214
+ .depositConfrimText {
215
+ display: flex;
216
+ gap: 18rpx;
217
+ line-height: 36rpx;
218
+ }
200
219
  }
@@ -18,7 +18,7 @@
18
18
  <view class="wariningAlert">{{t('notSameApp')}}</view>
19
19
  </block>
20
20
  <block wx:elif="{{pay.entity === 'offlineAccount'}}">
21
- <view wx:if="{{pay.iState === 'paying'}}" class="infoAlert" style="margin-bottom:20rpx;">{{t('code.help' + '.mode')}}</view>
21
+ <view wx:if="{{pay.iState === 'paying'}}" class="infoAlert" style="margin-bottom:20rpx;">{{t('code.help.' + mode)}}</view>
22
22
  <l-popup wx:if="{{showChannelSelectMp}}" show="{{showChannelSelectMp}}" content-align="bottom" bind:lintap="closeChannelSelectMp">
23
23
  <view class="my-panel-class">
24
24
  <l-radio-group
@@ -107,7 +107,21 @@
107
107
  </block>
108
108
  </block>
109
109
  </view>
110
- <view class="padding"></view>
110
+ <view class="padding">
111
+ <view wx:if="{{showDepositConfirm}}" class="depositConfrimBox">
112
+ <view class="depositConfrimText">
113
+ <l-icon name='warning' size="32" />
114
+ <span>微信支付成功,请点击下方「充值确认」按钮,确认后即可正常使用余额!</span>
115
+ </view>
116
+ <l-button
117
+ plain="{{true}}"
118
+ shape="semicircle"
119
+ bind:lintap="confirmShipMp"
120
+ >
121
+ 充值确认
122
+ </l-button>
123
+ </view>
124
+ </view>
111
125
  <view style="display:flex; align-items: center;justify-content: space-between;gap:16rpx;">
112
126
  <block wx:if="{{closable && !oakExecutable}}">
113
127
  <l-button
@@ -19,6 +19,7 @@ export type EmailConfig = {
19
19
  html?: string;
20
20
  codeDuration?: number;
21
21
  digit?: number;
22
+ emailSuffixes?: string[];
22
23
  };
23
24
  export type PfwConfig = {
24
25
  appId: string;
@@ -158,16 +158,55 @@ const triggers = [
158
158
  data: {
159
159
  id: 1,
160
160
  accountId: 1,
161
+ iState: 1,
162
+ pay$deposit: {
163
+ $entity: 'pay',
164
+ data: {
165
+ id: 1,
166
+ iState: 1,
167
+ }
168
+ }
161
169
  },
162
170
  filter: {
163
171
  id: depositId,
164
172
  }
165
- }, {
166
- forUpdate: true,
167
- });
168
- const { accountId } = deposit;
173
+ }, {});
174
+ const { accountId, pay$deposit } = deposit;
175
+ const payId = pay$deposit?.[0].id;
176
+ const selectionId = await generateNewIdAsync();
177
+ await context.select('deposit', {
178
+ id: selectionId,
179
+ data: {
180
+ id: 1,
181
+ accountId: 1,
182
+ account: {
183
+ id: 1,
184
+ avail: 1,
185
+ total: 1,
186
+ },
187
+ iState: 1,
188
+ shipId: 1,
189
+ ship: {
190
+ id: 1,
191
+ iState: 1,
192
+ },
193
+ pay$deposit: {
194
+ $entity: 'pay',
195
+ data: {
196
+ id: 1,
197
+ iState: 1,
198
+ }
199
+ }
200
+ },
201
+ filter: {
202
+ id: depositId,
203
+ }
204
+ }, {});
205
+ if (payId) {
206
+ context.saveOperationToEvent(selectionId, `${DATA_SUBSCRIBER_KEYS.depositStateChanged}-${payId}`);
207
+ }
169
208
  if (accountId) {
170
- context.saveOperationToEvent(id, `${DATA_SUBSCRIBER_KEYS.depositStateChanged}-${accountId}`);
209
+ context.saveOperationToEvent(selectionId, `${DATA_SUBSCRIBER_KEYS.depositStateChanged}-${accountId}`);
171
210
  }
172
211
  return 1;
173
212
  }
@@ -10,6 +10,17 @@ const triggers = [
10
10
  asRoot: true,
11
11
  fn: async ({ ids }, context, option) => {
12
12
  for (const id of ids) {
13
+ const [order] = await context.select('order', {
14
+ data: {
15
+ id: 1,
16
+ price: 1,
17
+ paid: 1,
18
+ }, filter: {
19
+ id,
20
+ }
21
+ }, {
22
+ forUpdate: true,
23
+ });
13
24
  const settlements = await context.select('settlement', {
14
25
  data: {
15
26
  id: 1,
@@ -26,8 +37,10 @@ const triggers = [
26
37
  forUpdate: true,
27
38
  });
28
39
  assert(settlements && settlements.length > 0);
40
+ let amount = 0;
29
41
  for (const settlement of settlements) {
30
42
  const { id: settlementId, price, accountId } = settlement;
43
+ amount += price;
31
44
  //创建对应的accountOper
32
45
  await context.operate('settlement', {
33
46
  id: await generateNewIdAsync(),
@@ -50,6 +63,7 @@ const triggers = [
50
63
  }
51
64
  }, {});
52
65
  }
66
+ assert(order.price === amount);
53
67
  }
54
68
  return;
55
69
  }
@@ -158,9 +158,70 @@ const triggers = [
158
158
  fn: async ({ operation }, context, option) => {
159
159
  const { filter, id } = operation;
160
160
  const { id: shipId } = filter;
161
+ const [ship] = await context.select('ship', {
162
+ data: {
163
+ id: 1,
164
+ deposit$ship: {
165
+ $entity: 'deposit',
166
+ data: {
167
+ id: 1,
168
+ }
169
+ },
170
+ shipOrder$ship: {
171
+ $entity: 'shipOrder',
172
+ data: {
173
+ id: 1,
174
+ orderId: 1,
175
+ }
176
+ }
177
+ },
178
+ filter,
179
+ }, {});
180
+ const { deposit$ship: deposits, shipOrder$ship: shipOrders } = ship || {};
181
+ const depositIds = deposits?.map((ele) => ele.id);
182
+ const orderIds = shipOrders?.map((ele) => ele.orderId);
161
183
  if (shipId) {
162
184
  context.saveOperationToEvent(id, `${DATA_SUBSCRIBER_KEYS.shipStateChanged}-${shipId}`);
163
185
  }
186
+ const selectionId = await generateNewIdAsync();
187
+ await context.select('ship', {
188
+ id: selectionId,
189
+ data: {
190
+ id: 1,
191
+ iState: 1,
192
+ deposit$ship: {
193
+ $entity: 'deposit',
194
+ data: {
195
+ id: 1,
196
+ iState: 1,
197
+ }
198
+ },
199
+ shipOrder$ship: {
200
+ $entity: 'shipOrder',
201
+ data: {
202
+ id: 1,
203
+ orderId: 1,
204
+ order: {
205
+ id: 1,
206
+ iState: 1,
207
+ }
208
+ }
209
+ }
210
+ },
211
+ filter: {
212
+ id: shipId,
213
+ }
214
+ }, {});
215
+ if (depositIds && depositIds.length > 0) {
216
+ depositIds.forEach((depositId) => {
217
+ context.saveOperationToEvent(selectionId, `${DATA_SUBSCRIBER_KEYS.shipStateChanged}-${depositId}`);
218
+ });
219
+ }
220
+ if (orderIds && orderIds.length > 0) {
221
+ orderIds.forEach((orderId) => {
222
+ context.saveOperationToEvent(selectionId, `${DATA_SUBSCRIBER_KEYS.shipStateChanged}-${orderId}`);
223
+ });
224
+ }
164
225
  return 1;
165
226
  }
166
227
  },
@@ -330,7 +391,7 @@ const triggers = [
330
391
  filter: {
331
392
  id
332
393
  }
333
- }, { dontCollect: true, forUpdate: true });
394
+ }, { forUpdate: true });
334
395
  const { type, shipOrder$ship } = ship;
335
396
  const wpPay = shipOrder$ship?.map((shipOrder) => shipOrder?.order?.pay$order).flat();
336
397
  if (type === 'virtual' || (type === 'pickup' && wpPay && wpPay.length > 0)) {
@@ -350,27 +411,26 @@ const triggers = [
350
411
  name: '当虚拟ship确认收货后更新deposit状态',
351
412
  entity: 'ship',
352
413
  action: 'succeedReceiving',
353
- when: 'commit',
414
+ when: 'after',
354
415
  asRoot: true,
355
- fn: async ({ ids }, context, option) => {
356
- // assert(ids.length === 1);
357
- for (const id of ids) {
358
- const [ship] = await context.select('ship', {
359
- data: {
360
- id: 1,
361
- type: 1,
362
- deposit$ship: {
363
- $entity: 'deposit',
364
- data: {
365
- id: 1,
366
- iState: 1,
367
- }
416
+ fn: async ({ operation }, context, option) => {
417
+ const { filter, id, data } = operation;
418
+ const ships = await context.select('ship', {
419
+ data: {
420
+ id: 1,
421
+ type: 1,
422
+ deposit$ship: {
423
+ $entity: 'deposit',
424
+ data: {
425
+ id: 1,
426
+ iState: 1,
368
427
  }
369
- },
370
- filter: {
371
- id
372
428
  }
373
- }, { dontCollect: true, forUpdate: true });
429
+ },
430
+ filter,
431
+ }, { forUpdate: true });
432
+ let count = 0;
433
+ for (const ship of ships) {
374
434
  const { type, deposit$ship: deposits } = ship;
375
435
  if (type === 'virtual' && deposits && deposits.length > 0) {
376
436
  const [deposit] = deposits;
@@ -382,9 +442,55 @@ const triggers = [
382
442
  id: deposit.id,
383
443
  }
384
444
  }, option);
445
+ count++;
385
446
  }
386
447
  }
448
+ return count;
387
449
  },
388
450
  },
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
+ },
389
495
  ];
390
496
  export default triggers;
@@ -11,6 +11,7 @@ export declare class ExternalPayUtilException<ED extends EntityDict> extends Oak
11
11
  name: string;
12
12
  message: string;
13
13
  _module: string | undefined;
14
+ params: Record<string, any> | undefined;
14
15
  opRecords: OpRecord<ED>[];
15
16
  tag1: string | undefined;
16
17
  tag2: boolean | undefined;
@@ -156,16 +156,17 @@ export default class WechatMpShipDebug {
156
156
  sender: {
157
157
  name: from.name,
158
158
  mobile: from.phone,
159
- country: from.area.parent.parent.name,
160
- province: from.area.parent.name,
161
- area: from.area.name,
162
- address: from.detail,
159
+ // country: from!.area!.parent!.parent!.name!, //国家
160
+ province: from.area.parent.parent.name, //省份
161
+ city: from.area.parent.name, //市
162
+ area: from.area.name, // 区
163
+ address: from.detail, //详细地址
163
164
  },
164
165
  receiver: {
165
166
  name: to.name,
166
167
  mobile: to.phone,
167
- country: to.area.parent.parent.name,
168
- province: to.area.parent.name,
168
+ province: to.area.parent.parent.name,
169
+ city: to.area.parent.name,
169
170
  area: to.area.name,
170
171
  address: to.detail,
171
172
  },
@@ -19,6 +19,7 @@ export type EmailConfig = {
19
19
  html?: string;
20
20
  codeDuration?: number;
21
21
  digit?: number;
22
+ emailSuffixes?: string[];
22
23
  };
23
24
  export type PfwConfig = {
24
25
  appId: string;
@@ -161,16 +161,55 @@ const triggers = [
161
161
  data: {
162
162
  id: 1,
163
163
  accountId: 1,
164
+ iState: 1,
165
+ pay$deposit: {
166
+ $entity: 'pay',
167
+ data: {
168
+ id: 1,
169
+ iState: 1,
170
+ }
171
+ }
164
172
  },
165
173
  filter: {
166
174
  id: depositId,
167
175
  }
168
- }, {
169
- forUpdate: true,
170
- });
171
- const { accountId } = deposit;
176
+ }, {});
177
+ const { accountId, pay$deposit } = deposit;
178
+ const payId = pay$deposit?.[0].id;
179
+ const selectionId = await (0, uuid_1.generateNewIdAsync)();
180
+ await context.select('deposit', {
181
+ id: selectionId,
182
+ data: {
183
+ id: 1,
184
+ accountId: 1,
185
+ account: {
186
+ id: 1,
187
+ avail: 1,
188
+ total: 1,
189
+ },
190
+ iState: 1,
191
+ shipId: 1,
192
+ ship: {
193
+ id: 1,
194
+ iState: 1,
195
+ },
196
+ pay$deposit: {
197
+ $entity: 'pay',
198
+ data: {
199
+ id: 1,
200
+ iState: 1,
201
+ }
202
+ }
203
+ },
204
+ filter: {
205
+ id: depositId,
206
+ }
207
+ }, {});
208
+ if (payId) {
209
+ context.saveOperationToEvent(selectionId, `${constants_1.DATA_SUBSCRIBER_KEYS.depositStateChanged}-${payId}`);
210
+ }
172
211
  if (accountId) {
173
- context.saveOperationToEvent(id, `${constants_1.DATA_SUBSCRIBER_KEYS.depositStateChanged}-${accountId}`);
212
+ context.saveOperationToEvent(selectionId, `${constants_1.DATA_SUBSCRIBER_KEYS.depositStateChanged}-${accountId}`);
174
213
  }
175
214
  return 1;
176
215
  }
@@ -13,6 +13,17 @@ const triggers = [
13
13
  asRoot: true,
14
14
  fn: async ({ ids }, context, option) => {
15
15
  for (const id of ids) {
16
+ const [order] = await context.select('order', {
17
+ data: {
18
+ id: 1,
19
+ price: 1,
20
+ paid: 1,
21
+ }, filter: {
22
+ id,
23
+ }
24
+ }, {
25
+ forUpdate: true,
26
+ });
16
27
  const settlements = await context.select('settlement', {
17
28
  data: {
18
29
  id: 1,
@@ -29,8 +40,10 @@ const triggers = [
29
40
  forUpdate: true,
30
41
  });
31
42
  (0, assert_1.default)(settlements && settlements.length > 0);
43
+ let amount = 0;
32
44
  for (const settlement of settlements) {
33
45
  const { id: settlementId, price, accountId } = settlement;
46
+ amount += price;
34
47
  //创建对应的accountOper
35
48
  await context.operate('settlement', {
36
49
  id: await (0, uuid_1.generateNewIdAsync)(),
@@ -53,6 +66,7 @@ const triggers = [
53
66
  }
54
67
  }, {});
55
68
  }
69
+ (0, assert_1.default)(order.price === amount);
56
70
  }
57
71
  return;
58
72
  }
@@ -161,9 +161,70 @@ const triggers = [
161
161
  fn: async ({ operation }, context, option) => {
162
162
  const { filter, id } = operation;
163
163
  const { id: shipId } = filter;
164
+ const [ship] = await context.select('ship', {
165
+ data: {
166
+ id: 1,
167
+ deposit$ship: {
168
+ $entity: 'deposit',
169
+ data: {
170
+ id: 1,
171
+ }
172
+ },
173
+ shipOrder$ship: {
174
+ $entity: 'shipOrder',
175
+ data: {
176
+ id: 1,
177
+ orderId: 1,
178
+ }
179
+ }
180
+ },
181
+ filter,
182
+ }, {});
183
+ const { deposit$ship: deposits, shipOrder$ship: shipOrders } = ship || {};
184
+ const depositIds = deposits?.map((ele) => ele.id);
185
+ const orderIds = shipOrders?.map((ele) => ele.orderId);
164
186
  if (shipId) {
165
187
  context.saveOperationToEvent(id, `${constants_1.DATA_SUBSCRIBER_KEYS.shipStateChanged}-${shipId}`);
166
188
  }
189
+ const selectionId = await (0, uuid_1.generateNewIdAsync)();
190
+ await context.select('ship', {
191
+ id: selectionId,
192
+ data: {
193
+ id: 1,
194
+ iState: 1,
195
+ deposit$ship: {
196
+ $entity: 'deposit',
197
+ data: {
198
+ id: 1,
199
+ iState: 1,
200
+ }
201
+ },
202
+ shipOrder$ship: {
203
+ $entity: 'shipOrder',
204
+ data: {
205
+ id: 1,
206
+ orderId: 1,
207
+ order: {
208
+ id: 1,
209
+ iState: 1,
210
+ }
211
+ }
212
+ }
213
+ },
214
+ filter: {
215
+ id: shipId,
216
+ }
217
+ }, {});
218
+ if (depositIds && depositIds.length > 0) {
219
+ depositIds.forEach((depositId) => {
220
+ context.saveOperationToEvent(selectionId, `${constants_1.DATA_SUBSCRIBER_KEYS.shipStateChanged}-${depositId}`);
221
+ });
222
+ }
223
+ if (orderIds && orderIds.length > 0) {
224
+ orderIds.forEach((orderId) => {
225
+ context.saveOperationToEvent(selectionId, `${constants_1.DATA_SUBSCRIBER_KEYS.shipStateChanged}-${orderId}`);
226
+ });
227
+ }
167
228
  return 1;
168
229
  }
169
230
  },
@@ -333,7 +394,7 @@ const triggers = [
333
394
  filter: {
334
395
  id
335
396
  }
336
- }, { dontCollect: true, forUpdate: true });
397
+ }, { forUpdate: true });
337
398
  const { type, shipOrder$ship } = ship;
338
399
  const wpPay = shipOrder$ship?.map((shipOrder) => shipOrder?.order?.pay$order).flat();
339
400
  if (type === 'virtual' || (type === 'pickup' && wpPay && wpPay.length > 0)) {
@@ -353,27 +414,26 @@ const triggers = [
353
414
  name: '当虚拟ship确认收货后更新deposit状态',
354
415
  entity: 'ship',
355
416
  action: 'succeedReceiving',
356
- when: 'commit',
417
+ when: 'after',
357
418
  asRoot: true,
358
- fn: async ({ ids }, context, option) => {
359
- // assert(ids.length === 1);
360
- for (const id of ids) {
361
- const [ship] = await context.select('ship', {
362
- data: {
363
- id: 1,
364
- type: 1,
365
- deposit$ship: {
366
- $entity: 'deposit',
367
- data: {
368
- id: 1,
369
- iState: 1,
370
- }
419
+ fn: async ({ operation }, context, option) => {
420
+ const { filter, id, data } = operation;
421
+ const ships = await context.select('ship', {
422
+ data: {
423
+ id: 1,
424
+ type: 1,
425
+ deposit$ship: {
426
+ $entity: 'deposit',
427
+ data: {
428
+ id: 1,
429
+ iState: 1,
371
430
  }
372
- },
373
- filter: {
374
- id
375
431
  }
376
- }, { dontCollect: true, forUpdate: true });
432
+ },
433
+ filter,
434
+ }, { forUpdate: true });
435
+ let count = 0;
436
+ for (const ship of ships) {
377
437
  const { type, deposit$ship: deposits } = ship;
378
438
  if (type === 'virtual' && deposits && deposits.length > 0) {
379
439
  const [deposit] = deposits;
@@ -385,9 +445,55 @@ const triggers = [
385
445
  id: deposit.id,
386
446
  }
387
447
  }, option);
448
+ count++;
388
449
  }
389
450
  }
451
+ return count;
390
452
  },
391
453
  },
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
+ },
392
498
  ];
393
499
  exports.default = triggers;
@@ -11,6 +11,7 @@ export declare class ExternalPayUtilException<ED extends EntityDict> extends Oak
11
11
  name: string;
12
12
  message: string;
13
13
  _module: string | undefined;
14
+ params: Record<string, any> | undefined;
14
15
  opRecords: OpRecord<ED>[];
15
16
  tag1: string | undefined;
16
17
  tag2: boolean | undefined;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeException = exports.StartPayFailure = exports.PayUnRefundable = exports.RefundExceedMax = exports.ExternalPayUtilException = exports.UploadShipException = void 0;
3
+ exports.StartPayFailure = exports.PayUnRefundable = exports.RefundExceedMax = exports.ExternalPayUtilException = exports.UploadShipException = void 0;
4
+ exports.makeException = makeException;
4
5
  const tslib_1 = require("tslib");
5
6
  const types_1 = require("oak-domain/lib/types");
6
7
  const DependentExceptions_1 = tslib_1.__importDefault(require("./DependentExceptions"));
@@ -68,4 +69,3 @@ function makeException(msg) {
68
69
  }
69
70
  return exception;
70
71
  }
71
- exports.makeException = makeException;
@@ -1,13 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.registerGetPayStateResult = void 0;
3
+ exports.registerGetPayStateResult = registerGetPayStateResult;
4
4
  const tslib_1 = require("tslib");
5
5
  const assert_1 = tslib_1.__importDefault(require("assert"));
6
6
  let _PAY_STATE = '';
7
7
  function registerGetPayStateResult(payState) {
8
8
  _PAY_STATE = payState;
9
9
  }
10
- exports.registerGetPayStateResult = registerGetPayStateResult;
11
10
  class WechatPay {
12
11
  wpProduct;
13
12
  constructor(wpProduct) {
@@ -159,16 +159,17 @@ class WechatMpShipDebug {
159
159
  sender: {
160
160
  name: from.name,
161
161
  mobile: from.phone,
162
- country: from.area.parent.parent.name,
163
- province: from.area.parent.name,
164
- area: from.area.name,
165
- address: from.detail,
162
+ // country: from!.area!.parent!.parent!.name!, //国家
163
+ province: from.area.parent.parent.name, //省份
164
+ city: from.area.parent.name, //市
165
+ area: from.area.name, // 区
166
+ address: from.detail, //详细地址
166
167
  },
167
168
  receiver: {
168
169
  name: to.name,
169
170
  mobile: to.phone,
170
- country: to.area.parent.parent.name,
171
- province: to.area.parent.name,
171
+ province: to.area.parent.parent.name,
172
+ city: to.area.parent.name,
172
173
  area: to.area.name,
173
174
  address: to.detail,
174
175
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oak-pay-business",
3
- "version": "3.0.1",
3
+ "version": "3.0.3",
4
4
  "description": "",
5
5
  "files": [
6
6
  "lib/**/*",
@@ -30,10 +30,10 @@
30
30
  "dependencies": {
31
31
  "classnames": "^2.3.1",
32
32
  "dayjs": "^1.11.5",
33
- "oak-domain": "^5.1.22",
33
+ "oak-domain": "^5.1.24",
34
34
  "oak-external-sdk": "^2.3.6",
35
- "oak-frontend-base": "^5.3.30",
36
- "oak-general-business": "~5.7.3",
35
+ "oak-frontend-base": "^5.3.31",
36
+ "oak-general-business": "~5.7.5",
37
37
  "react-markdown": "^9.0.3",
38
38
  "wechat-pay-nodejs": "^0.2.3"
39
39
  },