index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <template>
  2. <doc-alert title="【统计】会员、商品、交易统计" url="https://doc.iocoder.cn/mall/statistics/" />
  3. <div class="flex flex-col">
  4. <el-row :gutter="16" class="summary">
  5. <el-col :sm="6" :xs="12">
  6. <TradeStatisticValue
  7. tooltip="昨日订单数量"
  8. title="昨日订单数量"
  9. :value="summary?.value?.yesterdayOrderCount || 0"
  10. :percent="
  11. calculateRelativeRate(
  12. summary?.value?.yesterdayOrderCount,
  13. summary?.reference?.yesterdayOrderCount
  14. )
  15. "
  16. />
  17. </el-col>
  18. <el-col :sm="6" :xs="12">
  19. <TradeStatisticValue
  20. tooltip="本月订单数量"
  21. title="本月订单数量"
  22. :value="summary?.value?.monthOrderCount || 0"
  23. :percent="
  24. calculateRelativeRate(
  25. summary?.value?.monthOrderCount,
  26. summary?.reference?.monthOrderCount
  27. )
  28. "
  29. />
  30. </el-col>
  31. <el-col :sm="6" :xs="12">
  32. <TradeStatisticValue
  33. tooltip="昨日支付金额"
  34. title="昨日支付金额"
  35. prefix="¥"
  36. :decimals="2"
  37. :value="fenToYuan(summary?.value?.yesterdayPayPrice || 0)"
  38. :percent="
  39. calculateRelativeRate(
  40. summary?.value?.yesterdayPayPrice,
  41. summary?.reference?.yesterdayPayPrice
  42. )
  43. "
  44. />
  45. </el-col>
  46. <el-col :sm="6" :xs="12">
  47. <TradeStatisticValue
  48. tooltip="本月支付金额"
  49. title="本月支付金额"
  50. prefix="¥"
  51. ::decimals="2"
  52. :value="fenToYuan(summary?.value?.monthPayPrice || 0)"
  53. :percent="
  54. calculateRelativeRate(summary?.value?.monthPayPrice, summary?.reference?.monthPayPrice)
  55. "
  56. />
  57. </el-col>
  58. </el-row>
  59. <el-card shadow="never">
  60. <template #header>
  61. <!-- 标题 -->
  62. <div class="flex flex-row items-center justify-between">
  63. <CardTitle title="交易状况" />
  64. <!-- 查询条件 -->
  65. <ShortcutDateRangePicker ref="shortcutDateRangePicker" @change="getTradeTrendData">
  66. <el-button
  67. class="ml-4"
  68. @click="handleExport"
  69. :loading="exportLoading"
  70. v-hasPermi="['statistics:trade:export']"
  71. >
  72. <Icon icon="ep:download" class="mr-1" />导出
  73. </el-button>
  74. </ShortcutDateRangePicker>
  75. </div>
  76. </template>
  77. <!-- 统计值 -->
  78. <el-row :gutter="16">
  79. <el-col :md="6" :sm="12" :xs="24">
  80. <SummaryCard
  81. title="营业额"
  82. tooltip="商品支付金额、充值金额"
  83. icon="fa-solid:yen-sign"
  84. icon-color="bg-blue-100"
  85. icon-bg-color="text-blue-500"
  86. prefix="¥"
  87. :decimals="2"
  88. :value="fenToYuan(trendSummary?.value?.turnoverPrice || 0)"
  89. :percent="
  90. calculateRelativeRate(
  91. trendSummary?.value?.turnoverPrice,
  92. trendSummary?.reference?.turnoverPrice
  93. )
  94. "
  95. />
  96. </el-col>
  97. <el-col :md="6" :sm="12" :xs="24">
  98. <SummaryCard
  99. title="商品支付金额"
  100. tooltip="用户购买商品的实际支付金额,包括微信支付、余额支付、支付宝支付、线下支付金额(拼团商品在成团之后计入,线下支付订单在后台确认支付后计入)"
  101. icon="fa-solid:shopping-cart"
  102. icon-color="bg-purple-100"
  103. icon-bg-color="text-purple-500"
  104. prefix="¥"
  105. :decimals="2"
  106. :value="fenToYuan(trendSummary?.value?.orderPayPrice || 0)"
  107. :percent="
  108. calculateRelativeRate(
  109. trendSummary?.value?.orderPayPrice,
  110. trendSummary?.reference?.orderPayPrice
  111. )
  112. "
  113. />
  114. </el-col>
  115. <el-col :md="6" :sm="12" :xs="24">
  116. <SummaryCard
  117. title="充值金额"
  118. tooltip="用户成功充值的金额"
  119. icon="fa-solid:money-check-alt"
  120. icon-color="bg-yellow-100"
  121. icon-bg-color="text-yellow-500"
  122. prefix="¥"
  123. :decimals="2"
  124. :value="fenToYuan(trendSummary?.value?.rechargePrice || 0)"
  125. :percent="
  126. calculateRelativeRate(
  127. trendSummary?.value?.rechargePrice,
  128. trendSummary?.reference?.rechargePrice
  129. )
  130. "
  131. />
  132. </el-col>
  133. <el-col :md="6" :sm="12" :xs="24">
  134. <SummaryCard
  135. title="支出金额"
  136. tooltip="余额支付金额、支付佣金金额、商品退款金额"
  137. icon="ep:warning-filled"
  138. icon-color="bg-green-100"
  139. icon-bg-color="text-green-500"
  140. prefix="¥"
  141. :decimals="2"
  142. :value="fenToYuan(trendSummary?.value?.expensePrice || 0)"
  143. :percent="
  144. calculateRelativeRate(
  145. trendSummary?.value?.expensePrice,
  146. trendSummary?.reference?.expensePrice
  147. )
  148. "
  149. />
  150. </el-col>
  151. <el-col :md="6" :sm="12" :xs="24">
  152. <SummaryCard
  153. title="余额支付金额"
  154. tooltip="用户下单时使用余额实际支付的金额"
  155. icon="fa-solid:wallet"
  156. icon-color="bg-cyan-100"
  157. icon-bg-color="text-cyan-500"
  158. prefix="¥"
  159. :decimals="2"
  160. :value="fenToYuan(trendSummary?.value?.walletPayPrice || 0)"
  161. :percent="
  162. calculateRelativeRate(
  163. trendSummary?.value?.walletPayPrice,
  164. trendSummary?.reference?.walletPayPrice
  165. )
  166. "
  167. />
  168. </el-col>
  169. <el-col :md="6" :sm="12" :xs="24">
  170. <SummaryCard
  171. title="支付佣金金额"
  172. tooltip="后台给推广员支付的推广佣金,以实际支付为准"
  173. icon="fa-solid:award"
  174. icon-color="bg-yellow-100"
  175. icon-bg-color="text-yellow-500"
  176. prefix="¥"
  177. :decimals="2"
  178. :value="fenToYuan(trendSummary?.value?.brokerageSettlementPrice || 0)"
  179. :percent="
  180. calculateRelativeRate(
  181. trendSummary?.value?.brokerageSettlementPrice,
  182. trendSummary?.reference?.brokerageSettlementPrice
  183. )
  184. "
  185. />
  186. </el-col>
  187. <el-col :md="6" :sm="12" :xs="24">
  188. <SummaryCard
  189. title="商品退款金额"
  190. tooltip="用户成功退款的商品金额"
  191. icon="fa-solid:times-circle"
  192. icon-color="bg-blue-100"
  193. icon-bg-color="text-blue-500"
  194. prefix="¥"
  195. :decimals="2"
  196. :value="fenToYuan(trendSummary?.value?.afterSaleRefundPrice || 0)"
  197. :percent="
  198. calculateRelativeRate(
  199. trendSummary?.value?.afterSaleRefundPrice,
  200. trendSummary?.reference?.afterSaleRefundPrice
  201. )
  202. "
  203. />
  204. </el-col>
  205. </el-row>
  206. <!-- 折线图 -->
  207. <el-skeleton :loading="trendLoading" animated>
  208. <Echart :height="500" :options="lineChartOptions" />
  209. </el-skeleton>
  210. </el-card>
  211. </div>
  212. </template>
  213. <script lang="ts" setup>
  214. import * as TradeStatisticsApi from '@/api/mall/statistics/trade'
  215. import TradeStatisticValue from './components/TradeStatisticValue.vue'
  216. import SummaryCard from '@/components/SummaryCard/index.vue'
  217. import { EChartsOption } from 'echarts'
  218. import { DataComparisonRespVO } from '@/api/mall/statistics/common'
  219. import { TradeSummaryRespVO, TradeTrendSummaryRespVO } from '@/api/mall/statistics/trade'
  220. import { calculateRelativeRate, fenToYuan } from '@/utils'
  221. import download from '@/utils/download'
  222. import { CardTitle } from '@/components/Card'
  223. import * as DateUtil from '@/utils/formatTime'
  224. import dayjs from 'dayjs'
  225. /** 交易统计 */
  226. defineOptions({ name: 'TradeStatistics' })
  227. const message = useMessage() // 消息弹窗
  228. const trendLoading = ref(true) // 交易状态加载中
  229. const exportLoading = ref(false) // 导出的加载中
  230. const summary = ref<DataComparisonRespVO<TradeSummaryRespVO>>() // 交易统计数据
  231. const trendSummary = ref<DataComparisonRespVO<TradeTrendSummaryRespVO>>() // 交易状况统计数据
  232. const shortcutDateRangePicker = ref()
  233. /** 折线图配置 */
  234. const lineChartOptions = reactive<EChartsOption>({
  235. dataset: {
  236. dimensions: ['date', 'turnoverPrice', 'orderPayPrice', 'rechargePrice', 'expensePrice'],
  237. source: []
  238. },
  239. grid: {
  240. left: 20,
  241. right: 20,
  242. bottom: 20,
  243. top: 80,
  244. containLabel: true
  245. },
  246. legend: {
  247. top: 50
  248. },
  249. series: [
  250. { name: '营业额', type: 'line', smooth: true },
  251. { name: '商品支付金额', type: 'line', smooth: true },
  252. { name: '充值金额', type: 'line', smooth: true },
  253. { name: '支出金额', type: 'line', smooth: true }
  254. ],
  255. toolbox: {
  256. feature: {
  257. // 数据区域缩放
  258. dataZoom: {
  259. yAxisIndex: false // Y轴不缩放
  260. },
  261. brush: {
  262. type: ['lineX', 'clear'] // 区域缩放按钮、还原按钮
  263. },
  264. saveAsImage: { show: true, name: '交易状况' } // 保存为图片
  265. }
  266. },
  267. tooltip: {
  268. trigger: 'axis',
  269. axisPointer: {
  270. type: 'cross'
  271. },
  272. padding: [5, 10]
  273. },
  274. xAxis: {
  275. type: 'category',
  276. boundaryGap: false,
  277. axisTick: {
  278. show: false
  279. }
  280. },
  281. yAxis: {
  282. axisTick: {
  283. show: false
  284. }
  285. }
  286. }) as EChartsOption
  287. /** 处理交易状况查询 */
  288. const getTradeTrendData = async () => {
  289. trendLoading.value = true
  290. // 1. 处理时间: 开始与截止在同一天的, 折线图出不来, 需要延长一天
  291. const times = shortcutDateRangePicker.value.times
  292. if (DateUtil.isSameDay(times[0], times[1])) {
  293. // 前天
  294. times[0] = DateUtil.formatDate(dayjs(times[0]).subtract(1, 'd'))
  295. }
  296. // 查询数据
  297. await Promise.all([getTradeStatisticsAnalyse(), getTradeStatisticsList()])
  298. trendLoading.value = false
  299. }
  300. /** 查询交易统计 */
  301. const getTradeStatisticsSummary = async () => {
  302. summary.value = await TradeStatisticsApi.getTradeStatisticsSummary()
  303. }
  304. /** 查询交易状况数据统计 */
  305. const getTradeStatisticsAnalyse = async () => {
  306. const times = shortcutDateRangePicker.value.times
  307. trendSummary.value = await TradeStatisticsApi.getTradeStatisticsAnalyse({ times })
  308. }
  309. /** 查询交易状况数据列表 */
  310. const getTradeStatisticsList = async () => {
  311. // 查询数据
  312. const times = shortcutDateRangePicker.value.times
  313. const list = await TradeStatisticsApi.getTradeStatisticsList({ times })
  314. // 处理数据
  315. for (let item of list) {
  316. item.turnoverPrice = fenToYuan(item.turnoverPrice)
  317. item.orderPayPrice = fenToYuan(item.orderPayPrice)
  318. item.rechargePrice = fenToYuan(item.rechargePrice)
  319. item.expensePrice = fenToYuan(item.expensePrice)
  320. }
  321. // 更新 Echarts 数据
  322. if (lineChartOptions.dataset && lineChartOptions.dataset['source']) {
  323. lineChartOptions.dataset['source'] = list
  324. }
  325. }
  326. /** 导出按钮操作 */
  327. const handleExport = async () => {
  328. try {
  329. // 导出的二次确认
  330. await message.exportConfirm()
  331. // 发起导出
  332. exportLoading.value = true
  333. const times = shortcutDateRangePicker.value.times
  334. const data = await TradeStatisticsApi.exportTradeStatisticsExcel({ times })
  335. download.excel(data, '交易状况.xls')
  336. } catch {
  337. } finally {
  338. exportLoading.value = false
  339. }
  340. }
  341. /** 初始化 **/
  342. onMounted(async () => {
  343. await getTradeStatisticsSummary()
  344. })
  345. </script>
  346. <style lang="scss" scoped>
  347. .summary {
  348. .el-col {
  349. margin-bottom: 1rem;
  350. }
  351. }
  352. </style>