!273 商城首页

Merge pull request !273 from 疯狂的世界/dev
This commit is contained in:
芋道源码 2023-10-16 12:11:23 +00:00 committed by Gitee
commit 7b9ea62e6b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
16 changed files with 1086 additions and 327 deletions

View File

@ -0,0 +1,5 @@
/** 数据对照 Response VO */
export interface DataComparisonRespVO<T> {
value: T
reference: T
}

View File

@ -1,6 +1,6 @@
import request from '@/config/axios' import request from '@/config/axios'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { TradeStatisticsComparisonRespVO } from '@/api/mall/statistics/trade' import { DataComparisonRespVO } from '@/api/mall/statistics/common'
import { formatDate } from '@/utils/formatTime' import { formatDate } from '@/utils/formatTime'
/** 会员分析 Request VO */ /** 会员分析 Request VO */
@ -10,17 +10,17 @@ export interface MemberAnalyseReqVO {
/** 会员分析 Response VO */ /** 会员分析 Response VO */
export interface MemberAnalyseRespVO { export interface MemberAnalyseRespVO {
visitorCount: number visitUserCount: number
orderUserCount: number orderUserCount: number
payUserCount: number payUserCount: number
atv: number atv: number
comparison: TradeStatisticsComparisonRespVO<MemberAnalyseComparisonRespVO> comparison: DataComparisonRespVO<MemberAnalyseComparisonRespVO>
} }
/** 会员分析对照数据 Response VO */ /** 会员分析对照数据 Response VO */
export interface MemberAnalyseComparisonRespVO { export interface MemberAnalyseComparisonRespVO {
userCount: number registerUserCount: number
activeUserCount: number visitUserCount: number
rechargeUserCount: number rechargeUserCount: number
} }
@ -29,8 +29,8 @@ export interface MemberAreaStatisticsRespVO {
areaId: number areaId: number
areaName: string areaName: string
userCount: number userCount: number
orderCreateCount: number orderCreateUserCount: number
orderPayCount: number orderPayUserCount: number
orderPayPrice: number orderPayPrice: number
} }
@ -54,6 +54,20 @@ export interface MemberTerminalStatisticsRespVO {
userCount: number userCount: number
} }
/** 会员数量统计 Response VO */
export interface MemberCountRespVO {
/** 用户访问量 */
visitUserCount: string
/** 新增用户数量 */
createUserCount: number
}
/** 会员注册数量 Response VO */
export interface MemberRegisterCountRespVO {
date: string
count: number
}
// 查询会员统计 // 查询会员统计
export const getMemberSummary = () => { export const getMemberSummary = () => {
return request.get<MemberSummaryRespVO>({ return request.get<MemberSummaryRespVO>({
@ -89,3 +103,21 @@ export const getMemberTerminalStatisticsList = () => {
url: '/statistics/member/get-terminal-statistics-list' url: '/statistics/member/get-terminal-statistics-list'
}) })
} }
// 获得用户数量量对照
export const getUserCountComparison = () => {
return request.get<DataComparisonRespVO<MemberCountRespVO>>({
url: '/statistics/member/user-count-comparison'
})
}
// 获得会员注册数量列表
export const getMemberRegisterCountList = (
beginTime: dayjs.ConfigType,
endTime: dayjs.ConfigType
) => {
return request.get<MemberRegisterCountRespVO[]>({
url: '/statistics/member/register-count-list',
params: { times: [formatDate(beginTime), formatDate(endTime)] }
})
}

View File

@ -0,0 +1,6 @@
import request from '@/config/axios'
/** 获取钱包充值金额 */
export const getWalletRechargePrice = async () => {
return await request.get<number>({ url: `/statistics/pay/wallet-recharge-price` })
}

View File

@ -1,12 +1,7 @@
import request from '@/config/axios' import request from '@/config/axios'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import { formatDate } from '@/utils/formatTime' import { formatDate } from '@/utils/formatTime'
import { DataComparisonRespVO } from '@/api/mall/statistics/common'
/** 交易统计对照 Response VO */
export interface TradeStatisticsComparisonRespVO<T> {
value: T
reference: T
}
/** 交易统计 Response VO */ /** 交易统计 Response VO */
export interface TradeSummaryRespVO { export interface TradeSummaryRespVO {
@ -24,46 +19,100 @@ export interface TradeTrendReqVO {
/** 交易状况统计 Response VO */ /** 交易状况统计 Response VO */
export interface TradeTrendSummaryRespVO { export interface TradeTrendSummaryRespVO {
time: string time: string
turnover: number turnoverPrice: number
orderPayPrice: number orderPayPrice: number
rechargePrice: number rechargePrice: number
expensePrice: number expensePrice: number
balancePrice: number orderWalletPayPrice: number
brokerageSettlementPrice: number brokerageSettlementPrice: number
orderRefundPrice: number orderRefundPrice: number
} }
/** 交易订单数量 Response VO */
export interface TradeOrderCountRespVO {
/** 待发货 */
undelivered?: number
/** 待核销 */
pickUp?: number
/** 退款中 */
afterSaleApply?: number
/** 提现待审核 */
auditingWithdraw?: number
}
/** 交易订单统计 Response VO */
export interface TradeOrderSummaryRespVO {
/** 支付订单商品数 */
orderPayCount?: number
/** 总支付金额,单位:分 */
orderPayPrice?: number
}
/** 订单量趋势统计 Response VO */
export interface TradeOrderTrendRespVO {
/** 日期 */
date: string
/** 订单数量 */
orderPayCount: number
/** 订单支付金额 */
orderPayPrice: number
}
// 查询交易统计 // 查询交易统计
export const getTradeStatisticsSummary = () => { export const getTradeStatisticsSummary = () => {
return request.get<TradeStatisticsComparisonRespVO<TradeSummaryRespVO>>({ return request.get<DataComparisonRespVO<TradeSummaryRespVO>>({
url: '/statistics/trade/summary' url: '/statistics/trade/summary'
}) })
} }
// 获得交易状况统计 // 获得交易状况统计
export const getTradeTrendSummary = (params: TradeTrendReqVO) => { export const getTradeTrendSummary = (params: TradeTrendReqVO) => {
return request.get<TradeStatisticsComparisonRespVO<TradeTrendSummaryRespVO>>({ return request.get<DataComparisonRespVO<TradeTrendSummaryRespVO>>({
url: '/statistics/trade/trend/summary', url: '/statistics/trade/trend/summary',
params: formatDateParam(params) params: formatDateParam(params)
}) })
} }
// 获得交易状况明细 // 获得交易状况明细
export const getTradeTrendList = (params: TradeTrendReqVO) => { export const getTradeStatisticsList = (params: TradeTrendReqVO) => {
return request.get<TradeTrendSummaryRespVO[]>({ return request.get<TradeTrendSummaryRespVO[]>({
url: '/statistics/trade/trend/list', url: '/statistics/trade/list',
params: formatDateParam(params) params: formatDateParam(params)
}) })
} }
// 导出交易状况明细 // 导出交易状况明细
export const exportTradeTrend = (params: TradeTrendReqVO) => { export const exportTradeStatisticsExcel = (params: TradeTrendReqVO) => {
return request.download({ return request.download({
url: '/statistics/trade/trend/export-excel', url: '/statistics/trade/export-excel',
params: formatDateParam(params) params: formatDateParam(params)
}) })
} }
// 获得交易订单数量
export const getOrderCount = async () => {
return await request.get<TradeOrderCountRespVO>({ url: `/statistics/trade/order-count` })
}
// 获得交易订单数量对照
export const getOrderComparison = async () => {
return await request.get<DataComparisonRespVO<TradeOrderSummaryRespVO>>({
url: `/statistics/trade/order-comparison`
})
}
// 获得订单量趋势统计
export const getOrderCountTrendComparison = (
type: number,
beginTime: dayjs.ConfigType,
endTime: dayjs.ConfigType
) => {
return request.get<DataComparisonRespVO<TradeOrderTrendRespVO>[]>({
url: '/statistics/trade/order-count-trend',
params: { type, beginTime: formatDate(beginTime), endTime: formatDate(endTime) }
})
}
/** 时间参数需要格式化, 确保接口能识别 */ /** 时间参数需要格式化, 确保接口能识别 */
const formatDateParam = (params: TradeTrendReqVO) => { const formatDateParam = (params: TradeTrendReqVO) => {
return { times: [formatDate(params.times[0]), formatDate(params.times[1])] } as TradeTrendReqVO return { times: [formatDate(params.times[0]), formatDate(params.times[1])] } as TradeTrendReqVO

View File

@ -0,0 +1,89 @@
<template>
<div class="flex flex-row items-center gap-2">
<el-radio-group v-model="shortcutDays" @change="handleShortcutDaysChange">
<el-radio-button :label="1">昨天</el-radio-button>
<el-radio-button :label="7">最近7天</el-radio-button>
<el-radio-button :label="30">最近30天</el-radio-button>
</el-radio-group>
<el-date-picker
v-model="times"
value-format="YYYY-MM-DD HH:mm:ss"
type="daterange"
start-placeholder="开始日期"
end-placeholder="结束日期"
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
:shortcuts="shortcuts"
class="!w-240px"
@change="emitDateRangePicker"
/>
<slot></slot>
</div>
</template>
<script lang="ts" setup>
import dayjs from 'dayjs'
import * as DateUtil from '@/utils/formatTime'
/** 快捷日期范围选择组件 */
defineOptions({ name: 'ShortcutDateRangePicker' })
const shortcutDays = ref(7) // , 7
const times = ref<[dayjs.ConfigType, dayjs.ConfigType]>(['', '']) //
defineExpose({ times }) //
/** 日期快捷选择 */
const shortcuts = [
{
text: '昨天',
value: () => DateUtil.getDayRange(new Date(), -1)
},
{
text: '最近7天',
value: () => DateUtil.getLast7Days()
},
{
text: '本月',
value: () => [dayjs().startOf('M'), dayjs().subtract(1, 'd')]
},
{
text: '最近30天',
value: () => DateUtil.getLast30Days()
},
{
text: '最近1年',
value: () => DateUtil.getLast1Year()
}
]
/** 设置时间范围 */
function setTimes() {
const beginDate = dayjs().subtract(shortcutDays.value, 'd')
const yesterday = dayjs().subtract(1, 'd')
times.value = DateUtil.getDateRange(beginDate, yesterday)
}
/** 快捷日期单选按钮选中 */
const handleShortcutDaysChange = async () => {
//
setTimes()
//
await emitDateRangePicker()
}
/** 触发事件:时间范围选中 */
const emits = defineEmits<{
(e: 'change', times: [dayjs.ConfigType, dayjs.ConfigType]): void
}>()
/** 触发时间范围选中事件 */
const emitDateRangePicker = async () => {
// , 线,
if (DateUtil.isSameDay(times.value[0], times.value[1])) {
//
times.value[0] = DateUtil.formatDate(dayjs(times.value[0]).subtract(1, 'd'))
}
emits('change', times.value)
}
/** 初始化 **/
onMounted(() => {
handleShortcutDaysChange()
})
</script>

View File

@ -233,3 +233,16 @@ export const yuanToFen = (amount: string | number): number => {
export const fenToYuan = (price: string | number): number => { export const fenToYuan = (price: string | number): number => {
return formatToFraction(price) return formatToFraction(price)
} }
/**
*
*
* @param value
* @param reference
*/
export const calculateRelativeRate = (value?: number, reference?: number) => {
// 防止除0
if (!reference) return 0
return ((100 * ((value || 0) - reference)) / reference).toFixed(0)
}

View File

@ -0,0 +1,42 @@
<template>
<div class="flex flex-col gap-2 bg-[var(--el-bg-color-overlay)] p-6">
<div class="flex items-center justify-between text-gray-500">
<span>{{ title }}</span>
<el-tag>{{ tag }}</el-tag>
</div>
<div class="flex flex-row items-baseline justify-between">
<CountTo :prefix="prefix" :end-val="value" :decimals="decimals" class="text-3xl" />
<span :class="toNumber(percent) > 0 ? 'text-red-500' : 'text-green-500'">
{{ Math.abs(toNumber(percent)) }}%
<Icon :icon="toNumber(percent) > 0 ? 'ep:caret-top' : 'ep:caret-bottom'" class="!text-sm" />
</span>
</div>
<el-divider class="mb-1! mt-2!" />
<div class="flex flex-row items-center justify-between text-sm">
<span class="text-gray-500">昨日数据</span>
<span>{{ prefix || '' }}{{ reference }}</span>
</div>
</div>
</template>
<script lang="ts" setup>
import { propTypes } from '@/utils/propTypes'
import { toNumber } from 'lodash-es'
import { calculateRelativeRate } from '@/utils'
/** 交易对照卡片 */
defineOptions({ name: 'ComparisonCard' })
const props = defineProps({
title: propTypes.string.def('').isRequired,
tag: propTypes.string.def(''),
prefix: propTypes.string.def(''),
value: propTypes.number.def(0).isRequired,
reference: propTypes.number.def(0).isRequired,
decimals: propTypes.number.def(0)
})
//
const percent = computed(() =>
calculateRelativeRate(props.value as number, props.reference as number)
)
</script>

View File

@ -0,0 +1,91 @@
<template>
<el-card shadow="never">
<template #header>
<CardTitle title="用户统计" />
</template>
<!-- 折线图 -->
<Echart :height="300" :options="lineChartOptions" />
</el-card>
</template>
<script lang="ts" setup>
import dayjs from 'dayjs'
import { EChartsOption } from 'echarts'
import * as MemberStatisticsApi from '@/api/mall/statistics/member'
import { formatDate } from '@/utils/formatTime'
import { CardTitle } from '@/components/Card'
/** 会员用户统计卡片 */
defineOptions({ name: 'MemberStatisticsCard' })
const loading = ref(true) //
/** 折线图配置 */
const lineChartOptions = reactive<EChartsOption>({
dataset: {
dimensions: ['date', 'count'],
source: []
},
grid: {
left: 20,
right: 20,
bottom: 20,
top: 80,
containLabel: true
},
legend: {
top: 50
},
series: [{ name: '注册量', type: 'line', smooth: true, areaStyle: {} }],
toolbox: {
feature: {
//
dataZoom: {
yAxisIndex: false // Y
},
brush: {
type: ['lineX', 'clear'] //
},
saveAsImage: { show: true, name: '会员统计' } //
}
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross'
},
padding: [5, 10]
},
xAxis: {
type: 'category',
boundaryGap: false,
axisTick: {
show: false
},
axisLabel: {
formatter: (date: string) => formatDate(date, 'MM-DD')
}
},
yAxis: {
axisTick: {
show: false
}
}
}) as EChartsOption
const getMemberRegisterCountList = async () => {
loading.value = true
//
const beginTime = dayjs().subtract(30, 'd').startOf('d')
const endTime = dayjs().endOf('d')
const list = await MemberStatisticsApi.getMemberRegisterCountList(beginTime, endTime)
// Echarts
if (lineChartOptions.dataset && lineChartOptions.dataset['source']) {
lineChartOptions.dataset['source'] = list
}
loading.value = false
}
/** 初始化 **/
onMounted(() => {
getMemberRegisterCountList()
})
</script>

View File

@ -0,0 +1,91 @@
<template>
<el-card shadow="never">
<template #header>
<CardTitle title="运营数据" />
</template>
<div class="flex flex-row flex-wrap items-center gap-8 p-4">
<div
v-for="item in data"
:key="item.name"
class="h-20 w-20% flex flex-col cursor-pointer items-center justify-center gap-2"
@click="handleClick(item.routerName)"
>
<CountTo
:prefix="item.prefix"
:end-val="item.value"
:decimals="item.decimals"
class="text-3xl"
/>
<span class="text-center">{{ item.name }}</span>
</div>
</div>
</el-card>
</template>
<script lang="ts" setup>
import * as ProductSpuApi from '@/api/mall/product/spu'
import * as TradeStatisticsApi from '@/api/mall/statistics/trade'
import * as PayStatisticsApi from '@/api/mall/statistics/pay'
import { CardTitle } from '@/components/Card'
/** 运营数据卡片 */
defineOptions({ name: 'OperationDataCard' })
const router = useRouter() //
/** 数据 */
const data = reactive({
orderUndelivered: { name: '待发货订单', value: 9, routerName: 'TradeOrder' },
orderAfterSaleApply: { name: '退款中订单', value: 4, routerName: 'TradeAfterSale' },
orderWaitePickUp: { name: '待核销订单', value: 0, routerName: 'TradeOrder' },
productAlertStock: { name: '库存预警', value: 0, routerName: 'ProductSpu' },
productForSale: { name: '上架商品', value: 0, routerName: 'ProductSpu' },
productInWarehouse: { name: '仓库商品', value: 0, routerName: 'ProductSpu' },
withdrawAuditing: { name: '提现待审核', value: 0, routerName: 'TradeBrokerageWithdraw' },
rechargePrice: {
name: '账户充值',
value: 0.0,
prefix: '¥',
decimals: 2,
routerName: 'PayWalletRecharge'
}
})
/** 查询订单数据 */
const getOrderData = async () => {
const orderCount = await TradeStatisticsApi.getOrderCount()
data.orderUndelivered.value = orderCount.undelivered
data.orderAfterSaleApply.value = orderCount.afterSaleApply
data.orderWaitePickUp.value = orderCount.pickUp
data.withdrawAuditing.value = orderCount.auditingWithdraw
}
/** 查询商品数据 */
const getProductData = async () => {
// TODO: @
const productCount = await ProductSpuApi.getTabsCount()
data.productForSale.value = productCount['0']
data.productInWarehouse.value = productCount['1']
data.productAlertStock.value = productCount['3']
}
/** 查询钱包充值数据 */
const getWalletRechargeData = async () => {
data.rechargePrice.value = await PayStatisticsApi.getWalletRechargePrice()
}
/**
* 跳转到对应页面
*
* @param routerName 路由页面组件的名称
*/
const handleClick = (routerName: string) => {
router.push({ name: routerName })
}
/** 初始化 **/
onMounted(() => {
getOrderData()
getProductData()
getWalletRechargeData()
})
</script>

View File

@ -0,0 +1,79 @@
<template>
<el-card shadow="never">
<template #header>
<CardTitle title="快捷入口" />
</template>
<div class="flex flex-row flex-wrap gap-8 p-4">
<div
v-for="menu in menuList"
:key="menu.name"
class="h-20 w-20% flex flex-col cursor-pointer items-center justify-center gap-2"
@click="handleMenuClick(menu.routerName)"
>
<div :class="menu.bgColor" class="rounded p-3 text-white">
<Icon :icon="menu.icon" class="text-7.5!" />
</div>
<span>{{ menu.name }}</span>
</div>
</div>
</el-card>
</template>
<script lang="ts" setup>
/** 快捷入口卡片 */
import { CardTitle } from '@/components/Card'
defineOptions({ name: 'ShortcutCard' })
const router = useRouter() //
/** 菜单列表 */
const menuList = [
{ name: '用户管理', icon: 'ep:user-filled', bgColor: 'bg-red-400', routerName: 'MemberUser' },
{
name: '商品管理',
icon: 'fluent-mdl2:product',
bgColor: 'bg-orange-400',
routerName: 'ProductSpu'
},
{ name: '订单管理', icon: 'ep:list', bgColor: 'bg-yellow-500', routerName: 'TradeOrder' },
{
name: '售后管理',
icon: 'ri:refund-2-line',
bgColor: 'bg-green-600',
routerName: 'TradeAfterSale'
},
{
name: '分销管理',
icon: 'fa-solid:project-diagram',
bgColor: 'bg-cyan-500',
routerName: 'TradeBrokerageUser'
},
{
name: '优惠券',
icon: 'ep:ticket',
bgColor: 'bg-blue-500',
routerName: 'PromotionCoupon'
},
{
name: '拼团活动',
icon: 'fa:group',
bgColor: 'bg-purple-500',
routerName: 'PromotionBargainActivity'
},
{
name: '佣金提现',
icon: 'vaadin:money-withdraw',
bgColor: 'bg-rose-500',
routerName: 'TradeBrokerageWithdraw'
}
]
/**
* 跳转到菜单对应页面
*
* @param routerName 路由页面组件的名称
*/
const handleMenuClick = (routerName: string) => {
router.push({ name: routerName })
}
</script>

View File

@ -0,0 +1,208 @@
<template>
<el-card shadow="never">
<template #header>
<div class="flex flex-row items-center justify-between">
<CardTitle title="交易量趋势" />
<!-- 查询条件 -->
<div class="flex flex-row items-center gap-2">
<el-radio-group v-model="timeRangeType" @change="handleTimeRangeTypeChange">
<el-radio-button v-for="[key, value] in timeRange.entries()" :key="key" :label="key">
{{ value.name }}
</el-radio-button>
</el-radio-group>
</div>
</div>
</template>
<!-- 折线图 -->
<Echart :height="300" :options="eChartOptions" />
</el-card>
</template>
<script lang="ts" setup>
import dayjs, { Dayjs } from 'dayjs'
import { EChartsOption } from 'echarts'
import * as TradeStatisticsApi from '@/api/mall/statistics/trade'
import { fenToYuan } from '@/utils'
import { formatDate } from '@/utils/formatTime'
import { CardTitle } from '@/components/Card'
/** 交易量趋势 */
defineOptions({ name: 'TradeTrendCard' })
enum TimeRangeTypeEnum {
DAY30 = 1,
WEEK = 7,
MONTH = 30,
YEAR = 365
} //
const timeRangeType = ref(TimeRangeTypeEnum.DAY30) // , 30
const loading = ref(true) //
// Map
const timeRange = new Map()
.set(TimeRangeTypeEnum.DAY30, {
name: '30天',
series: [
{ name: '订单金额', type: 'bar', smooth: true, data: [] },
{ name: '订单数量', type: 'line', smooth: true, data: [] }
]
})
.set(TimeRangeTypeEnum.WEEK, {
name: '周',
series: [
{ name: '上周金额', type: 'bar', smooth: true, data: [] },
{ name: '本周金额', type: 'bar', smooth: true, data: [] },
{ name: '上周数量', type: 'line', smooth: true, data: [] },
{ name: '本周数量', type: 'line', smooth: true, data: [] }
]
})
.set(TimeRangeTypeEnum.MONTH, {
name: '月',
series: [
{ name: '上月金额', type: 'bar', smooth: true, data: [] },
{ name: '本月金额', type: 'bar', smooth: true, data: [] },
{ name: '上月数量', type: 'line', smooth: true, data: [] },
{ name: '本月数量', type: 'line', smooth: true, data: [] }
]
})
.set(TimeRangeTypeEnum.YEAR, {
name: '年',
series: [
{ name: '去年金额', type: 'bar', smooth: true, data: [] },
{ name: '今年金额', type: 'bar', smooth: true, data: [] },
{ name: '去年数量', type: 'line', smooth: true, data: [] },
{ name: '今年数量', type: 'line', smooth: true, data: [] }
]
})
/** 图表配置 */
const eChartOptions = reactive<EChartsOption>({
grid: {
left: 20,
right: 20,
bottom: 20,
top: 80,
containLabel: true
},
legend: {
top: 50,
data: []
},
series: [],
toolbox: {
feature: {
//
dataZoom: {
yAxisIndex: false // Y
},
brush: {
type: ['lineX', 'clear'] //
},
saveAsImage: { show: true, name: '订单量趋势' } //
}
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross'
},
padding: [5, 10]
},
xAxis: {
type: 'category',
inverse: true,
boundaryGap: false,
axisTick: {
show: false
},
data: [],
axisLabel: {
formatter: (date: string) => {
switch (timeRangeType.value) {
case TimeRangeTypeEnum.DAY30:
return formatDate(date, 'MM-DD')
case TimeRangeTypeEnum.WEEK:
let weekDay = formatDate(date, 'ddd')
if (weekDay == '0') weekDay = '日'
return '周' + weekDay
case TimeRangeTypeEnum.MONTH:
return formatDate(date, 'D')
case TimeRangeTypeEnum.YEAR:
return formatDate(date, 'M') + '月'
default:
return date
}
}
}
},
yAxis: {
axisTick: {
show: false
}
}
}) as EChartsOption
/** 时间范围类型单选按钮选中 */
const handleTimeRangeTypeChange = async () => {
//
let beginTime: Dayjs
let endTime: Dayjs
switch (timeRangeType.value) {
case TimeRangeTypeEnum.WEEK:
beginTime = dayjs().startOf('week')
endTime = dayjs().endOf('week')
break
case TimeRangeTypeEnum.MONTH:
beginTime = dayjs().startOf('month')
endTime = dayjs().endOf('month')
break
case TimeRangeTypeEnum.YEAR:
beginTime = dayjs().startOf('year')
endTime = dayjs().endOf('year')
break
case TimeRangeTypeEnum.DAY30:
default:
beginTime = dayjs().subtract(30, 'day').startOf('d')
endTime = dayjs().endOf('d')
break
}
//
await getOrderCountTrendComparison(beginTime, endTime)
}
/** 查询订单数量趋势对照数据 */
const getOrderCountTrendComparison = async (
beginTime: dayjs.ConfigType,
endTime: dayjs.ConfigType
) => {
loading.value = true
//
const list = await TradeStatisticsApi.getOrderCountTrendComparison(
timeRangeType.value,
beginTime,
endTime
)
//
const dates: string[] = []
const series = [...timeRange.get(timeRangeType.value).series]
for (let item of list) {
dates.push(item.value.date)
if (series.length === 2) {
series[0].data.push(fenToYuan(item?.value?.orderPayPrice || 0)) //
series[1].data.push(fenToYuan(item?.value?.orderPayCount || 0)) //
} else {
series[0].data.push(fenToYuan(item?.reference?.orderPayPrice || 0)) //
series[1].data.push(fenToYuan(item?.value?.orderPayPrice || 0)) //
series[2].data.push(item?.reference?.orderPayCount || 0) //
series[3].data.push(item?.value?.orderPayCount || 0) //
}
}
eChartOptions.xAxis!['data'] = dates
eChartOptions.series = series
// legend424
eChartOptions.legend['data'] = series.map((item) => item.name)
loading.value = false
}
/** 初始化 **/
onMounted(() => {
handleTimeRangeTypeChange()
})
</script>

View File

@ -0,0 +1,111 @@
<template>
<div class="flex flex-col">
<!-- 数据对照 -->
<el-row :gutter="16" class="row">
<el-col :md="6" :sm="12" :xs="24" :loading="loading">
<ComparisonCard
tag="今日"
title="销售额"
prefix="¥"
::decimals="2"
:value="fenToYuan(orderComparison?.value?.orderPayPrice || 0)"
:reference="fenToYuan(orderComparison?.reference?.orderPayPrice || 0)"
/>
</el-col>
<el-col :md="6" :sm="12" :xs="24" :loading="loading">
<ComparisonCard
tag="今日"
title="用户访问量"
:value="userComparison?.value?.visitUserCount || 0"
:reference="userComparison?.reference?.visitUserCount || 0"
/>
</el-col>
<el-col :md="6" :sm="12" :xs="24" :loading="loading">
<ComparisonCard
tag="今日"
title="订单量"
:value="fenToYuan(orderComparison?.value?.orderPayCount || 0)"
:reference="fenToYuan(orderComparison?.reference?.orderPayCount || 0)"
/>
</el-col>
<el-col :md="6" :sm="12" :xs="24" :loading="loading">
<ComparisonCard
tag="今日"
title="新增用户"
:value="userComparison?.value?.createUserCount || 0"
:reference="userComparison?.reference?.createUserCount || 0"
/>
</el-col>
</el-row>
<el-row :gutter="16" class="row">
<el-col :md="12">
<!-- 快捷入口 -->
<ShortcutCard />
</el-col>
<el-col :md="12">
<!-- 运营数据 -->
<OperationDataCard />
</el-col>
</el-row>
<el-row :gutter="16" class="mb-4">
<el-col :md="18" :sm="24">
<!-- 会员概览 -->
<MemberFunnelCard />
</el-col>
<el-col :md="6" :sm="24">
<!-- 会员终端 -->
<MemberTerminalCard />
</el-col>
</el-row>
<!-- 交易量趋势 -->
<TradeTrendCard class="mb-4" />
<!-- 会员统计 -->
<MemberStatisticsCard />
</div>
</template>
<script lang="ts" setup>
import * as TradeStatisticsApi from '@/api/mall/statistics/trade'
import * as MemberStatisticsApi from '@/api/mall/statistics/member'
import { DataComparisonRespVO } from '@/api/mall/statistics/common'
import { TradeOrderSummaryRespVO } from '@/api/mall/statistics/trade'
import { MemberCountRespVO } from '@/api/mall/statistics/member'
import { fenToYuan } from '@/utils'
import ComparisonCard from './components/ComparisonCard.vue'
import MemberStatisticsCard from './components/MemberStatisticsCard.vue'
import OperationDataCard from './components/OperationDataCard.vue'
import ShortcutCard from './components/ShortcutCard.vue'
import TradeTrendCard from './components/TradeTrendCard.vue'
import MemberTerminalCard from '@/views/mall/statistics/member/components/MemberTerminalCard.vue'
import MemberFunnelCard from '@/views/mall/statistics/member/components/MemberFunnelCard.vue'
/** 商城首页 */
defineOptions({ name: 'MallHome' })
const loading = ref(true) //
const orderComparison = ref<DataComparisonRespVO<TradeOrderSummaryRespVO>>() //
const userComparison = ref<DataComparisonRespVO<MemberCountRespVO>>() //
/** 查询交易对照卡片数据 */
const getOrderComparison = async () => {
orderComparison.value = await TradeStatisticsApi.getOrderComparison()
}
/** 查询会员用户数量对照卡片数据 */
const getUserCountComparison = async () => {
userComparison.value = await MemberStatisticsApi.getUserCountComparison()
}
/** 初始化 **/
onMounted(async () => {
loading.value = true
await Promise.all([getOrderComparison(), getUserCountComparison()])
loading.value = false
})
</script>
<style lang="scss" scoped>
.row {
.el-col {
margin-bottom: 1rem;
}
}
</style>

View File

@ -0,0 +1,119 @@
<template>
<el-card shadow="never">
<template #header>
<div class="my--1.5 flex flex-row items-center justify-between">
<CardTitle title="会员概览" />
<!-- 查询条件 -->
<ShortcutDateRangePicker @change="handleTimeRangeChange" />
</div>
</template>
<div class="min-w-225 py-1.75" v-loading="loading">
<div class="relative h-24 flex">
<div class="h-full w-75% bg-blue-50 <lg:w-35% <xl:w-55%">
<div class="ml-15 h-full flex flex-col justify-center">
<div class="font-bold">
注册用户数量{{ analyseData?.comparison?.value?.registerUserCount || 0 }}
</div>
<div class="mt-2 text-3.5">
环比增长率{{
calculateRelativeRate(
analyseData?.comparison?.value?.registerUserCount,
analyseData?.comparison?.reference?.registerUserCount
)
}}%
</div>
</div>
</div>
<div
class="trapezoid1 ml--38.5 mt-1.5 h-full w-77 flex flex-col items-center justify-center bg-blue-5 text-3.5 text-white"
>
<span class="text-6 font-bold">{{ analyseData?.visitUserCount || 0 }}</span>
<span>访客</span>
</div>
</div>
<div class="relative h-24 flex">
<div class="h-full w-75% flex bg-cyan-50 <lg:w-35% <xl:w-55%">
<div class="ml-15 h-full flex flex-col justify-center">
<div class="font-bold">
活跃用户数量{{ analyseData?.comparison?.value?.visitUserCount || 0 }}
</div>
<div class="mt-2 text-3.5">
环比增长率{{
calculateRelativeRate(
analyseData?.comparison?.value?.visitUserCount,
analyseData?.comparison?.reference?.visitUserCount
)
}}%
</div>
</div>
</div>
<div
class="trapezoid2 ml--28 mt-1.7 h-25 w-56 flex flex-col items-center justify-center bg-cyan-5 text-3.5 text-white"
>
<span class="text-6 font-bold">{{ analyseData?.orderUserCount || 0 }}</span>
<span>下单</span>
</div>
</div>
<div class="relative h-24 flex">
<div class="w-75% flex bg-slate-50 <lg:w-35% <xl:w-55%">
<div class="ml-15 h-full flex flex-row gap-x-16">
<div class="flex flex-col justify-center">
<div class="font-bold">
充值用户数量{{ analyseData?.comparison?.value?.rechargeUserCount || 0 }}
</div>
<div class="mt-2 text-3.5">
环比增长率{{
calculateRelativeRate(
analyseData?.comparison?.value?.rechargeUserCount,
analyseData?.comparison?.reference?.rechargeUserCount
)
}}%
</div>
</div>
<div class="flex flex-col justify-center">
<div class="font-bold">客单价{{ fenToYuan(analyseData?.atv || 0) }}</div>
</div>
</div>
</div>
<div
class="trapezoid3 ml--18 mt-3.25 h-23 w-36 flex flex-col items-center justify-center bg-slate-5 text-3.5 text-white"
>
<span class="text-6 font-bold">{{ analyseData?.payUserCount || 0 }}</span>
<span>成交用户</span>
</div>
</div>
</div>
</el-card>
</template>
<script lang="ts" setup>
import * as MemberStatisticsApi from '@/api/mall/statistics/member'
import dayjs from 'dayjs'
import { calculateRelativeRate, fenToYuan } from '@/utils'
import { MemberAnalyseRespVO } from '@/api/mall/statistics/member'
import { CardTitle } from '@/components/Card'
/** 会员概览卡片 */
defineOptions({ name: 'MemberFunnelCard' })
const loading = ref(true) //
const analyseData = ref<MemberAnalyseRespVO>() //
/** 查询会员概览数据列表 */
const handleTimeRangeChange = async (times: [dayjs.ConfigType, dayjs.ConfigType]) => {
loading.value = true
//
analyseData.value = await MemberStatisticsApi.getMemberAnalyse({ times })
loading.value = false
}
</script>
<style lang="scss" scoped>
.trapezoid1 {
transform: perspective(5em) rotateX(-11deg);
}
.trapezoid2 {
transform: perspective(7em) rotateX(-20deg);
}
.trapezoid3 {
transform: perspective(3em) rotateX(-13deg);
}
</style>

View File

@ -0,0 +1,69 @@
<template>
<el-card shadow="never" v-loading="loading">
<template #header>
<CardTitle title="会员终端" />
</template>
<Echart :height="300" :options="terminalChartOptions" />
</el-card>
</template>
<script lang="ts" setup>
import * as MemberStatisticsApi from '@/api/mall/statistics/member'
import { EChartsOption } from 'echarts'
import { MemberTerminalStatisticsRespVO } from '@/api/mall/statistics/member'
import { DICT_TYPE, DictDataType, getIntDictOptions } from '@/utils/dict'
import { CardTitle } from '@/components/Card'
/** 会员终端卡片 */
defineOptions({ name: 'MemberTerminalCard' })
const loading = ref(true) //
/** 会员终端统计图配置 */
const terminalChartOptions = reactive<EChartsOption>({
tooltip: {
trigger: 'item',
confine: true,
formatter: '{a} <br/>{b} : {c} ({d}%)'
},
legend: {
orient: 'vertical',
left: 'right'
},
roseType: 'area',
series: [
{
name: '会员终端',
type: 'pie',
label: {
show: false
},
labelLine: {
show: false
},
data: []
}
]
}) as EChartsOption
/** 按照终端,查询会员统计列表 */
const getMemberTerminalStatisticsList = async () => {
loading.value = true
const list = await MemberStatisticsApi.getMemberTerminalStatisticsList()
const dictDataList = getIntDictOptions(DICT_TYPE.TERMINAL)
terminalChartOptions.series![0].data = dictDataList.map((dictData: DictDataType) => {
const userCount = list.find(
(item: MemberTerminalStatisticsRespVO) => item.terminal === dictData.value
)?.userCount
return {
name: dictData.label,
value: userCount || 0
}
})
loading.value = false
}
/** 初始化 **/
onMounted(() => {
getMemberTerminalStatisticsList()
})
</script>

View File

@ -44,118 +44,20 @@
</el-row> </el-row>
<el-row :gutter="16" class="mb-4"> <el-row :gutter="16" class="mb-4">
<el-col :md="18" :sm="24"> <el-col :md="18" :sm="24">
<el-card shadow="never"> <!-- 会员概览 -->
<template #header> <MemberFunnelCard />
<div class="flex flex-row items-center justify-between">
<span>会员概览</span>
<!-- 查询条件 -->
<div class="my--2 flex flex-row items-center gap-2">
<el-radio-group v-model="shortcutDays" @change="handleDateTypeChange">
<el-radio-button :label="1">昨天</el-radio-button>
<el-radio-button :label="7">最近7天</el-radio-button>
<el-radio-button :label="30">最近30天</el-radio-button>
</el-radio-group>
<el-date-picker
v-model="queryParams.times"
value-format="YYYY-MM-DD HH:mm:ss"
type="daterange"
start-placeholder="开始日期"
end-placeholder="结束日期"
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
:shortcuts="shortcuts"
class="!w-240px"
@change="getMemberAnalyse"
/>
</div>
</div>
</template>
<div class="min-w-225 py-1.75" v-loading="analyseLoading">
<div class="relative h-24 flex">
<div class="h-full w-75% bg-blue-50 <lg:w-35% <xl:w-55%">
<div class="ml-15 h-full flex flex-col justify-center">
<div class="font-bold">
注册用户数量{{ analyseData?.comparison?.value?.userCount || 0 }}
</div>
<div class="mt-2 text-3.5">
环比增长率{{
calculateRelativeRate(
analyseData?.comparison?.value?.userCount,
analyseData?.comparison?.reference?.userCount
)
}}%
</div>
</div>
</div>
<div
class="trapezoid1 ml--38.5 mt-1.5 h-full w-77 flex flex-col items-center justify-center bg-blue-5 text-3.5 text-white"
>
<span class="text-6 font-bold">{{ analyseData?.visitorCount || 0 }}</span>
<span>访客</span>
</div>
</div>
<div class="relative h-24 flex">
<div class="h-full w-75% flex bg-cyan-50 <lg:w-35% <xl:w-55%">
<div class="ml-15 h-full flex flex-col justify-center">
<div class="font-bold">
活跃用户数量{{ analyseData?.comparison?.value?.activeUserCount || 0 }}
</div>
<div class="mt-2 text-3.5">
环比增长率{{
calculateRelativeRate(
analyseData?.comparison?.value?.activeUserCount,
analyseData?.comparison?.reference?.activeUserCount
)
}}%
</div>
</div>
</div>
<div
class="trapezoid2 ml--28 mt-1.7 h-25 w-56 flex flex-col items-center justify-center bg-cyan-5 text-3.5 text-white"
>
<span class="text-6 font-bold">{{ analyseData?.orderUserCount || 0 }}</span>
<span>下单</span>
</div>
</div>
<div class="relative h-24 flex">
<div class="w-75% flex bg-slate-50 <lg:w-35% <xl:w-55%">
<div class="ml-15 h-full flex flex-row gap-x-16">
<div class="flex flex-col justify-center">
<div class="font-bold">
充值用户数量{{ analyseData?.comparison?.value?.rechargeUserCount || 0 }}
</div>
<div class="mt-2 text-3.5">
环比增长率{{
calculateRelativeRate(
analyseData?.comparison?.value?.rechargeUserCount,
analyseData?.comparison?.reference?.rechargeUserCount
)
}}%
</div>
</div>
<div class="flex flex-col justify-center">
<div class="font-bold">客单价{{ fenToYuan(analyseData?.atv || 0) }}</div>
</div>
</div>
</div>
<div
class="trapezoid3 ml--18 mt-3.25 h-23 w-36 flex flex-col items-center justify-center bg-slate-5 text-3.5 text-white"
>
<span class="text-6 font-bold">{{ analyseData?.payUserCount || 0 }}</span>
<span>成交用户</span>
</div>
</div>
</div>
</el-card>
</el-col> </el-col>
<el-col :md="6" :sm="24"> <el-col :md="6" :sm="24">
<el-card shadow="never" header="会员终端" v-loading="loading"> <!-- 会员终端 -->
<Echart :height="300" :options="terminalChartOptions" /> <MemberTerminalCard />
</el-card>
</el-col> </el-col>
</el-row> </el-row>
<el-row :gutter="16"> <el-row :gutter="16">
<el-col :md="18" :sm="24"> <el-col :md="18" :sm="24">
<el-card shadow="never" header="会员地域分布"> <el-card shadow="never">
<template #header>
<CardTitle title="会员地域分布" />
</template>
<el-row v-loading="loading"> <el-row v-loading="loading">
<el-col :span="10"> <el-col :span="10">
<Echart :height="300" :options="areaChartOptions" /> <Echart :height="300" :options="areaChartOptions" />
@ -180,14 +82,14 @@
/> />
<el-table-column <el-table-column
label="订单创建数量" label="订单创建数量"
prop="orderCreateCount" prop="orderCreateUserCount"
align="center" align="center"
min-width="135" min-width="135"
sortable sortable
/> />
<el-table-column <el-table-column
label="订单支付数量" label="订单支付数量"
prop="orderPayCount" prop="orderPayUserCount"
align="center" align="center"
min-width="135" min-width="135"
sortable sortable
@ -206,7 +108,10 @@
</el-card> </el-card>
</el-col> </el-col>
<el-col :md="6" :sm="24"> <el-col :md="6" :sm="24">
<el-card shadow="never" header="会员性别比例" v-loading="loading"> <el-card shadow="never" v-loading="loading">
<template #header>
<CardTitle title="会员性别比例" />
</template>
<Echart :height="300" :options="sexChartOptions" /> <Echart :height="300" :options="sexChartOptions" />
</el-card> </el-card>
</el-col> </el-col>
@ -214,62 +119,33 @@
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import * as TradeMemberApi from '@/api/mall/statistics/member' import * as MemberStatisticsApi from '@/api/mall/statistics/member'
import TradeTrendValue from '../trade/components/TradeTrendValue.vue' import TradeTrendValue from '../trade/components/TradeTrendValue.vue'
import { EChartsOption } from 'echarts' import { EChartsOption } from 'echarts'
import china from '@/assets/map/json/china.json' import china from '@/assets/map/json/china.json'
import dayjs from 'dayjs'
import { fenToYuan } from '@/utils' import { fenToYuan } from '@/utils'
import * as DateUtil from '@/utils/formatTime'
import { import {
MemberAnalyseRespVO,
MemberAreaStatisticsRespVO, MemberAreaStatisticsRespVO,
MemberSexStatisticsRespVO, MemberSexStatisticsRespVO,
MemberAnalyseReqVO,
MemberSummaryRespVO, MemberSummaryRespVO,
MemberTerminalStatisticsRespVO MemberTerminalStatisticsRespVO
} from '@/api/mall/statistics/member' } from '@/api/mall/statistics/member'
import { DICT_TYPE, DictDataType, getIntDictOptions } from '@/utils/dict' import { DICT_TYPE, DictDataType, getIntDictOptions } from '@/utils/dict'
import echarts from '@/plugins/echarts' import echarts from '@/plugins/echarts'
import { fenToYuanFormat } from '@/utils/formatter' import { fenToYuanFormat } from '@/utils/formatter'
import MemberFunnelCard from './components/MemberFunnelCard.vue'
import MemberTerminalCard from './components/MemberTerminalCard.vue'
import { CardTitle } from '@/components/Card'
/** 会员统计 */ /** 会员统计 */
defineOptions({ name: 'MemberStatistics' }) defineOptions({ name: 'MemberStatistics' })
const loading = ref(true) // const loading = ref(true) //
const analyseLoading = ref(true) //
const queryParams = reactive<MemberAnalyseReqVO>({ times: ['', ''] }) //
const shortcutDays = ref(7) // , 7
const summary = ref<MemberSummaryRespVO>() // const summary = ref<MemberSummaryRespVO>() //
const analyseData = ref<MemberAnalyseRespVO>() //
const areaStatisticsList = shallowRef<MemberAreaStatisticsRespVO[]>() // const areaStatisticsList = shallowRef<MemberAreaStatisticsRespVO[]>() //
// //
echarts?.registerMap('china', china!) echarts?.registerMap('china', china as any)
/** 日期快捷选择 */
const shortcuts = [
{
text: '昨天',
value: () => DateUtil.getDayRange(new Date(), -1)
},
{
text: '最近7天',
value: () => DateUtil.getLast7Days()
},
{
text: '本月',
value: () => [dayjs().startOf('M'), dayjs().subtract(1, 'd')]
},
{
text: '最近30天',
value: () => DateUtil.getLast30Days()
},
{
text: '最近1年',
value: () => DateUtil.getLast1Year()
}
]
/** 会员终端统计图配置 */ /** 会员终端统计图配置 */
const terminalChartOptions = reactive<EChartsOption>({ const terminalChartOptions = reactive<EChartsOption>({
@ -331,8 +207,8 @@ const areaChartOptions = reactive<EChartsOption>({
formatter: (params: any) => { formatter: (params: any) => {
return `${params?.data?.areaName || params?.name}<br/> return `${params?.data?.areaName || params?.name}<br/>
会员数量${params?.data?.userCount || 0}<br/> 会员数量${params?.data?.userCount || 0}<br/>
订单创建数量${params?.data?.orderCreateCount || 0}<br/> 订单创建数量${params?.data?.orderCreateUserCount || 0}<br/>
订单支付数量${params?.data?.orderPayCount || 0}<br/> 订单支付数量${params?.data?.orderPayUserCount || 0}<br/>
订单支付金额${fenToYuan(params?.data?.orderPayPrice || 0)}` 订单支付金额${fenToYuan(params?.data?.orderPayPrice || 0)}`
} }
}, },
@ -357,37 +233,14 @@ const areaChartOptions = reactive<EChartsOption>({
] ]
}) as EChartsOption }) as EChartsOption
/** 计算环比 */
const calculateRelativeRate = (value?: number, reference?: number) => {
// 0
if (!reference) return 0
return ((100 * ((value || 0) - reference)) / reference).toFixed(0)
}
/** 设置时间范围 */
function setTimes() {
const beginDate = dayjs().subtract(shortcutDays.value, 'd')
const yesterday = dayjs().subtract(1, 'd')
queryParams.times = DateUtil.getDateRange(beginDate, yesterday)
}
/** 处理会员概览查询(日期单选按钮组选择后) */
const handleDateTypeChange = async () => {
//
setTimes()
//
await getMemberAnalyse()
}
/** 查询会员统计 */ /** 查询会员统计 */
const getMemberSummary = async () => { const getMemberSummary = async () => {
summary.value = await TradeMemberApi.getMemberSummary() summary.value = await MemberStatisticsApi.getMemberSummary()
} }
/** 按照省份,查询会员统计列表 */ /** 按照省份,查询会员统计列表 */
const getMemberAreaStatisticsList = async () => { const getMemberAreaStatisticsList = async () => {
const list = await TradeMemberApi.getMemberAreaStatisticsList() const list = await MemberStatisticsApi.getMemberAreaStatisticsList()
areaStatisticsList.value = list.map((item: MemberAreaStatisticsRespVO) => { areaStatisticsList.value = list.map((item: MemberAreaStatisticsRespVO) => {
return { return {
...item, ...item,
@ -401,20 +254,21 @@ const getMemberAreaStatisticsList = async () => {
}) })
let min = 0 let min = 0
let max = 0 let max = 0
areaChartOptions.series[0].data = areaStatisticsList.value.map((item) => { areaChartOptions.series![0].data = areaStatisticsList.value.map((item) => {
min = Math.min(min, item.orderPayCount) min = Math.min(min, item.orderPayUserCount || 0)
max = Math.max(max, item.orderPayCount) max = Math.max(max, item.orderPayUserCount || 0)
return { ...item, name: item.areaName, value: item.orderPayCount || 0 } return { ...item, name: item.areaName, value: item.orderPayUserCount || 0 }
}) })
areaChartOptions.visualMap.min = min areaChartOptions.visualMap!['min'] = min
areaChartOptions.visualMap.max = max areaChartOptions.visualMap!['max'] = max
} }
/** 按照性别,查询会员统计列表 */ /** 按照性别,查询会员统计列表 */
const getMemberSexStatisticsList = async () => { const getMemberSexStatisticsList = async () => {
const list = await TradeMemberApi.getMemberSexStatisticsList() const list = await MemberStatisticsApi.getMemberSexStatisticsList()
const dictDataList = getIntDictOptions(DICT_TYPE.SYSTEM_USER_SEX) const dictDataList = getIntDictOptions(DICT_TYPE.SYSTEM_USER_SEX)
sexChartOptions.series[0].data = dictDataList.map((dictData: DictDataType) => { dictDataList.push({ label: '未知', value: null } as any)
sexChartOptions.series![0].data = dictDataList.map((dictData: DictDataType) => {
const userCount = list.find((item: MemberSexStatisticsRespVO) => item.sex === dictData.value) const userCount = list.find((item: MemberSexStatisticsRespVO) => item.sex === dictData.value)
?.userCount ?.userCount
return { return {
@ -426,8 +280,9 @@ const getMemberSexStatisticsList = async () => {
/** 按照终端,查询会员统计列表 */ /** 按照终端,查询会员统计列表 */
const getMemberTerminalStatisticsList = async () => { const getMemberTerminalStatisticsList = async () => {
const list = await TradeMemberApi.getMemberTerminalStatisticsList() const list = await MemberStatisticsApi.getMemberTerminalStatisticsList()
const dictDataList = getIntDictOptions(DICT_TYPE.TERMINAL) const dictDataList = getIntDictOptions(DICT_TYPE.TERMINAL)
dictDataList.push({ label: '未知', value: null } as any)
terminalChartOptions.series![0].data = dictDataList.map((dictData: DictDataType) => { terminalChartOptions.series![0].data = dictDataList.map((dictData: DictDataType) => {
const userCount = list.find( const userCount = list.find(
(item: MemberTerminalStatisticsRespVO) => item.terminal === dictData.value (item: MemberTerminalStatisticsRespVO) => item.terminal === dictData.value
@ -439,20 +294,6 @@ const getMemberTerminalStatisticsList = async () => {
}) })
} }
/** 查询会员概览数据列表 */
const getMemberAnalyse = async () => {
analyseLoading.value = true
const times = queryParams.times
// , ,
if (DateUtil.isSameDay(times[0], times[1])) {
//
times[0] = DateUtil.formatDate(dayjs(times[0]).subtract(1, 'd'))
}
//
analyseData.value = await TradeMemberApi.getMemberAnalyse({ times })
analyseLoading.value = false
}
/** 初始化 **/ /** 初始化 **/
onMounted(async () => { onMounted(async () => {
loading.value = true loading.value = true
@ -460,8 +301,7 @@ onMounted(async () => {
getMemberSummary(), getMemberSummary(),
getMemberTerminalStatisticsList(), getMemberTerminalStatisticsList(),
getMemberAreaStatisticsList(), getMemberAreaStatisticsList(),
getMemberSexStatisticsList(), getMemberSexStatisticsList()
handleDateTypeChange()
]) ])
loading.value = false loading.value = false
}) })
@ -472,13 +312,4 @@ onMounted(async () => {
margin-bottom: 1rem; margin-bottom: 1rem;
} }
} }
.trapezoid1 {
transform: perspective(5em) rotateX(-11deg);
}
.trapezoid2 {
transform: perspective(7em) rotateX(-20deg);
}
.trapezoid3 {
transform: perspective(3em) rotateX(-13deg);
}
</style> </style>

View File

@ -59,25 +59,9 @@
<template #header> <template #header>
<!-- 标题 --> <!-- 标题 -->
<div class="flex flex-row items-center justify-between"> <div class="flex flex-row items-center justify-between">
<span>交易状况</span> <CardTitle title="交易状况" />
<!-- 查询条件 --> <!-- 查询条件 -->
<div class="flex flex-row items-center gap-2"> <ShortcutDateRangePicker ref="shortcutDateRangePicker" @change="getTradeTrendData">
<el-radio-group v-model="shortcutDays" @change="handleDateTypeChange">
<el-radio-button :label="1">昨天</el-radio-button>
<el-radio-button :label="7">最近7天</el-radio-button>
<el-radio-button :label="30">最近30天</el-radio-button>
</el-radio-group>
<el-date-picker
v-model="queryParams.times"
value-format="YYYY-MM-DD HH:mm:ss"
type="daterange"
start-placeholder="开始日期"
end-placeholder="结束日期"
:default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
:shortcuts="shortcuts"
class="!w-240px"
@change="getTradeTrendData"
/>
<el-button <el-button
class="ml-4" class="ml-4"
@click="handleExport" @click="handleExport"
@ -86,7 +70,7 @@
> >
<Icon icon="ep:download" class="mr-1" />导出 <Icon icon="ep:download" class="mr-1" />导出
</el-button> </el-button>
</div> </ShortcutDateRangePicker>
</div> </div>
</template> </template>
<!-- 统计值 --> <!-- 统计值 -->
@ -100,11 +84,11 @@
icon-bg-color="text-blue-500" icon-bg-color="text-blue-500"
prefix="¥" prefix="¥"
:decimals="2" :decimals="2"
:value="fenToYuan(trendSummary?.value?.turnover || 0)" :value="fenToYuan(trendSummary?.value?.turnoverPrice || 0)"
:percent=" :percent="
calculateRelativeRate( calculateRelativeRate(
trendSummary?.value?.turnover, trendSummary?.value?.turnoverPrice,
trendSummary?.reference?.turnover trendSummary?.reference?.turnoverPrice
) )
" "
/> />
@ -172,11 +156,11 @@
icon-bg-color="text-cyan-500" icon-bg-color="text-cyan-500"
prefix="¥" prefix="¥"
:decimals="2" :decimals="2"
:value="fenToYuan(trendSummary?.value?.balancePrice || 0)" :value="fenToYuan(trendSummary?.value?.orderWalletPayPrice || 0)"
:percent=" :percent="
calculateRelativeRate( calculateRelativeRate(
trendSummary?.value?.balancePrice, trendSummary?.value?.orderWalletPayPrice,
trendSummary?.reference?.balancePrice trendSummary?.reference?.orderWalletPayPrice
) )
" "
/> />
@ -230,58 +214,27 @@ import * as TradeStatisticsApi from '@/api/mall/statistics/trade'
import TradeStatisticValue from './components/TradeStatisticValue.vue' import TradeStatisticValue from './components/TradeStatisticValue.vue'
import TradeTrendValue from './components/TradeTrendValue.vue' import TradeTrendValue from './components/TradeTrendValue.vue'
import { EChartsOption } from 'echarts' import { EChartsOption } from 'echarts'
import { import { DataComparisonRespVO } from '@/api/mall/statistics/common'
TradeStatisticsComparisonRespVO, import { TradeSummaryRespVO, TradeTrendSummaryRespVO } from '@/api/mall/statistics/trade'
TradeSummaryRespVO, import { calculateRelativeRate, fenToYuan } from '@/utils'
TradeTrendReqVO,
TradeTrendSummaryRespVO
} from '@/api/mall/statistics/trade'
import dayjs from 'dayjs'
import { fenToYuan } from '@/utils'
import * as DateUtil from '@/utils/formatTime'
import download from '@/utils/download' import download from '@/utils/download'
import { CardTitle } from '@/components/Card'
/** 交易统计 */ /** 交易统计 */
defineOptions({ name: 'TradeStatistics' }) defineOptions({ name: 'TradeStatistics' })
const message = useMessage() // const message = useMessage() //
const loading = ref(true) //
const trendLoading = ref(true) // const trendLoading = ref(true) //
const exportLoading = ref(false) // const exportLoading = ref(false) //
const queryParams = reactive<TradeTrendReqVO>({ times: ['', ''] }) // const summary = ref<DataComparisonRespVO<TradeSummaryRespVO>>() //
const shortcutDays = ref(7) // , 7 const trendSummary = ref<DataComparisonRespVO<TradeTrendSummaryRespVO>>() //
const summary = ref<TradeStatisticsComparisonRespVO<TradeSummaryRespVO>>() // const shortcutDateRangePicker = ref()
const trendSummary = ref<TradeStatisticsComparisonRespVO<TradeTrendSummaryRespVO>>() //
/** 日期快捷选择 */
const shortcuts = [
{
text: '昨天',
value: () => DateUtil.getDayRange(new Date(), -1)
},
{
text: '最近7天',
value: () => DateUtil.getLast7Days()
},
{
text: '本月',
value: () => [dayjs().startOf('M'), dayjs().subtract(1, 'd')]
},
{
text: '最近30天',
value: () => DateUtil.getLast30Days()
},
{
text: '最近1年',
value: () => DateUtil.getLast1Year()
}
]
/** 折线图配置 */ /** 折线图配置 */
const lineChartOptions = reactive<EChartsOption>({ const lineChartOptions = reactive<EChartsOption>({
dataset: { dataset: {
dimensions: ['date', 'turnover', 'orderPayPrice', 'rechargePrice', 'expensePrice'], dimensions: ['date', 'turnoverPrice', 'orderPayPrice', 'rechargePrice', 'expensePrice'],
source: [] source: []
}, },
grid: { grid: {
@ -333,33 +286,10 @@ const lineChartOptions = reactive<EChartsOption>({
} }
}) as EChartsOption }) as EChartsOption
/** 计算环比 */
const calculateRelativeRate = (value?: number, reference?: number) => {
// 0
if (!reference) return 0
return ((100 * ((value || 0) - reference)) / reference).toFixed(0)
}
/** 设置时间范围 */
function setTimes() {
const beginDate = dayjs().subtract(shortcutDays.value, 'd')
const yesterday = dayjs().subtract(1, 'd')
queryParams.times = DateUtil.getDateRange(beginDate, yesterday)
}
/** 处理交易状况查询(日期单选按钮组选择后) */
const handleDateTypeChange = async () => {
//
setTimes()
//
await getTradeTrendData()
}
/** 处理交易状况查询 */ /** 处理交易状况查询 */
const getTradeTrendData = async () => { const getTradeTrendData = async () => {
trendLoading.value = true trendLoading.value = true
await Promise.all([getTradeTrendSummary(), getTradeTrendList()]) await Promise.all([getTradeTrendSummary(), getTradeStatisticsList()])
trendLoading.value = false trendLoading.value = false
} }
@ -370,24 +300,18 @@ const getTradeStatisticsSummary = async () => {
/** 查询交易状况数据统计 */ /** 查询交易状况数据统计 */
const getTradeTrendSummary = async () => { const getTradeTrendSummary = async () => {
loading.value = true const times = shortcutDateRangePicker.value.times
trendSummary.value = await TradeStatisticsApi.getTradeTrendSummary(queryParams) trendSummary.value = await TradeStatisticsApi.getTradeTrendSummary({ times })
loading.value = false
} }
/** 查询交易状况数据列表 */ /** 查询交易状况数据列表 */
const getTradeTrendList = async () => { const getTradeStatisticsList = async () => {
const times = queryParams.times
// , 线,
if (DateUtil.isSameDay(times[0], times[1])) {
//
times[0] = DateUtil.formatDate(dayjs(times[0]).subtract(1, 'd'))
}
// //
const list = await TradeStatisticsApi.getTradeTrendList({ times }) const times = shortcutDateRangePicker.value.times
const list = await TradeStatisticsApi.getTradeStatisticsList({ times })
// //
for (let item of list) { for (let item of list) {
item.turnover = fenToYuan(item.turnover) item.turnoverPrice = fenToYuan(item.turnoverPrice)
item.orderPayPrice = fenToYuan(item.orderPayPrice) item.orderPayPrice = fenToYuan(item.orderPayPrice)
item.rechargePrice = fenToYuan(item.rechargePrice) item.rechargePrice = fenToYuan(item.rechargePrice)
item.expensePrice = fenToYuan(item.expensePrice) item.expensePrice = fenToYuan(item.expensePrice)
@ -405,7 +329,8 @@ const handleExport = async () => {
await message.exportConfirm() await message.exportConfirm()
// //
exportLoading.value = true exportLoading.value = true
const data = await TradeStatisticsApi.exportTradeTrend(queryParams) const times = shortcutDateRangePicker.value.times
const data = await TradeStatisticsApi.exportTradeStatisticsExcel({ times })
download.excel(data, '交易状况.xls') download.excel(data, '交易状况.xls')
} catch { } catch {
} finally { } finally {
@ -416,7 +341,6 @@ const handleExport = async () => {
/** 初始化 **/ /** 初始化 **/
onMounted(async () => { onMounted(async () => {
await getTradeStatisticsSummary() await getTradeStatisticsSummary()
await handleDateTypeChange()
}) })
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>