@things-factory/marketplace-base 3.8.27 → 3.8.31
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/dist-server/entities/marketplace-order-shipping.js +12 -3
- package/dist-server/entities/marketplace-order-shipping.js.map +1 -1
- package/dist-server/entities/marketplace-order.js +4 -0
- package/dist-server/entities/marketplace-order.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-order/sync-all-marketplace-order.js +207 -101
- package/dist-server/graphql/resolvers/marketplace-order/sync-all-marketplace-order.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-order/sync-marketplace-order.js +211 -113
- package/dist-server/graphql/resolvers/marketplace-order/sync-marketplace-order.js.map +1 -1
- package/dist-server/graphql/resolvers/marketplace-report/marketplace-sales-report.js +13 -2
- package/dist-server/graphql/resolvers/marketplace-report/marketplace-sales-report.js.map +1 -1
- package/dist-server/graphql/types/marketplace-order-shipping/marketplace-order-shipping-patch.js +1 -0
- package/dist-server/graphql/types/marketplace-order-shipping/marketplace-order-shipping-patch.js.map +1 -1
- package/dist-server/graphql/types/marketplace-order-shipping/marketplace-order-shipping.js +2 -0
- package/dist-server/graphql/types/marketplace-order-shipping/marketplace-order-shipping.js.map +1 -1
- package/dist-server/graphql/types/marketplace-order-shipping/new-marketplace-order-shipping.js +1 -0
- package/dist-server/graphql/types/marketplace-order-shipping/new-marketplace-order-shipping.js.map +1 -1
- package/dist-server/graphql/types/marketplace-report/marketplace-sales-report.js +9 -1
- package/dist-server/graphql/types/marketplace-report/marketplace-sales-report.js.map +1 -1
- package/package.json +5 -4
- package/server/entities/marketplace-order-shipping.ts +7 -0
- package/server/entities/marketplace-order.ts +3 -0
- package/server/graphql/resolvers/marketplace-order/sync-all-marketplace-order.ts +321 -168
- package/server/graphql/resolvers/marketplace-order/sync-marketplace-order.ts +310 -168
- package/server/graphql/resolvers/marketplace-report/marketplace-sales-report.ts +14 -2
- package/server/graphql/types/marketplace-order-shipping/marketplace-order-shipping-patch.ts +1 -0
- package/server/graphql/types/marketplace-order-shipping/marketplace-order-shipping.ts +2 -0
- package/server/graphql/types/marketplace-order-shipping/new-marketplace-order-shipping.ts +1 -0
- package/server/graphql/types/marketplace-report/marketplace-sales-report.ts +9 -1
|
@@ -12,7 +12,7 @@ exports.MarketplaceSalesReport = (0, graphql_tag_1.default) `
|
|
|
12
12
|
shippingRebate: Float
|
|
13
13
|
commissionFee: Float
|
|
14
14
|
serviceFee: Float
|
|
15
|
-
transactionFee:
|
|
15
|
+
transactionFee: Float
|
|
16
16
|
totalRealeasedAmount: Float
|
|
17
17
|
voucherCode: String
|
|
18
18
|
shippingMode: String
|
|
@@ -20,6 +20,7 @@ exports.MarketplaceSalesReport = (0, graphql_tag_1.default) `
|
|
|
20
20
|
orderNo: String
|
|
21
21
|
orderCreatedAt: String
|
|
22
22
|
buyerUsername: String
|
|
23
|
+
payoutDate: String
|
|
23
24
|
payTime: String
|
|
24
25
|
totalAmount: Float
|
|
25
26
|
refundAmount: Float
|
|
@@ -60,6 +61,13 @@ exports.MarketplaceSalesReport = (0, graphql_tag_1.default) `
|
|
|
60
61
|
fulfillmentCenter: String
|
|
61
62
|
variationSku: String
|
|
62
63
|
itemCommissionFee: Float
|
|
64
|
+
address1: String
|
|
65
|
+
address2: String
|
|
66
|
+
address3: String
|
|
67
|
+
city: String
|
|
68
|
+
state: String
|
|
69
|
+
postcode: String
|
|
70
|
+
trackingNo: String
|
|
63
71
|
}
|
|
64
72
|
`;
|
|
65
73
|
//# sourceMappingURL=marketplace-sales-report.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"marketplace-sales-report.js","sourceRoot":"","sources":["../../../../server/graphql/types/marketplace-report/marketplace-sales-report.ts"],"names":[],"mappings":";;;;;;AAAA,8DAA6B;AAEhB,QAAA,sBAAsB,GAAG,IAAA,qBAAG,EAAA
|
|
1
|
+
{"version":3,"file":"marketplace-sales-report.js","sourceRoot":"","sources":["../../../../server/graphql/types/marketplace-report/marketplace-sales-report.ts"],"names":[],"mappings":";;;;;;AAAA,8DAA6B;AAEhB,QAAA,sBAAsB,GAAG,IAAA,qBAAG,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgExC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/marketplace-base",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.31",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -24,9 +24,10 @@
|
|
|
24
24
|
"migration:create": "node ../../node_modules/typeorm/cli.js migration:create -d ./server/migrations"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@things-factory/integration-fulfillment": "^3.8.
|
|
28
|
-
"@things-factory/integration-marketplace": "^3.8.
|
|
27
|
+
"@things-factory/integration-fulfillment": "^3.8.29",
|
|
28
|
+
"@things-factory/integration-marketplace": "^3.8.29",
|
|
29
|
+
"@things-factory/product-base": "^3.8.31",
|
|
29
30
|
"@things-factory/shell": "^3.8.0"
|
|
30
31
|
},
|
|
31
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "5deb948aa45a0aea4d787b5380667dc0c9d1f889"
|
|
32
33
|
}
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
} from 'typeorm'
|
|
11
11
|
|
|
12
12
|
import { User } from '@things-factory/auth-base'
|
|
13
|
+
import { FulfillmentCenter } from '@things-factory/integration-fulfillment'
|
|
13
14
|
import { MarketplaceStore } from '@things-factory/integration-marketplace'
|
|
14
15
|
import { Domain } from '@things-factory/shell'
|
|
15
16
|
|
|
@@ -154,6 +155,12 @@ export class MarketplaceOrderShipping {
|
|
|
154
155
|
@Column({ type: 'float', nullable: true })
|
|
155
156
|
sellerShippingFeeVoucher: number
|
|
156
157
|
|
|
158
|
+
@Column({ nullable: true })
|
|
159
|
+
releaseOrderId: string
|
|
160
|
+
|
|
161
|
+
@ManyToOne(type => FulfillmentCenter, { nullable: true })
|
|
162
|
+
fulfillmentCenter: FulfillmentCenter
|
|
163
|
+
|
|
157
164
|
@CreateDateColumn()
|
|
158
165
|
createdAt: Date
|
|
159
166
|
|
|
@@ -5,6 +5,7 @@ import { Bizplace, getCustomerBizplaces } from '@things-factory/biz-base'
|
|
|
5
5
|
import { FulfillmentAPI, FulfillmentCenter } from '@things-factory/integration-fulfillment'
|
|
6
6
|
import { MarketplaceStore, StoreAPI } from '@things-factory/integration-marketplace'
|
|
7
7
|
import { Domain } from '@things-factory/shell'
|
|
8
|
+
import { Product, ProductBundle, ProductBundleSetting } from '@things-factory/product-base'
|
|
8
9
|
|
|
9
10
|
import {
|
|
10
11
|
MarketplaceOrder,
|
|
@@ -134,6 +135,36 @@ export const syncAllMarketplaceOrder = {
|
|
|
134
135
|
updater: user
|
|
135
136
|
}
|
|
136
137
|
|
|
138
|
+
if (
|
|
139
|
+
!marketplaceOrder?.releaseOrderId &&
|
|
140
|
+
cancelStatuses.includes(marketplaceOrder.status) &&
|
|
141
|
+
!cancelStatuses.includes(existingMarketplaceOrder.status)
|
|
142
|
+
) {
|
|
143
|
+
for (let item of marketplaceOrder.marketplaceOrderItems) {
|
|
144
|
+
let foundVariations = await getRepository(MarketplaceProductVariation).find({
|
|
145
|
+
where: {
|
|
146
|
+
domain: marketplaceOrder.domain,
|
|
147
|
+
sku: item.marketplaceProductVariation.sku
|
|
148
|
+
},
|
|
149
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
let activeVariations: MarketplaceProductVariation[] = foundVariations.filter(
|
|
153
|
+
variation =>
|
|
154
|
+
variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED' && variation.sku != null
|
|
155
|
+
)
|
|
156
|
+
|
|
157
|
+
await Promise.all(
|
|
158
|
+
activeVariations.map(async variation => {
|
|
159
|
+
await this.calculateReserveQtyForBundle(variation, marketplaceOrder.domain, item.qty, '-')
|
|
160
|
+
|
|
161
|
+
variation.reserveQty -= item.qty
|
|
162
|
+
variation.qty += item.qty
|
|
163
|
+
await getRepository(MarketplaceProductVariation).save(variation)
|
|
164
|
+
})
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
}
|
|
137
168
|
if (marketplaceOrder?.releaseOrderId) {
|
|
138
169
|
const fulfillmentCenter: FulfillmentCenter = marketplaceOrder.fulfillmentCenter
|
|
139
170
|
const centerId: string = fulfillmentCenter.centerId
|
|
@@ -330,13 +361,17 @@ export const syncAllMarketplaceOrder = {
|
|
|
330
361
|
}
|
|
331
362
|
|
|
332
363
|
let orderTotalWeight: number = 0
|
|
333
|
-
let
|
|
364
|
+
let foundVariations = []
|
|
334
365
|
for (var j = 0; j < order.orderItems.length; j++) {
|
|
335
366
|
var item = order.orderItems[j]
|
|
336
|
-
foundVariation = await getRepository(MarketplaceProductVariation).findOne({
|
|
367
|
+
let foundVariation = await getRepository(MarketplaceProductVariation).findOne({
|
|
337
368
|
where: { domain: marketplaceStore.domain, variationId: item.variationId }
|
|
338
369
|
})
|
|
339
370
|
|
|
371
|
+
if (foundVariation) {
|
|
372
|
+
foundVariations.push(foundVariation)
|
|
373
|
+
}
|
|
374
|
+
|
|
340
375
|
if (!foundVariation) {
|
|
341
376
|
let newVariation: any = {
|
|
342
377
|
variationId: item.variationId,
|
|
@@ -424,158 +459,199 @@ export const syncAllMarketplaceOrder = {
|
|
|
424
459
|
if (nonMatchedOrderItems.length > 0 && !cancelStatuses.includes(marketplaceOrder.status)) {
|
|
425
460
|
await Promise.all(
|
|
426
461
|
nonMatchedOrderItems.map(async item => {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
MarketplaceProductVariation
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
variation.
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
462
|
+
for (var foundVariation of foundVariations) {
|
|
463
|
+
if (foundVariation.sku) {
|
|
464
|
+
let allVariations: MarketplaceProductVariation[] = await getRepository(
|
|
465
|
+
MarketplaceProductVariation
|
|
466
|
+
).find({
|
|
467
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
468
|
+
relations: [
|
|
469
|
+
'domain',
|
|
470
|
+
'marketplaceProduct',
|
|
471
|
+
'marketplaceProduct.marketplaceStore',
|
|
472
|
+
'marketplaceProduct.marketplaceStore.marketplaceDistributors'
|
|
473
|
+
]
|
|
474
|
+
})
|
|
475
|
+
|
|
476
|
+
let activeVariations: MarketplaceProductVariation[] = allVariations.filter(
|
|
477
|
+
variation => variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
478
|
+
)
|
|
479
|
+
|
|
480
|
+
await Promise.all(
|
|
481
|
+
activeVariations.map(async variation => {
|
|
482
|
+
await this.calculateReserveQtyForBundle(
|
|
483
|
+
variation,
|
|
484
|
+
marketplaceOrder.domain,
|
|
485
|
+
item.qty,
|
|
486
|
+
'-'
|
|
487
|
+
)
|
|
488
|
+
|
|
489
|
+
variation.reserveQty -= item.qty
|
|
490
|
+
variation.qty += item.qty
|
|
491
|
+
|
|
492
|
+
variation = await getRepository(MarketplaceProductVariation).save(variation)
|
|
493
|
+
})
|
|
494
|
+
)
|
|
495
|
+
}
|
|
451
496
|
}
|
|
452
|
-
|
|
453
|
-
foundVariation.qty += item.qty
|
|
454
|
-
foundVariation = await getRepository(MarketplaceProductVariation).save(foundVariation)
|
|
455
497
|
})
|
|
456
498
|
)
|
|
457
499
|
|
|
458
500
|
await getRepository(MarketplaceOrderItem).delete(nonMatchedOrderItems)
|
|
459
501
|
}
|
|
460
502
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
itm
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
503
|
+
if (!cancelStatuses.includes(marketplaceOrder.status)) {
|
|
504
|
+
existingOrderItems = await Promise.all(
|
|
505
|
+
marketplaceOrderItems.map(async item => {
|
|
506
|
+
const matchedOrderItem = existingOrderItems.find(
|
|
507
|
+
itm =>
|
|
508
|
+
itm.name == item.name &&
|
|
509
|
+
itm.marketplaceProductVariation.variationId ==
|
|
510
|
+
item.marketplaceProductVariation.variationId
|
|
511
|
+
)
|
|
512
|
+
if (matchedOrderItem) {
|
|
513
|
+
for (var foundVariation of foundVariations) {
|
|
514
|
+
if (foundVariation.sku) {
|
|
515
|
+
let allVariations: MarketplaceProductVariation[] = await getRepository(
|
|
516
|
+
MarketplaceProductVariation
|
|
517
|
+
).find({
|
|
518
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
519
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
520
|
+
})
|
|
521
|
+
|
|
522
|
+
let activeVariations: MarketplaceProductVariation[] = allVariations.filter(
|
|
523
|
+
variation => variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
524
|
+
)
|
|
525
|
+
|
|
526
|
+
await Promise.all(
|
|
527
|
+
activeVariations.map(async variation => {
|
|
528
|
+
if (
|
|
529
|
+
!existingMarketplaceOrder?.releaseOrderId &&
|
|
530
|
+
matchedOrderItem.qty - item.qty != 0
|
|
531
|
+
) {
|
|
532
|
+
await this.calculateReserveQtyForBundle(
|
|
533
|
+
variation,
|
|
534
|
+
marketplaceOrder.domain,
|
|
535
|
+
matchedOrderItem.qty - item.qty
|
|
536
|
+
)
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
variation.reserveQty = existingMarketplaceOrder?.releaseOrderId
|
|
540
|
+
? variation.reserveQty
|
|
541
|
+
: variation.reserveQty - item.qty + matchedOrderItem.qty
|
|
542
|
+
|
|
543
|
+
variation.qty = existingMarketplaceOrder?.releaseOrderId
|
|
544
|
+
? variation.qty
|
|
545
|
+
: variation.qty + item.qty - matchedOrderItem.qty
|
|
546
|
+
|
|
547
|
+
variation = await getRepository(MarketplaceProductVariation).save(variation)
|
|
548
|
+
})
|
|
549
|
+
)
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
return {
|
|
553
|
+
...matchedOrderItem,
|
|
554
|
+
...item,
|
|
555
|
+
updater: user
|
|
556
|
+
}
|
|
501
557
|
}
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
|
|
558
|
+
})
|
|
559
|
+
)
|
|
560
|
+
}
|
|
505
561
|
} else {
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
itm
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
562
|
+
if (!cancelStatuses.includes(marketplaceOrder.status)) {
|
|
563
|
+
existingOrderItems = await Promise.all(
|
|
564
|
+
marketplaceOrderItems.map(async item => {
|
|
565
|
+
const matchedOrderItem = existingOrderItems.find(
|
|
566
|
+
itm =>
|
|
567
|
+
itm.name == item.name &&
|
|
568
|
+
itm.marketplaceProductVariation.variationId ==
|
|
569
|
+
item.marketplaceProductVariation.variationId
|
|
570
|
+
)
|
|
571
|
+
if (matchedOrderItem) {
|
|
572
|
+
for (var foundVariation of foundVariations) {
|
|
573
|
+
if (foundVariation.sku) {
|
|
574
|
+
let allVariations: MarketplaceProductVariation[] = await getRepository(
|
|
575
|
+
MarketplaceProductVariation
|
|
576
|
+
).find({
|
|
577
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
578
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
579
|
+
})
|
|
580
|
+
|
|
581
|
+
let activeVariations: MarketplaceProductVariation[] = allVariations.filter(
|
|
582
|
+
variation => variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
583
|
+
)
|
|
584
|
+
|
|
585
|
+
await Promise.all(
|
|
586
|
+
activeVariations.map(async variation => {
|
|
587
|
+
if (
|
|
588
|
+
!existingMarketplaceOrder?.releaseOrderId &&
|
|
589
|
+
matchedOrderItem.qty - item.qty != 0
|
|
590
|
+
) {
|
|
591
|
+
await this.calculateReserveQtyForBundle(
|
|
592
|
+
variation,
|
|
593
|
+
marketplaceOrder.domain,
|
|
594
|
+
matchedOrderItem.qty - item.qty
|
|
595
|
+
)
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
variation.reserveQty = existingMarketplaceOrder?.releaseOrderId
|
|
599
|
+
? variation.reserveQty
|
|
600
|
+
: variation.reserveQty - item.qty + matchedOrderItem.qty
|
|
601
|
+
|
|
602
|
+
variation.qty = existingMarketplaceOrder?.releaseOrderId
|
|
603
|
+
? variation.qty
|
|
604
|
+
: variation.qty + item.qty - matchedOrderItem.qty
|
|
605
|
+
|
|
606
|
+
variation = await getRepository(MarketplaceProductVariation).save(variation)
|
|
607
|
+
})
|
|
608
|
+
)
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
return {
|
|
612
|
+
...matchedOrderItem,
|
|
613
|
+
...item,
|
|
614
|
+
updater: user
|
|
615
|
+
}
|
|
616
|
+
} else {
|
|
617
|
+
for (var foundVariation of foundVariations) {
|
|
618
|
+
if (foundVariation.sku) {
|
|
619
|
+
let allVariations: MarketplaceProductVariation[] = await getRepository(
|
|
620
|
+
MarketplaceProductVariation
|
|
621
|
+
).find({
|
|
622
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
623
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
624
|
+
})
|
|
625
|
+
|
|
626
|
+
let activeVariations: MarketplaceProductVariation[] = allVariations.filter(
|
|
627
|
+
variation => variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
628
|
+
)
|
|
629
|
+
|
|
630
|
+
await Promise.all(
|
|
631
|
+
activeVariations.map(async variation => {
|
|
632
|
+
await this.calculateReserveQtyForBundle(
|
|
633
|
+
variation,
|
|
634
|
+
marketplaceOrder.domain,
|
|
635
|
+
item.qty
|
|
636
|
+
)
|
|
637
|
+
|
|
638
|
+
variation.reserveQty += item.qty
|
|
639
|
+
if (variation.qty - item.qty >= 0) {
|
|
640
|
+
variation.qty -= item.qty
|
|
641
|
+
}
|
|
642
|
+
variation = await getRepository(MarketplaceProductVariation).save(variation)
|
|
643
|
+
})
|
|
644
|
+
)
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
return {
|
|
648
|
+
...item,
|
|
649
|
+
updater: user
|
|
650
|
+
}
|
|
567
651
|
}
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
return {
|
|
573
|
-
...item,
|
|
574
|
-
updater: user
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
})
|
|
578
|
-
)
|
|
652
|
+
})
|
|
653
|
+
)
|
|
654
|
+
}
|
|
579
655
|
}
|
|
580
656
|
|
|
581
657
|
marketplaceOrderItems = existingOrderItems
|
|
@@ -588,35 +664,43 @@ export const syncAllMarketplaceOrder = {
|
|
|
588
664
|
}
|
|
589
665
|
}
|
|
590
666
|
} else {
|
|
591
|
-
if (
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
667
|
+
if (!cancelStatuses.includes(marketplaceOrder.status)) {
|
|
668
|
+
for (var foundVariation of foundVariations) {
|
|
669
|
+
if (foundVariation.sku) {
|
|
670
|
+
let allVariations: MarketplaceProductVariation[] = await getRepository(
|
|
671
|
+
MarketplaceProductVariation
|
|
672
|
+
).find({
|
|
673
|
+
where: { domain: foundVariation.domain, sku: foundVariation.sku },
|
|
674
|
+
relations: ['domain', 'marketplaceProduct', 'marketplaceProduct.marketplaceStore']
|
|
675
|
+
})
|
|
598
676
|
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
)
|
|
677
|
+
let item = order.orderItems.find(e => e.variationId == foundVariation.variationId)
|
|
678
|
+
let activeVariations: MarketplaceProductVariation[] = allVariations.filter(
|
|
679
|
+
variation => variation.marketplaceProduct.marketplaceStore.status != 'TERMINATED'
|
|
680
|
+
)
|
|
604
681
|
|
|
605
|
-
|
|
606
|
-
|
|
682
|
+
await Promise.all(
|
|
683
|
+
activeVariations.map(async variation => {
|
|
684
|
+
await this.calculateReserveQtyForBundle(variation, marketplaceOrder.domain, item.qty)
|
|
685
|
+
variation.reserveQty += item.qty
|
|
686
|
+
if (variation.qty - item.qty >= 0) {
|
|
687
|
+
variation.qty -= item.qty
|
|
688
|
+
}
|
|
607
689
|
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
690
|
+
variation = await getRepository(MarketplaceProductVariation).save(variation)
|
|
691
|
+
})
|
|
692
|
+
)
|
|
693
|
+
}
|
|
611
694
|
|
|
612
|
-
|
|
613
|
-
foundVariation = await getRepository(MarketplaceProductVariation).save(foundVariation)
|
|
695
|
+
foundVariation = await getRepository(MarketplaceProductVariation).save(foundVariation)
|
|
614
696
|
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
697
|
+
if (order?.orderShipping) {
|
|
698
|
+
savedMarketplaceOrderShipping.totalWeight = orderTotalWeight
|
|
699
|
+
savedMarketplaceOrderShipping = await getRepository(MarketplaceOrderShipping).save(
|
|
700
|
+
savedMarketplaceOrderShipping
|
|
701
|
+
)
|
|
702
|
+
}
|
|
703
|
+
}
|
|
620
704
|
}
|
|
621
705
|
}
|
|
622
706
|
|
|
@@ -634,8 +718,77 @@ export const syncAllMarketplaceOrder = {
|
|
|
634
718
|
hasMorePage = false
|
|
635
719
|
}
|
|
636
720
|
}
|
|
721
|
+
|
|
722
|
+
if (marketplaceStore.platform === 'shopee') {
|
|
723
|
+
let pageNo: number = 0
|
|
724
|
+
let hasMore = true
|
|
725
|
+
let perPage: number = 100
|
|
726
|
+
var payoutDateList = []
|
|
727
|
+
|
|
728
|
+
while (hasMore) {
|
|
729
|
+
const { result: payoutDates, more } = await StoreAPI.getStoreOrderPayoutDates(marketplaceStore, {
|
|
730
|
+
fromDate,
|
|
731
|
+
toDate,
|
|
732
|
+
pagination: { page: pageNo, limit: perPage }
|
|
733
|
+
})
|
|
734
|
+
|
|
735
|
+
payoutDateList.push(...payoutDates)
|
|
736
|
+
if (more) pageNo++
|
|
737
|
+
hasMore = more
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
await Promise.all(
|
|
741
|
+
payoutDateList.map(async item => {
|
|
742
|
+
await getRepository(MarketplaceOrder).update(
|
|
743
|
+
{
|
|
744
|
+
orderNo: item.orderNo
|
|
745
|
+
},
|
|
746
|
+
{
|
|
747
|
+
payoutDate: item.payoutDate
|
|
748
|
+
}
|
|
749
|
+
)
|
|
750
|
+
})
|
|
751
|
+
)
|
|
752
|
+
}
|
|
637
753
|
}
|
|
638
754
|
|
|
639
755
|
return true
|
|
756
|
+
},
|
|
757
|
+
async calculateReserveQtyForBundle(variation, domain, qty, operator = '+') {
|
|
758
|
+
const productBundle: ProductBundle = await getRepository(ProductBundle).findOne({
|
|
759
|
+
where: { sku: variation.sku, domain }
|
|
760
|
+
})
|
|
761
|
+
|
|
762
|
+
if (productBundle) {
|
|
763
|
+
const productBundleSettings: ProductBundleSetting[] = await getRepository(ProductBundleSetting).find({
|
|
764
|
+
where: { productBundle },
|
|
765
|
+
relations: ['productBundle', 'product']
|
|
766
|
+
})
|
|
767
|
+
|
|
768
|
+
for (let setting of productBundleSettings) {
|
|
769
|
+
const product: Product = await getRepository(Product).findOne({
|
|
770
|
+
where: { id: setting.product.id }
|
|
771
|
+
})
|
|
772
|
+
|
|
773
|
+
const mpvs: MarketplaceProductVariation[] = await getRepository(MarketplaceProductVariation).find({
|
|
774
|
+
where: { domain, sku: product.sku },
|
|
775
|
+
relations: ['domain']
|
|
776
|
+
})
|
|
777
|
+
|
|
778
|
+
for (let mpv of mpvs) {
|
|
779
|
+
if (operator === '+') {
|
|
780
|
+
mpv.reserveQty += setting.bundleQty * qty
|
|
781
|
+
if (mpv.qty - setting.bundleQty * qty >= 0) {
|
|
782
|
+
mpv.qty -= setting.bundleQty * qty
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
if (operator === '-') {
|
|
786
|
+
mpv.reserveQty -= setting.bundleQty * qty
|
|
787
|
+
mpv.qty += setting.bundleQty * qty
|
|
788
|
+
}
|
|
789
|
+
await getRepository(MarketplaceProductVariation).save(mpv)
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
}
|
|
640
793
|
}
|
|
641
794
|
}
|