From d06232668d7d5bd21a40338ab80ad6bc5c7f771c Mon Sep 17 00:00:00 2001 From: "97694732@qq.com" Date: Thu, 18 Jun 2026 10:46:14 +0800 Subject: [PATCH] =?UTF-8?q?feat:syncBook=E5=90=8E=E8=B0=83=E7=94=A8product?= =?UTF-8?q?/save=E8=8E=B7=E5=8F=96=E7=9C=9F=E5=AE=9E=E5=95=86=E5=93=81ID?= =?UTF-8?q?=E5=86=8D=E8=B5=B0=E6=B3=A2=E6=AC=A1=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/upload/upload.vue | 82 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 4 deletions(-) diff --git a/pages/upload/upload.vue b/pages/upload/upload.vue index a3107e8..905047c 100644 --- a/pages/upload/upload.vue +++ b/pages/upload/upload.vue @@ -2141,9 +2141,20 @@ export default { throw new Error(respData && respData.msg || '上传失败') } - // syncBook 成功后调用波次接口 + // syncBook 成功后保存商品到 product 表,获取真实商品ID var syncData = respData.data || {} - var productId = syncData.product_id || syncData.id || '' + var bookInfoId = syncData.id || '' + var barcode = this.currentTab === 'isbn' ? (this.isbn || '') : (this.noIsbnIsbn || this.noIsbnUnifyIsbn || '') + var productName = this.currentTab === 'isbn' ? (this.bookName || '') : (this.noIsbnBookName || '') + var appearanceValue = parseInt(this.currentTab === 'isbn' ? this.conditionValue : this.noIsbnConditionValue) || 0 + var productPrice = this.currentTab === 'isbn' + ? (this.fixPrice ? String(Math.round(parseFloat(this.fixPrice) * 100)) : '0') + : (this.noIsbnOriginalPrice ? String(Math.round(parseFloat(this.noIsbnOriginalPrice) * 100)) : '0') + var productId = await this.callProductSaveApi(productName, appearanceValue, barcode, productPrice, imageUrls) + if (!productId) { + console.warn('【product/save】保存商品失败,跳过波次') + return + } if (warehouseData && productId) { await this.callWaveApi(warehouseData, productId) } else { @@ -2272,9 +2283,17 @@ export default { throw new Error(respData && respData.msg || '上传失败') } - // syncBook 成功后调用波次接口 + // syncBook 成功后保存商品到 product 表,获取真实商品ID var syncData = respData.data || {} - var productId = syncData.product_id || syncData.id || '' + var barcode = this.noIsbnIsbn || this.noIsbnUnifyIsbn || '' + var productName = this.noIsbnBookName || '' + var appearanceValue = parseInt(this.noIsbnConditionValue) || 0 + var productPrice = this.noIsbnOriginalPrice ? String(Math.round(parseFloat(this.noIsbnOriginalPrice) * 100)) : '0' + var productId = await this.callProductSaveApi(productName, appearanceValue, barcode, productPrice, imageUrls) + if (!productId) { + console.warn('【product/save】保存商品失败,跳过波次') + return + } if (this.noIsbnWarehouseData && productId) { await this.callWaveApi(this.noIsbnWarehouseData, productId) } else { @@ -2316,6 +2335,61 @@ export default { } }, + // 保存商品到 product 表,返回商品ID + async callProductSaveApi(name, appearance, barcode, price, imageUrls) { + var timestamp = String(Math.floor(Date.now() / 1000)) + const token = uni.getStorageSync('token') || '' + const params = { + app_key: 'psi', + client_id: 'psi', + name: name, + appearance: String(appearance), + barcode: barcode, + price: price, + 'live_image[]': imageUrls.join(','), + timestamp: timestamp, + sign_method: 'md5' + } + var sign = calculateSign(params) + params.sign = sign + + try { + const res = await new Promise(function (resolve, reject) { + uni.request({ + url: 'https://psi.api.buzhiyushu.cn/api/product/save', + method: 'POST', + header: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'Authorization': 'Bearer ' + token + }, + data: params, + success: function (r) { resolve(r) }, + fail: function (e) { reject(e) } + }) + }) + console.log('【product/save】返回值:', res.statusCode, res.data) + + if (res.statusCode === 200 && res.data) { + var saveResp = res.data + if (typeof saveResp === 'string') { + try { saveResp = JSON.parse(saveResp) } catch (e) { saveResp = {} } + } + if (saveResp.code === 200 && saveResp.data && saveResp.data.id) { + return saveResp.data.id + } else { + uni.showToast({ title: '保存商品: ' + (saveResp.msg || '返回数据异常'), icon: 'none', duration: 3000 }) + } + } else { + uni.showToast({ title: '保存商品: 请求失败 HTTP ' + res.statusCode, icon: 'none', duration: 3000 }) + } + return '' + } catch (e) { + console.warn('【product/save】请求失败:', e) + uni.showToast({ title: '保存商品: 网络请求失败', icon: 'none', duration: 3000 }) + return '' + } + }, + // 调用波次接口(syncBook 成功后调用) async callWaveApi(warehouseData, productId) { var timestamp = String(Math.floor(Date.now() / 1000))