UNPKG

@pisell/pisellos

Version:

一个可扩展的前端模块化SDK框架,支持插件系统

105 lines (103 loc) 3.64 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/modules/Order/index.ts var Order_exports = {}; __export(Order_exports, { OrderModule: () => OrderModule }); module.exports = __toCommonJS(Order_exports); var import_BaseModule = require("../BaseModule"); var import_utils = require("./utils"); var import_utils2 = require("../Product/utils"); var OrderModule = class extends import_BaseModule.BaseModule { constructor(name, version) { super(name, version); this.defaultName = "order"; this.defaultVersion = "1.0.0"; } async initialize(core, options) { this.core = core; this.store = options.store; this.request = this.core.getPlugin("request"); } createOrder(params) { var _a; const order = { type: params.type || "appointment_booking", // 要从外面拿,virtual platform: "H5", sales_channel: "my_pisel", order_sales_channel: "online_store", bookings: [], shop_note: "", schedule_date: "", is_deposit: 0, relation_products: [], relation_forms: [] }; let is_deposit = 0; if (params.cartItems.length > 0) { params.cartItems.forEach((item) => { if (!item._origin.duration) { const { duration, durationType } = (0, import_utils.generateDuration)(item); item._origin.duration = duration; item._origin.sub_type = durationType; } if ((0, import_utils2.isNormalProduct)(item._origin)) { order.relation_products.push(item._origin.product); const relationForms = item._origin.relation_forms || []; order.relation_forms.push(...relationForms); delete item._origin.relation_forms; } else { order.bookings.push(item._origin); } if (item == null ? void 0 : item.deposit) { is_deposit = 1; } }); if (order.type === "appointment_booking") { const firstAppointmentCartItem = (_a = params.cartItems.filter((n) => !(0, import_utils2.isNormalProduct)(n._productOrigin))) == null ? void 0 : _a[0]; if (firstAppointmentCartItem) { order.schedule_date = firstAppointmentCartItem.start_date + " " + firstAppointmentCartItem.start_time + ":00"; } } order.is_deposit = is_deposit; } return order; } checkBeforeSubmitOrder(params) { const { cartItems, type } = params; if (type === "holder") { const hasNoHolderId = cartItems.some((item) => !item.holder_id); if (hasNoHolderId) { return false; } } return true; } async submitOrder(order) { const { url, query } = order; const fetchUrl = url || "/order/appointment"; const params = this.createOrder(query); return this.request.post(fetchUrl, params); } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { OrderModule });