feat(admin): merge stash changes into comclib-analytics (order/finance/product + rpc sql)

This commit is contained in:
comlibmb
2026-02-10 18:49:21 +08:00
parent bf394eb65d
commit 80e5a1ddeb
23 changed files with 1599 additions and 143 deletions

View File

@@ -41,7 +41,7 @@
<view class="icon-box blue"><text class="icon">🕒</text></view>
<view class="item-info">
<text class="item-label">营业额</text>
<text class="item-value">442753.70</text>
<text class="item-value">{{ stats.revenue }}</text>
<view class="trend-row">
<text class="trend-label">环比增长:</text>
<text class="trend-value up">44275370% ▲</text>
@@ -52,7 +52,7 @@
<view class="icon-box green"><text class="icon">¥</text></view>
<view class="item-info">
<text class="item-label">商品支付金额</text>
<text class="item-value">434693.52</text>
<text class="item-value">{{ stats.payAmount }}</text>
<view class="trend-row">
<text class="trend-label">环比增长:</text>
<text class="trend-value up">43469352% ▲</text>
@@ -63,7 +63,7 @@
<view class="icon-box orange"><text class="icon">🔒</text></view>
<view class="item-info">
<text class="item-label">购买会员金额</text>
<text class="item-value">8059.18</text>
<text class="item-value">{{ stats.memberAmount }}</text>
<view class="trend-row">
<text class="trend-label">环比增长:</text>
<text class="trend-value up">805918% ▲</text>
@@ -74,7 +74,7 @@
<view class="icon-box purple"><text class="icon">💰</text></view>
<view class="item-info">
<text class="item-label">充值金额</text>
<text class="item-value">0.00</text>
<text class="item-value">{{ stats.rechargeAmount }}</text>
<view class="trend-row">
<text class="trend-label">环比增长:</text>
<text class="trend-value">0% -</text>
@@ -85,7 +85,7 @@
<view class="icon-box cyan"><text class="icon">🛒</text></view>
<view class="item-info">
<text class="item-label">线下收银金额</text>
<text class="item-value">1</text>
<text class="item-value">{{ stats.offlineAmount }}</text>
<view class="trend-row">
<text class="trend-label">环比增长:</text>
<text class="trend-value up">100% ▲</text>
@@ -100,7 +100,7 @@
<view class="icon-box light-green"><text class="icon">↘</text></view>
<view class="item-info">
<text class="item-label">支出金额</text>
<text class="item-value">442752.69</text>
<text class="item-value">{{ stats.expenditure }}</text>
<view class="trend-row">
<text class="trend-label">环比增长:</text>
<text class="trend-value up">44275269% ▲</text>
@@ -111,7 +111,7 @@
<view class="icon-box gold"><text class="icon">💳</text></view>
<view class="item-info">
<text class="item-label">余额支付金额</text>
<text class="item-value">442752.69</text>
<text class="item-value">{{ stats.balancePay }}</text>
<view class="trend-row">
<text class="trend-label">环比增长:</text>
<text class="trend-value up">5293.00% ▲</text>
@@ -122,7 +122,7 @@
<view class="icon-box red-purple"><text class="icon"></text></view>
<view class="item-info">
<text class="item-label">支付佣金金额</text>
<text class="item-value">0.00</text>
<text class="item-value">{{ stats.commissionPay }}</text>
<view class="trend-row">
<text class="trend-label">环比增长:</text>
<text class="trend-value">0% -</text>
@@ -133,7 +133,7 @@
<view class="icon-box blue-gray"><text class="icon">📦</text></view>
<view class="item-info">
<text class="item-label">商品退款金额</text>
<text class="item-value">0.00</text>
<text class="item-value">{{ stats.refundAmount }}</text>
<view class="trend-row">
<text class="trend-label">环比增长:</text>
<text class="trend-value">0% -</text>
@@ -281,42 +281,69 @@
</template>
<script setup lang="uts">
import { ref, onMounted } from 'vue'
import { ref, onMounted, reactive } from 'vue'
import EChartsView from '@/uni_modules/charts/EChartsView.vue'
import { fetchFinanceOverview } from '@/services/admin/financeService.uts'
import { rpcOrNull } from '@/services/analytics/rpc.uts'
const dateOptions = ['今天', '昨天', '最近7天', '最近30天', '本月', '本年']
const activeDateTab = ref(0)
// 响应式统计数据
const stats = reactive({
revenue: '0.00', // 营业额
payAmount: '0.00', // 商品支付金额
memberAmount: '0.00', // 购买会员金额
rechargeAmount: '0.00', // 充值金额
offlineAmount: '0.00', // 线下收银金额
expenditure: '0.00', // 支出金额
balancePay: '0.00', // 余额支付金额
commissionPay: '0.00', // 支付佣金金额
refundAmount: '0.00', // 商品退款金额
// 环比数据 (示例暂留)
revenueTrend: '0%',
rechargeTrend: '0%'
})
const orderAmountOption = ref<any>(null)
const overviewTrendOption = ref<any>(null)
/**
* 工具函数:将 UTS 对象转换为纯 JavaScript 对象
* 确保 ECharts 在 renderjs 中能正确接收数据
* 加载统计数据
*/
function toPlainObject(obj : any) : any {
if (obj == null) return null
if (typeof obj !== 'object') return obj
if (Array.isArray(obj)) {
return (obj as Array<any>).map((item : any) : any => toPlainObject(item))
}
const plain : Record<string, any> = {}
const keys = Object.keys(obj as Record<string, any>)
for (let i = 0; i < keys.length; i++) {
const key = keys[i]
if (key.startsWith('_') || key == 'toJSON') continue
const value = (obj as Record<string, any>)[key]
if (typeof value == 'function') continue
if (value != null && typeof value == 'object' && !Array.isArray(value)) {
plain[key] = toPlainObject(value)
} else {
plain[key] = value
async function loadData() {
// TODO: 根据 activeDateTab 计算具体的 startTime 和 endTime
const startTime = '2026-01-01T00:00:00Z'
const endTime = '2026-12-31T23:59:59Z'
try {
// 1. 获取财务概况 (充值、提现等)
const financeRes = await fetchFinanceOverview(startTime, endTime)
if (financeRes != null) {
stats.rechargeAmount = financeRes.recharge_amount.toFixed(2)
// 支出金额暂以提现成功金额为例
stats.expenditure = financeRes.extract_amount.toFixed(2)
}
// 2. 获取订单统计 (营业额、退款等)
const orderRes = await rpcOrNull('rpc_admin_order_stats', {
p_start_time: startTime,
p_end_time: endTime
} as UTSJSONObject)
if (orderRes != null) {
stats.revenue = ((orderRes as any).total_amount ?? 0).toFixed(2)
stats.payAmount = stats.revenue // 简单处理
stats.refundAmount = ((orderRes as any).refund_amount ?? 0).toFixed(2)
}
} catch (e) {
console.error('Failed to load transaction stats:', e)
}
return plain
}
onMounted(() => {
loadData()
// 延迟初始化图表确保容器就位
setTimeout(() => {
initCharts()