8 changed files with 233 additions and 195 deletions
@ -0,0 +1,111 @@
@@ -0,0 +1,111 @@
|
||||
/** |
||||
* 充值记录:月份区间、状态文案、列表展示映射 |
||||
*/ |
||||
import { getRechargeRecords } from '../api/recharge' |
||||
import { RechargeRecordItem } from '../types/recharge' |
||||
import { userStore } from '../store' |
||||
|
||||
/** 列表项(页面展示结构) */ |
||||
export interface RechargeRecordViewItem { |
||||
id: string |
||||
storeName: string |
||||
rechargeTime: string |
||||
rechargeType: string |
||||
amount: number |
||||
status: string |
||||
} |
||||
|
||||
/** 当前年月 YYYY-MM */ |
||||
export const getCurrentYearMonth = (): string => { |
||||
const now = new Date() |
||||
const year = now.getFullYear() |
||||
const month = String(now.getMonth() + 1).padStart(2, '0') |
||||
return `${year}-${month}` |
||||
} |
||||
|
||||
/** 某月起止时间(供 records 接口过滤) */ |
||||
export const getMonthDateRange = (yearMonth: string): { startDate: string; endDate: string } => { |
||||
const [yStr, mStr] = yearMonth.split('-') |
||||
const year = Number(yStr) |
||||
const month = Number(mStr) |
||||
const lastDay = new Date(year, month, 0).getDate() |
||||
const day = String(lastDay).padStart(2, '0') |
||||
return { |
||||
startDate: `${yearMonth}-01 00:00:00`, |
||||
endDate: `${yearMonth}-${day} 23:59:59`, |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 支付状态(后端枚举,适用于 recharge/records.status 等) |
||||
* 来源:后端「支付状态定义」 |
||||
*/ |
||||
export enum RechargePaymentStatus { |
||||
Invalid = 0, |
||||
Pending = 1, |
||||
Initialized = 2, |
||||
Paying = 3, |
||||
Success = 4, |
||||
Failed = 5, |
||||
Cancelled = 6, |
||||
Refunding = 7, |
||||
Refunded = 8, |
||||
RefundFailed = 9, |
||||
Closed = 10, |
||||
} |
||||
|
||||
export const RECHARGE_PAYMENT_STATUS_LABEL: Record<number, string> = { |
||||
[RechargePaymentStatus.Invalid]: '无效', |
||||
[RechargePaymentStatus.Pending]: '待支付', |
||||
[RechargePaymentStatus.Initialized]: '已初始化', |
||||
[RechargePaymentStatus.Paying]: '支付中', |
||||
[RechargePaymentStatus.Success]: '支付成功', |
||||
[RechargePaymentStatus.Failed]: '支付失败', |
||||
[RechargePaymentStatus.Cancelled]: '已取消', |
||||
[RechargePaymentStatus.Refunding]: '退款中', |
||||
[RechargePaymentStatus.Refunded]: '已退款', |
||||
[RechargePaymentStatus.RefundFailed]: '退款失败', |
||||
[RechargePaymentStatus.Closed]: '已关闭', |
||||
} |
||||
|
||||
/** |
||||
* 充值状态文案(后端支付状态定义) |
||||
*/ |
||||
export const formatRechargeStatus = (status: number): string => { |
||||
if (RECHARGE_PAYMENT_STATUS_LABEL[status] !== undefined) { |
||||
return RECHARGE_PAYMENT_STATUS_LABEL[status] |
||||
} |
||||
return '未知状态' |
||||
} |
||||
|
||||
export const mapRechargeRecordToView = (item: RechargeRecordItem): RechargeRecordViewItem => ({ |
||||
id: String(item.id || item.outTradeNo || item.logTime), |
||||
storeName: item.bpName || '--', |
||||
rechargeTime: item.logTime || '--', |
||||
rechargeType: item.rcgTypeName || '账户充值', |
||||
amount: item.amount, |
||||
status: formatRechargeStatus(item.status), |
||||
}) |
||||
|
||||
/** |
||||
* 拉取指定月份充值记录(需已登录且有客户 sn) |
||||
*/ |
||||
export const fetchRechargeRecordsByMonth = async ( |
||||
yearMonth: string |
||||
): Promise<RechargeRecordViewItem[]> => { |
||||
const customerSn = userStore.userInfo?.sn |
||||
if (!customerSn) { |
||||
throw new Error('NO_CUSTOMER_SN') |
||||
} |
||||
|
||||
const { startDate, endDate } = getMonthDateRange(yearMonth) |
||||
const res = await getRechargeRecords({ |
||||
customerSn, |
||||
startDate, |
||||
endDate, |
||||
pageIndex: 1, |
||||
pageSize: 100, |
||||
}) |
||||
|
||||
return (res.data?.data || []).map(mapRechargeRecordToView) |
||||
} |
||||
Loading…
Reference in new issue