ts-glitter 17.2.8 → 17.3.0
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/lowcode/Entry.js +1 -1
- package/lowcode/Entry.ts +1 -1
- package/lowcode/cms-plugin/shopping-information.js +21 -0
- package/lowcode/cms-plugin/shopping-information.ts +21 -0
- package/lowcode/glitter-base/global/currency.js +1 -1
- package/lowcode/glitter-base/global/currency.ts +1 -2
- package/lowcode/glitter-base/global/language.js +72 -69
- package/lowcode/glitter-base/global/language.ts +367 -366
- package/lowcode/public-components/product/product-list.js +28 -20
- package/lowcode/public-components/product/product-list.ts +105 -81
- package/package.json +1 -1
- package/src/api-public/controllers/shop.js +2 -0
- package/src/api-public/controllers/shop.js.map +1 -1
- package/src/api-public/controllers/shop.ts +2 -2
- package/src/api-public/services/shopping.d.ts +7 -1
- package/src/api-public/services/shopping.js +53 -25
- package/src/api-public/services/shopping.js.map +1 -1
- package/src/api-public/services/shopping.ts +68 -32
|
@@ -25,7 +25,8 @@ import app from '../../app';
|
|
|
25
25
|
import { onlinePayArray, paymentInterface } from '../models/glitter-finance.js';
|
|
26
26
|
import { App } from '../../services/app.js';
|
|
27
27
|
import { Stock } from './stock';
|
|
28
|
-
import {SeoConfig} from
|
|
28
|
+
import { SeoConfig } from '../../seo-config.js';
|
|
29
|
+
import { sendmail } from '../../services/ses.js';
|
|
29
30
|
|
|
30
31
|
type BindItem = {
|
|
31
32
|
id: string;
|
|
@@ -312,6 +313,7 @@ export class Shopping {
|
|
|
312
313
|
.join(' or ')})`
|
|
313
314
|
);
|
|
314
315
|
}
|
|
316
|
+
|
|
315
317
|
if (`${query.id || ''}`) {
|
|
316
318
|
if (`${query.id}`.includes(',')) {
|
|
317
319
|
querySql.push(`id in (${query.id})`);
|
|
@@ -450,8 +452,6 @@ export class Shopping {
|
|
|
450
452
|
|
|
451
453
|
// 組合 SQL 條件
|
|
452
454
|
querySql.push(`(${statusCondition} ${scheduleConditions})`);
|
|
453
|
-
//
|
|
454
|
-
console.log(`(${statusCondition} ${scheduleConditions})`)
|
|
455
455
|
}
|
|
456
456
|
if (query.channel) {
|
|
457
457
|
const channelSplit = query.channel.split(',').map((channel) => channel.trim());
|
|
@@ -464,6 +464,7 @@ export class Shopping {
|
|
|
464
464
|
query.id_list && querySql.push(`(id in (${query.id_list}))`);
|
|
465
465
|
query.min_price && querySql.push(`(id in (select product_id from \`${this.app}\`.t_variants where content->>'$.sale_price'>=${query.min_price})) `);
|
|
466
466
|
query.max_price && querySql.push(`(id in (select product_id from \`${this.app}\`.t_variants where content->>'$.sale_price'<=${query.max_price})) `);
|
|
467
|
+
|
|
467
468
|
const products = await this.querySql(querySql, query);
|
|
468
469
|
|
|
469
470
|
// 產品清單
|
|
@@ -555,20 +556,18 @@ export class Shopping {
|
|
|
555
556
|
}
|
|
556
557
|
|
|
557
558
|
if (query.domain && products.data[0]) {
|
|
558
|
-
products.data =
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
)
|
|
567
|
-
}) || products.data[0];
|
|
568
|
-
|
|
559
|
+
products.data =
|
|
560
|
+
products.data.find((dd: any) => {
|
|
561
|
+
return (
|
|
562
|
+
(dd.content.language_data &&
|
|
563
|
+
dd.content.language_data[`${query.language}`].seo &&
|
|
564
|
+
dd.content.language_data[`${query.language}`].seo.domain === decodeURIComponent(query.domain!!)) ||
|
|
565
|
+
(dd.content.seo && dd.content.seo.domain === decodeURIComponent(query.domain!!))
|
|
566
|
+
);
|
|
567
|
+
}) || products.data[0];
|
|
569
568
|
}
|
|
570
|
-
if (
|
|
571
|
-
products.data.json_ld = await SeoConfig.getProductJsonLd(this.app,products.data.content);
|
|
569
|
+
if (query.domain || query.id) {
|
|
570
|
+
products.data.json_ld = await SeoConfig.getProductJsonLd(this.app, products.data.content);
|
|
572
571
|
}
|
|
573
572
|
return products;
|
|
574
573
|
} catch (e) {
|
|
@@ -2193,7 +2192,6 @@ export class Shopping {
|
|
|
2193
2192
|
}
|
|
2194
2193
|
|
|
2195
2194
|
// 確認用戶資訊
|
|
2196
|
-
console.log(`cart.email==>`, cart.email);
|
|
2197
2195
|
const userData = (await userClass.getUserData(cart.email, 'email_or_phone')) ?? { userID: -1 };
|
|
2198
2196
|
// 所有優惠券
|
|
2199
2197
|
const allVoucher: VoucherData[] = (
|
|
@@ -2519,7 +2517,6 @@ export class Shopping {
|
|
|
2519
2517
|
}
|
|
2520
2518
|
}
|
|
2521
2519
|
|
|
2522
|
-
console.log(`update.orderData=>`, update.orderData);
|
|
2523
2520
|
migrateOrder(data.orderData.lineItems);
|
|
2524
2521
|
migrateOrder(origin[0].orderData.lineItems);
|
|
2525
2522
|
|
|
@@ -2940,10 +2937,7 @@ OR JSON_UNQUOTE(JSON_EXTRACT(orderData, '$.orderStatus')) NOT IN (-99)) `);
|
|
|
2940
2937
|
if (original_status === 1) {
|
|
2941
2938
|
return;
|
|
2942
2939
|
}
|
|
2943
|
-
|
|
2944
|
-
for (const b of order_data['orderData'].lineItems) {
|
|
2945
|
-
await this.calcSoldOutStock(b.count, b.id, b.spec);
|
|
2946
|
-
}
|
|
2940
|
+
|
|
2947
2941
|
await db.execute(
|
|
2948
2942
|
`UPDATE \`${this.app}\`.t_checkout
|
|
2949
2943
|
SET status = ?
|
|
@@ -2959,6 +2953,20 @@ OR JSON_UNQUOTE(JSON_EXTRACT(orderData, '$.orderStatus')) NOT IN (-99)) `);
|
|
|
2959
2953
|
)
|
|
2960
2954
|
)[0];
|
|
2961
2955
|
|
|
2956
|
+
const brandAndMemberType = await App.checkBrandAndMemberType(this.app);
|
|
2957
|
+
const store_info = await new User(this.app).getConfigV2({ key: 'store-information', user_id: 'manager' });
|
|
2958
|
+
for (const b of order_data['orderData'].lineItems) {
|
|
2959
|
+
// 更改為已付款
|
|
2960
|
+
this.calcSoldOutStock(b.count, b.id, b.spec);
|
|
2961
|
+
// 確認是否有商品信件通知
|
|
2962
|
+
this.soldMailNotice({
|
|
2963
|
+
brand_domain: brandAndMemberType.domain,
|
|
2964
|
+
shop_name: store_info.shop_name,
|
|
2965
|
+
product_id: b.id,
|
|
2966
|
+
order_data: cartData.orderData,
|
|
2967
|
+
});
|
|
2968
|
+
}
|
|
2969
|
+
|
|
2962
2970
|
// 訂單已付款信件通知(管理員, 消費者)
|
|
2963
2971
|
new ManagerNotify(this.app).checkout({
|
|
2964
2972
|
orderData: cartData.orderData,
|
|
@@ -3140,8 +3148,10 @@ OR JSON_UNQUOTE(JSON_EXTRACT(orderData, '$.orderStatus')) NOT IN (-99)) `);
|
|
|
3140
3148
|
);
|
|
3141
3149
|
}
|
|
3142
3150
|
const store_config = await new User(this.app).getConfigV2({ key: 'store_manager', user_id: 'manager' });
|
|
3151
|
+
content.total_sales = 0;
|
|
3143
3152
|
await Promise.all(
|
|
3144
3153
|
content.variants.map((a: any) => {
|
|
3154
|
+
content.total_sales += a.sold_out ?? 0;
|
|
3145
3155
|
content.min_price = content.min_price ?? a.sale_price;
|
|
3146
3156
|
content.max_price = content.max_price ?? a.sale_price;
|
|
3147
3157
|
if (a.sale_price < content.min_price) {
|
|
@@ -3278,6 +3288,37 @@ OR JSON_UNQUOTE(JSON_EXTRACT(orderData, '$.orderStatus')) NOT IN (-99)) `);
|
|
|
3278
3288
|
}
|
|
3279
3289
|
}
|
|
3280
3290
|
|
|
3291
|
+
//商品完成購買寄送信件
|
|
3292
|
+
public async soldMailNotice(json: { brand_domain: string; shop_name: string; product_id: string; order_data: any }) {
|
|
3293
|
+
try {
|
|
3294
|
+
const order_data = json.order_data;
|
|
3295
|
+
const order_id = order_data.orderID;
|
|
3296
|
+
const pd_data = (
|
|
3297
|
+
await db.query(
|
|
3298
|
+
`select *
|
|
3299
|
+
from \`${this.app}\`.t_manager_post
|
|
3300
|
+
where id = ?`,
|
|
3301
|
+
[json.product_id]
|
|
3302
|
+
)
|
|
3303
|
+
)[0]['content'];
|
|
3304
|
+
if (pd_data.email_notice && pd_data.email_notice.length > 0 && order_data.user_info.email) {
|
|
3305
|
+
const notice = pd_data.email_notice
|
|
3306
|
+
.replace(/@\{\{訂單號碼\}\}/g, `<a href="https://${json.brand_domain}/order_detail?cart_token=${order_id}">${order_id}</a>`)
|
|
3307
|
+
.replace(/@\{\{訂單金額\}\}/g, order_data.total)
|
|
3308
|
+
.replace(/@\{\{app_name\}\}/g, json.shop_name)
|
|
3309
|
+
.replace(/@\{\{user_name\}\}/g, order_data.user_info.name ?? '')
|
|
3310
|
+
.replace(/@\{\{姓名\}\}/g, order_data.customer_info.name ?? '')
|
|
3311
|
+
.replace(/@\{\{電話\}\}/g, order_data.user_info.phone ?? '')
|
|
3312
|
+
.replace(/@\{\{地址\}\}/g, order_data.user_info.address ?? '')
|
|
3313
|
+
.replace(/@\{\{信箱\}\}/g, order_data.user_info.email ?? '');
|
|
3314
|
+
|
|
3315
|
+
sendmail(`${json.shop_name} <${process.env.smtp}>`, order_data.user_info.email, `${pd_data.title} 購買通知信`, notice, () => {});
|
|
3316
|
+
}
|
|
3317
|
+
} catch (e) {
|
|
3318
|
+
console.error('soldMailNotice error', e);
|
|
3319
|
+
}
|
|
3320
|
+
}
|
|
3321
|
+
|
|
3281
3322
|
async getDataAnalyze(tags: string[], query?: any) {
|
|
3282
3323
|
try {
|
|
3283
3324
|
console.log('AnalyzeTimer Start');
|
|
@@ -3402,13 +3443,6 @@ OR JSON_UNQUOTE(JSON_EXTRACT(orderData, '$.orderStatus')) NOT IN (-99)) `);
|
|
|
3402
3443
|
}
|
|
3403
3444
|
});
|
|
3404
3445
|
|
|
3405
|
-
function wasteTimeRank(obj: Record<string, number>, n: number): { key: string; value: number }[] {
|
|
3406
|
-
const sortedEntries = Object.entries(obj)
|
|
3407
|
-
.map(([key, value]) => ({ key, value }))
|
|
3408
|
-
.sort((a, b) => b.value - a.value);
|
|
3409
|
-
return sortedEntries.slice(0, n);
|
|
3410
|
-
}
|
|
3411
|
-
|
|
3412
3446
|
console.log('AnalyzeTimer ==>', timer);
|
|
3413
3447
|
|
|
3414
3448
|
return result;
|
|
@@ -5565,7 +5599,7 @@ OR JSON_UNQUOTE(JSON_EXTRACT(orderData, '$.orderStatus')) NOT IN (-99)) `);
|
|
|
5565
5599
|
});
|
|
5566
5600
|
})
|
|
5567
5601
|
);
|
|
5568
|
-
|
|
5602
|
+
|
|
5569
5603
|
let max_id =
|
|
5570
5604
|
(
|
|
5571
5605
|
await db.query(
|
|
@@ -5574,14 +5608,16 @@ OR JSON_UNQUOTE(JSON_EXTRACT(orderData, '$.orderStatus')) NOT IN (-99)) `);
|
|
|
5574
5608
|
[]
|
|
5575
5609
|
)
|
|
5576
5610
|
)[0]['max(id)'] || 0;
|
|
5577
|
-
|
|
5611
|
+
|
|
5612
|
+
productArray.map((product: any) => {
|
|
5578
5613
|
if (!product.id) {
|
|
5579
5614
|
product.id = max_id++;
|
|
5580
5615
|
}
|
|
5581
5616
|
product.type = 'product';
|
|
5582
5617
|
this.checkVariantDataType(product.variants);
|
|
5583
5618
|
return [product.id || null, this.token?.userID, JSON.stringify(product)];
|
|
5584
|
-
})
|
|
5619
|
+
});
|
|
5620
|
+
|
|
5585
5621
|
const data = await db.query(
|
|
5586
5622
|
`replace
|
|
5587
5623
|
INTO \`${this.app}\`.\`t_manager_post\` (id,userID,content) values ?`,
|