You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
145 lines
3.3 KiB
145 lines
3.3 KiB
import request from '@/utils/request-legacy';
|
|
import type {ApiResult, PageResult} from '@/api/index';
|
|
import type {Payment, PaymentParam} from './model';
|
|
import type {ShopOrder} from '@/api/shop/shopOrder/model';
|
|
import {SERVER_API_URL} from "@/utils/server";
|
|
|
|
/**
|
|
* 分页查询支付方式
|
|
*/
|
|
export async function pagePayment(params: PaymentParam) {
|
|
const res = await request.get<ApiResult<PageResult<Payment>>>(
|
|
SERVER_API_URL + '/system/payment/page',
|
|
params
|
|
);
|
|
if (res.code === 0) {
|
|
return res.data;
|
|
}
|
|
return Promise.reject(new Error(res.message));
|
|
}
|
|
|
|
/**
|
|
* 查询支付方式列表
|
|
*/
|
|
export async function listPayment(params?: PaymentParam) {
|
|
const res = await request.get<ApiResult<Payment[]>>(
|
|
SERVER_API_URL + '/system/payment',
|
|
params
|
|
);
|
|
if (res.code === 0 && res.data) {
|
|
return res.data;
|
|
}
|
|
return Promise.reject(new Error(res.message));
|
|
}
|
|
|
|
/**
|
|
* 添加支付方式
|
|
*/
|
|
export async function addPayment(data: Payment) {
|
|
const res = await request.post<ApiResult<unknown>>(
|
|
SERVER_API_URL + '/system/payment',
|
|
data
|
|
);
|
|
if (res.code === 0) {
|
|
return res.message;
|
|
}
|
|
return Promise.reject(new Error(res.message));
|
|
}
|
|
|
|
/**
|
|
* 修改支付方式
|
|
*/
|
|
export async function updatePayment(data: Payment) {
|
|
const res = await request.put<ApiResult<unknown>>(
|
|
SERVER_API_URL + '/system/payment',
|
|
data
|
|
);
|
|
if (res.code === 0) {
|
|
return res.message;
|
|
}
|
|
return Promise.reject(new Error(res.message));
|
|
}
|
|
|
|
/**
|
|
* 删除支付方式
|
|
*/
|
|
export async function removePayment(id?: number) {
|
|
const res = await request.del<ApiResult<unknown>>(
|
|
SERVER_API_URL + '/system/payment/' + id
|
|
);
|
|
if (res.code === 0) {
|
|
return res.message;
|
|
}
|
|
return Promise.reject(new Error(res.message));
|
|
}
|
|
|
|
/**
|
|
* 批量删除支付方式
|
|
*/
|
|
export async function removeBatchPayment(data: (number | undefined)[]) {
|
|
const res = await request.del<ApiResult<unknown>>(
|
|
SERVER_API_URL + '/system/payment/batch',
|
|
{
|
|
data
|
|
}
|
|
);
|
|
if (res.code === 0) {
|
|
return res.message;
|
|
}
|
|
return Promise.reject(new Error(res.message));
|
|
}
|
|
|
|
/**
|
|
* 根据id查询支付方式
|
|
*/
|
|
export async function getPayment(id: number) {
|
|
const res = await request.get<ApiResult<Payment>>(
|
|
SERVER_API_URL + '/system/payment/' + id
|
|
);
|
|
if (res.code === 0 && res.data) {
|
|
return res.data;
|
|
}
|
|
return Promise.reject(new Error(res.message));
|
|
}
|
|
|
|
/**
|
|
* 生成支付二维码(微信native)
|
|
*/
|
|
export async function getNativeCode(data: ShopOrder) {
|
|
const res = await request.post<ApiResult<unknown>>(
|
|
SERVER_API_URL + '/system/wx-native-pay/codeUrl',
|
|
data
|
|
);
|
|
if (res.code === 0) {
|
|
return res.data;
|
|
}
|
|
return Promise.reject(new Error(res.message));
|
|
}
|
|
|
|
/**
|
|
* 使用余额支付
|
|
*/
|
|
export async function payByBalance(data: ShopOrder) {
|
|
const res = await request.post<ApiResult<unknown>>(
|
|
SERVER_API_URL + '/system/payment/balancePay',
|
|
data
|
|
);
|
|
if (res.code === 0) {
|
|
return res.message;
|
|
}
|
|
return Promise.reject(new Error(res.message));
|
|
}
|
|
|
|
/**
|
|
* 选择支付方式
|
|
*/
|
|
export async function selectPayment(params?: PaymentParam) {
|
|
const res = await request.get<ApiResult<Payment[]>>(
|
|
SERVER_API_URL + '/system/payment/select',
|
|
params
|
|
);
|
|
if (res.code === 0) {
|
|
return res.data;
|
|
}
|
|
return Promise.reject(new Error(res.message));
|
|
}
|