refactor:删除pushToShop+releaseGoodsAuto,新增波次接口create-with-wave
This commit is contained in:
parent
3d8a9678e9
commit
92860f29d1
@ -2065,43 +2065,50 @@ export default {
|
|||||||
this.isSubmitting = true
|
this.isSubmitting = true
|
||||||
uni.showLoading({ title: '上传中...', mask: true })
|
uni.showLoading({ title: '上传中...', mask: true })
|
||||||
try {
|
try {
|
||||||
console.log('【上传】MinIO图片URL列表:', imageUrls)
|
var timestamp = String(Math.floor(Date.now() / 1000))
|
||||||
|
|
||||||
// 品相纯数字
|
// 出版时间转时间戳
|
||||||
const conditionDisplay = (this.currentTab === 'isbn' ? this.conditionValue : this.noIsbnConditionValue).replace('~', '')
|
var pubTimeStr = this.printTime || ''
|
||||||
|
var pubTimestamp = '0'
|
||||||
// 构建 form-data 参数
|
if (pubTimeStr) {
|
||||||
const userId = uni.getStorageSync('aboutId') || ''
|
var parts = pubTimeStr.split('-')
|
||||||
const apiData = {
|
if (parts.length >= 2) {
|
||||||
user_id: userId,
|
var d = new Date(parseInt(parts[0], 10), parseInt(parts[1], 10) - 1, 1)
|
||||||
warehouse_id: String(warehouseData.warehouseId || ''),
|
var ts = Math.floor(d.getTime() / 1000)
|
||||||
location_id: String(warehouseData.locationId || ''),
|
if (ts >= 0) { pubTimestamp = String(ts) }
|
||||||
isbn: '',
|
}
|
||||||
price: '',
|
|
||||||
stock: '',
|
|
||||||
appearance: conditionDisplay,
|
|
||||||
product_name: '',
|
|
||||||
photos: imageUrls
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.currentTab === 'isbn') {
|
const params = {
|
||||||
apiData.isbn = this.isbn || ''
|
app_key: 'psi',
|
||||||
apiData.price = this.price ? String(Math.round(parseFloat(this.price) * 100)) : ''
|
client_id: 'psi',
|
||||||
apiData.stock = String(this.stock ?? '')
|
fid: '0',
|
||||||
apiData.product_name = this.bookName || ''
|
type: '4',
|
||||||
} else {
|
isbn: this.isbn || '',
|
||||||
apiData.isbn = this.noIsbnIsbn || this.noIsbnUnifyIsbn || ''
|
f_isbn: '0',
|
||||||
apiData.price = this.noIsbnPrice ? String(Math.round(parseFloat(this.noIsbnPrice) * 100)) : ''
|
book_name: this.bookName || '',
|
||||||
apiData.stock = String(this.noIsbnStock ?? '')
|
f_book_name: '',
|
||||||
apiData.product_name = this.noIsbnBookName || ''
|
author: this.author || '',
|
||||||
|
publisher: this.publisher || '',
|
||||||
|
publication_time: pubTimestamp,
|
||||||
|
binding_layout: '',
|
||||||
|
fix_price: this.price ? String(Math.round(parseFloat(this.price) * 100)) : '',
|
||||||
|
page_count: '0',
|
||||||
|
word_count: '',
|
||||||
|
book_format: '',
|
||||||
|
'live_image[]': imageUrls.join(','),
|
||||||
|
timestamp: timestamp,
|
||||||
|
sign_method: 'md5'
|
||||||
}
|
}
|
||||||
|
|
||||||
// 调用 API 推送到店铺
|
var sign = calculateSign(params)
|
||||||
const apiUrl = 'https://psi.api.buzhiyushu.cn/api/product/pushToShop'
|
params.sign = sign
|
||||||
|
|
||||||
|
const apiUrl = 'https://psi.api.buzhiyushu.cn/api/syncBook'
|
||||||
const token = uni.getStorageSync('token') || ''
|
const token = uni.getStorageSync('token') || ''
|
||||||
console.log('【上传】推送API:', apiUrl, apiData)
|
console.log('【syncBook】请求地址:', apiUrl)
|
||||||
|
console.log('【syncBook】请求参数:', params)
|
||||||
|
|
||||||
// 使用 uni.request 以 form-urlencoded 方式发送
|
|
||||||
const res = await new Promise(function (resolve, reject) {
|
const res = await new Promise(function (resolve, reject) {
|
||||||
uni.request({
|
uni.request({
|
||||||
url: apiUrl,
|
url: apiUrl,
|
||||||
@ -2110,31 +2117,19 @@ export default {
|
|||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
'Authorization': 'Bearer ' + token
|
'Authorization': 'Bearer ' + token
|
||||||
},
|
},
|
||||||
data: {
|
data: params,
|
||||||
user_id: apiData.user_id,
|
|
||||||
warehouse_id: apiData.warehouse_id,
|
|
||||||
location_id: apiData.location_id,
|
|
||||||
isbn: apiData.isbn,
|
|
||||||
price: apiData.price,
|
|
||||||
stock: apiData.stock,
|
|
||||||
appearance: apiData.appearance,
|
|
||||||
product_name: apiData.product_name,
|
|
||||||
photos: apiData.photos.join(',')
|
|
||||||
},
|
|
||||||
success: function (r) { resolve(r) },
|
success: function (r) { resolve(r) },
|
||||||
fail: function (e) { reject(e) }
|
fail: function (e) { reject(e) }
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log('【上传】API响应:', res.statusCode, res.data)
|
console.log('【syncBook】返回值:', res.statusCode, res.data)
|
||||||
|
|
||||||
uni.hideLoading()
|
uni.hideLoading()
|
||||||
|
|
||||||
if (res.statusCode !== 200) {
|
if (res.statusCode !== 200) {
|
||||||
throw new Error('API返回: HTTP ' + res.statusCode)
|
throw new Error('API返回: HTTP ' + res.statusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析 JSON 响应
|
|
||||||
var respData = res.data
|
var respData = res.data
|
||||||
if (typeof respData === 'string') {
|
if (typeof respData === 'string') {
|
||||||
try { respData = JSON.parse(respData) } catch (e) { respData = { code: 500, msg: respData } }
|
try { respData = JSON.parse(respData) } catch (e) { respData = { code: 500, msg: respData } }
|
||||||
@ -2146,47 +2141,13 @@ export default {
|
|||||||
throw new Error(respData && respData.msg || '上传失败')
|
throw new Error(respData && respData.msg || '上传失败')
|
||||||
}
|
}
|
||||||
|
|
||||||
// pushToShop 成功后,调用 releaseGoodsAuto API
|
// syncBook 成功后调用波次接口
|
||||||
var pushData = respData.data || {}
|
var syncData = respData.data || {}
|
||||||
var goodsUserId = uni.getStorageSync('aboutId') || ''
|
var productId = syncData.product_id || syncData.id || ''
|
||||||
var goodsWarehouseId = pushData.warehouse_id
|
if (warehouseData && productId) {
|
||||||
var goodsProductId = pushData.product_id
|
await this.callWaveApi(warehouseData, productId)
|
||||||
if (goodsUserId && goodsWarehouseId && goodsProductId) {
|
|
||||||
console.log('【上传】调用releaseGoodsAuto:', goodsUserId, goodsWarehouseId, goodsProductId)
|
|
||||||
var releaseUrl = 'https://api.buzhiyushu.cn/zhishu/product/releaseGoodsAuto'
|
|
||||||
// 手动构建 multipart/form-data 正文(兼容 App 环境,FormData 不可用)
|
|
||||||
var boundary = '----Boundary' + Math.random().toString(36).slice(2)
|
|
||||||
var bodyArr = []
|
|
||||||
var appendField = function(name, val) {
|
|
||||||
bodyArr.push('--' + boundary)
|
|
||||||
bodyArr.push('Content-Disposition: form-data; name="' + name + '"')
|
|
||||||
bodyArr.push('')
|
|
||||||
bodyArr.push(String(val))
|
|
||||||
}
|
|
||||||
appendField('userId', goodsUserId)
|
|
||||||
appendField('warehouseId', goodsWarehouseId)
|
|
||||||
appendField('productId', goodsProductId)
|
|
||||||
bodyArr.push('--' + boundary + '--')
|
|
||||||
var formBody = bodyArr.join('\r\n')
|
|
||||||
console.log('【上传】releaseGoodsAuto请求地址:', releaseUrl)
|
|
||||||
console.log('【上传】releaseGoodsAuto请求参数:', { userId: String(goodsUserId), warehouseId: String(goodsWarehouseId), productId: String(goodsProductId) })
|
|
||||||
uni.request({
|
|
||||||
url: releaseUrl,
|
|
||||||
method: 'POST',
|
|
||||||
header: {
|
|
||||||
'Content-Type': 'multipart/form-data; boundary=' + boundary,
|
|
||||||
'Authorization': 'Basic ZWxhc3RpYzo1bVJESVVnNTJWQzBmcDE0bnctRg=='
|
|
||||||
},
|
|
||||||
data: formBody,
|
|
||||||
success: function (r2) {
|
|
||||||
console.log('【上传】releaseGoodsAuto响应:', r2.statusCode, r2.data)
|
|
||||||
},
|
|
||||||
fail: function (e2) {
|
|
||||||
console.warn('【上传】releaseGoodsAuto失败:', JSON.stringify(e2))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
console.warn('【上传】pushToShop返回缺少data字段,跳过releaseGoodsAuto')
|
console.warn('【syncBook】缺少warehouseData或productId,跳过波次')
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存上传记录到本地
|
// 保存上传记录到本地
|
||||||
@ -2197,37 +2158,21 @@ export default {
|
|||||||
type: this.currentTab,
|
type: this.currentTab,
|
||||||
apiUrl: apiUrl,
|
apiUrl: apiUrl,
|
||||||
apiResponse: res.data,
|
apiResponse: res.data,
|
||||||
data: apiData
|
data: params
|
||||||
})
|
})
|
||||||
uni.setStorageSync('uploadHistory', uploadHistory.slice(0, 100))
|
uni.setStorageSync('uploadHistory', uploadHistory.slice(0, 100))
|
||||||
|
|
||||||
// 清空表单
|
// 清空表单
|
||||||
if (this.currentTab === 'isbn') {
|
this.photoList = []
|
||||||
this.photoList = []
|
this.isbn = ''
|
||||||
this.isbn = ''
|
this.bookName = ''
|
||||||
this.bookName = ''
|
this.author = ''
|
||||||
this.price = ''
|
this.publisher = ''
|
||||||
this.stock = 1
|
this.fixPrice = ''
|
||||||
this.author = ''
|
this.price = ''
|
||||||
this.publisher = ''
|
this.stock = 1
|
||||||
this.fixPrice = ''
|
this.printTime = ''
|
||||||
this.printTime = ''
|
this.productList = []
|
||||||
this.productList = []
|
|
||||||
} else {
|
|
||||||
this.noIsbnPhotoList = []
|
|
||||||
this.noIsbnBookName = ''
|
|
||||||
this.noIsbnPrice = ''
|
|
||||||
this.noIsbnStock = 1
|
|
||||||
this.noIsbnAuthor = ''
|
|
||||||
this.noIsbnPublisher = ''
|
|
||||||
this.noIsbnOriginalPrice = ''
|
|
||||||
this.noIsbnIsbn = ''
|
|
||||||
this.noIsbnUnifyIsbn = ''
|
|
||||||
this.noIsbnPrintTime = ''
|
|
||||||
this.noIsbnFormat = ''
|
|
||||||
this.noIsbnBinding = ''
|
|
||||||
this.noIsbnProductList = []
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
uni.hideLoading()
|
uni.hideLoading()
|
||||||
console.error('【上传】失败:', e)
|
console.error('【上传】失败:', e)
|
||||||
@ -2327,100 +2272,13 @@ export default {
|
|||||||
throw new Error(respData && respData.msg || '上传失败')
|
throw new Error(respData && respData.msg || '上传失败')
|
||||||
}
|
}
|
||||||
|
|
||||||
// syncBook 成功后调用 pushToShop 推送到店铺
|
// syncBook 成功后调用波次接口
|
||||||
try {
|
var syncData = respData.data || {}
|
||||||
const warehouseData = this.noIsbnWarehouseData
|
var productId = syncData.product_id || syncData.id || ''
|
||||||
const conditionDisplay = this.noIsbnConditionValue.replace('~', '')
|
if (this.noIsbnWarehouseData && productId) {
|
||||||
const userId = uni.getStorageSync('aboutId') || ''
|
await this.callWaveApi(this.noIsbnWarehouseData, productId)
|
||||||
const tokenPush = uni.getStorageSync('token') || ''
|
} else {
|
||||||
const pushUrl = 'https://psi.api.buzhiyushu.cn/api/product/pushToShop'
|
console.warn('【syncBook】缺少warehouseData或productId,跳过波次')
|
||||||
const pushData = {
|
|
||||||
user_id: userId,
|
|
||||||
warehouse_id: String(warehouseData.warehouseId || ''),
|
|
||||||
location_id: String(warehouseData.locationId || ''),
|
|
||||||
isbn: (respData.data && (respData.data.isbn || '')) || this.noIsbnIsbn || this.noIsbnUnifyIsbn || '',
|
|
||||||
price: this.noIsbnPrice ? String(Math.round(parseFloat(this.noIsbnPrice) * 100)) : '',
|
|
||||||
stock: String(this.noIsbnStock ?? ''),
|
|
||||||
appearance: conditionDisplay,
|
|
||||||
product_name: this.noIsbnBookName || '',
|
|
||||||
photos: imageUrls.join(',')
|
|
||||||
}
|
|
||||||
console.log('【syncBook】pushToShop请求地址:', pushUrl)
|
|
||||||
console.log('【syncBook】pushToShop请求参数:', pushData)
|
|
||||||
const pushRes = await new Promise(function (resolve, reject) {
|
|
||||||
uni.request({
|
|
||||||
url: pushUrl,
|
|
||||||
method: 'POST',
|
|
||||||
header: {
|
|
||||||
'Content-Type': 'application/x-www-form-urlencoded',
|
|
||||||
'Authorization': 'Bearer ' + tokenPush
|
|
||||||
},
|
|
||||||
data: pushData,
|
|
||||||
success: function (r) { resolve(r) },
|
|
||||||
fail: function (e) { reject(e) }
|
|
||||||
})
|
|
||||||
})
|
|
||||||
console.log('【syncBook】pushToShop返回值:', pushRes.statusCode, pushRes.data)
|
|
||||||
|
|
||||||
// pushToShop 成功后,调用 releaseGoodsAuto API
|
|
||||||
if (pushRes.statusCode === 200) {
|
|
||||||
var pushRespData = pushRes.data
|
|
||||||
if (typeof pushRespData === 'string') {
|
|
||||||
try { pushRespData = JSON.parse(pushRespData) } catch (e) { pushRespData = {} }
|
|
||||||
}
|
|
||||||
if (pushRespData && pushRespData.code === 200) {
|
|
||||||
var pushRespInner = pushRespData.data || {}
|
|
||||||
var goodsUserId2 = uni.getStorageSync('aboutId') || ''
|
|
||||||
var goodsWarehouseId2 = pushRespInner.warehouse_id
|
|
||||||
var goodsProductId2 = pushRespInner.product_id
|
|
||||||
if (goodsUserId2 && goodsWarehouseId2 && goodsProductId2) {
|
|
||||||
console.log('【syncBook】调用releaseGoodsAuto:', goodsUserId2, goodsWarehouseId2, goodsProductId2)
|
|
||||||
var releaseUrl2 = 'https://api.buzhiyushu.cn/zhishu/product/releaseGoodsAuto'
|
|
||||||
var boundary2 = '----Boundary' + Math.random().toString(36).slice(2)
|
|
||||||
var bodyArr2 = []
|
|
||||||
var appendField2 = function(name, val) {
|
|
||||||
bodyArr2.push('--' + boundary2)
|
|
||||||
bodyArr2.push('Content-Disposition: form-data; name="' + name + '"')
|
|
||||||
bodyArr2.push('')
|
|
||||||
bodyArr2.push(String(val))
|
|
||||||
}
|
|
||||||
appendField2('userId', goodsUserId2)
|
|
||||||
appendField2('warehouseId', goodsWarehouseId2)
|
|
||||||
appendField2('productId', goodsProductId2)
|
|
||||||
bodyArr2.push('--' + boundary2 + '--')
|
|
||||||
var formBody2 = bodyArr2.join('\r\n')
|
|
||||||
console.log('【syncBook】releaseGoodsAuto请求地址:', releaseUrl2)
|
|
||||||
console.log('【syncBook】releaseGoodsAuto请求参数:', { userId: String(goodsUserId2), warehouseId: String(goodsWarehouseId2), productId: String(goodsProductId2) })
|
|
||||||
uni.request({
|
|
||||||
url: releaseUrl2,
|
|
||||||
method: 'POST',
|
|
||||||
header: {
|
|
||||||
'Content-Type': 'multipart/form-data; boundary=' + boundary2,
|
|
||||||
'Authorization': 'Basic ZWxhc3RpYzo1bVJESVVnNTJWQzBmcDE0bnctRg=='
|
|
||||||
},
|
|
||||||
data: formBody2,
|
|
||||||
success: function (r3) {
|
|
||||||
console.log('【syncBook】releaseGoodsAuto响应:', r3.statusCode, r3.data)
|
|
||||||
},
|
|
||||||
fail: function (e3) {
|
|
||||||
console.warn('【syncBook】releaseGoodsAuto失败:', JSON.stringify(e3))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
console.warn('【syncBook】pushToShop返回缺少warehouse_id/product_id,跳过releaseGoodsAuto')
|
|
||||||
}
|
|
||||||
} else if (pushRespData && pushRespData.msg) {
|
|
||||||
// code 非 200,显示错误信息
|
|
||||||
uni.showToast({ title: pushRespData.msg, icon: 'none', duration: 3000 })
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// HTTP 非 200
|
|
||||||
var errMsg = 'pushToShop请求失败: HTTP ' + pushRes.statusCode
|
|
||||||
console.error('【syncBook】' + errMsg)
|
|
||||||
uni.showToast({ title: errMsg, icon: 'none', duration: 3000 })
|
|
||||||
}
|
|
||||||
} catch (ePush) {
|
|
||||||
console.warn('【syncBook】pushToShop失败:', ePush)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存上传记录到本地
|
// 保存上传记录到本地
|
||||||
@ -2458,6 +2316,56 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 调用波次接口(syncBook 成功后调用)
|
||||||
|
async callWaveApi(warehouseData, productId) {
|
||||||
|
var timestamp = String(Math.floor(Date.now() / 1000))
|
||||||
|
var price = this.currentTab === 'isbn'
|
||||||
|
? (this.price ? String(Math.round(parseFloat(this.price) * 100)) : '0')
|
||||||
|
: (this.noIsbnPrice ? String(Math.round(parseFloat(this.noIsbnPrice) * 100)) : '0')
|
||||||
|
var stock = this.currentTab === 'isbn'
|
||||||
|
? String(this.stock ?? '1')
|
||||||
|
: String(this.noIsbnStock ?? '1')
|
||||||
|
|
||||||
|
const params = {
|
||||||
|
app_key: 'psi',
|
||||||
|
client_id: 'psi',
|
||||||
|
warehouse_id: String(warehouseData.warehouseId || ''),
|
||||||
|
'items[0][product_id]': String(productId),
|
||||||
|
'items[0][quantity]': stock,
|
||||||
|
'items[0][unit_price]': price,
|
||||||
|
direction: '1',
|
||||||
|
timestamp: timestamp,
|
||||||
|
sign_method: 'md5'
|
||||||
|
}
|
||||||
|
|
||||||
|
var sign = calculateSign(params)
|
||||||
|
params.sign = sign
|
||||||
|
|
||||||
|
const token = uni.getStorageSync('token') || ''
|
||||||
|
var waveUrl = 'https://psi.api.buzhiyushu.cn/api/purchase-order/create-with-wave'
|
||||||
|
console.log('【波次】请求地址:', waveUrl)
|
||||||
|
console.log('【波次】请求参数:', params)
|
||||||
|
|
||||||
|
try {
|
||||||
|
const waveRes = await new Promise(function (resolve, reject) {
|
||||||
|
uni.request({
|
||||||
|
url: waveUrl,
|
||||||
|
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('【波次】返回值:', waveRes.statusCode, waveRes.data)
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('【波次】请求失败:', e)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
// 无ISBN - 书名搜索(使用与ISBN相同的kongfz接口)
|
// 无ISBN - 书名搜索(使用与ISBN相同的kongfz接口)
|
||||||
searchNoIsbn() {
|
searchNoIsbn() {
|
||||||
if (!this.isLoggedIn) {
|
if (!this.isLoggedIn) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user