This commit is contained in:
@@ -140,12 +140,19 @@ export interface ListResponse<T> {
|
||||
total: number
|
||||
}
|
||||
|
||||
export interface FundSummaryParams {
|
||||
shop_name?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取资金概览 (代理端主页用)
|
||||
* GET /api/admin/shops/fund-summary
|
||||
*/
|
||||
export function getFundSummary() {
|
||||
return get<{ items: FundSummary[] }>('/api/admin/shops/fund-summary').then(res => res.items?.[0])
|
||||
export function getFundSummary(params?: FundSummaryParams) {
|
||||
return get<{ items: FundSummary[] }>(
|
||||
'/api/admin/shops/fund-summary',
|
||||
params?.shop_name ? { params } : undefined
|
||||
).then(res => res.items?.[0])
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,6 +4,11 @@ import { getFundSummary, getCommissionRecords, getCommissionStats } from '@/api/
|
||||
import type { FundSummary, CommissionRecord, CommissionStats } from '@/api/commission'
|
||||
import SimplePicker from '@/components/SimplePicker.vue'
|
||||
|
||||
type LoginUserInfo = {
|
||||
shop_id?: number
|
||||
username?: string
|
||||
}
|
||||
|
||||
const commissionSummary = ref<FundSummary | null>(null)
|
||||
const shopId = ref<number>(0)
|
||||
const commissionRecords = ref<CommissionRecord[]>([])
|
||||
@@ -64,8 +69,12 @@ function formatTime(time: string) {
|
||||
return `${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')} ${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`
|
||||
}
|
||||
|
||||
function getLoginUserInfo() {
|
||||
return uni.getStorageSync('user_info') as LoginUserInfo | undefined
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
const userInfo = uni.getStorageSync('user_info')
|
||||
const userInfo = getLoginUserInfo()
|
||||
if (userInfo?.shop_id) {
|
||||
shopId.value = userInfo.shop_id
|
||||
}
|
||||
@@ -76,7 +85,8 @@ onMounted(() => {
|
||||
|
||||
async function loadCommissionSummary() {
|
||||
try {
|
||||
commissionSummary.value = await getFundSummary()
|
||||
const userInfo = getLoginUserInfo()
|
||||
commissionSummary.value = await getFundSummary(userInfo?.username ? { shop_name: userInfo.username } : undefined)
|
||||
} catch (error) {
|
||||
console.error('加载佣金概览失败:', error)
|
||||
}
|
||||
@@ -330,4 +340,4 @@ function onScroll(e: any) {
|
||||
.space-y-3 > view:not(:last-child) {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
@@ -22,6 +22,11 @@
|
||||
|
||||
// 是否为代理账号
|
||||
const isAgent = computed(() => userInfo.value?.user_type === 3)
|
||||
const todayStat = computed(() => dailyStats.value[0] || null)
|
||||
|
||||
function getLoginUserInfo() {
|
||||
return uni.getStorageSync('user_info') as Partial<UserInfo> | undefined
|
||||
}
|
||||
|
||||
// 格式化金额(分转元,带千分号)
|
||||
function formatAmount(amount : number) {
|
||||
@@ -32,6 +37,7 @@
|
||||
}
|
||||
|
||||
// 格式化日期 (MM-DD)
|
||||
// 根据用户类型动态生成菜单
|
||||
function formatDate(dateStr : string) {
|
||||
const date = new Date(dateStr)
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
@@ -39,7 +45,14 @@
|
||||
return `${month}-${day}`
|
||||
}
|
||||
|
||||
// 根据用户类型动态生成菜单
|
||||
function getTodayDate() {
|
||||
const today = new Date()
|
||||
const year = today.getFullYear()
|
||||
const month = String(today.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(today.getDate()).padStart(2, '0')
|
||||
return `${year}-${month}-${day}`
|
||||
}
|
||||
|
||||
const menuItems = computed(() => {
|
||||
const menus = [
|
||||
{
|
||||
@@ -90,17 +103,25 @@
|
||||
})
|
||||
|
||||
// 加载佣金数据
|
||||
async function loadCommissionData() {
|
||||
async function loadCommissionData(shopName?: string) {
|
||||
if (!isAgent.value || !shopId.value) return
|
||||
|
||||
loadingCommission.value = true
|
||||
|
||||
try {
|
||||
// 1. 加载佣金概览 (新接口 /shops/fund-summary)
|
||||
const summary = await getFundSummary()
|
||||
const summary = await getFundSummary(shopName ? { shop_name: shopName } : undefined)
|
||||
commissionSummary.value = summary
|
||||
const today = getTodayDate()
|
||||
const todayStats = await getCommissionDailyStats(shopId.value, {
|
||||
days: 1,
|
||||
start_date: today,
|
||||
end_date: today,
|
||||
})
|
||||
dailyStats.value = todayStats || []
|
||||
return
|
||||
|
||||
// 2. 加载最近7天佣金统计
|
||||
// 2. 加载最近30天佣金统计
|
||||
const stats = await getCommissionDailyStats(shopId.value, { days: 30 })
|
||||
dailyStats.value = stats || []
|
||||
}
|
||||
@@ -126,11 +147,14 @@
|
||||
shopId.value = user.shop_id
|
||||
}
|
||||
|
||||
const loginUserInfo = getLoginUserInfo()
|
||||
const fundSummaryShopName = loginUserInfo?.username || user.username
|
||||
|
||||
console.log('首页数据加载成功:', { user })
|
||||
|
||||
// 如果是代理账号,加载佣金数据
|
||||
if (user.user_type === 3) {
|
||||
await loadCommissionData()
|
||||
await loadCommissionData(fundSummaryShopName)
|
||||
}
|
||||
}
|
||||
catch (error : any) {
|
||||
@@ -253,7 +277,7 @@
|
||||
</view>
|
||||
|
||||
<!-- 今日佣金 -->
|
||||
<view v-if="dailyStats.length > 0">
|
||||
<view>
|
||||
<view class="flex items-center justify-between mb-3">
|
||||
<text class="text-16px font-700 text-[#212121]">今日佣金</text>
|
||||
<text class="text-13px text-[#999]" @click="navigateTo('/pages/agent-system/commission-center/index')">更多</text>
|
||||
@@ -263,22 +287,25 @@
|
||||
<view class="text-center">
|
||||
<text class="text-12px text-[#999] block mb-1">日期</text>
|
||||
<text class="text-14px font-600 text-[#212121]">
|
||||
{{ formatDate(dailyStats[0].date) }}
|
||||
{{ todayStat ? formatDate(todayStat.date) : '--' }}
|
||||
</text>
|
||||
</view>
|
||||
<view class="text-center">
|
||||
<text class="text-12px text-[#999] block mb-1">佣金金额</text>
|
||||
<text class="text-14px font-600 text-[#212121]">
|
||||
{{ formatAmount(dailyStats[0].total_amount) }}
|
||||
{{ formatAmount(todayStat?.total_amount || 0) }}
|
||||
</text>
|
||||
</view>
|
||||
<view class="text-center">
|
||||
<text class="text-12px text-[#999] block mb-1">订单笔数</text>
|
||||
<text class="text-14px font-600 text-[#212121]">
|
||||
{{ dailyStats[0].total_count }}
|
||||
{{ todayStat?.total_count || 0 }}
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="!todayStat" class="mt-3 pt-3 border-t border-[#f5f5f5] text-center">
|
||||
<text class="text-12px text-[#999]">今日暂无佣金数据</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -6,6 +6,11 @@ import { createWithdrawal, getWithdrawalRecords } from '@/api/withdrawal'
|
||||
import type { WithdrawalRecord } from '@/api/withdrawal'
|
||||
import SimplePicker from '@/components/SimplePicker.vue'
|
||||
|
||||
type LoginUserInfo = {
|
||||
shop_id?: number
|
||||
username?: string
|
||||
}
|
||||
|
||||
const commissionSummary = ref<FundSummary | null>(null)
|
||||
const shopId = ref<number>(0)
|
||||
const withdrawAmount = ref('')
|
||||
@@ -73,8 +78,12 @@ function formatTime(time: string) {
|
||||
return `${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')} ${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`
|
||||
}
|
||||
|
||||
function getLoginUserInfo() {
|
||||
return uni.getStorageSync('user_info') as LoginUserInfo | undefined
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
const userInfo = uni.getStorageSync('user_info')
|
||||
const userInfo = getLoginUserInfo()
|
||||
if (userInfo?.shop_id) {
|
||||
shopId.value = userInfo.shop_id
|
||||
}
|
||||
@@ -85,7 +94,8 @@ onMounted(() => {
|
||||
async function loadCommissionSummary() {
|
||||
loading.value = true
|
||||
try {
|
||||
commissionSummary.value = await getFundSummary()
|
||||
const userInfo = getLoginUserInfo()
|
||||
commissionSummary.value = await getFundSummary(userInfo?.username ? { shop_name: userInfo.username } : undefined)
|
||||
withdrawAmount.value = availableAmount.value.toFixed(2)
|
||||
} catch (error) {
|
||||
console.error('加载佣金概览失败:', error)
|
||||
@@ -367,4 +377,4 @@ function onScroll(e: any) {
|
||||
.space-y-3 > view:not(:last-child) {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user