ts-glitter 20.7.4 → 20.7.6
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/jr9x7k3aau.json +1 -0
- package/lowcode/Entry.js +1 -1
- package/lowcode/Entry.ts +1 -1
- package/lowcode/backend-manager/bg-notify.js +2 -0
- package/lowcode/backend-manager/bg-notify.ts +2 -0
- package/lowcode/backend-manager/bg-widget.js +280 -155
- package/lowcode/backend-manager/bg-widget.ts +387 -244
- package/lowcode/backend-manager/splitPage.js +27 -52
- package/lowcode/backend-manager/splitPage.ts +29 -47
- package/lowcode/cms-plugin/app-release.js +63 -13
- package/lowcode/cms-plugin/app-release.ts +73 -13
- package/lowcode/cms-plugin/auto-fcm-advertise.js +23 -24
- package/lowcode/cms-plugin/auto-fcm-advertise.ts +286 -285
- package/lowcode/cms-plugin/auto-reply.js +285 -273
- package/lowcode/cms-plugin/auto-reply.ts +673 -660
- package/lowcode/cms-plugin/module/data.ts +1 -0
- package/lowcode/cms-plugin/module/order-setting.js +134 -117
- package/lowcode/cms-plugin/module/order-setting.ts +152 -138
- package/lowcode/cms-plugin/pos-pages/products-page.js +8 -16
- package/lowcode/cms-plugin/pos-pages/products-page.ts +10 -12
- package/lowcode/cms-plugin/shopping-order-manager.js +244 -289
- package/lowcode/cms-plugin/shopping-order-manager.ts +128 -156
- package/lowcode/cms-plugin/shopping-order-return.js +1 -1
- package/lowcode/cms-plugin/shopping-order-return.ts +1 -1
- package/lowcode/cms-plugin/shopping-product-setting.js +3 -3
- package/lowcode/cms-plugin/shopping-product-setting.ts +3 -3
- package/lowcode/cms-plugin/shopping-setting-advance.js +3 -28
- package/lowcode/cms-plugin/shopping-setting-advance.ts +3 -28
- package/lowcode/cms-plugin/stock-history.js +31 -15
- package/lowcode/cms-plugin/stock-history.ts +43 -25
- package/lowcode/cms-plugin/third-party-google.js +2 -2
- package/lowcode/cms-plugin/third-party-google.ts +2 -2
- package/lowcode/cms-plugin/user-list.js +166 -113
- package/lowcode/cms-plugin/user-list.ts +136 -78
- package/lowcode/form-view/e-commerce/path-select.js +100 -87
- package/lowcode/form-view/e-commerce/path-select.ts +372 -343
- package/lowcode/glitter-base/route/stock.ts +153 -141
- package/lowcode/glitterBundle/plugins/editor-elem.js +139 -149
- package/lowcode/glitterBundle/plugins/editor-elem.ts +207 -222
- package/lowcode/public-components/blogs/list.js +8 -16
- package/lowcode/public-components/blogs/list.ts +10 -12
- package/lowcode/public-components/product/product-list.js +8 -16
- package/lowcode/public-components/product/product-list.ts +10 -12
- package/lowcode/public-components/user-manager/um-login.js +268 -265
- package/lowcode/public-components/user-manager/um-login.ts +987 -983
- package/lowcode/public-models/order-info.js +12 -20
- package/lowcode/public-models/order-info.ts +13 -12
- package/package.json +1 -1
- package/src/Language.js.map +1 -1
- package/src/api-public/controllers/ai-chat.js.map +1 -1
- package/src/api-public/controllers/ai-points.js.map +1 -1
- package/src/api-public/controllers/app-release.js.map +1 -1
- package/src/api-public/controllers/article.js.map +1 -1
- package/src/api-public/controllers/chat.js.map +1 -1
- package/src/api-public/controllers/customer-sessions.js.map +1 -1
- package/src/api-public/controllers/delivery.js.map +1 -1
- package/src/api-public/controllers/fb-message.js.map +1 -1
- package/src/api-public/controllers/fb-service.js.map +1 -1
- package/src/api-public/controllers/fcm.js.map +1 -1
- package/src/api-public/controllers/graph-api.js.map +1 -1
- package/src/api-public/controllers/index.js.map +1 -1
- package/src/api-public/controllers/invoice.js.map +1 -1
- package/src/api-public/controllers/lambda.js.map +1 -1
- package/src/api-public/controllers/line-message.js.map +1 -1
- package/src/api-public/controllers/manager.js.map +1 -1
- package/src/api-public/controllers/oauth.js.map +1 -1
- package/src/api-public/controllers/post.js.map +1 -1
- package/src/api-public/controllers/progress.js.map +1 -1
- package/src/api-public/controllers/rebate.js.map +1 -1
- package/src/api-public/controllers/recommend.js.map +1 -1
- package/src/api-public/controllers/reconciliation.js.map +1 -1
- package/src/api-public/controllers/shop.js.map +1 -1
- package/src/api-public/controllers/shopee.js.map +1 -1
- package/src/api-public/controllers/sms-points.js.map +1 -1
- package/src/api-public/controllers/sms.js.map +1 -1
- package/src/api-public/controllers/smtp.js.map +1 -1
- package/src/api-public/controllers/sql_api.js.map +1 -1
- package/src/api-public/controllers/stock.js.map +1 -1
- package/src/api-public/controllers/track.js.map +1 -1
- package/src/api-public/controllers/user.js +1 -1
- package/src/api-public/controllers/user.js.map +1 -1
- package/src/api-public/controllers/user.ts +1 -1
- package/src/api-public/controllers/voucher.js.map +1 -1
- package/src/api-public/controllers/wallet.js.map +1 -1
- package/src/api-public/models/glitter-finance.js +2 -1
- package/src/api-public/models/glitter-finance.js.map +1 -1
- package/src/api-public/services/EcInvoice.js.map +1 -1
- package/src/api-public/services/ai-pointes.js.map +1 -1
- package/src/api-public/services/ai-robot.d.ts +1 -0
- package/src/api-public/services/ai-robot.js.map +1 -1
- package/src/api-public/services/article.js.map +1 -1
- package/src/api-public/services/auto-send-email.js.map +1 -1
- package/src/api-public/services/chat.js.map +1 -1
- package/src/api-public/services/checkout-event.d.ts +3 -1
- package/src/api-public/services/checkout-event.js +7 -4
- package/src/api-public/services/checkout-event.js.map +1 -1
- package/src/api-public/services/checkout-event.ts +26 -17
- package/src/api-public/services/checkout.js.map +1 -1
- package/src/api-public/services/custom-code.js.map +1 -1
- package/src/api-public/services/customer-sessions.js.map +1 -1
- package/src/api-public/services/data-analyze.js +3 -3
- package/src/api-public/services/data-analyze.js.map +1 -1
- package/src/api-public/services/data-analyze.ts +3 -3
- package/src/api-public/services/delivery.js.map +1 -1
- package/src/api-public/services/ezpay/tool.d.ts +1 -0
- package/src/api-public/services/ezpay/tool.js.map +1 -1
- package/src/api-public/services/fake-data-model/fake-order.js.map +1 -1
- package/src/api-public/services/fake-data-model/fake-product.js.map +1 -1
- package/src/api-public/services/fake-data-model/fake-user.js.map +1 -1
- package/src/api-public/services/fb-api.d.ts +1 -0
- package/src/api-public/services/fb-api.js.map +1 -1
- package/src/api-public/services/fb-message.d.ts +1 -0
- package/src/api-public/services/fb-message.js.map +1 -1
- package/src/api-public/services/fb-service.js +4 -4
- package/src/api-public/services/fb-service.js.map +1 -1
- package/src/api-public/services/filter-protect-data.js.map +1 -1
- package/src/api-public/services/financial-service.d.ts +1 -0
- package/src/api-public/services/financial-service.js.map +1 -1
- package/src/api-public/services/form-check.js.map +1 -1
- package/src/api-public/services/graph-api.js.map +1 -1
- package/src/api-public/services/initial-fake-data.js.map +1 -1
- package/src/api-public/services/invoice.js.map +1 -1
- package/src/api-public/services/language-setting.js.map +1 -1
- package/src/api-public/services/line-message.d.ts +1 -0
- package/src/api-public/services/line-message.js.map +1 -1
- package/src/api-public/services/mail.js.map +1 -1
- package/src/api-public/services/manager.js.map +1 -1
- package/src/api-public/services/model/handlePaymentTransaction.js.map +1 -1
- package/src/api-public/services/model/shopnex-line-message.js.map +1 -1
- package/src/api-public/services/monitor.d.ts +1 -0
- package/src/api-public/services/monitor.js.map +1 -1
- package/src/api-public/services/notify.js.map +1 -1
- package/src/api-public/services/order-event.js.map +1 -1
- package/src/api-public/services/paynow-logistics.js.map +1 -1
- package/src/api-public/services/phone-verify.js.map +1 -1
- package/src/api-public/services/pos.js.map +1 -1
- package/src/api-public/services/post.js.map +1 -1
- package/src/api-public/services/product-initial.js.map +1 -1
- package/src/api-public/services/public-table-check.js.map +1 -1
- package/src/api-public/services/rebate.js.map +1 -1
- package/src/api-public/services/recommend.js.map +1 -1
- package/src/api-public/services/reconciliation.js.map +1 -1
- package/src/api-public/services/schedule.js.map +1 -1
- package/src/api-public/services/share-permission.d.ts +1 -1
- package/src/api-public/services/share-permission.js.map +1 -1
- package/src/api-public/services/shopee.d.ts +1 -0
- package/src/api-public/services/shopee.js.map +1 -1
- package/src/api-public/services/shopping.js +5 -9
- package/src/api-public/services/shopping.js.map +1 -1
- package/src/api-public/services/shopping.ts +4 -10
- package/src/api-public/services/sms-pointes.js.map +1 -1
- package/src/api-public/services/sms.js.map +1 -1
- package/src/api-public/services/stock.js.map +1 -1
- package/src/api-public/services/terms-check.js.map +1 -1
- package/src/api-public/services/updated-table-checked.js.map +1 -1
- package/src/api-public/services/user-update.js.map +1 -1
- package/src/api-public/services/user.d.ts +6 -1
- package/src/api-public/services/user.js +23 -16
- package/src/api-public/services/user.js.map +1 -1
- package/src/api-public/services/user.ts +100 -90
- package/src/api-public/services/voucher.js.map +1 -1
- package/src/api-public/services/wallet.js.map +1 -1
- package/src/api-public/services/workers.js.map +1 -1
- package/src/api-public/utils/ut-database.js.map +1 -1
- package/src/api-public/utils/ut-permission.d.ts +1 -0
- package/src/api-public/utils/ut-permission.js.map +1 -1
- package/src/app-project/serverless/src/controllers/index.js.map +1 -1
- package/src/app-project/serverless/src/controllers/sample.js.map +1 -1
- package/src/app-project/serverless/src/modules/database.d.ts +2 -1
- package/src/app-project/serverless/src/modules/database.js.map +1 -1
- package/src/app-project/serverless/src/modules/exception.js.map +1 -1
- package/src/app-project/serverless/src/modules/hooks.js.map +1 -1
- package/src/app-project/serverless/src/modules/logger.js.map +1 -1
- package/src/app-project/serverless/src/modules/redis.d.ts +1 -1
- package/src/app-project/serverless/src/modules/redis.js.map +1 -1
- package/src/app-project/serverless/src/modules/response.js.map +1 -1
- package/src/app-project/serverless/src/modules/ssh.js.map +1 -1
- package/src/config.d.ts +1 -1
- package/src/config.js.map +1 -1
- package/src/controllers/ai.js.map +1 -1
- package/src/controllers/app.js.map +1 -1
- package/src/controllers/backend-server.js.map +1 -1
- package/src/controllers/filemanager.js.map +1 -1
- package/src/controllers/global-event.js.map +1 -1
- package/src/controllers/index.js.map +1 -1
- package/src/controllers/page.js.map +1 -1
- package/src/controllers/private_config.js.map +1 -1
- package/src/controllers/template.js.map +1 -1
- package/src/controllers/user.js.map +1 -1
- package/src/domain-check.js.map +1 -1
- package/src/export/export-test.js.map +1 -1
- package/src/firebase/message.js +2 -1
- package/src/firebase/message.js.map +1 -1
- package/src/helper/app_creater.js +2 -1
- package/src/helper/app_creater.js.map +1 -1
- package/src/helper/glitter-util.d.ts +1 -0
- package/src/helper/glitter-util.js.map +1 -1
- package/src/index.js +3 -3
- package/src/index.js.map +1 -1
- package/src/lambda/interface.d.ts +1 -1
- package/src/lambda/interface.js +2 -2
- package/src/lambda/interface.js.map +1 -1
- package/src/modules/AWSLib.js +3 -2
- package/src/modules/AWSLib.js.map +1 -1
- package/src/modules/caught-error.js +1 -3
- package/src/modules/caught-error.js.map +1 -1
- package/src/modules/caught-error.ts +1 -3
- package/src/modules/database.d.ts +2 -1
- package/src/modules/database.js.map +1 -1
- package/src/modules/exception.js.map +1 -1
- package/src/modules/firebase.js.map +1 -1
- package/src/modules/hooks.js.map +1 -1
- package/src/modules/logger.js.map +1 -1
- package/src/modules/redis.d.ts +1 -1
- package/src/modules/redis.js.map +1 -1
- package/src/modules/response.js.map +1 -1
- package/src/modules/ssh.js.map +1 -1
- package/src/modules/tool.d.ts +4 -4
- package/src/modules/tool.js +2 -1
- package/src/modules/tool.js.map +1 -1
- package/src/public-config-initial/auto-fcm.js.map +1 -1
- package/src/run.js +2 -1
- package/src/run.js.map +1 -1
- package/src/seo-config.d.ts +1 -0
- package/src/seo-config.js +3 -3
- package/src/seo-config.js.map +1 -1
- package/src/services/ai.js.map +1 -1
- package/src/services/app.js.map +1 -1
- package/src/services/backend-service.js.map +1 -1
- package/src/services/create-instance.js +4 -3
- package/src/services/create-instance.js.map +1 -1
- package/src/services/global-event.js.map +1 -1
- package/src/services/ios-release.js.map +1 -1
- package/src/services/page.js.map +1 -1
- package/src/services/private_config.js.map +1 -1
- package/src/services/release.js.map +1 -1
- package/src/services/saas-table-check.js +2 -2
- package/src/services/saas-table-check.js.map +1 -1
- package/src/services/seo.js.map +1 -1
- package/src/services/ses.js +2 -1
- package/src/services/ses.js.map +1 -1
- package/src/services/system-schedule.js.map +1 -1
- package/src/services/template.js.map +1 -1
- package/src/services/tool.js +3 -2
- package/src/services/tool.js.map +1 -1
- package/src/services/user.js.map +1 -1
- package/src/services/web-socket.js.map +1 -1
- package/src/update-progress-track.js.map +1 -1
- package/src/update-script.js.map +1 -1
- package/src/api-public/services/checkout-service.js +0 -1074
|
@@ -1,1074 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.CheckoutService = void 0;
|
|
30
|
-
const ut_timer_js_1 = require("../utils/ut-timer.js");
|
|
31
|
-
const user_js_1 = require("./user.js");
|
|
32
|
-
const rebate_js_1 = require("./rebate.js");
|
|
33
|
-
const database_js_1 = __importDefault(require("../../modules/database.js"));
|
|
34
|
-
const exception_js_1 = __importDefault(require("../../modules/exception.js"));
|
|
35
|
-
const private_config_js_1 = require("../../services/private_config.js");
|
|
36
|
-
const shipment_config_js_1 = require("../config/shipment-config.js");
|
|
37
|
-
const stock_js_1 = require("./stock.js");
|
|
38
|
-
const shopee_js_1 = require("./shopee.js");
|
|
39
|
-
const recommend_js_1 = require("./recommend.js");
|
|
40
|
-
const glitter_finance_js_1 = require("../models/glitter-finance.js");
|
|
41
|
-
const tool_js_1 = __importDefault(require("../../modules/tool.js"));
|
|
42
|
-
const order_event_js_1 = require("./order-event.js");
|
|
43
|
-
const notify_js_1 = require("./notify.js");
|
|
44
|
-
const auto_fcm_js_1 = require("../../public-config-initial/auto-fcm.js");
|
|
45
|
-
const auto_send_email_js_1 = require("./auto-send-email.js");
|
|
46
|
-
const invoice_js_1 = require("./invoice.js");
|
|
47
|
-
const redis_js_1 = __importDefault(require("../../modules/redis.js"));
|
|
48
|
-
const financial_service_js_1 = __importStar(require("./financial-service.js"));
|
|
49
|
-
const sms_js_1 = require("./sms.js");
|
|
50
|
-
const line_message_js_1 = require("./line-message.js");
|
|
51
|
-
const shopping_js_1 = require("./shopping.js");
|
|
52
|
-
class CheckoutService extends shopping_js_1.Shopping {
|
|
53
|
-
async getPaymentSetting() {
|
|
54
|
-
return glitter_finance_js_1.onlinePayArray;
|
|
55
|
-
}
|
|
56
|
-
async toCheckout(data, type = 'add', replace_order_id) {
|
|
57
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11;
|
|
58
|
-
try {
|
|
59
|
-
const utTimer = new ut_timer_js_1.UtTimer('TO-CHECKOUT');
|
|
60
|
-
const checkPoint = utTimer.checkPoint;
|
|
61
|
-
const userClass = new user_js_1.User(this.app);
|
|
62
|
-
const rebateClass = new rebate_js_1.Rebate(this.app);
|
|
63
|
-
let checkoutPayment = (_a = data.user_info) === null || _a === void 0 ? void 0 : _a.payment;
|
|
64
|
-
let scheduledData;
|
|
65
|
-
data.line_items = (_b = (data.line_items || data.lineItems)) !== null && _b !== void 0 ? _b : [];
|
|
66
|
-
data.isExhibition = data.checkOutType === 'POS' && ((_d = (_c = data.pos_store) === null || _c === void 0 ? void 0 : _c.includes('exhibition_')) !== null && _d !== void 0 ? _d : false);
|
|
67
|
-
if (replace_order_id) {
|
|
68
|
-
const orderData = (await database_js_1.default.query(`SELECT *
|
|
69
|
-
FROM \`${this.app}\`.t_checkout
|
|
70
|
-
WHERE cart_token = ?
|
|
71
|
-
AND status = 0;
|
|
72
|
-
`, [replace_order_id]))[0];
|
|
73
|
-
if (!orderData) {
|
|
74
|
-
throw exception_js_1.default.BadRequestError('BAD_REQUEST', 'ToCheckout Error: Cannot find this orderID', null);
|
|
75
|
-
}
|
|
76
|
-
await database_js_1.default.query(`DELETE
|
|
77
|
-
FROM \`${this.app}\`.t_checkout
|
|
78
|
-
WHERE cart_token = ?
|
|
79
|
-
AND status = 0;
|
|
80
|
-
`, [replace_order_id]);
|
|
81
|
-
const { lineItems, user_info, code, customer_info, use_rebate } = orderData.orderData;
|
|
82
|
-
data.line_items = lineItems;
|
|
83
|
-
data.email = orderData.email;
|
|
84
|
-
data.user_info = user_info;
|
|
85
|
-
data.code = code;
|
|
86
|
-
data.customer_info = customer_info;
|
|
87
|
-
data.use_rebate = use_rebate;
|
|
88
|
-
}
|
|
89
|
-
if (data.order_id && type === 'POS') {
|
|
90
|
-
const order = (await database_js_1.default.query(`SELECT *
|
|
91
|
-
FROM \`${this.app}\`.t_checkout
|
|
92
|
-
WHERE cart_token = ?
|
|
93
|
-
`, [data.order_id]))[0];
|
|
94
|
-
if (order) {
|
|
95
|
-
for (const b of order.orderData.lineItems) {
|
|
96
|
-
const pdDqlData = (await this.getProduct({
|
|
97
|
-
page: 0,
|
|
98
|
-
limit: 50,
|
|
99
|
-
id: b.id,
|
|
100
|
-
status: 'inRange',
|
|
101
|
-
channel: data.checkOutType === 'POS' ? (data.isExhibition ? 'exhibition' : 'pos') : undefined,
|
|
102
|
-
whereStore: data.checkOutType === 'POS' ? data.pos_store : undefined,
|
|
103
|
-
})).data;
|
|
104
|
-
const pd = pdDqlData.content;
|
|
105
|
-
const variant = pd.variants.find((dd) => dd.spec.join('-') === b.spec.join('-'));
|
|
106
|
-
await updateStock(variant, b.deduction_log);
|
|
107
|
-
await this.updateVariantsWithSpec(variant, b.id, b.spec);
|
|
108
|
-
await database_js_1.default.query(`UPDATE \`${this.app}\`.t_manager_post
|
|
109
|
-
SET content = ?
|
|
110
|
-
WHERE id = ?
|
|
111
|
-
`, [JSON.stringify(pd), pdDqlData.id]);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
async function updateStock(variant, deductionLog) {
|
|
116
|
-
Object.keys(deductionLog).forEach(key => {
|
|
117
|
-
try {
|
|
118
|
-
variant.stockList[key].count += deductionLog[key];
|
|
119
|
-
}
|
|
120
|
-
catch (e) {
|
|
121
|
-
console.error(`Error updating stock for variant ${variant.id}:`, e);
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
if (data.checkOutType === 'POS') {
|
|
126
|
-
this.token = undefined;
|
|
127
|
-
}
|
|
128
|
-
const hasAuthentication = (data) => {
|
|
129
|
-
return ((this.token && this.token.userID) ||
|
|
130
|
-
data.email ||
|
|
131
|
-
(data.user_info && data.user_info.email) ||
|
|
132
|
-
(data.user_info && data.user_info.phone));
|
|
133
|
-
};
|
|
134
|
-
if (type !== 'preview' && !hasAuthentication(data)) {
|
|
135
|
-
throw exception_js_1.default.BadRequestError('BAD_REQUEST', 'ToCheckout Error: No email and phone', null);
|
|
136
|
-
}
|
|
137
|
-
const checkOutType = (_e = data.checkOutType) !== null && _e !== void 0 ? _e : 'manual';
|
|
138
|
-
const getUserDataAsync = async (type, token, data) => {
|
|
139
|
-
if (type === 'preview' &&
|
|
140
|
-
!((token === null || token === void 0 ? void 0 : token.userID) || (data.user_info && data.user_info.email) || (data.user_info && data.user_info.phone))) {
|
|
141
|
-
return {};
|
|
142
|
-
}
|
|
143
|
-
if ((token === null || token === void 0 ? void 0 : token.userID) && type !== 'POS' && checkOutType !== 'POS') {
|
|
144
|
-
return await userClass.getUserData(`${token.userID}`, 'userID');
|
|
145
|
-
}
|
|
146
|
-
return ((data.user_info.email && (await userClass.getUserData(data.user_info.email, 'email_or_phone'))) ||
|
|
147
|
-
(data.user_info.phone && (await userClass.getUserData(data.user_info.phone, 'email_or_phone'))) ||
|
|
148
|
-
{});
|
|
149
|
-
};
|
|
150
|
-
checkPoint('check user auth');
|
|
151
|
-
const userData = await getUserDataAsync(type, this.token, data);
|
|
152
|
-
data.email = ((_f = userData === null || userData === void 0 ? void 0 : userData.userData) === null || _f === void 0 ? void 0 : _f.email) || ((_g = userData === null || userData === void 0 ? void 0 : userData.userData) === null || _g === void 0 ? void 0 : _g.phone) || '';
|
|
153
|
-
if (!data.email || data.email === 'no-email') {
|
|
154
|
-
data.email =
|
|
155
|
-
((_h = data.user_info) === null || _h === void 0 ? void 0 : _h.email) && data.user_info.email !== 'no-email'
|
|
156
|
-
? data.user_info.email
|
|
157
|
-
: ((_j = data.user_info) === null || _j === void 0 ? void 0 : _j.phone) || '';
|
|
158
|
-
}
|
|
159
|
-
if (!data.email && type !== 'preview') {
|
|
160
|
-
data.email = 'no-email';
|
|
161
|
-
}
|
|
162
|
-
const appStatus = await rebateClass.mainStatus();
|
|
163
|
-
if (appStatus && userData && data.use_rebate && data.use_rebate > 0) {
|
|
164
|
-
const userRebate = await rebateClass.getOneRebate({ user_id: userData.userID });
|
|
165
|
-
const sum = userRebate ? userRebate.point : 0;
|
|
166
|
-
if (sum < data.use_rebate) {
|
|
167
|
-
data.use_rebate = 0;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
else {
|
|
171
|
-
data.use_rebate = 0;
|
|
172
|
-
}
|
|
173
|
-
checkPoint('check rebate');
|
|
174
|
-
const shipment = await this.getShipmentRefer(data.user_info);
|
|
175
|
-
const shipment_setting = await (async () => {
|
|
176
|
-
try {
|
|
177
|
-
const config = await private_config_js_1.Private_config.getConfig({
|
|
178
|
-
appName: this.app,
|
|
179
|
-
key: 'logistics_setting',
|
|
180
|
-
});
|
|
181
|
-
if (!config) {
|
|
182
|
-
return {
|
|
183
|
-
support: [],
|
|
184
|
-
shipmentSupport: [],
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
return config[0].value;
|
|
188
|
-
}
|
|
189
|
-
catch (e) {
|
|
190
|
-
return [];
|
|
191
|
-
}
|
|
192
|
-
})();
|
|
193
|
-
checkPoint('set shipment');
|
|
194
|
-
shipment_setting.custom_delivery = shipment_setting.custom_delivery
|
|
195
|
-
? await Promise.all(shipment_setting.custom_delivery.map(async (form) => {
|
|
196
|
-
const config = await new user_js_1.User(this.app).getConfigV2({
|
|
197
|
-
user_id: 'manager',
|
|
198
|
-
key: `form_delivery_${form.id}`,
|
|
199
|
-
});
|
|
200
|
-
form.form = config.list || [];
|
|
201
|
-
return form;
|
|
202
|
-
})).then(dataArray => dataArray)
|
|
203
|
-
: [];
|
|
204
|
-
shipment_setting.support = (_k = shipment_setting.support) !== null && _k !== void 0 ? _k : [];
|
|
205
|
-
const languageInfo = (_m = (_l = shipment_setting.language_data) === null || _l === void 0 ? void 0 : _l[data.language]) === null || _m === void 0 ? void 0 : _m.info;
|
|
206
|
-
shipment_setting.info = languageInfo !== null && languageInfo !== void 0 ? languageInfo : shipment_setting.info;
|
|
207
|
-
const carData = {
|
|
208
|
-
customer_info: data.customer_info || {},
|
|
209
|
-
lineItems: [],
|
|
210
|
-
total: 0,
|
|
211
|
-
email: (_q = (_o = data.email) !== null && _o !== void 0 ? _o : (_p = data.user_info) === null || _p === void 0 ? void 0 : _p.email) !== null && _q !== void 0 ? _q : '',
|
|
212
|
-
user_info: data.user_info,
|
|
213
|
-
shipment_fee: 0,
|
|
214
|
-
rebate: 0,
|
|
215
|
-
goodsWeight: 0,
|
|
216
|
-
use_rebate: data.use_rebate || 0,
|
|
217
|
-
orderID: data.order_id || `${Date.now()}`,
|
|
218
|
-
shipment_support: shipment_setting.support,
|
|
219
|
-
shipment_info: shipment_setting.info,
|
|
220
|
-
shipment_selector: [
|
|
221
|
-
...shipment_config_js_1.ShipmentConfig.list.map(dd => ({
|
|
222
|
-
name: dd.title,
|
|
223
|
-
value: dd.value,
|
|
224
|
-
})),
|
|
225
|
-
...((_r = shipment_setting.custom_delivery) !== null && _r !== void 0 ? _r : []).map((dd) => ({
|
|
226
|
-
form: dd.form,
|
|
227
|
-
name: dd.name,
|
|
228
|
-
value: dd.id,
|
|
229
|
-
system_form: dd.system_form,
|
|
230
|
-
})),
|
|
231
|
-
].filter(option => shipment_setting.support.includes(option.value)),
|
|
232
|
-
use_wallet: 0,
|
|
233
|
-
method: (_s = data.user_info) === null || _s === void 0 ? void 0 : _s.method,
|
|
234
|
-
user_email: (_w = (_u = (_t = userData === null || userData === void 0 ? void 0 : userData.account) !== null && _t !== void 0 ? _t : data.email) !== null && _u !== void 0 ? _u : (_v = data.user_info) === null || _v === void 0 ? void 0 : _v.email) !== null && _w !== void 0 ? _w : '',
|
|
235
|
-
useRebateInfo: { point: 0 },
|
|
236
|
-
custom_form_format: data.custom_form_format,
|
|
237
|
-
custom_form_data: data.custom_form_data,
|
|
238
|
-
custom_receipt_form: data.custom_receipt_form,
|
|
239
|
-
orderSource: checkOutType === 'POS' ? 'POS' : '',
|
|
240
|
-
code_array: data.code_array,
|
|
241
|
-
give_away: data.give_away,
|
|
242
|
-
user_rebate_sum: 0,
|
|
243
|
-
language: data.language,
|
|
244
|
-
pos_info: data.pos_info,
|
|
245
|
-
client_ip_address: data.client_ip_address,
|
|
246
|
-
fbc: data.fbc,
|
|
247
|
-
fbp: data.fbp,
|
|
248
|
-
editRecord: [],
|
|
249
|
-
};
|
|
250
|
-
if (!((_x = data.user_info) === null || _x === void 0 ? void 0 : _x.name) && userData && userData.userData) {
|
|
251
|
-
const { name, phone } = userData.userData;
|
|
252
|
-
carData.user_info = Object.assign(Object.assign({}, carData.user_info), { name,
|
|
253
|
-
phone });
|
|
254
|
-
}
|
|
255
|
-
const add_on_items = [];
|
|
256
|
-
const gift_product = [];
|
|
257
|
-
const saveStockArray = [];
|
|
258
|
-
function getVariant(prod, item) {
|
|
259
|
-
var _a;
|
|
260
|
-
if (prod.product_category === 'kitchen') {
|
|
261
|
-
let price = 0;
|
|
262
|
-
let show_understocking = false;
|
|
263
|
-
let stock = Infinity;
|
|
264
|
-
if (prod.specs.length) {
|
|
265
|
-
price = item.spec.reduce((total, spec, index) => {
|
|
266
|
-
const dpe = prod.specs[index].option.find((dd) => dd.title === spec);
|
|
267
|
-
if (dpe) {
|
|
268
|
-
const currentStock = Number(dpe.stock) || Infinity;
|
|
269
|
-
stock = Math.min(stock, currentStock);
|
|
270
|
-
if (dpe.stock !== undefined) {
|
|
271
|
-
show_understocking = true;
|
|
272
|
-
}
|
|
273
|
-
return total + (Number(dpe.price) || 0);
|
|
274
|
-
}
|
|
275
|
-
return total;
|
|
276
|
-
}, 0);
|
|
277
|
-
}
|
|
278
|
-
else {
|
|
279
|
-
price = Number(prod.price) || 0;
|
|
280
|
-
show_understocking = Boolean((_a = prod.stock) !== null && _a !== void 0 ? _a : '');
|
|
281
|
-
stock = Number(prod.stock) || 0;
|
|
282
|
-
}
|
|
283
|
-
if (stock === Infinity) {
|
|
284
|
-
show_understocking = false;
|
|
285
|
-
}
|
|
286
|
-
return {
|
|
287
|
-
sku: '',
|
|
288
|
-
spec: [],
|
|
289
|
-
type: 'variants',
|
|
290
|
-
stock,
|
|
291
|
-
v_width: 0,
|
|
292
|
-
product_id: prod.id,
|
|
293
|
-
sale_price: price,
|
|
294
|
-
origin_price: 0,
|
|
295
|
-
compare_price: 0,
|
|
296
|
-
preview_image: prod.preview_image && prod.preview_image[0],
|
|
297
|
-
shipment_type: 'none',
|
|
298
|
-
show_understocking: String(show_understocking),
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
else {
|
|
302
|
-
return prod.variants.find((dd) => dd.spec.join('-') === item.spec.join('-'));
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
data.line_items = await Promise.all(data.line_items.map(async (item) => {
|
|
306
|
-
var _a, _b, _c, _d, _e;
|
|
307
|
-
const getProductData = (await this.getProduct({
|
|
308
|
-
page: 0,
|
|
309
|
-
limit: 1,
|
|
310
|
-
id: `${item.id}`,
|
|
311
|
-
status: 'inRange',
|
|
312
|
-
channel: checkOutType === 'POS' ? (data.isExhibition ? 'exhibition' : 'pos') : undefined,
|
|
313
|
-
whereStore: checkOutType === 'POS' ? data.pos_store : undefined,
|
|
314
|
-
setUserID: `${(userData === null || userData === void 0 ? void 0 : userData.userID) || ''}`,
|
|
315
|
-
})).data;
|
|
316
|
-
if (getProductData) {
|
|
317
|
-
const content = getProductData.content;
|
|
318
|
-
const variant = getVariant(content, item);
|
|
319
|
-
const count = Number(item.count);
|
|
320
|
-
if ((Number.isInteger(variant.stock) || variant.show_understocking === 'false') &&
|
|
321
|
-
!isNaN(count) &&
|
|
322
|
-
count > 0) {
|
|
323
|
-
const isPOS = checkOutType === 'POS';
|
|
324
|
-
const isUnderstockingVisible = variant.show_understocking !== 'false';
|
|
325
|
-
const isManualType = type === 'manual' || type === 'manual-preview';
|
|
326
|
-
if (isPOS && isUnderstockingVisible && !data.isExhibition) {
|
|
327
|
-
variant.stock = ((_b = (_a = variant.stockList) === null || _a === void 0 ? void 0 : _a[data.pos_store]) === null || _b === void 0 ? void 0 : _b.count) || 0;
|
|
328
|
-
}
|
|
329
|
-
if (variant.stock < item.count && isUnderstockingVisible && !isManualType) {
|
|
330
|
-
if (isPOS) {
|
|
331
|
-
item.pre_order = true;
|
|
332
|
-
}
|
|
333
|
-
else {
|
|
334
|
-
item.count = variant.stock;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
if (variant && item.count > 0) {
|
|
338
|
-
Object.assign(item, {
|
|
339
|
-
specs: content.specs,
|
|
340
|
-
language_data: content.language_data,
|
|
341
|
-
product_category: content.product_category,
|
|
342
|
-
preview_image: variant.preview_image || content.preview_image[0],
|
|
343
|
-
title: content.title,
|
|
344
|
-
sale_price: variant.sale_price,
|
|
345
|
-
origin_price: variant.origin_price,
|
|
346
|
-
collection: content.collection,
|
|
347
|
-
sku: variant.sku,
|
|
348
|
-
stock: variant.stock,
|
|
349
|
-
show_understocking: variant.show_understocking,
|
|
350
|
-
stockList: variant.stockList,
|
|
351
|
-
weight: parseInt(variant.weight || '0', 10),
|
|
352
|
-
designated_logistics: (_c = content.designated_logistics) !== null && _c !== void 0 ? _c : { type: 'all', list: [] },
|
|
353
|
-
});
|
|
354
|
-
const shipmentValue = (() => {
|
|
355
|
-
if (!variant.shipment_type || variant.shipment_type === 'none')
|
|
356
|
-
return 0;
|
|
357
|
-
if (variant.shipment_type === 'weight') {
|
|
358
|
-
return item.count * variant.weight;
|
|
359
|
-
}
|
|
360
|
-
if (variant.shipment_type === 'volume') {
|
|
361
|
-
return item.count * variant.v_length * variant.v_width * variant.v_height;
|
|
362
|
-
}
|
|
363
|
-
return 0;
|
|
364
|
-
})();
|
|
365
|
-
item.shipment_obj = {
|
|
366
|
-
type: variant.shipment_type,
|
|
367
|
-
value: shipmentValue,
|
|
368
|
-
};
|
|
369
|
-
variant.shipment_weight = parseInt(variant.shipment_weight || '0', 10);
|
|
370
|
-
carData.lineItems.push(item);
|
|
371
|
-
if (checkOutType == 'group_buy') {
|
|
372
|
-
if (!scheduledData) {
|
|
373
|
-
const sql = `WHERE JSON_CONTAINS(content->'$.pending_order', '"${data.temp_cart_id}"'`;
|
|
374
|
-
const scheduledDataQuery = `
|
|
375
|
-
SELECT *
|
|
376
|
-
FROM \`${this.app}\`.\`t_live_purchase_interactions\` ${sql});
|
|
377
|
-
`;
|
|
378
|
-
scheduledData = (await database_js_1.default.query(scheduledDataQuery, []))[0];
|
|
379
|
-
if (scheduledData) {
|
|
380
|
-
const { content } = scheduledData;
|
|
381
|
-
const productData = content.item_list.find((pb) => pb.id === item.id);
|
|
382
|
-
if (productData) {
|
|
383
|
-
const variantData = productData.content.variants.find((dd) => dd.spec.join('-') === item.spec.join('-'));
|
|
384
|
-
if (variantData) {
|
|
385
|
-
item.sale_price = variantData.live_model.live_price;
|
|
386
|
-
carData.total += item.sale_price * item.count;
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
else if (type !== 'manual') {
|
|
393
|
-
if (content.productType.giveaway) {
|
|
394
|
-
variant.sale_price = 0;
|
|
395
|
-
}
|
|
396
|
-
else {
|
|
397
|
-
carData.total += variant.sale_price * item.count;
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
if (!['preview', 'manual', 'manual-preview'].includes(type) && variant.show_understocking !== 'false') {
|
|
402
|
-
const remainingStock = Math.max(variant.stock - item.count, 0);
|
|
403
|
-
variant.stock = remainingStock;
|
|
404
|
-
if (type === 'POS') {
|
|
405
|
-
if (data.isExhibition) {
|
|
406
|
-
if (data.pos_store) {
|
|
407
|
-
await this.updateExhibitionActiveStock(data.pos_store, variant.variant_id, item.count);
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
else {
|
|
411
|
-
variant.deduction_log = { [data.pos_store]: item.count };
|
|
412
|
-
variant.stockList[data.pos_store].count -= item.count;
|
|
413
|
-
item.deduction_log = variant.deduction_log;
|
|
414
|
-
}
|
|
415
|
-
}
|
|
416
|
-
else {
|
|
417
|
-
const returnData = new stock_js_1.Stock(this.app, this.token).allocateStock(variant.stockList, item.count);
|
|
418
|
-
variant.deduction_log = returnData.deductionLog;
|
|
419
|
-
item.deduction_log = returnData.deductionLog;
|
|
420
|
-
}
|
|
421
|
-
saveStockArray.push(() => new Promise(async (resolve, reject) => {
|
|
422
|
-
var _a;
|
|
423
|
-
try {
|
|
424
|
-
if (data.checkOutType == 'group_buy') {
|
|
425
|
-
if (!scheduledData) {
|
|
426
|
-
const sql = `WHERE JSON_CONTAINS(content->'$.pending_order', '"${data.temp_cart_id}"'`;
|
|
427
|
-
const scheduledDataQuery = `
|
|
428
|
-
SELECT *
|
|
429
|
-
FROM \`${this.app}\`.\`t_live_purchase_interactions\` ${sql});
|
|
430
|
-
`;
|
|
431
|
-
scheduledData = (await database_js_1.default.query(scheduledDataQuery, []))[0];
|
|
432
|
-
}
|
|
433
|
-
if (scheduledData) {
|
|
434
|
-
const { content } = scheduledData;
|
|
435
|
-
const productData = content.item_list.find((pb) => pb.id === item.id);
|
|
436
|
-
if (productData) {
|
|
437
|
-
const variantData = productData.content.variants.find((dd) => dd.spec.join('-') === item.spec.join('-'));
|
|
438
|
-
if (variantData) {
|
|
439
|
-
const stockService = new stock_js_1.Stock(this.app, this.token);
|
|
440
|
-
const { stockList, deductionLog } = stockService.allocateStock(variantData.stockList, item.count);
|
|
441
|
-
variantData.stockList = stockList;
|
|
442
|
-
item.deduction_log = deductionLog;
|
|
443
|
-
carData.scheduled_id = scheduledData.id;
|
|
444
|
-
await this.updateVariantsForScheduled(content, scheduledData.id);
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
else {
|
|
450
|
-
if (content.shopee_id) {
|
|
451
|
-
await new shopee_js_1.Shopee(this.app, this.token).asyncStockToShopee({
|
|
452
|
-
product: getProductData,
|
|
453
|
-
callback: () => {
|
|
454
|
-
},
|
|
455
|
-
});
|
|
456
|
-
}
|
|
457
|
-
if (content.product_category === 'kitchen' && ((_a = variant.spec) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
458
|
-
variant.spec.forEach((d1, index) => {
|
|
459
|
-
const option = content.specs[index].option.find((d2) => d2.title === d1);
|
|
460
|
-
if ((option === null || option === void 0 ? void 0 : option.stock) !== undefined) {
|
|
461
|
-
option.stock = parseInt(option.stock, 10) - item.count;
|
|
462
|
-
}
|
|
463
|
-
});
|
|
464
|
-
const store_config = await userClass.getConfigV2({
|
|
465
|
-
key: 'store_manager',
|
|
466
|
-
user_id: 'manager',
|
|
467
|
-
});
|
|
468
|
-
item.deduction_log = { [store_config.list[0].id]: item.count };
|
|
469
|
-
}
|
|
470
|
-
else {
|
|
471
|
-
await this.updateVariantsWithSpec(variant, item.id, item.spec);
|
|
472
|
-
}
|
|
473
|
-
await database_js_1.default.query(`UPDATE \`${this.app}\`.\`t_manager_post\`
|
|
474
|
-
SET ?
|
|
475
|
-
WHERE id = ${getProductData.id}`, [{ content: JSON.stringify(content) }]);
|
|
476
|
-
}
|
|
477
|
-
resolve(true);
|
|
478
|
-
}
|
|
479
|
-
catch (error) {
|
|
480
|
-
reject(error);
|
|
481
|
-
}
|
|
482
|
-
}));
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
Object.assign(item, {
|
|
486
|
-
is_add_on_items: content.productType.addProduct && !content.productType.product,
|
|
487
|
-
is_hidden: content.visible === 'false',
|
|
488
|
-
is_gift: content.productType.giveaway,
|
|
489
|
-
sale_price: content.productType.giveaway ? 0 : item.sale_price,
|
|
490
|
-
min_qty: (_d = content.min_qty) !== null && _d !== void 0 ? _d : item.min_qty,
|
|
491
|
-
max_qty: (_e = content.max_qty) !== null && _e !== void 0 ? _e : item.max_qty,
|
|
492
|
-
});
|
|
493
|
-
item.is_add_on_items && add_on_items.push(item);
|
|
494
|
-
item.is_gift && gift_product.push(item);
|
|
495
|
-
}
|
|
496
|
-
return item;
|
|
497
|
-
})).then(dataArray => dataArray);
|
|
498
|
-
checkPoint('get product info');
|
|
499
|
-
const maxProductMap = new Map();
|
|
500
|
-
let hasMaxProduct = false;
|
|
501
|
-
for (const product of data.line_items) {
|
|
502
|
-
if (product.max_qty && product.max_qty > 0) {
|
|
503
|
-
maxProductMap.set(product.id, true);
|
|
504
|
-
hasMaxProduct = true;
|
|
505
|
-
}
|
|
506
|
-
}
|
|
507
|
-
if (hasMaxProduct && data.email !== 'no-email') {
|
|
508
|
-
const cartTokenSQL = `
|
|
509
|
-
SELECT cart_token
|
|
510
|
-
FROM \`${this.app}\`.t_checkout
|
|
511
|
-
WHERE email IN (${[-99, (_y = userData === null || userData === void 0 ? void 0 : userData.userData) === null || _y === void 0 ? void 0 : _y.email, (_z = userData === null || userData === void 0 ? void 0 : userData.userData) === null || _z === void 0 ? void 0 : _z.phone]
|
|
512
|
-
.filter(Boolean)
|
|
513
|
-
.map(item => database_js_1.default.escape(item))
|
|
514
|
-
.join(',')})
|
|
515
|
-
AND order_status <> '-1'
|
|
516
|
-
`;
|
|
517
|
-
const soldHistory = await database_js_1.default.query(`
|
|
518
|
-
SELECT *
|
|
519
|
-
FROM \`${this.app}\`.t_products_sold_history
|
|
520
|
-
WHERE product_id IN (${[...maxProductMap.keys()].join(',')})
|
|
521
|
-
AND order_id IN (${cartTokenSQL})
|
|
522
|
-
`, []);
|
|
523
|
-
const purchaseHistory = new Map();
|
|
524
|
-
for (const history of soldHistory) {
|
|
525
|
-
const pid = Number(history.product_id);
|
|
526
|
-
purchaseHistory.set(pid, ((_0 = purchaseHistory.get(pid)) !== null && _0 !== void 0 ? _0 : 0) + history.count);
|
|
527
|
-
}
|
|
528
|
-
for (const item of data.line_items) {
|
|
529
|
-
if (maxProductMap.has(item.id)) {
|
|
530
|
-
item.buy_history_count = purchaseHistory.get(item.id) || 0;
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
checkPoint('set max product');
|
|
535
|
-
carData.shipment_fee = this.getShipmentFee(data.user_info, carData.lineItems, shipment);
|
|
536
|
-
carData.total += carData.shipment_fee;
|
|
537
|
-
const f_rebate = await this.formatUseRebate(carData.total, carData.use_rebate);
|
|
538
|
-
carData.useRebateInfo = f_rebate;
|
|
539
|
-
carData.use_rebate = f_rebate.point;
|
|
540
|
-
carData.total -= carData.use_rebate;
|
|
541
|
-
carData.code = data.code;
|
|
542
|
-
carData.voucherList = [];
|
|
543
|
-
checkPoint('set carData');
|
|
544
|
-
if (userData && userData.account) {
|
|
545
|
-
const userRebate = await rebateClass.getOneRebate({ user_id: userData.userID });
|
|
546
|
-
carData.user_rebate_sum = (userRebate === null || userRebate === void 0 ? void 0 : userRebate.point) || 0;
|
|
547
|
-
}
|
|
548
|
-
if (data.distribution_code) {
|
|
549
|
-
const linkList = await new recommend_js_1.Recommend(this.app, this.token).getLinkList({
|
|
550
|
-
page: 0,
|
|
551
|
-
limit: 99999,
|
|
552
|
-
code: data.distribution_code,
|
|
553
|
-
status: true,
|
|
554
|
-
no_detail: true,
|
|
555
|
-
});
|
|
556
|
-
if (linkList.data.length > 0) {
|
|
557
|
-
const content = linkList.data[0].content;
|
|
558
|
-
if (this.checkDuring(content)) {
|
|
559
|
-
carData.distribution_info = content;
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
checkPoint('distribution code');
|
|
564
|
-
if (type !== 'manual' && type !== 'manual-preview') {
|
|
565
|
-
carData.lineItems = carData.lineItems.filter(dd => {
|
|
566
|
-
return !add_on_items.includes(dd) && !gift_product.includes(dd);
|
|
567
|
-
});
|
|
568
|
-
const c_carData = await this.checkVoucher(structuredClone(carData));
|
|
569
|
-
add_on_items.forEach(dd => {
|
|
570
|
-
var _a;
|
|
571
|
-
try {
|
|
572
|
-
const isAddOnItem = (_a = c_carData.voucherList) === null || _a === void 0 ? void 0 : _a.some(voucher => {
|
|
573
|
-
return (voucher.reBackType === 'add_on_items' &&
|
|
574
|
-
voucher.add_on_products.find(d2 => {
|
|
575
|
-
return `${dd.id}` === `${d2}`;
|
|
576
|
-
}));
|
|
577
|
-
});
|
|
578
|
-
if (isAddOnItem) {
|
|
579
|
-
carData.lineItems.push(dd);
|
|
580
|
-
}
|
|
581
|
-
}
|
|
582
|
-
catch (e) {
|
|
583
|
-
console.error('Error processing add-on items:', e);
|
|
584
|
-
}
|
|
585
|
-
});
|
|
586
|
-
await this.checkVoucher(carData);
|
|
587
|
-
checkPoint('check voucher');
|
|
588
|
-
let can_add_gift = [];
|
|
589
|
-
(_1 = carData.voucherList) === null || _1 === void 0 ? void 0 : _1.filter(dd => dd.reBackType === 'giveaway').forEach(dd => can_add_gift.push(dd.add_on_products));
|
|
590
|
-
gift_product.forEach(dd => {
|
|
591
|
-
const max_count = can_add_gift.filter(d1 => d1.includes(dd.id)).length;
|
|
592
|
-
if (dd.count <= max_count) {
|
|
593
|
-
for (let a = 0; a < dd.count; a++) {
|
|
594
|
-
can_add_gift = can_add_gift.filter(d1 => !d1.includes(dd.id));
|
|
595
|
-
}
|
|
596
|
-
carData.lineItems.push(dd);
|
|
597
|
-
}
|
|
598
|
-
});
|
|
599
|
-
for (const giveawayData of carData.voucherList.filter(dd => dd.reBackType === 'giveaway')) {
|
|
600
|
-
if (!((_2 = giveawayData.add_on_products) === null || _2 === void 0 ? void 0 : _2.length))
|
|
601
|
-
continue;
|
|
602
|
-
const productPromises = giveawayData.add_on_products.map(async (id) => {
|
|
603
|
-
const getGiveawayData = (await this.getProduct({
|
|
604
|
-
page: 0,
|
|
605
|
-
limit: 1,
|
|
606
|
-
id: `${id}`,
|
|
607
|
-
status: 'inRange',
|
|
608
|
-
channel: checkOutType === 'POS' ? (data.isExhibition ? 'exhibition' : 'pos') : undefined,
|
|
609
|
-
whereStore: checkOutType === 'POS' ? data.pos_store : undefined,
|
|
610
|
-
})).data.content;
|
|
611
|
-
getGiveawayData.voucher_id = giveawayData.id;
|
|
612
|
-
return getGiveawayData;
|
|
613
|
-
});
|
|
614
|
-
giveawayData.add_on_products = await Promise.all(productPromises);
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
const configData = await private_config_js_1.Private_config.getConfig({
|
|
618
|
-
appName: this.app,
|
|
619
|
-
key: 'glitter_finance',
|
|
620
|
-
});
|
|
621
|
-
const keyData = (_3 = configData[0]) === null || _3 === void 0 ? void 0 : _3.value;
|
|
622
|
-
if (keyData) {
|
|
623
|
-
carData.payment_info_custom = keyData.payment_info_custom;
|
|
624
|
-
}
|
|
625
|
-
await new Promise(resolve => {
|
|
626
|
-
var _a;
|
|
627
|
-
let n = 0;
|
|
628
|
-
carData.payment_customer_form = (_a = carData.payment_customer_form) !== null && _a !== void 0 ? _a : [];
|
|
629
|
-
keyData.payment_info_custom.map((item, index) => {
|
|
630
|
-
userClass
|
|
631
|
-
.getConfigV2({
|
|
632
|
-
user_id: 'manager',
|
|
633
|
-
key: `form_finance_${item.id}`,
|
|
634
|
-
})
|
|
635
|
-
.then(data => {
|
|
636
|
-
carData.payment_customer_form[index] = {
|
|
637
|
-
id: item.id,
|
|
638
|
-
list: data.list,
|
|
639
|
-
};
|
|
640
|
-
n++;
|
|
641
|
-
if (keyData.payment_info_custom.length === n) {
|
|
642
|
-
resolve();
|
|
643
|
-
}
|
|
644
|
-
});
|
|
645
|
-
});
|
|
646
|
-
if (n === 0) {
|
|
647
|
-
resolve();
|
|
648
|
-
}
|
|
649
|
-
});
|
|
650
|
-
checkPoint('set payment');
|
|
651
|
-
keyData.cash_on_delivery = (_4 = keyData.cash_on_delivery) !== null && _4 !== void 0 ? _4 : { shipmentSupport: [] };
|
|
652
|
-
carData.payment_info_line_pay = keyData.payment_info_line_pay;
|
|
653
|
-
carData.payment_info_atm = keyData.payment_info_atm;
|
|
654
|
-
const defaultPayArray = glitter_finance_js_1.onlinePayArray.map(item => item.key);
|
|
655
|
-
keyData.cash_on_delivery.shipmentSupport = (_5 = keyData.cash_on_delivery.shipmentSupport) !== null && _5 !== void 0 ? _5 : [];
|
|
656
|
-
carData.shipment_support = ((_6 = (() => {
|
|
657
|
-
if (checkoutPayment === 'cash_on_delivery') {
|
|
658
|
-
return keyData.cash_on_delivery;
|
|
659
|
-
}
|
|
660
|
-
else if (defaultPayArray.includes(checkoutPayment)) {
|
|
661
|
-
return keyData[checkoutPayment];
|
|
662
|
-
}
|
|
663
|
-
else if (checkoutPayment === 'atm') {
|
|
664
|
-
return keyData.payment_info_atm;
|
|
665
|
-
}
|
|
666
|
-
else if (checkoutPayment === 'line') {
|
|
667
|
-
return keyData.payment_info_line_pay;
|
|
668
|
-
}
|
|
669
|
-
else {
|
|
670
|
-
const customPay = keyData.payment_info_custom.find((c) => c.id === checkoutPayment);
|
|
671
|
-
return customPay !== null && customPay !== void 0 ? customPay : {};
|
|
672
|
-
}
|
|
673
|
-
})().shipmentSupport) !== null && _6 !== void 0 ? _6 : []);
|
|
674
|
-
let subtotal = 0;
|
|
675
|
-
carData.lineItems.map(item => {
|
|
676
|
-
var _a;
|
|
677
|
-
if (item.is_gift) {
|
|
678
|
-
item.sale_price = 0;
|
|
679
|
-
}
|
|
680
|
-
if (!item.is_gift) {
|
|
681
|
-
subtotal += item.count * (item.sale_price - ((_a = item.discount_price) !== null && _a !== void 0 ? _a : 0));
|
|
682
|
-
}
|
|
683
|
-
});
|
|
684
|
-
if (carData.total < 0 || carData.use_rebate > subtotal) {
|
|
685
|
-
carData.use_rebate = 0;
|
|
686
|
-
carData.total = subtotal + carData.shipment_fee;
|
|
687
|
-
}
|
|
688
|
-
carData.lineItems.map(item => {
|
|
689
|
-
carData.goodsWeight += item.weight * item.count;
|
|
690
|
-
});
|
|
691
|
-
const excludedValuesByTotal = new Set(['UNIMARTC2C', 'FAMIC2C', 'HILIFEC2C', 'OKMARTC2C']);
|
|
692
|
-
const excludedValuesByWeight = new Set(['normal', 'black_cat']);
|
|
693
|
-
const isExcludedByTotal = (dd) => {
|
|
694
|
-
return carData.total > 20000 && excludedValuesByTotal.has(dd.value);
|
|
695
|
-
};
|
|
696
|
-
const isExcludedByWeight = (dd) => {
|
|
697
|
-
return carData.goodsWeight > 20 && excludedValuesByWeight.has(dd.value);
|
|
698
|
-
};
|
|
699
|
-
const isIncludedInDesignatedLogistics = (dd) => {
|
|
700
|
-
return carData.lineItems.every(item => {
|
|
701
|
-
return (item.designated_logistics === undefined ||
|
|
702
|
-
item.designated_logistics.type === 'all' ||
|
|
703
|
-
item.designated_logistics.list.includes(dd.value));
|
|
704
|
-
});
|
|
705
|
-
};
|
|
706
|
-
carData.shipment_selector = carData.shipment_selector
|
|
707
|
-
.filter((dd) => {
|
|
708
|
-
return isIncludedInDesignatedLogistics(dd);
|
|
709
|
-
})
|
|
710
|
-
.map(dd => {
|
|
711
|
-
dd.isExcludedByTotal = isExcludedByTotal(dd);
|
|
712
|
-
dd.isExcludedByWeight = isExcludedByWeight(dd);
|
|
713
|
-
return dd;
|
|
714
|
-
});
|
|
715
|
-
carData.code_array = (carData.code_array || []).filter(code => {
|
|
716
|
-
return (carData.voucherList || []).find(dd => dd.code === code);
|
|
717
|
-
});
|
|
718
|
-
function getCartFormulaPass(keyData) {
|
|
719
|
-
const data = keyData.cartSetting;
|
|
720
|
-
if (!data || data.orderFormula === undefined)
|
|
721
|
-
return true;
|
|
722
|
-
const formulaSet = new Set(data.orderFormula);
|
|
723
|
-
const total = carData.total -
|
|
724
|
-
(formulaSet.has('shipment_fee') ? 0 : carData.shipment_fee) +
|
|
725
|
-
(formulaSet.has('discount') || !carData.discount ? 0 : carData.discount) +
|
|
726
|
-
(formulaSet.has('use_rebate') ? 0 : carData.use_rebate);
|
|
727
|
-
return (!data.minimumTotal || total >= data.minimumTotal) && (!data.maximumTotal || total <= data.maximumTotal);
|
|
728
|
-
}
|
|
729
|
-
carData.payment_setting = (await this.getPaymentSetting()).filter((dd) => {
|
|
730
|
-
const k = keyData[dd.key];
|
|
731
|
-
if (!k || !k.toggle || !getCartFormulaPass(k))
|
|
732
|
-
return false;
|
|
733
|
-
dd.custome_name = k.custome_name;
|
|
734
|
-
if (carData.orderSource === 'POS') {
|
|
735
|
-
if (dd.key === 'ut_credit_card') {
|
|
736
|
-
dd.pwd = k['pwd'];
|
|
737
|
-
}
|
|
738
|
-
return dd.type === 'pos';
|
|
739
|
-
}
|
|
740
|
-
return dd.type !== 'pos';
|
|
741
|
-
});
|
|
742
|
-
carData.off_line_support = (_7 = keyData.off_line_support) !== null && _7 !== void 0 ? _7 : {};
|
|
743
|
-
checkoutPayment = checkoutPayment || (carData.payment_setting[0] && carData.payment_setting[0].key);
|
|
744
|
-
carData.user_info.payment = checkoutPayment;
|
|
745
|
-
Object.entries(carData.off_line_support).map(([key, value]) => {
|
|
746
|
-
if (!value)
|
|
747
|
-
return;
|
|
748
|
-
if (key === 'cash_on_delivery') {
|
|
749
|
-
carData.off_line_support[key] = getCartFormulaPass(keyData[key]);
|
|
750
|
-
}
|
|
751
|
-
else if (key === 'atm') {
|
|
752
|
-
carData.off_line_support[key] = getCartFormulaPass(keyData.payment_info_atm);
|
|
753
|
-
}
|
|
754
|
-
else if (key === 'line') {
|
|
755
|
-
carData.off_line_support[key] = getCartFormulaPass(keyData.payment_info_line_pay);
|
|
756
|
-
}
|
|
757
|
-
else {
|
|
758
|
-
const customPay = keyData.payment_info_custom.find((c) => c.id === key);
|
|
759
|
-
carData.off_line_support[key] = getCartFormulaPass(customPay !== null && customPay !== void 0 ? customPay : {});
|
|
760
|
-
}
|
|
761
|
-
});
|
|
762
|
-
if (Array.isArray(carData.shipment_support)) {
|
|
763
|
-
await Promise.all(carData.shipment_support.map(async (sup) => {
|
|
764
|
-
return await userClass
|
|
765
|
-
.getConfigV2({ key: 'shipment_config_' + sup, user_id: 'manager' })
|
|
766
|
-
.then(r => {
|
|
767
|
-
return getCartFormulaPass(r);
|
|
768
|
-
})
|
|
769
|
-
.catch(() => {
|
|
770
|
-
return true;
|
|
771
|
-
});
|
|
772
|
-
})).then(dataArray => {
|
|
773
|
-
var _a;
|
|
774
|
-
carData.shipment_support = (_a = carData.shipment_support) === null || _a === void 0 ? void 0 : _a.filter((_, index) => dataArray[index]);
|
|
775
|
-
});
|
|
776
|
-
}
|
|
777
|
-
checkPoint('return preview');
|
|
778
|
-
if (type === 'preview' || type === 'manual-preview')
|
|
779
|
-
return { data: carData };
|
|
780
|
-
if (userData && userData.userID) {
|
|
781
|
-
await rebateClass.insertRebate(userData.userID, carData.use_rebate * -1, '使用折抵', {
|
|
782
|
-
order_id: carData.orderID,
|
|
783
|
-
});
|
|
784
|
-
if (carData.voucherList && carData.voucherList.length > 0) {
|
|
785
|
-
for (const voucher of carData.voucherList) {
|
|
786
|
-
await this.insertVoucherHistory(userData.userID, carData.orderID, voucher.id);
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
const sum = (await database_js_1.default.query(`SELECT sum(money)
|
|
790
|
-
FROM \`${this.app}\`.t_wallet
|
|
791
|
-
WHERE status in (1, 2)
|
|
792
|
-
and userID = ?`, [userData.userID]))[0]['sum(money)'] || 0;
|
|
793
|
-
carData.use_wallet = sum < carData.total ? sum : carData.total;
|
|
794
|
-
}
|
|
795
|
-
checkPoint('check user rebate');
|
|
796
|
-
if (type === 'manual' || type === 'split') {
|
|
797
|
-
carData.orderSource = type;
|
|
798
|
-
let tempVoucher = {
|
|
799
|
-
discount_total: data.voucher.discount_total,
|
|
800
|
-
end_ISO_Date: '',
|
|
801
|
-
for: 'all',
|
|
802
|
-
forKey: [],
|
|
803
|
-
method: data.voucher.method,
|
|
804
|
-
overlay: false,
|
|
805
|
-
rebate_total: data.voucher.rebate_total,
|
|
806
|
-
reBackType: data.voucher.reBackType,
|
|
807
|
-
rule: 'min_price',
|
|
808
|
-
ruleValue: 0,
|
|
809
|
-
startDate: '',
|
|
810
|
-
startTime: '',
|
|
811
|
-
start_ISO_Date: '',
|
|
812
|
-
status: 1,
|
|
813
|
-
target: '',
|
|
814
|
-
targetList: [],
|
|
815
|
-
title: data.voucher.title,
|
|
816
|
-
trigger: 'auto',
|
|
817
|
-
type: 'voucher',
|
|
818
|
-
value: data.voucher.value,
|
|
819
|
-
id: data.voucher.id,
|
|
820
|
-
bind: [],
|
|
821
|
-
bind_subtotal: 0,
|
|
822
|
-
times: 1,
|
|
823
|
-
counting: 'single',
|
|
824
|
-
conditionType: 'item',
|
|
825
|
-
includeDiscount: 'before',
|
|
826
|
-
device: ['normal'],
|
|
827
|
-
productOffStart: 'price_all',
|
|
828
|
-
};
|
|
829
|
-
carData.discount = data.discount;
|
|
830
|
-
carData.voucherList = [tempVoucher];
|
|
831
|
-
carData.customer_info = data.customer_info;
|
|
832
|
-
carData.total = (_8 = data.total) !== null && _8 !== void 0 ? _8 : 0;
|
|
833
|
-
carData.rebate = tempVoucher.rebate_total;
|
|
834
|
-
if (tempVoucher.reBackType == 'shipment_free' || type == 'split') {
|
|
835
|
-
carData.shipment_fee = 0;
|
|
836
|
-
}
|
|
837
|
-
if (tempVoucher.reBackType == 'rebate') {
|
|
838
|
-
let customerData = await userClass.getUserData(data.email || data.user_info.email, 'account');
|
|
839
|
-
if (!customerData) {
|
|
840
|
-
await userClass.createUser(data.email, tool_js_1.default.randomString(8), {
|
|
841
|
-
email: data.email,
|
|
842
|
-
name: data.customer_info.name,
|
|
843
|
-
phone: data.customer_info.phone,
|
|
844
|
-
}, {}, true);
|
|
845
|
-
customerData = await userClass.getUserData(data.email || data.user_info.email, 'account');
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
await order_event_js_1.OrderEvent.insertOrder({
|
|
849
|
-
cartData: carData,
|
|
850
|
-
status: data.pay_status,
|
|
851
|
-
app: this.app,
|
|
852
|
-
});
|
|
853
|
-
new notify_js_1.ManagerNotify(this.app).checkout({ orderData: carData, status: 0 });
|
|
854
|
-
const emailList = new Set([carData.customer_info, carData.user_info].map(dd => dd && dd.email));
|
|
855
|
-
for (const email of emailList) {
|
|
856
|
-
if (email) {
|
|
857
|
-
await auto_fcm_js_1.AutoFcm.orderChangeInfo({
|
|
858
|
-
app: this.app,
|
|
859
|
-
tag: 'order-create',
|
|
860
|
-
order_id: carData.orderID,
|
|
861
|
-
phone_email: email,
|
|
862
|
-
});
|
|
863
|
-
auto_send_email_js_1.AutoSendEmail.customerOrder(this.app, 'auto-email-order-create', carData.orderID, email, carData.language);
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
checkPoint('manual order done');
|
|
867
|
-
return {
|
|
868
|
-
data: carData,
|
|
869
|
-
};
|
|
870
|
-
}
|
|
871
|
-
else if (type === 'POS') {
|
|
872
|
-
carData.orderSource = 'POS';
|
|
873
|
-
if (checkOutType === 'POS' && Array.isArray(data.voucherList)) {
|
|
874
|
-
const manualVoucher = data.voucherList.find((item) => item.id === 0);
|
|
875
|
-
if (manualVoucher) {
|
|
876
|
-
manualVoucher.discount = (_9 = manualVoucher.discount_total) !== null && _9 !== void 0 ? _9 : 0;
|
|
877
|
-
carData.total -= manualVoucher.discount;
|
|
878
|
-
carData.discount += manualVoucher.discount;
|
|
879
|
-
carData.voucherList.push(manualVoucher);
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
const trans = await database_js_1.default.Transaction.build();
|
|
883
|
-
if (data.pre_order) {
|
|
884
|
-
carData.progress = 'pre_order';
|
|
885
|
-
carData.orderStatus = '0';
|
|
886
|
-
const payTotal = data.pos_info.payment
|
|
887
|
-
.map((dd) => dd.total)
|
|
888
|
-
.reduce((acc, val) => acc + val, 0);
|
|
889
|
-
if (carData.total <= payTotal) {
|
|
890
|
-
data.pay_status = 1;
|
|
891
|
-
}
|
|
892
|
-
else {
|
|
893
|
-
data.pay_status = 3;
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
else if (carData.user_info.shipment === 'now') {
|
|
897
|
-
carData.orderStatus = '1';
|
|
898
|
-
carData.progress = 'finish';
|
|
899
|
-
}
|
|
900
|
-
await order_event_js_1.OrderEvent.insertOrder({
|
|
901
|
-
cartData: carData,
|
|
902
|
-
status: data.pay_status,
|
|
903
|
-
app: this.app,
|
|
904
|
-
});
|
|
905
|
-
if (data.invoice_select !== 'nouse') {
|
|
906
|
-
carData.invoice = await new invoice_js_1.Invoice(this.app).postCheckoutInvoice(carData, carData.user_info.send_type !== 'carrier');
|
|
907
|
-
}
|
|
908
|
-
await trans.commit();
|
|
909
|
-
await trans.release();
|
|
910
|
-
await Promise.all(saveStockArray.map(dd => dd()));
|
|
911
|
-
await this.releaseCheckout((_10 = data.pay_status) !== null && _10 !== void 0 ? _10 : 0, carData.orderID);
|
|
912
|
-
checkPoint('release pos checkout');
|
|
913
|
-
for (const email of new Set([carData.customer_info, carData.user_info].map(dd => {
|
|
914
|
-
return dd && dd.email;
|
|
915
|
-
}))) {
|
|
916
|
-
if (email) {
|
|
917
|
-
await auto_fcm_js_1.AutoFcm.orderChangeInfo({
|
|
918
|
-
app: this.app,
|
|
919
|
-
tag: 'order-create',
|
|
920
|
-
order_id: carData.orderID,
|
|
921
|
-
phone_email: email,
|
|
922
|
-
});
|
|
923
|
-
auto_send_email_js_1.AutoSendEmail.customerOrder(this.app, 'auto-email-order-create', carData.orderID, email, carData.language);
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
return { result: 'SUCCESS', message: 'POS訂單新增成功', data: carData };
|
|
927
|
-
}
|
|
928
|
-
const id = 'redirect_' + tool_js_1.default.randomString(6);
|
|
929
|
-
const redirect_url = new URL(data.return_url);
|
|
930
|
-
redirect_url.searchParams.set('cart_token', carData.orderID);
|
|
931
|
-
await redis_js_1.default.setValue(id, redirect_url.href);
|
|
932
|
-
if (carData.use_wallet === carData.total) {
|
|
933
|
-
await database_js_1.default.query(`INSERT INTO \`${this.app}\`.t_wallet (orderID, userID, money, status, note)
|
|
934
|
-
values (?, ?, ?, ?, ?);`, [
|
|
935
|
-
carData.orderID,
|
|
936
|
-
userData.userID,
|
|
937
|
-
carData.use_wallet * -1,
|
|
938
|
-
1,
|
|
939
|
-
JSON.stringify({
|
|
940
|
-
note: '使用錢包購物',
|
|
941
|
-
orderData: carData,
|
|
942
|
-
}),
|
|
943
|
-
]);
|
|
944
|
-
carData.method = 'off_line';
|
|
945
|
-
await order_event_js_1.OrderEvent.insertOrder({
|
|
946
|
-
cartData: carData,
|
|
947
|
-
status: 1,
|
|
948
|
-
app: this.app,
|
|
949
|
-
});
|
|
950
|
-
if (carData.use_wallet > 0) {
|
|
951
|
-
new invoice_js_1.Invoice(this.app).postCheckoutInvoice(carData.orderID, false);
|
|
952
|
-
}
|
|
953
|
-
await Promise.all(saveStockArray.map(dd => dd()));
|
|
954
|
-
checkPoint('insert order & create invoice');
|
|
955
|
-
return {
|
|
956
|
-
is_free: true,
|
|
957
|
-
return_url: `${process.env.DOMAIN}/api-public/v1/ec/redirect?g-app=${this.app}&return=${id}`,
|
|
958
|
-
};
|
|
959
|
-
}
|
|
960
|
-
else {
|
|
961
|
-
const keyData = (await private_config_js_1.Private_config.getConfig({
|
|
962
|
-
appName: this.app,
|
|
963
|
-
key: 'glitter_finance',
|
|
964
|
-
}))[0].value;
|
|
965
|
-
let kd = (_11 = keyData[carData.customer_info.payment_select]) !== null && _11 !== void 0 ? _11 : {
|
|
966
|
-
ReturnURL: '',
|
|
967
|
-
NotifyURL: '',
|
|
968
|
-
};
|
|
969
|
-
switch (carData.customer_info.payment_select) {
|
|
970
|
-
case 'ecPay':
|
|
971
|
-
case 'newWebPay':
|
|
972
|
-
const subMitData = await new financial_service_js_1.default(this.app, {
|
|
973
|
-
HASH_IV: kd.HASH_IV,
|
|
974
|
-
HASH_KEY: kd.HASH_KEY,
|
|
975
|
-
ActionURL: kd.ActionURL,
|
|
976
|
-
NotifyURL: `${process.env.DOMAIN}/api-public/v1/ec/notify?g-app=${this.app}&type=${carData.customer_info.payment_select}`,
|
|
977
|
-
ReturnURL: `${process.env.DOMAIN}/api-public/v1/ec/redirect?g-app=${this.app}&return=${id}`,
|
|
978
|
-
MERCHANT_ID: kd.MERCHANT_ID,
|
|
979
|
-
TYPE: carData.customer_info.payment_select,
|
|
980
|
-
}).createOrderPage(carData);
|
|
981
|
-
await Promise.all(saveStockArray.map(dd => {
|
|
982
|
-
return dd();
|
|
983
|
-
}));
|
|
984
|
-
checkPoint('select newWebPay');
|
|
985
|
-
return {
|
|
986
|
-
form: subMitData,
|
|
987
|
-
};
|
|
988
|
-
case 'paypal':
|
|
989
|
-
kd.ReturnURL = `${process.env.DOMAIN}/api-public/v1/ec/redirect?g-app=${this.app}&return=${id}`;
|
|
990
|
-
kd.NotifyURL = `${process.env.DOMAIN}/api-public/v1/ec/notify?g-app=${this.app}&type=${carData.customer_info.payment_select}`;
|
|
991
|
-
await Promise.all(saveStockArray.map(dd => {
|
|
992
|
-
return dd();
|
|
993
|
-
}));
|
|
994
|
-
checkPoint('select paypal');
|
|
995
|
-
return await new financial_service_js_1.PayPal(this.app, kd).checkout(carData);
|
|
996
|
-
case 'line_pay':
|
|
997
|
-
kd.ReturnURL = `${process.env.DOMAIN}/api-public/v1/ec/redirect?g-app=${this.app}&return=${id}&type=${carData.customer_info.payment_select}`;
|
|
998
|
-
kd.NotifyURL = `${process.env.DOMAIN}/api-public/v1/ec/notify?g-app=${this.app}&type=${carData.customer_info.payment_select}`;
|
|
999
|
-
await Promise.all(saveStockArray.map(dd => {
|
|
1000
|
-
return dd();
|
|
1001
|
-
}));
|
|
1002
|
-
checkPoint('select linepay');
|
|
1003
|
-
return await new financial_service_js_1.LinePay(this.app, kd).createOrder(carData);
|
|
1004
|
-
case 'paynow': {
|
|
1005
|
-
kd.ReturnURL = `${process.env.DOMAIN}/api-public/v1/ec/redirect?g-app=${this.app}&return=${id}&type=${carData.customer_info.payment_select}`;
|
|
1006
|
-
kd.NotifyURL = `${process.env.DOMAIN}/api-public/v1/ec/notify?g-app=${this.app}&paynow=true&type=${carData.customer_info.payment_select}`;
|
|
1007
|
-
await Promise.all(saveStockArray.map(dd => {
|
|
1008
|
-
return dd();
|
|
1009
|
-
}));
|
|
1010
|
-
checkPoint('select paynow');
|
|
1011
|
-
return await new financial_service_js_1.PayNow(this.app, kd).createOrder(carData);
|
|
1012
|
-
}
|
|
1013
|
-
case 'jkopay': {
|
|
1014
|
-
kd.ReturnURL = `${process.env.DOMAIN}/api-public/v1/ec/redirect?g-app=${this.app}&jkopay=true&return=${id}`;
|
|
1015
|
-
kd.NotifyURL = `${process.env.DOMAIN}/api-public/v1/ec/notify?g-app=${this.app}&type=jkopay&return=${id}`;
|
|
1016
|
-
checkPoint('select jkopay');
|
|
1017
|
-
return await new financial_service_js_1.JKO(this.app, kd).createOrder(carData);
|
|
1018
|
-
}
|
|
1019
|
-
default:
|
|
1020
|
-
carData.method = 'off_line';
|
|
1021
|
-
await order_event_js_1.OrderEvent.insertOrder({
|
|
1022
|
-
cartData: carData,
|
|
1023
|
-
status: 0,
|
|
1024
|
-
app: this.app,
|
|
1025
|
-
});
|
|
1026
|
-
await Promise.all(saveStockArray.map(dd => {
|
|
1027
|
-
return dd();
|
|
1028
|
-
}));
|
|
1029
|
-
new notify_js_1.ManagerNotify(this.app).checkout({
|
|
1030
|
-
orderData: carData,
|
|
1031
|
-
status: 0,
|
|
1032
|
-
});
|
|
1033
|
-
for (const phone of new Set([carData.customer_info, carData.user_info].map(dd => {
|
|
1034
|
-
return dd && dd.phone;
|
|
1035
|
-
}))) {
|
|
1036
|
-
let sns = new sms_js_1.SMS(this.app);
|
|
1037
|
-
await sns.sendCustomerSns('auto-sns-order-create', carData.orderID, phone);
|
|
1038
|
-
console.info('訂單簡訊寄送成功');
|
|
1039
|
-
}
|
|
1040
|
-
if (carData.customer_info.lineID) {
|
|
1041
|
-
let line = new line_message_js_1.LineMessage(this.app);
|
|
1042
|
-
await line.sendCustomerLine('auto-line-order-create', carData.orderID, carData.customer_info.lineID);
|
|
1043
|
-
console.info('訂單line訊息寄送成功');
|
|
1044
|
-
}
|
|
1045
|
-
for (const email of new Set([carData.customer_info, carData.user_info].map(dd => {
|
|
1046
|
-
return dd && dd.email;
|
|
1047
|
-
}))) {
|
|
1048
|
-
if (email) {
|
|
1049
|
-
await auto_fcm_js_1.AutoFcm.orderChangeInfo({
|
|
1050
|
-
app: this.app,
|
|
1051
|
-
tag: 'order-create',
|
|
1052
|
-
order_id: carData.orderID,
|
|
1053
|
-
phone_email: email,
|
|
1054
|
-
});
|
|
1055
|
-
auto_send_email_js_1.AutoSendEmail.customerOrder(this.app, 'auto-email-order-create', carData.orderID, email, carData.language);
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
await this.releaseVoucherHistory(carData.orderID, 1);
|
|
1059
|
-
checkPoint('default release checkout');
|
|
1060
|
-
return {
|
|
1061
|
-
off_line: true,
|
|
1062
|
-
return_url: `${process.env.DOMAIN}/api-public/v1/ec/redirect?g-app=${this.app}&return=${id}`,
|
|
1063
|
-
};
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
catch (e) {
|
|
1068
|
-
console.error(e);
|
|
1069
|
-
throw exception_js_1.default.BadRequestError('BAD_REQUEST', 'ToCheckout Func Error:' + e, null);
|
|
1070
|
-
}
|
|
1071
|
-
}
|
|
1072
|
-
}
|
|
1073
|
-
exports.CheckoutService = CheckoutService;
|
|
1074
|
-
//# sourceMappingURL=checkout-service.js.map
|