@polyv/product-sdk 1.0.0-rc-20250612.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.js +1 -0
- package/index.es.d.ts +1520 -0
- package/index.es.js +1201 -0
- package/index.umd.js +1 -0
- package/package.json +25 -0
package/index.es.js
ADDED
|
@@ -0,0 +1,1201 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
var PolyvApiUrl = /* @__PURE__ */ ((PolyvApiUrl2) => {
|
|
5
|
+
PolyvApiUrl2["GetProductTagList"] = "/live/v4/watch/channel/product/tag/list";
|
|
6
|
+
PolyvApiUrl2["GetProductListByShowId"] = "/live/v3/sdk/watch/interactive/product/list-by-showId";
|
|
7
|
+
PolyvApiUrl2["GetProductListByTag"] = "/live/v4/watch/channel/product/list";
|
|
8
|
+
PolyvApiUrl2["GetProductDataById"] = "/live/v3/sdk/watch/interactive/product/get-by-product-id";
|
|
9
|
+
PolyvApiUrl2["GetOrderList"] = "/live/v4/watch/channel/viewer/product/order/list";
|
|
10
|
+
PolyvApiUrl2["GetOrderDetail"] = "/live/v4/watch/channel/viewer/product/order/get-detail";
|
|
11
|
+
PolyvApiUrl2["ConfirmOrder"] = "/live/v4/watch/channel/viewer/product/order/finish";
|
|
12
|
+
PolyvApiUrl2["CreateOrder"] = "/live/v4/watch/channel/product/order/create";
|
|
13
|
+
PolyvApiUrl2["PayOrder"] = "/live/v4/watch/channel/product/order/pay";
|
|
14
|
+
PolyvApiUrl2["ApplyOrderRefund"] = "/live/v4/watch/channel/product/order/refund";
|
|
15
|
+
PolyvApiUrl2["GetOrderPaymentProviders"] = "/live/v4/watch/channel/product/order/payment-providers/get";
|
|
16
|
+
PolyvApiUrl2["GetAddressList"] = "/live/v4/watch/channel/viewer/address/list";
|
|
17
|
+
PolyvApiUrl2["GetDefaultAddress"] = "/live/v4/watch/channel/viewer/address/get-default";
|
|
18
|
+
PolyvApiUrl2["AddAddress"] = "/live/v4/watch/channel/viewer/address/save";
|
|
19
|
+
PolyvApiUrl2["UpdateAddress"] = "/live/v4/watch/channel/viewer/address/update";
|
|
20
|
+
PolyvApiUrl2["DeleteAddress"] = "/live/v4/watch/channel/viewer/address/delete";
|
|
21
|
+
return PolyvApiUrl2;
|
|
22
|
+
})(PolyvApiUrl || {});
|
|
23
|
+
function boolToYN(o) {
|
|
24
|
+
if ("boolean" != typeof o) throw new Error("The value argument must be a boolean type");
|
|
25
|
+
return o ? "Y" : "N";
|
|
26
|
+
}
|
|
27
|
+
function ynToBool(o, n) {
|
|
28
|
+
let e = String(o).toUpperCase();
|
|
29
|
+
if ("Y" !== e && "N" !== e) {
|
|
30
|
+
if (null == n) throw new Error('The value argument must be "Y" or "N"');
|
|
31
|
+
e = String(n).toUpperCase();
|
|
32
|
+
}
|
|
33
|
+
return "Y" === e;
|
|
34
|
+
}
|
|
35
|
+
var ProductType = /* @__PURE__ */ ((ProductType2) => {
|
|
36
|
+
ProductType2["Normal"] = "normal";
|
|
37
|
+
ProductType2["Finance"] = "finance";
|
|
38
|
+
ProductType2["Position"] = "position";
|
|
39
|
+
return ProductType2;
|
|
40
|
+
})(ProductType || {});
|
|
41
|
+
var ProductLinkType = /* @__PURE__ */ ((ProductLinkType2) => {
|
|
42
|
+
ProductLinkType2[ProductLinkType2["Normal"] = 10] = "Normal";
|
|
43
|
+
ProductLinkType2[ProductLinkType2["MultiPlatform"] = 11] = "MultiPlatform";
|
|
44
|
+
ProductLinkType2[ProductLinkType2["Native"] = 12] = "Native";
|
|
45
|
+
return ProductLinkType2;
|
|
46
|
+
})(ProductLinkType || {});
|
|
47
|
+
var ProductLinkJumpWay = /* @__PURE__ */ ((ProductLinkJumpWay2) => {
|
|
48
|
+
ProductLinkJumpWay2["PopUp"] = "POP_UP";
|
|
49
|
+
ProductLinkJumpWay2["NewWindow"] = "NEW_WINDOW";
|
|
50
|
+
ProductLinkJumpWay2["CurrentWindow"] = "CURRENT_WINDOW";
|
|
51
|
+
return ProductLinkJumpWay2;
|
|
52
|
+
})(ProductLinkJumpWay || {});
|
|
53
|
+
var ProductStatus = /* @__PURE__ */ ((ProductStatus2) => {
|
|
54
|
+
ProductStatus2[ProductStatus2["OnSale"] = 1] = "OnSale";
|
|
55
|
+
ProductStatus2[ProductStatus2["OffSale"] = 0] = "OffSale";
|
|
56
|
+
return ProductStatus2;
|
|
57
|
+
})(ProductStatus || {});
|
|
58
|
+
var ProductMediaType = /* @__PURE__ */ ((ProductMediaType2) => {
|
|
59
|
+
ProductMediaType2["Image"] = "image";
|
|
60
|
+
ProductMediaType2["MaterialVideo"] = "material-video";
|
|
61
|
+
return ProductMediaType2;
|
|
62
|
+
})(ProductMediaType || {});
|
|
63
|
+
var ProductExplainStatus = /* @__PURE__ */ ((ProductExplainStatus2) => {
|
|
64
|
+
ProductExplainStatus2["NotExplained"] = "notExplained";
|
|
65
|
+
ProductExplainStatus2["Explaining"] = "explaining";
|
|
66
|
+
ProductExplainStatus2["Explained"] = "explained";
|
|
67
|
+
return ProductExplainStatus2;
|
|
68
|
+
})(ProductExplainStatus || {});
|
|
69
|
+
var ProductExplainType = /* @__PURE__ */ ((ProductExplainType2) => {
|
|
70
|
+
ProductExplainType2["Live"] = "live";
|
|
71
|
+
ProductExplainType2["Playback"] = "recordFile";
|
|
72
|
+
return ProductExplainType2;
|
|
73
|
+
})(ProductExplainType || {});
|
|
74
|
+
var ProductBuyType = /* @__PURE__ */ ((ProductBuyType2) => {
|
|
75
|
+
ProductBuyType2["DirectBuy"] = "inner";
|
|
76
|
+
ProductBuyType2["Link"] = "link";
|
|
77
|
+
return ProductBuyType2;
|
|
78
|
+
})(ProductBuyType || {});
|
|
79
|
+
var ProductPriceType = /* @__PURE__ */ ((ProductPriceType2) => {
|
|
80
|
+
ProductPriceType2["Amount"] = "AMOUNT";
|
|
81
|
+
ProductPriceType2["Custom"] = "CUSTOM";
|
|
82
|
+
return ProductPriceType2;
|
|
83
|
+
})(ProductPriceType || {});
|
|
84
|
+
var ProductDeliveryType = /* @__PURE__ */ ((ProductDeliveryType2) => {
|
|
85
|
+
ProductDeliveryType2["Express"] = "express";
|
|
86
|
+
ProductDeliveryType2["Virtual"] = "virtual";
|
|
87
|
+
return ProductDeliveryType2;
|
|
88
|
+
})(ProductDeliveryType || {});
|
|
89
|
+
var ProductServiceType = /* @__PURE__ */ ((ProductServiceType2) => {
|
|
90
|
+
ProductServiceType2["WxWorkCode"] = "wxWorkCode";
|
|
91
|
+
ProductServiceType2["Custom"] = "custom";
|
|
92
|
+
return ProductServiceType2;
|
|
93
|
+
})(ProductServiceType || {});
|
|
94
|
+
var AuthType = /* @__PURE__ */ ((AuthType2) => {
|
|
95
|
+
AuthType2["None"] = "none";
|
|
96
|
+
AuthType2["Custom"] = "custom";
|
|
97
|
+
AuthType2["External"] = "external";
|
|
98
|
+
AuthType2["Direct"] = "direct";
|
|
99
|
+
AuthType2["EnterpriseWeChat"] = "enterpriseWeChat";
|
|
100
|
+
return AuthType2;
|
|
101
|
+
})(AuthType || {});
|
|
102
|
+
function parseFeature(features) {
|
|
103
|
+
let list = [];
|
|
104
|
+
try {
|
|
105
|
+
const arr = JSON.parse(features);
|
|
106
|
+
list = arr.filter((i) => !!i);
|
|
107
|
+
} catch (e) {
|
|
108
|
+
console.error("parseFeature error", e);
|
|
109
|
+
}
|
|
110
|
+
return list;
|
|
111
|
+
}
|
|
112
|
+
function filterInternalData(internalData) {
|
|
113
|
+
const basicData = {
|
|
114
|
+
productId: internalData.productId,
|
|
115
|
+
cover: internalData.cover,
|
|
116
|
+
coverList: [internalData.cover],
|
|
117
|
+
videoList: [],
|
|
118
|
+
mediaList: [],
|
|
119
|
+
name: internalData.name,
|
|
120
|
+
description: internalData.productDesc,
|
|
121
|
+
detail: internalData.productDetail,
|
|
122
|
+
status: internalData.status,
|
|
123
|
+
displayNumber: internalData.showId,
|
|
124
|
+
buttonText: internalData.btnShow,
|
|
125
|
+
featureTags: parseFeature(internalData.features)
|
|
126
|
+
};
|
|
127
|
+
const linkData = {
|
|
128
|
+
linkType: internalData.linkType,
|
|
129
|
+
jumpWay: ProductLinkJumpWay.NewWindow,
|
|
130
|
+
link: internalData.link,
|
|
131
|
+
pcLink: internalData.pcLink,
|
|
132
|
+
mobileLink: internalData.mobileLink,
|
|
133
|
+
mobileAppLink: internalData.mobileAppLink,
|
|
134
|
+
androidLink: internalData.androidLink,
|
|
135
|
+
iosLink: internalData.iosLink,
|
|
136
|
+
otherLink: internalData.otherLink,
|
|
137
|
+
wxMiniprogramOriginalId: internalData.wxMiniprogramOriginalId,
|
|
138
|
+
wxMiniprogramAppId: internalData.wxMiniprogramAppId,
|
|
139
|
+
wxMiniprogramLink: internalData.wxMiniprogramLink
|
|
140
|
+
};
|
|
141
|
+
if (internalData.ext) {
|
|
142
|
+
try {
|
|
143
|
+
const extData = JSON.parse(internalData.ext);
|
|
144
|
+
basicData.coverList = extData.coverList || [internalData.cover];
|
|
145
|
+
basicData.videoList = (extData.videoList || []).map((item) => item.videoId);
|
|
146
|
+
linkData.jumpWay = extData.jumpWay;
|
|
147
|
+
const mediaList = [];
|
|
148
|
+
basicData.videoList.forEach((item) => {
|
|
149
|
+
mediaList.push({
|
|
150
|
+
type: ProductMediaType.MaterialVideo,
|
|
151
|
+
materialId: item
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
basicData.coverList.forEach((item) => {
|
|
155
|
+
mediaList.push({
|
|
156
|
+
type: ProductMediaType.Image,
|
|
157
|
+
url: item
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
basicData.mediaList = mediaList;
|
|
161
|
+
} catch (e) {
|
|
162
|
+
console.error("filterInternlData error", e);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
const explainData = {
|
|
166
|
+
explainStatus: internalData.explainStatus,
|
|
167
|
+
explainType: internalData.explainType
|
|
168
|
+
};
|
|
169
|
+
let productData;
|
|
170
|
+
const productType = internalData.productType;
|
|
171
|
+
switch (productType) {
|
|
172
|
+
case ProductType.Normal: {
|
|
173
|
+
productData = {
|
|
174
|
+
...basicData,
|
|
175
|
+
...linkData,
|
|
176
|
+
...explainData,
|
|
177
|
+
productType: ProductType.Normal,
|
|
178
|
+
priceType: internalData.priceType,
|
|
179
|
+
buyType: internalData.buyType,
|
|
180
|
+
realPrice: internalData.realPrice,
|
|
181
|
+
originPrice: internalData.price,
|
|
182
|
+
customPrice: internalData.customPrice,
|
|
183
|
+
priceVisible: ynToBool(internalData.openPriceEnable, "Y"),
|
|
184
|
+
deliveryType: internalData.deliveryType,
|
|
185
|
+
customerServiceContact: internalData.customerServiceContact,
|
|
186
|
+
customerServiceType: internalData.customerServiceType,
|
|
187
|
+
stockEnabled: ynToBool(internalData.stockEnabled, "N"),
|
|
188
|
+
stock: internalData.stock
|
|
189
|
+
};
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
case ProductType.Finance: {
|
|
193
|
+
productData = {
|
|
194
|
+
...basicData,
|
|
195
|
+
...linkData,
|
|
196
|
+
...explainData,
|
|
197
|
+
productType: ProductType.Finance,
|
|
198
|
+
yield: internalData.yield
|
|
199
|
+
};
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
case ProductType.Position: {
|
|
203
|
+
basicData.description = "";
|
|
204
|
+
basicData.detail = internalData.productDesc;
|
|
205
|
+
let treatment = "";
|
|
206
|
+
try {
|
|
207
|
+
const params = JSON.parse(internalData.params);
|
|
208
|
+
treatment = params.treatment;
|
|
209
|
+
} catch (e) {
|
|
210
|
+
console.error(e);
|
|
211
|
+
}
|
|
212
|
+
productData = {
|
|
213
|
+
...basicData,
|
|
214
|
+
...linkData,
|
|
215
|
+
...explainData,
|
|
216
|
+
productType: ProductType.Position,
|
|
217
|
+
treatment
|
|
218
|
+
};
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (!productData) {
|
|
223
|
+
throw new Error("generate data fail");
|
|
224
|
+
}
|
|
225
|
+
return productData;
|
|
226
|
+
}
|
|
227
|
+
class EventEmitter {
|
|
228
|
+
constructor() {
|
|
229
|
+
this.__eventStore = {};
|
|
230
|
+
}
|
|
231
|
+
__addOnEvent(t, e, n, o) {
|
|
232
|
+
if (!e || !n) return;
|
|
233
|
+
let r = this.__eventStore[e];
|
|
234
|
+
r || (r = []), r.push({ type: t, handler: n, callbackHandler: n.bind(o) }), this.__eventStore[e] = r;
|
|
235
|
+
}
|
|
236
|
+
on(t, e, n = this) {
|
|
237
|
+
this.__addOnEvent("normal", t, e, n);
|
|
238
|
+
}
|
|
239
|
+
once(t, e, n = this) {
|
|
240
|
+
this.__addOnEvent("once", t, e, n);
|
|
241
|
+
}
|
|
242
|
+
off(t, e) {
|
|
243
|
+
let n = this.__eventStore[t];
|
|
244
|
+
n && (n = n.filter((t2) => t2.handler !== e), this.__eventStore[t] = n);
|
|
245
|
+
}
|
|
246
|
+
emit(t, e) {
|
|
247
|
+
const n = this.__eventStore[t];
|
|
248
|
+
n && n.forEach((n2) => {
|
|
249
|
+
const { type: o, handler: r, callbackHandler: _ } = n2;
|
|
250
|
+
"function" == typeof _ && _(e), "once" === o && this.off(t, r);
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
destroy() {
|
|
254
|
+
this.__eventStore = {};
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
258
|
+
function hasOwnProp(r, n) {
|
|
259
|
+
return hasOwnProperty.call(r, n);
|
|
260
|
+
}
|
|
261
|
+
function assignProps(r, ...n) {
|
|
262
|
+
if (null == r) throw new TypeError("Cannot convert undefined or null to object");
|
|
263
|
+
for (let o = 0; o < n.length; o++) {
|
|
264
|
+
const t = n[o];
|
|
265
|
+
if (null != t) for (const n2 in t) "__proto__" !== n2 && hasOwnProp(t, n2) && (r[n2] = t[n2]);
|
|
266
|
+
}
|
|
267
|
+
return r;
|
|
268
|
+
}
|
|
269
|
+
function addToResult(n, o, e, t) {
|
|
270
|
+
if (null == e && (e = ""), "" !== e || !t.ignoreEmpty) {
|
|
271
|
+
if ("function" == typeof t.encode) {
|
|
272
|
+
o = t.encode(o);
|
|
273
|
+
e = -1 !== ["boolean", "string", "number"].indexOf(typeof e) ? t.encode(String(e)) : "";
|
|
274
|
+
}
|
|
275
|
+
n.push(o + "=" + e);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
function handleMultiValues(n, o, e, t) {
|
|
279
|
+
e.forEach((e2) => {
|
|
280
|
+
addToResult(n, o, e2, t);
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
function stringify(n, o) {
|
|
284
|
+
const e = assignProps({ encode: encodeURIComponent }, o), t = [];
|
|
285
|
+
let i, r;
|
|
286
|
+
for (i in n) hasOwnProp(n, i) && (r = n[i], Array.isArray(r) ? handleMultiValues(t, i, r, e) : addToResult(t, i, r, e));
|
|
287
|
+
return t.join("&");
|
|
288
|
+
}
|
|
289
|
+
function splitURL(e) {
|
|
290
|
+
const t = { leftContext: "" };
|
|
291
|
+
let n = e.indexOf("#");
|
|
292
|
+
return -1 !== n && (t.hash = e.slice(n + 1), e = e.slice(0, n)), n = e.indexOf("?"), -1 !== n && (t.search = e.slice(n + 1), e = e.slice(0, n)), t.leftContext = e, t;
|
|
293
|
+
}
|
|
294
|
+
function joinURL(e) {
|
|
295
|
+
let t = e.leftContext;
|
|
296
|
+
return null != e.search && (t += "?" + e.search), null != e.hash && (t += "#" + e.hash), t;
|
|
297
|
+
}
|
|
298
|
+
function concat(i, r, t) {
|
|
299
|
+
if (i = String(i), null == r) return i;
|
|
300
|
+
if (!(r = "string" == typeof r ? r.replace(/^[?&]/, "") : stringify(r, t))) return i;
|
|
301
|
+
const n = splitURL(i);
|
|
302
|
+
let e = n.search || "";
|
|
303
|
+
return e && "&" !== e.slice(-1) && (e += "&"), e += r, n.search = e, joinURL(n);
|
|
304
|
+
}
|
|
305
|
+
var ProductEvents = /* @__PURE__ */ ((ProductEvents2) => {
|
|
306
|
+
ProductEvents2["OnSaleProduct"] = "OnSaleProduct";
|
|
307
|
+
ProductEvents2["OffSaleProduct"] = "OffSaleProduct";
|
|
308
|
+
ProductEvents2["AddProduct"] = "AddProduct";
|
|
309
|
+
ProductEvents2["DeleteProduct"] = "DeleteProduct";
|
|
310
|
+
ProductEvents2["ChangeProduct"] = "ChangeProduct";
|
|
311
|
+
ProductEvents2["MoveProduct"] = "MoveProduct";
|
|
312
|
+
ProductEvents2["ChangeProductRank"] = "ChangeProductRank";
|
|
313
|
+
ProductEvents2["ProductSoldOut"] = "ProductSoldOut";
|
|
314
|
+
ProductEvents2["PushProduct"] = "PushProduct";
|
|
315
|
+
ProductEvents2["CancelPushProduct"] = "CancelPushProduct";
|
|
316
|
+
ProductEvents2["ProductListEnabled"] = "ProductListEnabled";
|
|
317
|
+
ProductEvents2["RefreshProductList"] = "RefreshProductList";
|
|
318
|
+
ProductEvents2["ProductClick"] = "ProductClick";
|
|
319
|
+
ProductEvents2["ProductClickTimes"] = "ProductClickTimes";
|
|
320
|
+
return ProductEvents2;
|
|
321
|
+
})(ProductEvents || {});
|
|
322
|
+
const appName = "product";
|
|
323
|
+
class Product {
|
|
324
|
+
constructor(iarCore, config) {
|
|
325
|
+
__publicField(this, "ProductType", ProductType);
|
|
326
|
+
__publicField(this, "ProductLinkType", ProductLinkType);
|
|
327
|
+
__publicField(this, "ProductLinkJumpWay", ProductLinkJumpWay);
|
|
328
|
+
__publicField(this, "ProductBuyType", ProductBuyType);
|
|
329
|
+
__publicField(this, "ProductStatus", ProductStatus);
|
|
330
|
+
__publicField(this, "ProductEvents", ProductEvents);
|
|
331
|
+
__publicField(this, "ProductPriceType", ProductPriceType);
|
|
332
|
+
__publicField(this, "ProductExplainStatus", ProductExplainStatus);
|
|
333
|
+
__publicField(this, "ProductMediaType", ProductMediaType);
|
|
334
|
+
__publicField(this, "ProductDeliveryType", ProductDeliveryType);
|
|
335
|
+
__publicField(this, "ProductServiceType", ProductServiceType);
|
|
336
|
+
__publicField(this, "eventEmitter", new EventEmitter());
|
|
337
|
+
__publicField(this, "__handleProductMessage", (socketData) => {
|
|
338
|
+
const status = Number(socketData.status);
|
|
339
|
+
switch (status) {
|
|
340
|
+
// 上架商品
|
|
341
|
+
case 1: {
|
|
342
|
+
this.eventEmitter.emit(ProductEvents.OnSaleProduct, {
|
|
343
|
+
productData: filterInternalData(socketData.content)
|
|
344
|
+
});
|
|
345
|
+
this.eventEmitter.emit(ProductEvents.RefreshProductList, {});
|
|
346
|
+
break;
|
|
347
|
+
}
|
|
348
|
+
// 下架商品
|
|
349
|
+
case 2: {
|
|
350
|
+
this.eventEmitter.emit(ProductEvents.OffSaleProduct, {
|
|
351
|
+
productData: filterInternalData(socketData.content)
|
|
352
|
+
});
|
|
353
|
+
this.eventEmitter.emit(ProductEvents.RefreshProductList, {});
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
// 删除商品
|
|
357
|
+
case 3: {
|
|
358
|
+
this.eventEmitter.emit(ProductEvents.DeleteProduct, {
|
|
359
|
+
productId: socketData.content.productId
|
|
360
|
+
});
|
|
361
|
+
this.eventEmitter.emit(ProductEvents.RefreshProductList, {});
|
|
362
|
+
break;
|
|
363
|
+
}
|
|
364
|
+
// 添加商品
|
|
365
|
+
case 4: {
|
|
366
|
+
this.eventEmitter.emit(ProductEvents.AddProduct, {
|
|
367
|
+
productData: filterInternalData(socketData.content)
|
|
368
|
+
});
|
|
369
|
+
this.eventEmitter.emit(ProductEvents.RefreshProductList, {});
|
|
370
|
+
break;
|
|
371
|
+
}
|
|
372
|
+
// 修改商品,例如商品开价
|
|
373
|
+
case 5: {
|
|
374
|
+
this.eventEmitter.emit(ProductEvents.ChangeProduct, {
|
|
375
|
+
productData: filterInternalData(socketData.content)
|
|
376
|
+
});
|
|
377
|
+
this.eventEmitter.emit(ProductEvents.RefreshProductList, {});
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
// 移动商品
|
|
381
|
+
case 6:
|
|
382
|
+
case 7: {
|
|
383
|
+
const content = socketData.content;
|
|
384
|
+
const targetProducts = [
|
|
385
|
+
filterInternalData(content[0]),
|
|
386
|
+
filterInternalData(content[1])
|
|
387
|
+
];
|
|
388
|
+
this.eventEmitter.emit(ProductEvents.MoveProduct, {
|
|
389
|
+
targetProducts
|
|
390
|
+
});
|
|
391
|
+
this.eventEmitter.emit(ProductEvents.RefreshProductList, {});
|
|
392
|
+
break;
|
|
393
|
+
}
|
|
394
|
+
// 修改排序
|
|
395
|
+
case 15: {
|
|
396
|
+
this.eventEmitter.emit(ProductEvents.ChangeProductRank, {
|
|
397
|
+
productData: filterInternalData(socketData.content)
|
|
398
|
+
});
|
|
399
|
+
this.eventEmitter.emit(ProductEvents.RefreshProductList, {});
|
|
400
|
+
break;
|
|
401
|
+
}
|
|
402
|
+
// 推送商品
|
|
403
|
+
case 9: {
|
|
404
|
+
const content = socketData.content;
|
|
405
|
+
this.eventEmitter.emit(ProductEvents.PushProduct, {
|
|
406
|
+
productData: filterInternalData(content),
|
|
407
|
+
pushRule: content.productPushRule
|
|
408
|
+
});
|
|
409
|
+
this.eventEmitter.emit(ProductEvents.RefreshProductList, {});
|
|
410
|
+
break;
|
|
411
|
+
}
|
|
412
|
+
// 商品列表开关
|
|
413
|
+
case 10: {
|
|
414
|
+
const content = socketData.content;
|
|
415
|
+
this.eventEmitter.emit(ProductEvents.ProductListEnabled, {
|
|
416
|
+
enabled: content.enabled === "Y"
|
|
417
|
+
});
|
|
418
|
+
this.eventEmitter.emit(ProductEvents.RefreshProductList, {});
|
|
419
|
+
break;
|
|
420
|
+
}
|
|
421
|
+
// 取消推送
|
|
422
|
+
case 11: {
|
|
423
|
+
this.eventEmitter.emit(ProductEvents.CancelPushProduct, {
|
|
424
|
+
productId: socketData.content.productId
|
|
425
|
+
});
|
|
426
|
+
this.eventEmitter.emit(ProductEvents.RefreshProductList, {});
|
|
427
|
+
break;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
__publicField(this, "__handleRefreshProductList", () => {
|
|
432
|
+
this.eventEmitter.emit(ProductEvents.RefreshProductList, {});
|
|
433
|
+
});
|
|
434
|
+
__publicField(this, "__handleProductClickEvent", (socketData) => {
|
|
435
|
+
this.eventEmitter.emit(ProductEvents.ProductClick, {
|
|
436
|
+
productId: socketData.productId,
|
|
437
|
+
name: socketData.positionName,
|
|
438
|
+
productType: socketData.type
|
|
439
|
+
});
|
|
440
|
+
});
|
|
441
|
+
__publicField(this, "__handleProductClickTimes", (socketData) => {
|
|
442
|
+
this.eventEmitter.emit(ProductEvents.ProductClickTimes, {
|
|
443
|
+
productId: socketData.productId,
|
|
444
|
+
name: socketData.positionName,
|
|
445
|
+
productType: socketData.type,
|
|
446
|
+
times: socketData.times
|
|
447
|
+
});
|
|
448
|
+
});
|
|
449
|
+
this.iarCore = iarCore;
|
|
450
|
+
this.config = config;
|
|
451
|
+
iarCore.addSocketHandles(appName, {
|
|
452
|
+
PRODUCT_MESSAGE: this.__handleProductMessage
|
|
453
|
+
});
|
|
454
|
+
iarCore.addSocketHandles(appName, {
|
|
455
|
+
REFRESH_PRODUCT_LIST: this.__handleRefreshProductList,
|
|
456
|
+
PRODUCT_CLICK: this.__handleProductClickEvent,
|
|
457
|
+
PRODUCT_CLICK_TIMES: this.__handleProductClickTimes
|
|
458
|
+
}, "product");
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* 获取商品标签列表
|
|
462
|
+
* @param params 获取参数
|
|
463
|
+
* @example
|
|
464
|
+
* ```js
|
|
465
|
+
* const data = await productTarget.getProductTagList({ pageNumber: 1 });
|
|
466
|
+
* console.log('标签列表', data.contents);
|
|
467
|
+
* ```
|
|
468
|
+
*/
|
|
469
|
+
async getProductTagList(params = {}) {
|
|
470
|
+
const pageNumber = params.pageNumber ?? 1;
|
|
471
|
+
const pageSize = params.pageSize ?? 10;
|
|
472
|
+
return this.iarCore.polyvApi.get(
|
|
473
|
+
PolyvApiUrl.GetProductTagList,
|
|
474
|
+
{
|
|
475
|
+
pageNumber,
|
|
476
|
+
pageSize
|
|
477
|
+
}
|
|
478
|
+
);
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* 获取商品列表
|
|
482
|
+
*
|
|
483
|
+
* 该方法可通过 **商品序号**、**标签 id + 关键词** 两种方式获取商品列表,
|
|
484
|
+
* @param params 获取参数
|
|
485
|
+
* @example
|
|
486
|
+
* ```js
|
|
487
|
+
* // 通过商品序号获取:获取 12 号商品之后的商品列表
|
|
488
|
+
* const data = await productTarget.getProductList({ displayNumber: 12 });
|
|
489
|
+
*
|
|
490
|
+
* // 通过标签 id 或关键词获取:获取标签 id 为 8 的商品列表,并根据关键词 '水果' 进行搜索,页数为第 2 页
|
|
491
|
+
* const data = await productTarget.getProductList({ tagId: 8, keyword: '水果', page: 2 });
|
|
492
|
+
* ```
|
|
493
|
+
*/
|
|
494
|
+
async getProductList(params = {}) {
|
|
495
|
+
const { count = 10 } = params;
|
|
496
|
+
let productList = [];
|
|
497
|
+
let toppingProduct;
|
|
498
|
+
let total = 0;
|
|
499
|
+
if (params.keyword || params.tagId) {
|
|
500
|
+
const { page = 1 } = params;
|
|
501
|
+
const data = await this.iarCore.polyvApi.get(
|
|
502
|
+
PolyvApiUrl.GetProductListByTag,
|
|
503
|
+
{
|
|
504
|
+
keyword: params.keyword,
|
|
505
|
+
tagId: params.tagId,
|
|
506
|
+
pageNumber: page,
|
|
507
|
+
pageSize: count
|
|
508
|
+
}
|
|
509
|
+
);
|
|
510
|
+
productList = data.contents;
|
|
511
|
+
total = data.totalItems;
|
|
512
|
+
} else {
|
|
513
|
+
const data = await this.iarCore.polyvApi.get(
|
|
514
|
+
PolyvApiUrl.GetProductListByShowId,
|
|
515
|
+
{
|
|
516
|
+
count,
|
|
517
|
+
showId: params.displayNumber
|
|
518
|
+
},
|
|
519
|
+
{
|
|
520
|
+
useAESDecrypt: true
|
|
521
|
+
}
|
|
522
|
+
);
|
|
523
|
+
productList = data.content;
|
|
524
|
+
toppingProduct = data.toppingProduct;
|
|
525
|
+
total = data.total;
|
|
526
|
+
}
|
|
527
|
+
return {
|
|
528
|
+
contents: productList.map((data) => {
|
|
529
|
+
return filterInternalData(data);
|
|
530
|
+
}),
|
|
531
|
+
toppingProduct: toppingProduct ? filterInternalData(toppingProduct) : void 0,
|
|
532
|
+
total
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
/**
|
|
536
|
+
* 获取商品数据
|
|
537
|
+
* @param productId 商品 id
|
|
538
|
+
*/
|
|
539
|
+
async getProductData(productId) {
|
|
540
|
+
var _a;
|
|
541
|
+
const data = await this.iarCore.polyvApi.get(
|
|
542
|
+
PolyvApiUrl.GetProductDataById,
|
|
543
|
+
{
|
|
544
|
+
productId
|
|
545
|
+
},
|
|
546
|
+
{
|
|
547
|
+
useAESDecrypt: true
|
|
548
|
+
}
|
|
549
|
+
);
|
|
550
|
+
const productData = filterInternalData(data);
|
|
551
|
+
if ((_a = productData.detail) == null ? void 0 : _a.endsWith(".json")) {
|
|
552
|
+
const res = await this.iarCore.otherApi.get(productData.detail, {});
|
|
553
|
+
productData.detail = res.productDetail;
|
|
554
|
+
}
|
|
555
|
+
return productData;
|
|
556
|
+
}
|
|
557
|
+
/**
|
|
558
|
+
* 发送商品点击事件
|
|
559
|
+
*
|
|
560
|
+
* 当观众点击商品时,调用该方法发送商品点击事件
|
|
561
|
+
* @param params 发送参数
|
|
562
|
+
* @example
|
|
563
|
+
* ```js
|
|
564
|
+
* await productTarget.sendProductClickEvent({
|
|
565
|
+
* productId: 123,
|
|
566
|
+
* name: '商品名称',
|
|
567
|
+
* productType: 'normal',
|
|
568
|
+
* });
|
|
569
|
+
* ```
|
|
570
|
+
*/
|
|
571
|
+
async sendProductClickEvent(params) {
|
|
572
|
+
const userInfo = await this.iarCore.getUserInfo();
|
|
573
|
+
const channelInfo = await this.iarCore.getChannelInfo();
|
|
574
|
+
this.iarCore.emitSocket({
|
|
575
|
+
EVENT: "PRODUCT_CLICK",
|
|
576
|
+
data: {
|
|
577
|
+
productId: params.productId,
|
|
578
|
+
type: params.productType,
|
|
579
|
+
nickName: userInfo.nick,
|
|
580
|
+
positionName: params.name
|
|
581
|
+
},
|
|
582
|
+
roomId: channelInfo.channelId
|
|
583
|
+
}, "product");
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* 关闭当前正在推送中的商品
|
|
587
|
+
*
|
|
588
|
+
* 当需要关闭 UI 层的推送节点时,调用该方法关闭当前正在推送中的商品
|
|
589
|
+
* @example
|
|
590
|
+
* ```js
|
|
591
|
+
* await productTarget.closeProductPush();
|
|
592
|
+
* ```
|
|
593
|
+
*/
|
|
594
|
+
closeProductPush() {
|
|
595
|
+
this.eventEmitter.emit(ProductEvents.CancelPushProduct, {});
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* 获取商品讲解开关
|
|
599
|
+
*
|
|
600
|
+
* 获取当前频道是否开启商品讲解
|
|
601
|
+
* @example
|
|
602
|
+
* ```js
|
|
603
|
+
* const enabled = await productTarget.getProductExplainEnabled();
|
|
604
|
+
* console.log('商品讲解开关', enabled);
|
|
605
|
+
* ```
|
|
606
|
+
*/
|
|
607
|
+
async getProductExplainEnabled() {
|
|
608
|
+
const channelConfig = await this.config.getProductConfig();
|
|
609
|
+
return (channelConfig == null ? void 0 : channelConfig.productExplainEnabled) ?? false;
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* 获取当前频道是否开启点击"外链购买"商品的封面/标题区域直接跳转外链
|
|
613
|
+
* @example
|
|
614
|
+
* ```js
|
|
615
|
+
* const enabled = await productTarget.getOutLinkProductRedirectEnabled();
|
|
616
|
+
* console.log('商品点击直接跳转外链开关', enabled);
|
|
617
|
+
* ```
|
|
618
|
+
*/
|
|
619
|
+
async getOutLinkProductRedirectEnabled() {
|
|
620
|
+
const channelConfig = await this.config.getProductConfig();
|
|
621
|
+
return (channelConfig == null ? void 0 : channelConfig.outLinkProductRedirectEnabled) ?? false;
|
|
622
|
+
}
|
|
623
|
+
/**
|
|
624
|
+
* 生成商品讲解页面地址
|
|
625
|
+
* @param params url 携带参数
|
|
626
|
+
* @example
|
|
627
|
+
* ```js
|
|
628
|
+
* const url = await productTarget.generateProductExplainPageUrl({ productId: 123 });
|
|
629
|
+
* console.log('商品讲解页面地址', url);
|
|
630
|
+
* ```
|
|
631
|
+
*/
|
|
632
|
+
async generateProductExplainPageUrl(params) {
|
|
633
|
+
const domainInfo = this.iarCore.getDomainInfo();
|
|
634
|
+
const channelInfo = await this.iarCore.getChannelInfo();
|
|
635
|
+
const queryParams = {
|
|
636
|
+
channelId: channelInfo.channelId,
|
|
637
|
+
...params || {}
|
|
638
|
+
};
|
|
639
|
+
return concat(`${domainInfo.watchPageDomain}/landing/product/explain`, queryParams);
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* 获取商品支付订单是否开启
|
|
643
|
+
* @example
|
|
644
|
+
* ```js
|
|
645
|
+
* const enabled = await productTarget.getProductPayOrderEnabled();
|
|
646
|
+
* console.log('商品支付订单是否开启', enabled);
|
|
647
|
+
* ```
|
|
648
|
+
*/
|
|
649
|
+
async getProductPayOrderEnabled() {
|
|
650
|
+
const channelConfig = await this.config.getProductConfig();
|
|
651
|
+
if (!channelConfig) return false;
|
|
652
|
+
return channelConfig.productPayOrderEnabled;
|
|
653
|
+
}
|
|
654
|
+
async getCurrentPushingProduct() {
|
|
655
|
+
const channelConfig = await this.config.getProductConfig();
|
|
656
|
+
if (!channelConfig) return;
|
|
657
|
+
return channelConfig.channelProductPushingStatusVO;
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* 判断当前用户是否支持直接购买商品
|
|
661
|
+
* @example
|
|
662
|
+
* ```js
|
|
663
|
+
* const supported = await productTarget.getSupportToDirectBuy();
|
|
664
|
+
* console.log('是否支持直接购买', supported);
|
|
665
|
+
* ```
|
|
666
|
+
*/
|
|
667
|
+
async getSupportToDirectBuy() {
|
|
668
|
+
if (!await this.getProductPayOrderEnabled()) {
|
|
669
|
+
return false;
|
|
670
|
+
}
|
|
671
|
+
const userInfo = await this.iarCore.getUserInfo();
|
|
672
|
+
if (!userInfo.unionId) return false;
|
|
673
|
+
const authType = userInfo.authType;
|
|
674
|
+
if (!authType || authType === AuthType.None) {
|
|
675
|
+
return true;
|
|
676
|
+
}
|
|
677
|
+
const notSupportAuthTypes = [
|
|
678
|
+
AuthType.Custom,
|
|
679
|
+
AuthType.External,
|
|
680
|
+
AuthType.Direct,
|
|
681
|
+
AuthType.EnterpriseWeChat
|
|
682
|
+
];
|
|
683
|
+
if (notSupportAuthTypes.includes(authType)) {
|
|
684
|
+
return false;
|
|
685
|
+
}
|
|
686
|
+
return true;
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
var PaymentProvider = /* @__PURE__ */ ((PaymentProvider2) => {
|
|
690
|
+
PaymentProvider2["Wechat"] = "WECHAT";
|
|
691
|
+
PaymentProvider2["Alipay"] = "ALIPAY";
|
|
692
|
+
return PaymentProvider2;
|
|
693
|
+
})(PaymentProvider || {});
|
|
694
|
+
var OrderStatus = /* @__PURE__ */ ((OrderStatus2) => {
|
|
695
|
+
OrderStatus2["WaitPay"] = "wait_pay";
|
|
696
|
+
OrderStatus2["WaitDelivery"] = "wait_delivery";
|
|
697
|
+
OrderStatus2["Delivering"] = "delivering";
|
|
698
|
+
OrderStatus2["Finish"] = "finish";
|
|
699
|
+
OrderStatus2["Close"] = "close";
|
|
700
|
+
OrderStatus2["Refunding"] = "refunding";
|
|
701
|
+
OrderStatus2["Refunded"] = "refunded";
|
|
702
|
+
return OrderStatus2;
|
|
703
|
+
})(OrderStatus || {});
|
|
704
|
+
var PayStatus = /* @__PURE__ */ ((PayStatus2) => {
|
|
705
|
+
PayStatus2["WaitPay"] = "wait_pay";
|
|
706
|
+
PayStatus2["Payed"] = "payed";
|
|
707
|
+
PayStatus2["Free"] = "free";
|
|
708
|
+
return PayStatus2;
|
|
709
|
+
})(PayStatus || {});
|
|
710
|
+
var RefundStatus = /* @__PURE__ */ ((RefundStatus2) => {
|
|
711
|
+
RefundStatus2["Success"] = "SUCCESS";
|
|
712
|
+
RefundStatus2["Fail"] = "FAIL";
|
|
713
|
+
RefundStatus2["Processing"] = "PROCESSING";
|
|
714
|
+
return RefundStatus2;
|
|
715
|
+
})(RefundStatus || {});
|
|
716
|
+
var CreateOrderFailReason = /* @__PURE__ */ ((CreateOrderFailReason2) => {
|
|
717
|
+
CreateOrderFailReason2["Unknown"] = "unknown";
|
|
718
|
+
return CreateOrderFailReason2;
|
|
719
|
+
})(CreateOrderFailReason || {});
|
|
720
|
+
var OrderRefundFailReason = /* @__PURE__ */ ((OrderRefundFailReason2) => {
|
|
721
|
+
OrderRefundFailReason2["Unknown"] = "unknown";
|
|
722
|
+
return OrderRefundFailReason2;
|
|
723
|
+
})(OrderRefundFailReason || {});
|
|
724
|
+
function mapInternalProductToOrderProduct(internalProduct) {
|
|
725
|
+
return {
|
|
726
|
+
customerServiceContact: internalProduct.customerServiceContact,
|
|
727
|
+
customerServiceType: internalProduct.customerServiceType,
|
|
728
|
+
deliveryType: internalProduct.deliveryType,
|
|
729
|
+
cover: internalProduct.productCover,
|
|
730
|
+
name: internalProduct.productName,
|
|
731
|
+
productId: internalProduct.productId,
|
|
732
|
+
productSnapshotId: internalProduct.productSnapshotId,
|
|
733
|
+
quantity: internalProduct.quantity,
|
|
734
|
+
realPrice: internalProduct.amount,
|
|
735
|
+
totalAmount: internalProduct.totalAmount
|
|
736
|
+
};
|
|
737
|
+
}
|
|
738
|
+
function mapInternalAddressToExpressInfo(internalAddress) {
|
|
739
|
+
if (!internalAddress) {
|
|
740
|
+
return {
|
|
741
|
+
id: "",
|
|
742
|
+
address: "",
|
|
743
|
+
area: "",
|
|
744
|
+
mobile: "",
|
|
745
|
+
name: ""
|
|
746
|
+
};
|
|
747
|
+
}
|
|
748
|
+
return {
|
|
749
|
+
id: "",
|
|
750
|
+
address: internalAddress.address,
|
|
751
|
+
area: internalAddress.area,
|
|
752
|
+
mobile: internalAddress.mobile,
|
|
753
|
+
name: internalAddress.name
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
function mapInternalOrderToOrderData(internalOrder) {
|
|
757
|
+
const basicDataForList = {
|
|
758
|
+
amount: internalOrder.amount,
|
|
759
|
+
channelId: internalOrder.channelId,
|
|
760
|
+
products: internalOrder.products.map(mapInternalProductToOrderProduct),
|
|
761
|
+
orderNo: internalOrder.orderNo,
|
|
762
|
+
expressInfo: mapInternalAddressToExpressInfo()
|
|
763
|
+
};
|
|
764
|
+
switch (internalOrder.status) {
|
|
765
|
+
case OrderStatus.WaitPay:
|
|
766
|
+
return {
|
|
767
|
+
...basicDataForList,
|
|
768
|
+
status: OrderStatus.WaitPay,
|
|
769
|
+
expiredAt: internalOrder.expireTime
|
|
770
|
+
};
|
|
771
|
+
case OrderStatus.Close:
|
|
772
|
+
return {
|
|
773
|
+
...basicDataForList,
|
|
774
|
+
status: OrderStatus.Close,
|
|
775
|
+
expiredAt: internalOrder.expireTime
|
|
776
|
+
};
|
|
777
|
+
default:
|
|
778
|
+
return {
|
|
779
|
+
...basicDataForList,
|
|
780
|
+
status: internalOrder.status
|
|
781
|
+
};
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
function mapInternalOrderDetailToOrderData(detail) {
|
|
785
|
+
const expressInfo = mapInternalAddressToExpressInfo(detail.addressExt);
|
|
786
|
+
const basicData = {
|
|
787
|
+
amount: detail.amount,
|
|
788
|
+
channelId: null,
|
|
789
|
+
products: detail.products.map(mapInternalProductToOrderProduct),
|
|
790
|
+
orderNo: detail.orderNo,
|
|
791
|
+
createAt: detail.createTime,
|
|
792
|
+
transactionId: detail.transactionId,
|
|
793
|
+
expressEnabled: ynToBool(detail.expressEnabled, "N"),
|
|
794
|
+
expressInfo
|
|
795
|
+
};
|
|
796
|
+
switch (detail.status) {
|
|
797
|
+
case OrderStatus.WaitPay:
|
|
798
|
+
return {
|
|
799
|
+
...basicData,
|
|
800
|
+
status: OrderStatus.WaitPay,
|
|
801
|
+
expiredAt: detail.expireTime
|
|
802
|
+
};
|
|
803
|
+
case OrderStatus.WaitDelivery:
|
|
804
|
+
return {
|
|
805
|
+
...basicData,
|
|
806
|
+
status: OrderStatus.WaitDelivery,
|
|
807
|
+
payAt: detail.payTime
|
|
808
|
+
};
|
|
809
|
+
case OrderStatus.Delivering:
|
|
810
|
+
return {
|
|
811
|
+
...basicData,
|
|
812
|
+
status: OrderStatus.Delivering,
|
|
813
|
+
payAt: detail.payTime,
|
|
814
|
+
deliveryAt: detail.deliveryTime
|
|
815
|
+
};
|
|
816
|
+
case OrderStatus.Finish:
|
|
817
|
+
return {
|
|
818
|
+
...basicData,
|
|
819
|
+
status: OrderStatus.Finish,
|
|
820
|
+
payAt: detail.payTime,
|
|
821
|
+
deliveryAt: detail.deliveryTime,
|
|
822
|
+
finishAt: detail.finishTime
|
|
823
|
+
};
|
|
824
|
+
case OrderStatus.Close:
|
|
825
|
+
return {
|
|
826
|
+
...basicData,
|
|
827
|
+
status: OrderStatus.Close,
|
|
828
|
+
expiredAt: detail.expireTime
|
|
829
|
+
};
|
|
830
|
+
case OrderStatus.Refunding:
|
|
831
|
+
return {
|
|
832
|
+
...basicData,
|
|
833
|
+
status: OrderStatus.Refunding,
|
|
834
|
+
payAt: detail.payTime,
|
|
835
|
+
refundAt: detail.refundTime,
|
|
836
|
+
deliveryAt: detail.deliveryTime
|
|
837
|
+
};
|
|
838
|
+
case OrderStatus.Refunded:
|
|
839
|
+
return {
|
|
840
|
+
...basicData,
|
|
841
|
+
status: OrderStatus.Refunded,
|
|
842
|
+
payAt: detail.payTime,
|
|
843
|
+
refundAt: detail.refundTime,
|
|
844
|
+
deliveryAt: detail.deliveryTime,
|
|
845
|
+
expiredAt: detail.expireTime
|
|
846
|
+
};
|
|
847
|
+
default: {
|
|
848
|
+
console.error(`Unknown order status:${detail.status}`);
|
|
849
|
+
const fallback = {
|
|
850
|
+
...basicData,
|
|
851
|
+
status: detail.status
|
|
852
|
+
};
|
|
853
|
+
return fallback;
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
function mapInternalCreateOrderResponse(data) {
|
|
858
|
+
return {
|
|
859
|
+
type: data.type,
|
|
860
|
+
aliPayLink: data.codeUrl,
|
|
861
|
+
orderNo: data.payId,
|
|
862
|
+
payStatus: data.payStatus,
|
|
863
|
+
wxAppId: data.appId,
|
|
864
|
+
nonceStr: data.nonceStr,
|
|
865
|
+
package: data.prepayId,
|
|
866
|
+
paySign: data.paySign,
|
|
867
|
+
signType: data.signType,
|
|
868
|
+
timeStamp: Number(data.timeStamp),
|
|
869
|
+
payProvider: data.payProvider
|
|
870
|
+
};
|
|
871
|
+
}
|
|
872
|
+
class Order {
|
|
873
|
+
constructor(iarCore, config) {
|
|
874
|
+
__publicField(this, "OrderStatus", OrderStatus);
|
|
875
|
+
__publicField(this, "PayStatus", PayStatus);
|
|
876
|
+
__publicField(this, "PaymentProvider", PaymentProvider);
|
|
877
|
+
__publicField(this, "ProductBuyType", ProductBuyType);
|
|
878
|
+
__publicField(this, "ProductType", ProductType);
|
|
879
|
+
__publicField(this, "ProductDeliveryType", ProductDeliveryType);
|
|
880
|
+
__publicField(this, "RefundStatus", RefundStatus);
|
|
881
|
+
__publicField(this, "CreateOrderFailReason", CreateOrderFailReason);
|
|
882
|
+
__publicField(this, "OrderRefundFailReason", OrderRefundFailReason);
|
|
883
|
+
this.iarCore = iarCore;
|
|
884
|
+
this.config = config;
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
* 获取订单列表
|
|
888
|
+
* @param params 获取参数
|
|
889
|
+
* @example
|
|
890
|
+
* ```js
|
|
891
|
+
* const data = await orderTarget.getOrderList({ pageNumber: 1, pageSize: 10 });
|
|
892
|
+
* console.log('订单列表', data.contents);
|
|
893
|
+
* ```
|
|
894
|
+
*/
|
|
895
|
+
async getOrderList(params = {}) {
|
|
896
|
+
const { pageNumber = 1, pageSize = 10, orderStatus } = params;
|
|
897
|
+
const res = await this.iarCore.polyvApi.get(
|
|
898
|
+
PolyvApiUrl.GetOrderList,
|
|
899
|
+
{
|
|
900
|
+
pageNumber,
|
|
901
|
+
pageSize,
|
|
902
|
+
orderStatus
|
|
903
|
+
}
|
|
904
|
+
);
|
|
905
|
+
return {
|
|
906
|
+
pageNumber: res.pageNumber,
|
|
907
|
+
pageSize: res.pageSize,
|
|
908
|
+
totalItems: res.totalItems,
|
|
909
|
+
totalPages: res.totalPages,
|
|
910
|
+
contents: res.contents.map(mapInternalOrderToOrderData)
|
|
911
|
+
};
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* 获取订单详情
|
|
915
|
+
* @param params 获取参数
|
|
916
|
+
* @example
|
|
917
|
+
* ```js
|
|
918
|
+
* const data = await orderTarget.getOrderDetail({ orderNo: '1234567890' });
|
|
919
|
+
* console.log('订单详情', data);
|
|
920
|
+
* ```
|
|
921
|
+
*/
|
|
922
|
+
async getOrderDetail(params) {
|
|
923
|
+
const internalDetail = await this.iarCore.polyvApi.get(
|
|
924
|
+
PolyvApiUrl.GetOrderDetail,
|
|
925
|
+
{
|
|
926
|
+
orderNo: params.orderNo,
|
|
927
|
+
syncPayStatus: boolToYN(params.syncPayStatus)
|
|
928
|
+
}
|
|
929
|
+
);
|
|
930
|
+
return mapInternalOrderDetailToOrderData(internalDetail);
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* 创建订单
|
|
934
|
+
* @param params 创建订单参数
|
|
935
|
+
* @example
|
|
936
|
+
* ```js
|
|
937
|
+
* const res = await orderTarget.createOrder({ address: { name: '张三', mobile: '13800138000', area: '广东省 广州市 天河区', address: '天河路1号' }, products: [{ productId: 1, quantity: 1 }], payProvider: PaymentProvider.Wechat });
|
|
938
|
+
* if (res.success) {
|
|
939
|
+
* console.log('创建订单成功', res.orderNo);
|
|
940
|
+
* } else {
|
|
941
|
+
* console.log('创建订单失败', res.failReason, res.failMessage);
|
|
942
|
+
* }
|
|
943
|
+
* ```
|
|
944
|
+
*/
|
|
945
|
+
async createOrder(params) {
|
|
946
|
+
try {
|
|
947
|
+
const res = await this.iarCore.polyvApi.post(
|
|
948
|
+
PolyvApiUrl.CreateOrder,
|
|
949
|
+
params
|
|
950
|
+
);
|
|
951
|
+
return {
|
|
952
|
+
success: true,
|
|
953
|
+
...mapInternalCreateOrderResponse(res)
|
|
954
|
+
};
|
|
955
|
+
} catch (err) {
|
|
956
|
+
return {
|
|
957
|
+
success: false,
|
|
958
|
+
failReason: CreateOrderFailReason.Unknown,
|
|
959
|
+
failMessage: err instanceof Error ? err.message : void 0
|
|
960
|
+
};
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
/**
|
|
964
|
+
* 确认收货
|
|
965
|
+
* @param orderNo 订单号
|
|
966
|
+
* @example
|
|
967
|
+
* ```js
|
|
968
|
+
* await orderTarget.confirmOrder('1234567890');
|
|
969
|
+
* ```
|
|
970
|
+
*/
|
|
971
|
+
async confirmOrder(orderNo) {
|
|
972
|
+
return this.iarCore.polyvApi.post(concat(PolyvApiUrl.ConfirmOrder, { orderNo }), {});
|
|
973
|
+
}
|
|
974
|
+
/**
|
|
975
|
+
* 申请退款
|
|
976
|
+
* @param orderNo 订单号
|
|
977
|
+
* @example
|
|
978
|
+
* ```js
|
|
979
|
+
* const res = await orderTarget.applyOrderRefund('1234567890');
|
|
980
|
+
* if (res.success) {
|
|
981
|
+
* console.log('退款成功', res);
|
|
982
|
+
* } else {
|
|
983
|
+
* console.log('退款失败', res.failReason, res.failMessage);
|
|
984
|
+
* }
|
|
985
|
+
* ```
|
|
986
|
+
*/
|
|
987
|
+
async applyOrderRefund(orderNo) {
|
|
988
|
+
try {
|
|
989
|
+
const res = await this.iarCore.polyvApi.post(PolyvApiUrl.ApplyOrderRefund, { orderNo });
|
|
990
|
+
return {
|
|
991
|
+
success: true,
|
|
992
|
+
...res
|
|
993
|
+
};
|
|
994
|
+
} catch (err) {
|
|
995
|
+
return {
|
|
996
|
+
success: false,
|
|
997
|
+
failReason: OrderRefundFailReason.Unknown,
|
|
998
|
+
failMessage: err instanceof Error ? err.message : void 0
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
function mapInternalAddressToAddressData(data) {
|
|
1004
|
+
if (!data) {
|
|
1005
|
+
return {
|
|
1006
|
+
id: "",
|
|
1007
|
+
address: "",
|
|
1008
|
+
area: "",
|
|
1009
|
+
mobile: "",
|
|
1010
|
+
name: ""
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
return {
|
|
1014
|
+
id: data.id,
|
|
1015
|
+
address: data.address,
|
|
1016
|
+
area: data.area,
|
|
1017
|
+
mobile: data.mobile,
|
|
1018
|
+
name: data.name
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
class Address {
|
|
1022
|
+
constructor(iarCore, config) {
|
|
1023
|
+
this.iarCore = iarCore;
|
|
1024
|
+
this.config = config;
|
|
1025
|
+
}
|
|
1026
|
+
/**
|
|
1027
|
+
* 获取地址列表
|
|
1028
|
+
* @param params 分页参数
|
|
1029
|
+
* @example
|
|
1030
|
+
* ```js
|
|
1031
|
+
* const data = await addressTarget.getAddressList({ pageNumber: 1, pageSize: 10 });
|
|
1032
|
+
* console.log('地址列表', data.contents);
|
|
1033
|
+
* ```
|
|
1034
|
+
*/
|
|
1035
|
+
async getAddressList(options = {}) {
|
|
1036
|
+
const { pageNumber = 1, pageSize = 10 } = options;
|
|
1037
|
+
const res = await this.iarCore.polyvApi.get(
|
|
1038
|
+
PolyvApiUrl.GetAddressList,
|
|
1039
|
+
{
|
|
1040
|
+
pageNumber,
|
|
1041
|
+
pageSize
|
|
1042
|
+
}
|
|
1043
|
+
);
|
|
1044
|
+
return {
|
|
1045
|
+
...res,
|
|
1046
|
+
contents: res.contents.map(mapInternalAddressToAddressData)
|
|
1047
|
+
};
|
|
1048
|
+
}
|
|
1049
|
+
/**
|
|
1050
|
+
* 获取默认地址
|
|
1051
|
+
* @example
|
|
1052
|
+
* ```js
|
|
1053
|
+
* const data = await addressTarget.getDefaultAddress();
|
|
1054
|
+
* console.log('默认地址', data);
|
|
1055
|
+
*/
|
|
1056
|
+
async getDefaultAddress() {
|
|
1057
|
+
const res = await this.iarCore.polyvApi.get(
|
|
1058
|
+
PolyvApiUrl.GetDefaultAddress,
|
|
1059
|
+
{}
|
|
1060
|
+
);
|
|
1061
|
+
return mapInternalAddressToAddressData(res);
|
|
1062
|
+
}
|
|
1063
|
+
/**
|
|
1064
|
+
* 新增地址
|
|
1065
|
+
* @param params 新增地址参数
|
|
1066
|
+
* @example
|
|
1067
|
+
* ```js
|
|
1068
|
+
* const data = await addressTarget.addAddress({
|
|
1069
|
+
* phone: '13800138000',
|
|
1070
|
+
* name: '张三',
|
|
1071
|
+
* area: '广东省/广州市/番禺区',
|
|
1072
|
+
* address: '国家创新创业基地',
|
|
1073
|
+
* });
|
|
1074
|
+
* console.log('新增地址', data);
|
|
1075
|
+
*/
|
|
1076
|
+
async addAddress(params) {
|
|
1077
|
+
const res = await this.iarCore.polyvApi.post(
|
|
1078
|
+
PolyvApiUrl.AddAddress,
|
|
1079
|
+
params
|
|
1080
|
+
);
|
|
1081
|
+
return mapInternalAddressToAddressData(res);
|
|
1082
|
+
}
|
|
1083
|
+
/**
|
|
1084
|
+
* 修改地址
|
|
1085
|
+
* @param params 修改地址参数
|
|
1086
|
+
* @example
|
|
1087
|
+
* ```js
|
|
1088
|
+
* await addressTarget.updateAddress({
|
|
1089
|
+
* id: '123',
|
|
1090
|
+
* address: '国家创新创业基地',
|
|
1091
|
+
* area: '广东省/广州市/番禺区',
|
|
1092
|
+
* phone: '13800138000',
|
|
1093
|
+
* name: '张三',
|
|
1094
|
+
* });
|
|
1095
|
+
*/
|
|
1096
|
+
async updateAddress(params) {
|
|
1097
|
+
return await this.iarCore.polyvApi.post(
|
|
1098
|
+
PolyvApiUrl.UpdateAddress,
|
|
1099
|
+
params
|
|
1100
|
+
);
|
|
1101
|
+
}
|
|
1102
|
+
/**
|
|
1103
|
+
* 删除地址
|
|
1104
|
+
* @param id 地址 id
|
|
1105
|
+
* @example
|
|
1106
|
+
* ```js
|
|
1107
|
+
* await addressTarget.deleteAddress('123');
|
|
1108
|
+
* ```
|
|
1109
|
+
*/
|
|
1110
|
+
async deleteAddress(id) {
|
|
1111
|
+
return await this.iarCore.polyvApi.post(
|
|
1112
|
+
PolyvApiUrl.DeleteAddress,
|
|
1113
|
+
{ id }
|
|
1114
|
+
);
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
class Payment {
|
|
1118
|
+
constructor(iarCore, config) {
|
|
1119
|
+
__publicField(this, "PaymentProvider", PaymentProvider);
|
|
1120
|
+
/** 支付方式缓存 */
|
|
1121
|
+
__publicField(this, "__payProviderCache");
|
|
1122
|
+
this.iarCore = iarCore;
|
|
1123
|
+
this.config = config;
|
|
1124
|
+
}
|
|
1125
|
+
/**
|
|
1126
|
+
* 获取微信/支付宝支付参数
|
|
1127
|
+
* @param options 支付订单参数
|
|
1128
|
+
* @example
|
|
1129
|
+
* ```js
|
|
1130
|
+
* const data = await paymentTarget.payOrder({ orderNo: '1234567890', payProvider: PaymentProvider.Wechat });
|
|
1131
|
+
* console.log('支付参数', data);
|
|
1132
|
+
* ```
|
|
1133
|
+
*/
|
|
1134
|
+
async getPayOrderParams(options) {
|
|
1135
|
+
const res = await this.iarCore.polyvApi.get(
|
|
1136
|
+
PolyvApiUrl.PayOrder,
|
|
1137
|
+
options
|
|
1138
|
+
);
|
|
1139
|
+
return mapInternalCreateOrderResponse(res);
|
|
1140
|
+
}
|
|
1141
|
+
/**
|
|
1142
|
+
* 获取支付方式
|
|
1143
|
+
* @example
|
|
1144
|
+
* ```js
|
|
1145
|
+
* const data = await paymentTarget.getPayProviders();
|
|
1146
|
+
* console.log('支付方式', data);
|
|
1147
|
+
* ```
|
|
1148
|
+
*/
|
|
1149
|
+
async getPayProviders() {
|
|
1150
|
+
if (this.__payProviderCache) {
|
|
1151
|
+
return this.__payProviderCache;
|
|
1152
|
+
}
|
|
1153
|
+
const fetchPromise = this.iarCore.polyvApi.get(
|
|
1154
|
+
PolyvApiUrl.GetOrderPaymentProviders,
|
|
1155
|
+
{}
|
|
1156
|
+
).catch((error) => {
|
|
1157
|
+
this.__payProviderCache = void 0;
|
|
1158
|
+
throw error;
|
|
1159
|
+
});
|
|
1160
|
+
this.__payProviderCache = fetchPromise;
|
|
1161
|
+
return await fetchPromise;
|
|
1162
|
+
}
|
|
1163
|
+
}
|
|
1164
|
+
var ProductPushRule = /* @__PURE__ */ ((ProductPushRule2) => {
|
|
1165
|
+
ProductPushRule2["BigCard"] = "bigCard";
|
|
1166
|
+
ProductPushRule2["SmallCard"] = "smallCard";
|
|
1167
|
+
return ProductPushRule2;
|
|
1168
|
+
})(ProductPushRule || {});
|
|
1169
|
+
;
|
|
1170
|
+
console.log(
|
|
1171
|
+
"%c@polyv/product-sdk",
|
|
1172
|
+
"background:#67C23A;padding: 2px 6px;border-radius: 3px;color: #fff",
|
|
1173
|
+
"[version: 1.0.0-rc-20250612.3]",
|
|
1174
|
+
"[buildTime: 2025-06-12 02:28:30]"
|
|
1175
|
+
);
|
|
1176
|
+
export {
|
|
1177
|
+
Address,
|
|
1178
|
+
AuthType,
|
|
1179
|
+
CreateOrderFailReason,
|
|
1180
|
+
Order,
|
|
1181
|
+
OrderRefundFailReason,
|
|
1182
|
+
OrderStatus,
|
|
1183
|
+
PayStatus,
|
|
1184
|
+
Payment,
|
|
1185
|
+
PaymentProvider,
|
|
1186
|
+
Product,
|
|
1187
|
+
ProductBuyType,
|
|
1188
|
+
ProductDeliveryType,
|
|
1189
|
+
ProductEvents,
|
|
1190
|
+
ProductExplainStatus,
|
|
1191
|
+
ProductExplainType,
|
|
1192
|
+
ProductLinkJumpWay,
|
|
1193
|
+
ProductLinkType,
|
|
1194
|
+
ProductMediaType,
|
|
1195
|
+
ProductPriceType,
|
|
1196
|
+
ProductPushRule,
|
|
1197
|
+
ProductServiceType,
|
|
1198
|
+
ProductStatus,
|
|
1199
|
+
ProductType,
|
|
1200
|
+
RefundStatus
|
|
1201
|
+
};
|