"use client" import { Badge } from "@/components/ui/badge" import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card" import { EmptyState } from "@/components/ui/empty-state" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table" import { getShopIncomeStats } from "@/lib/api" import type { ShopIncomeStats } from "@/lib/api/shops" import { listWalletTransactions } from "@/lib/api/transactions" import { toApiError } from "@/lib/errors" import { useMyShop } from "@/lib/hooks/use-my-shop" import type { WalletTransaction } from "@/lib/types" import { AlertCircle, ArrowDownLeft, ArrowUpRight, CreditCard, DollarSign } from "lucide-react" import { useEffect, useState } from "react" const emptyStats: ShopIncomeStats = { monthlyIncome: "0", pendingSettlement: "0", totalWithdrawn: "0", totalOrders: 0, completedOrders: 0, } export default function ShopIncomePage() { const { shop, loading, error } = useMyShop() const [transactions, setTransactions] = useState([]) const [stats, setStats] = useState(emptyStats) const [isLoading, setIsLoading] = useState(false) const [loadError, setLoadError] = useState(null) useEffect(() => { if (!shop) return const shopId = shop.id let cancelled = false async function load() { setIsLoading(true) setLoadError(null) try { const [nextStats, nextTransactions] = await Promise.all([ getShopIncomeStats(shopId), listWalletTransactions({ offset: 0, limit: 1000 }), ]) if (cancelled) return setStats(nextStats) setTransactions(nextTransactions) } catch (error) { if (cancelled) return setLoadError(toApiError(error).msg) } finally { if (!cancelled) setIsLoading(false) } } void load() return () => { cancelled = true } }, [shop]) if (loading) { return (
) } if (error) { return (
) } if (!shop) { return (
) } const relatedTransactions = transactions.filter( (transaction) => transaction.type === "income" || transaction.type === "withdrawal", ) return (

收入统计

本月收入
¥{stats.monthlyIncome}
待结算
¥{stats.pendingSettlement}
累计提现
¥{stats.totalWithdrawn}
交易明细 类型 描述 金额 时间 {isLoading ? ( ) : loadError ? ( ) : relatedTransactions.length > 0 ? ( relatedTransactions.map((transaction) => (
{Number(transaction.amount) > 0 ? ( ) : ( )} 0 ? "success" : "destructive"}> {transaction.type === "topup" ? "充值" : transaction.type === "payment" ? "支付" : transaction.type === "income" ? "收入" : transaction.type === "withdrawal" ? "提现" : "退款"}
{transaction.description} 0 ? "text-success" : "text-destructive" } > {Number(transaction.amount) > 0 ? "+" : ""} {transaction.amount} {new Date(transaction.createdAt).toLocaleString()}
)) ) : ( )}
) }