Files
lgp-wx-plus/api/page/order.js
年糕崽崽 516f077568 初始化
缺陷:主题配色需要优化整体的同风格
2026-08-14 23:17:19 +08:00

97 lines
3.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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})
}
/**
* 上传转账凭证图片到 OSSwx/upload/image
*
* uni.uploadFile 不走 request.js 拦截器,所以这里手动拼 baseURL + token + 解包 result。
* 返回后端 result.url可直接访问的图片地址供 submitVoucher 拼成逗号串提交。
*
* @param filePath chooseImage 返回的本地 tempFilePath
* @returns Promise<string> 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)
},
})
})
}