Files
mini-programs/src/services/orderService.ts

183 lines
3.5 KiB
TypeScript

import httpService from "./httpService";
import type { ApiResponse } from "./httpService";
export interface SignType {
/** 仅在微信支付 v2 版本接口适用 */
MD5;
/** 仅在微信支付 v2 版本接口适用 */
"HMAC-SHA256";
/** 仅在微信支付 v3 版本接口适用 */
RSA;
}
export enum OrderStatus {
PENDING = 0,
PAID,
FINISHED,
}
export enum CancelType {
NONE = 0, // 未取消
USER, // 用户主动取消
TIMEOUT, // 超时
}
export interface PayMentParams {
order_id: number;
order_no: string;
status: number;
appId: string;
timeStamp: string;
nonceStr: string;
package: string;
signType: keyof SignType;
paySign: string;
}
// 用户接口
export interface OrderResponse {
participant_id: number;
payment_required: boolean;
payment_params: PayMentParams;
}
export interface OrderInfo {
time: string;
address: string;
registrant_nickname: string;
registrant_phone: string;
cost: string;
}
export interface RefundPolicy {
application_time: string;
refund_rule: string;
}
export interface GameStatus {
current_players: number;
max_players: number;
is_full: boolean;
can_join: boolean;
}
export interface GameDetails {
game_id: number;
game_title: string;
game_description: string;
}
export interface GameOrderRes {
order_info: OrderInfo;
refund_policy: RefundPolicy[];
notice: string;
game_status: GameStatus;
game_details: GameDetails;
}
// 发布球局类
class OrderService {
// 查询订单列表
async getOrderList(pagination: { page: number, pageSize: number }) {
return httpService.post("/user/orders", pagination, { showLoading: true });
}
// 获取订单详情
async getOrderDetail(order_id: number): Promise<ApiResponse<any>> {
return httpService.post(
"/payment/order_details",
{ order_id },
{
showLoading: true,
},
);
}
// 创建订单
async createOrder(game_id: number): Promise<ApiResponse<OrderResponse>> {
return httpService.post(
"/payment/create_order",
{ game_id },
{
showLoading: true,
},
);
}
// 检查订单信息
async getCheckOrderInfo(game_id: number): Promise<ApiResponse<GameOrderRes>> {
return httpService.post(
"/payment/check_order",
{ game_id },
{
showLoading: true,
},
);
}
// 获取未支付订单
async getUnpaidOrder(game_id: number): Promise<ApiResponse<any>> {
return httpService.post(
"/payment/get_unpaid_order",
{ game_id },
{
showLoading: true,
},
);
}
// 取消未支付订单
async cancelUnpaidOrder({
order_no,
cancel_reason,
}: {
order_no: number;
cancel_reason: string;
}): Promise<ApiResponse<any>> {
return httpService.post(
"/payment/cancel_order",
{ order_no, cancel_reason },
{
showLoading: true,
},
);
}
// 申请退款
async applicateRefund({
order_no,
refund_reason,
refund_amount,
}: {
order_no: number;
refund_reason: string;
refund_amount: number;
}): Promise<ApiResponse<any>> {
return httpService.post(
"/payment/apply_refund",
{ order_no, refund_reason, refund_amount },
{
showLoading: true,
},
);
}
// 删除订单
async deleteOrder({
order_id,
}: {
order_id: number;
}): Promise<ApiResponse<any>> {
return httpService.post(
"/payment/delete_order",
{ order_id },
{
showLoading: true,
},
);
}
}
// 导出认证服务实例
export default new OrderService();