Skip to content

Commit 9bdba0f

Browse files
YunaiVgitee-org
authored andcommitted
!351 商品统计
Merge pull request !351 from 疯狂的世界/dev
2 parents 8801c82 + 1fb7701 commit 9bdba0f

File tree

8 files changed

+492
-25
lines changed

8 files changed

+492
-25
lines changed

src/api/mall/statistics/product.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import request from '@/config/axios'
2+
import { DataComparisonRespVO } from '@/api/mall/statistics/common'
3+
4+
export interface ProductStatisticsVO {
5+
id: number
6+
day: string
7+
spuId: number
8+
spuName: string
9+
spuPicUrl: string
10+
browseCount: number
11+
browseUserCount: number
12+
favoriteCount: number
13+
cartCount: number
14+
orderCount: number
15+
orderPayCount: number
16+
orderPayPrice: number
17+
afterSaleCount: number
18+
afterSaleRefundPrice: number
19+
browseConvertPercent: number
20+
}
21+
22+
// 商品统计 API
23+
export const ProductStatisticsApi = {
24+
// 获得商品统计分析
25+
getProductStatisticsAnalyse: (params: any) => {
26+
return request.get<DataComparisonRespVO<ProductStatisticsVO>>({
27+
url: '/statistics/product/analyse',
28+
params
29+
})
30+
},
31+
// 获得商品状况明细
32+
getProductStatisticsList: (params: any) => {
33+
return request.get<ProductStatisticsVO[]>({
34+
url: '/statistics/product/list',
35+
params
36+
})
37+
},
38+
// 导出获得商品状况明细 Excel
39+
exportProductStatisticsExcel: (params: any) => {
40+
return request.download({
41+
url: '/statistics/product/export-excel',
42+
params
43+
})
44+
},
45+
// 获得商品排行榜分页
46+
getProductStatisticsRankPage: async (params: any) => {
47+
return await request.get({
48+
url: `/statistics/product/rank-page`,
49+
params
50+
})
51+
}
52+
}

src/api/mall/statistics/trade.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ export const getTradeStatisticsSummary = () => {
6666
}
6767

6868
// 获得交易状况统计
69-
export const getTradeTrendSummary = (params: TradeTrendReqVO) => {
69+
export const getTradeStatisticsAnalyse = (params: TradeTrendReqVO) => {
7070
return request.get<DataComparisonRespVO<TradeTrendSummaryRespVO>>({
71-
url: '/statistics/trade/trend/summary',
71+
url: '/statistics/trade/analyse',
7272
params: formatDateParam(params)
7373
})
7474
}

src/config/axios/service.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,11 @@ service.interceptors.request.use(
7070
}
7171
// get参数编码
7272
if (config.method?.toUpperCase() === 'GET' && params) {
73-
let url = config.url + '?'
74-
for (const propName of Object.keys(params)) {
75-
const value = params[propName]
76-
if (value !== void 0 && value !== null && typeof value !== 'undefined') {
77-
if (typeof value === 'object') {
78-
for (const val of Object.keys(value)) {
79-
const params = propName + '[' + val + ']'
80-
const subPart = encodeURIComponent(params) + '='
81-
url += subPart + encodeURIComponent(value[val]) + '&'
82-
}
83-
} else {
84-
url += `${propName}=${encodeURIComponent(value)}&`
85-
}
86-
}
87-
}
88-
// 给 get 请求加上时间戳参数,避免从缓存中拿数据
89-
// const now = new Date().getTime()
90-
// params = params.substring(0, url.length - 1) + `?_t=${now}`
91-
url = url.slice(0, -1)
9273
config.params = {}
93-
config.url = url
74+
const paramsStr = qs.stringify(params, { allowDots: true })
75+
if (paramsStr) {
76+
config.url = config.url + '?' + paramsStr
77+
}
9478
}
9579
return config
9680
},

src/utils/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,12 @@ export const getUrlValue = (key: string, urlStr: string = location.href): string
285285
export const getUrlNumberValue = (key: string, urlStr: string = location.href): number => {
286286
return toNumber(getUrlValue(key, urlStr))
287287
}
288+
289+
/**
290+
* 构建排序字段
291+
* @param prop 字段名称
292+
* @param order 顺序
293+
*/
294+
export const buildSortingField = ({ prop, order }) => {
295+
return { field: prop, order: order === 'ascending' ? 'asc' : 'desc' }
296+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<template>
2+
<el-card shadow="never">
3+
<template #header>
4+
<!-- 标题 -->
5+
<div class="flex flex-row items-center justify-between">
6+
<CardTitle title="商品排行" />
7+
<!-- 查询条件 -->
8+
<ShortcutDateRangePicker ref="shortcutDateRangePicker" @change="handleDateRangeChange" />
9+
</div>
10+
</template>
11+
<!-- 排行列表 -->
12+
<el-table v-loading="loading" :data="list" @sort-change="handleSortChange">
13+
<el-table-column label="商品ID" prop="spuId" min-width="70" />
14+
<el-table-column label="商品图片" align="center" prop="picUrl" width="80">
15+
<template #default="{ row }">
16+
<el-image
17+
:src="row.picUrl"
18+
:preview-src-list="[row.picUrl]"
19+
class="h-30px w-30px"
20+
preview-teleported
21+
/>
22+
</template>
23+
</el-table-column>
24+
<el-table-column label="商品名称" prop="name" min-width="200" :show-overflow-tooltip="true" />
25+
<el-table-column label="浏览量" prop="browseCount" min-width="90" sortable="custom" />
26+
<el-table-column label="访客数" prop="browseUserCount" min-width="90" sortable="custom" />
27+
<el-table-column label="加购件数" prop="cartCount" min-width="105" sortable="custom" />
28+
<el-table-column label="下单件数" prop="orderCount" min-width="105" sortable="custom" />
29+
<el-table-column label="支付件数" prop="orderPayCount" min-width="105" sortable="custom" />
30+
<el-table-column label="支付金额" prop="orderPayPrice" min-width="105" sortable="custom" />
31+
<el-table-column label="收藏数" prop="favoriteCount" min-width="90" sortable="custom" />
32+
<el-table-column
33+
label="访客-支付转化率(%)"
34+
prop="browseConvertPercent"
35+
min-width="180"
36+
sortable="custom"
37+
:formatter="formatConvertRate"
38+
/>
39+
</el-table>
40+
<!-- 分页 -->
41+
<Pagination
42+
:total="total"
43+
v-model:page="queryParams.pageNo"
44+
v-model:limit="queryParams.pageSize"
45+
@pagination="getSpuList"
46+
/>
47+
</el-card>
48+
</template>
49+
<script lang="ts" setup>
50+
import { ProductStatisticsApi, ProductStatisticsVO } from '@/api/mall/statistics/product'
51+
import { CardTitle } from '@/components/Card'
52+
import { buildSortingField } from '@/utils'
53+
54+
/** 商品排行 */
55+
defineOptions({ name: 'ProductRank' })
56+
57+
// 格式化:访客-支付转化率
58+
const formatConvertRate = (row: ProductStatisticsVO) => {
59+
return `${row.browseConvertPercent}%`
60+
}
61+
62+
const handleSortChange = (params: any) => {
63+
queryParams.sortingFields = [buildSortingField(params)]
64+
getSpuList()
65+
}
66+
67+
const handleDateRangeChange = (times: any[]) => {
68+
queryParams.times = times as []
69+
getSpuList()
70+
}
71+
72+
const shortcutDateRangePicker = ref()
73+
// 查询参数
74+
const queryParams = reactive({
75+
pageNo: 1,
76+
pageSize: 10,
77+
times: [],
78+
sortingFields: {}
79+
})
80+
// 列表的加载中
81+
const loading = ref(false)
82+
// 列表的总页数
83+
const total = ref(0)
84+
// 列表的数据
85+
const list = ref<ProductStatisticsVO[]>([])
86+
87+
/** 查询商品列表 */
88+
const getSpuList = async () => {
89+
loading.value = true
90+
try {
91+
const data = await ProductStatisticsApi.getProductStatisticsRankPage(queryParams)
92+
list.value = data.list
93+
total.value = data.total
94+
} finally {
95+
loading.value = false
96+
}
97+
}
98+
99+
/** 初始化 **/
100+
onMounted(async () => {
101+
await getSpuList()
102+
})
103+
</script>
104+
<style lang="scss" scoped></style>

0 commit comments

Comments
 (0)