import {get, post} from '../request'; import {API_BASE} from '../env'; /** * 订单 API(对齐后端 lgp-admin-plus-api/app/Service/wx/WxOrderService.php) * 前缀 wx/order,走鉴权组(nl.wx 中间件)。 * 金额字段后端是整数分,详情接口会带 *_text 元字段,这里直接用。 */ const prefix = 'order/' /** 我的订单列表,可按状态筛,透传分页参数 {status, page, pageSize} */ export const getOrderListApi = async (params = {}) => { return await get(`${prefix}list`, params) } /** 订单详情(含明细、支付记录、发货记录) */ export const getOrderDetailApi = async (id) => { return await get(`${prefix}detail`, {id}) } /** * 清单转订单。 * @param listId 清单 id * @param params 收货信息:receiver_name / receiver_phone / receiver_address / delivery_type / remark */ export const createOrderApi = async (listId, params = {}) => { return await post(`${prefix}create`, {list_id: listId, ...params}) } /** * 上传转账凭证。 * @param orderId 订单 id * @param voucher 凭证图 URL(多张逗号分隔或数组) * @param amount 可选,本次转账金额(分),不传则按订单未付金额 */ export const submitVoucherApi = async (orderId, voucher, amount) => { const body = {order_id: orderId, voucher} if (amount !== undefined && amount !== null) { body.amount = amount } return await post(`${prefix}voucher`, body) } /** 调起微信 JSAPI 支付,后端返回 uni.requestPayment 所需参数 */ export const wechatPayApi = async (orderId) => { return await post(`${prefix}wechat-pay`, {order_id: orderId}) } /** 取消订单(仅未付款/已付款未发货可用) */ export const cancelOrderApi = async (id) => { return await post(`${prefix}cancel`, {id}) } /** 确认收货(已发货状态可用) */ export const completeOrderApi = async (id) => { return await post(`${prefix}complete`, {id}) } /** * 上传转账凭证图片到 OSS(wx/upload/image)。 * * uni.uploadFile 不走 request.js 拦截器,所以这里手动拼 baseURL + token + 解包 result。 * 返回后端 result.url(可直接访问的图片地址),供 submitVoucher 拼成逗号串提交。 * * @param filePath chooseImage 返回的本地 tempFilePath * @returns Promise OSS 图片 URL */ export const uploadVoucherImageApi = (filePath) => { return new Promise((resolve, reject) => { const token = uni.getStorageSync('token') uni.uploadFile({ url: `${API_BASE}upload/image`, filePath, name: 'file', header: token ? {Authorization: `Bearer ${token}`} : {}, success: (res) => { try { const body = typeof res.data === 'string' ? JSON.parse(res.data) : res.data if (body.code === 0 && body.result && body.result.url) { resolve(body.result.url) } else { uni.showToast({title: body.message || '上传失败', icon: 'none'}) reject(new Error(body.message || '上传失败')) } } catch (e) { uni.showToast({title: '上传失败', icon: 'none'}) reject(e) } }, fail: (err) => { uni.showToast({title: '上传失败', icon: 'none'}) reject(err) }, }) }) }