feat: 支持商品管理
This commit is contained in:
32
packages/app/src/utils/shop.ts
Normal file
32
packages/app/src/utils/shop.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import type { ShopOrderStatus, PaymentParams } from '@mp-pilates/shared'
|
||||
import { post } from './request'
|
||||
export const shopMoney = (fen: number) => (fen / 100).toFixed(2)
|
||||
export const shopStatus: Record<ShopOrderStatus, string> = {
|
||||
PENDING: '待付款',
|
||||
PAID: '待到馆取货',
|
||||
COMPLETED: '已取货',
|
||||
CANCELLED: '已取消',
|
||||
}
|
||||
export const shopError = (error: unknown) =>
|
||||
uni.showToast({
|
||||
title: error instanceof Error ? error.message : '操作失败,请重试',
|
||||
icon: 'none',
|
||||
})
|
||||
export async function payShopOrder(id: string) {
|
||||
const params = await post<PaymentParams>(`/shop/orders/${id}/pay`)
|
||||
await new Promise<void>((resolve, reject) =>
|
||||
uni.requestPayment({
|
||||
...params,
|
||||
provider: 'wxpay',
|
||||
success: () => resolve(),
|
||||
fail: (error) =>
|
||||
reject(
|
||||
new Error(
|
||||
error.errMsg.includes('cancel')
|
||||
? '已取消支付,可在订单中继续付款'
|
||||
: '支付未完成,请刷新订单确认状态',
|
||||
),
|
||||
),
|
||||
}),
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user