boss 4 päivää sitten
vanhempi
commit
3df0c19abd

+ 10 - 0
src/api/consumeReport.js

@@ -0,0 +1,10 @@
+import request from '@/utils/request'
+
+// 获取归属代理下所有租户的模块消费统计报告
+export function getConsumptionReport(params) {
+  return request({
+    url: '/proxy/module-consumption/report',
+    method: 'get',
+    params
+  })
+}

+ 12 - 0
src/router/index.js

@@ -135,6 +135,18 @@ export const constantRoutes = [
         name: 'FeeConfig',
         component: () => import('@/views/fee/index'),
         meta: { title: '收费配置', icon: 'el-icon-ticket' }
+      },
+      {
+        path: 'moduleUsage',
+        name: 'FeeModuleUsage',
+        component: () => import('@/views/fee/moduleUsage/index'),
+        meta: { title: '模块使用统计', icon: 'el-icon-data-analysis' }
+      },
+      {
+        path: 'consumeReport',
+        name: 'FeeConsumeReport',
+        component: () => import('@/views/fee/consumeReport/index'),
+        meta: { title: '模块消费统计', icon: 'el-icon-s-order' }
       }
     ]
   },

+ 192 - 0
src/views/fee/consumeReport/index.vue

@@ -0,0 +1,192 @@
+<template>
+  <div class="app-container">
+    <!-- ===== KPI 概览卡片 ===== -->
+    <el-row :gutter="16" class="mb16">
+      <el-col :span="6" v-for="card in overviewCards" :key="card.label">
+        <el-card shadow="hover" class="overview-card">
+          <div class="card-inner">
+            <div class="card-icon" :style="{ background: card.bg }"><i :class="card.icon"></i></div>
+            <div class="card-info">
+              <span class="card-value">{{ card.value }}</span>
+              <span class="card-label">{{ card.label }}</span>
+            </div>
+          </div>
+        </el-card>
+      </el-col>
+    </el-row>
+
+    <!-- ===== 搜索栏 ===== -->
+    <el-card shadow="never" class="mb16 filter-card">
+      <el-form :model="queryParams" ref="queryForm" :inline="true" size="small">
+        <el-form-item label="消费时间">
+          <el-date-picker v-model="dateRange" type="daterange" range-separator="至"
+            start-placeholder="开始日期" end-placeholder="结束日期"
+            value-format="yyyy-MM-dd" style="width:240px" />
+        </el-form-item>
+        <el-form-item>
+          <el-button type="primary" icon="el-icon-search" @click="handleQuery">查询</el-button>
+          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
+        </el-form-item>
+      </el-form>
+    </el-card>
+
+    <!-- ===== 模块消费交叉汇总表 ===== -->
+    <el-table border v-loading="loading" :data="tenantList" size="small" style="width:100%" show-summary :summary-method="getSummary">
+      <el-table-column type="index" label="序号" width="55" align="center" fixed="left" />
+      <el-table-column label="租户名称" align="center" prop="tenantName" min-width="120" fixed="left" />
+      <el-table-column v-for="mod in moduleColumns" :key="mod.code" :label="mod.name" align="center" :min-width="mod.minWidth || 90">
+        <template slot-scope="scope">
+          <span style="color:#1890ff">¥{{ getModuleAmount(scope.row, mod.code) }}</span>
+        </template>
+      </el-table-column>
+      <el-table-column label="消费总额" align="center" prop="totalAmount" width="120" fixed="right">
+        <template slot-scope="scope">
+          <span style="color:#f5222d;font-weight:bold">¥{{ scope.row.totalAmount || '0.00' }}</span>
+        </template>
+      </el-table-column>
+    </el-table>
+
+    <!-- ===== 模块消费汇总表 ===== -->
+    <el-card shadow="never" class="mt16">
+      <div slot="header"><span>各模块消费汇总</span></div>
+      <el-table border :data="moduleBreakdown" size="small" style="width:100%">
+        <el-table-column type="index" label="序号" width="55" align="center" />
+        <el-table-column label="模块" align="center" prop="moduleName" min-width="120" />
+        <el-table-column label="消费笔数" align="center" prop="count" width="100" />
+        <el-table-column label="消费金额" align="center" prop="totalAmount" width="140">
+          <template slot-scope="scope">
+            <span style="color:#1890ff;font-weight:bold">¥{{ scope.row.totalAmount || '0.00' }}</span>
+          </template>
+        </el-table-column>
+        <el-table-column label="占比" align="center" width="100">
+          <template slot-scope="scope">
+            <el-progress :percentage="getPercent(scope.row.totalAmount)" :stroke-width="16" :show-text="true" />
+          </template>
+        </el-table-column>
+      </el-table>
+    </el-card>
+  </div>
+</template>
+
+<script>
+import { getConsumptionReport } from '@/api/consumeReport'
+
+export default {
+  name: 'AgentConsumeReport',
+  data() {
+    return {
+      loading: false,
+      dateRange: [],
+      moduleColumns: [],
+      moduleBreakdown: [],
+      tenantList: [],
+      moduleTotalMap: {},
+      queryParams: {
+        beginTime: null,
+        endTime: null
+      },
+      overviewCards: [
+        { label: '消费总额', value: '¥0.00', icon: 'el-icon-wallet', bg: '#e6f7ff' },
+        { label: '消费笔数', value: 0, icon: 'el-icon-document', bg: '#fff7e6' },
+        { label: '涉及租户数', value: 0, icon: 'el-icon-office-building', bg: '#f6ffed' },
+        { label: '涉及模块数', value: 0, icon: 'el-icon-data-line', bg: '#f9f0ff' }
+      ]
+    }
+  },
+  created() {
+    const now = new Date()
+    const y = now.getFullYear()
+    const m = String(now.getMonth() + 1).padStart(2, '0')
+    this.dateRange = [y + '-' + m + '-01', y + '-' + m + '-' + String(new Date(y, now.getMonth() + 1, 0).getDate()).padStart(2, '0')]
+    this.getReport()
+  },
+  methods: {
+    getReport() {
+      this.loading = true
+      if (this.dateRange && this.dateRange.length === 2) {
+        this.queryParams.beginTime = this.dateRange[0]
+        this.queryParams.endTime = this.dateRange[1]
+      } else {
+        this.queryParams.beginTime = null
+        this.queryParams.endTime = null
+      }
+      getConsumptionReport(this.queryParams).then(res => {
+        const data = res.data || {}
+        this.buildModuleColumns(data.moduleBreakdown || [])
+        this.moduleBreakdown = data.moduleBreakdown || []
+        this.tenantList = data.tenantBreakdown || []
+        this.updateOverview(data.summary || {})
+        this.loading = false
+      }).catch(() => { this.loading = false })
+    },
+    buildModuleColumns(modules) {
+      this.moduleColumns = modules.map(m => ({
+        code: m.moduleCode,
+        name: m.moduleName,
+        minWidth: m.moduleName.length > 4 ? 90 : 80
+      }))
+      this.moduleTotalMap = {}
+      modules.forEach(m => {
+        this.moduleTotalMap[m.moduleCode] = parseFloat(m.totalAmount) || 0
+      })
+    },
+    getModuleAmount(row, moduleCode) {
+      const modules = row.modules || {}
+      const val = modules[moduleCode]
+      return val != null ? parseFloat(val).toFixed(2) : '0.00'
+    },
+    getPercent(amount) {
+      const val = parseFloat(amount) || 0
+      const total = parseFloat((this.overviewCards[0].value || '¥0').replace('¥', '')) || 1
+      return Math.round(val / total * 100)
+    },
+    updateOverview(summary) {
+      this.overviewCards[0].value = '¥' + (parseFloat(summary.totalAmount) || 0).toFixed(2)
+      this.overviewCards[1].value = summary.totalCount || 0
+      this.overviewCards[2].value = summary.tenantCount || 0
+      this.overviewCards[3].value = summary.moduleCount || 0
+    },
+    getSummary({ columns, data }) {
+      const sums = []
+      columns.forEach((col, idx) => {
+        if (idx === 0) { sums[idx] = '合计'; return }
+        if (idx === 1) { sums[idx] = ''; return }
+        const prop = col.property
+        if (prop === 'totalAmount') {
+          const val = data.reduce((s, r) => s + (parseFloat(r[prop]) || 0), 0)
+          sums[idx] = '¥' + val.toFixed(2)
+        } else {
+          sums[idx] = ''
+        }
+      })
+      this.moduleColumns.forEach((mod, mi) => {
+        const colIdx = mi + 2
+        const val = data.reduce((s, r) => s + parseFloat(this.getModuleAmount(r, mod.code)), 0)
+        sums[colIdx] = '¥' + val.toFixed(2)
+      })
+      return sums
+    },
+    handleQuery() { this.getReport() },
+    resetQuery() {
+      this.dateRange = []
+      this.resetForm('queryForm')
+      this.handleQuery()
+    }
+  }
+}
+</script>
+
+<style scoped>
+.overview-card { cursor: default; }
+.card-inner { display: flex; align-items: center; }
+.card-icon {
+  width: 46px; height: 46px; border-radius: 50%;
+  display: flex; align-items: center; justify-content: center;
+  margin-right: 14px; font-size: 22px; color: #fff;
+}
+.card-value { font-size: 22px; font-weight: bold; color: #333; display: block; }
+.card-label { font-size: 12px; color: #999; }
+.filter-card { padding-bottom: 0; }
+.mb16 { margin-bottom: 16px; }
+.mt16 { margin-top: 16px; }
+</style>

+ 126 - 0
src/views/fee/moduleUsage/index.vue

@@ -0,0 +1,126 @@
+<template>
+  <div class="app-container">
+    <el-row :gutter="16" class="mb16">
+      <el-col :span="6" v-for="card in overviewCards" :key="card.label">
+        <el-card shadow="hover" class="overview-card">
+          <div class="card-inner">
+            <div class="card-icon" :style="{ background: card.bg }"><i :class="card.icon"></i></div>
+            <div class="card-info">
+              <span class="card-value">{{ card.value }}</span>
+              <span class="card-label">{{ card.label }}</span>
+            </div>
+          </div>
+        </el-card>
+      </el-col>
+    </el-row>
+
+    <el-card shadow="never" class="mb16 filter-card">
+      <el-form :model="queryParams" ref="queryForm" :inline="true" size="small">
+        <el-form-item label="租户名称" prop="tenantName">
+          <el-input v-model="queryParams.tenantName" placeholder="请输入租户名称" clearable @keyup.enter.native="handleQuery" />
+        </el-form-item>
+        <el-form-item>
+          <el-button type="primary" icon="el-icon-search" @click="handleQuery">查询</el-button>
+          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
+        </el-form-item>
+      </el-form>
+    </el-card>
+
+    <el-table border v-loading="loading" :data="list" size="small" style="width:100%" show-summary :summary-method="getSummary">
+      <el-table-column label="租户名称" align="center" prop="tenantName" min-width="120" fixed="left" />
+      <el-table-column label="外呼次数" align="center" prop="outboundCallCount" min-width="75" />
+      <el-table-column label="语音分钟" align="center" prop="voiceCallMinutes" min-width="75" />
+      <el-table-column label="短信量" align="center" prop="smsSentCount" min-width="65" />
+      <el-table-column label="流量(GB)" align="center" prop="flowUsageGB" min-width="75" />
+      <el-table-column label="个微用户" align="center" prop="wxUserCount" min-width="75" />
+      <el-table-column label="CID加个微" align="center" prop="cidAddWxCount" min-width="80" />
+      <el-table-column label="个微绑定" align="center" prop="wxAccountCount" min-width="75" />
+      <el-table-column label="企微用户" align="center" prop="qwUserCount" min-width="75" />
+      <el-table-column label="CID加企微" align="center" prop="cidAddQwCount" min-width="80" />
+      <el-table-column label="企微绑定" align="center" prop="qwAccountCount" min-width="75" />
+      <el-table-column label="SOP" align="center" prop="sopCount" min-width="55" />
+      <el-table-column label="课程" align="center" prop="courseCount" min-width="55" />
+      <el-table-column label="直播" align="center" prop="liveCount" min-width="55" />
+      <el-table-column label="商品" align="center" prop="productCount" min-width="55" />
+      <el-table-column label="工作流" align="center" prop="workflowCount" min-width="65" />
+      <el-table-column label="销售账户" align="center" prop="salesAccountCount" min-width="75" />
+      <el-table-column label="AI Token" align="center" prop="aiTokenUsed" min-width="90" />
+      <el-table-column label="员工" align="center" prop="employeeCount" min-width="55" />
+      <el-table-column label="活跃模块" align="center" prop="activeModuleCount" min-width="75">
+        <template slot-scope="scope">
+          <el-tag type="success" size="mini">{{ scope.row.activeModuleCount || 0 }}</el-tag>
+        </template>
+      </el-table-column>
+      <el-table-column label="消费总额" align="center" prop="totalConsumeAmount" width="110" fixed="right">
+        <template slot-scope="scope">
+          <span style="color:#1890ff;font-weight:bold">¥{{ scope.row.totalConsumeAmount || '0.00' }}</span>
+        </template>
+      </el-table-column>
+    </el-table>
+
+    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
+  </div>
+</template>
+
+<script>
+import request from '@/utils/request'
+
+export default {
+  name: 'AgentModuleUsage',
+  data() {
+    return {
+      loading: false, list: [], total: 0,
+      queryParams: { pageNum: 1, pageSize: 10, tenantName: null },
+      overviewCards: [
+        { label: '租户总数', value: 0, icon: 'el-icon-office-building', bg: '#e6f7ff' },
+        { label: '活跃模块总数', value: 0, icon: 'el-icon-data-line', bg: '#f6ffed' },
+        { label: '消费总额', value: '¥0.00', icon: 'el-icon-wallet', bg: '#fff7e6' },
+        { label: 'AI调用总量', value: 0, icon: 'el-icon-cpu', bg: '#f9f0ff' }
+      ]
+    }
+  },
+  created() { this.getList() },
+  methods: {
+    getList() {
+      this.loading = true
+      request({ url: '/proxy/module-usage/list', method: 'get', params: this.queryParams }).then(res => {
+        this.list = res.rows || []
+        this.total = res.total || 0
+        this.updateOverview(this.list)
+        this.loading = false
+      }).catch(() => { this.loading = false })
+    },
+    updateOverview(list) {
+      this.overviewCards[0].value = this.total
+      this.overviewCards[1].value = list.reduce((s, r) => s + (r.activeModuleCount || 0), 0)
+      this.overviewCards[2].value = '¥' + list.reduce((s, r) => s + (parseFloat(r.totalConsumeAmount) || 0), 0).toFixed(2)
+      this.overviewCards[3].value = list.reduce((s, r) => s + (r.aiCallTotal || 0) + (r.aiChatTotal || 0), 0)
+    },
+    getSummary({ columns, data }) {
+      const sums = []; const numFields = ['outboundCallCount','voiceCallMinutes','smsSentCount','flowUsageGB',
+        'wxUserCount','cidAddWxCount','wxAccountCount','qwUserCount','cidAddQwCount','qwAccountCount',
+        'sopCount','courseCount','liveCount','productCount','workflowCount','salesAccountCount','aiTokenUsed','employeeCount','activeModuleCount']
+      columns.forEach((col, idx) => {
+        if (idx === 0) { sums[idx] = '合计'; return }
+        const prop = col.property
+        if (numFields.includes(prop)) { sums[idx] = data.reduce((s, r) => s + (r[prop] || 0), 0) }
+        else if (prop === 'totalConsumeAmount') { sums[idx] = '¥' + data.reduce((s, r) => s + (parseFloat(r[prop]) || 0), 0).toFixed(2) }
+        else { sums[idx] = '' }
+      })
+      return sums
+    },
+    handleQuery() { this.queryParams.pageNum = 1; this.getList() },
+    resetQuery() { this.resetForm('queryForm'); this.handleQuery() }
+  }
+}
+</script>
+
+<style scoped>
+.overview-card { cursor: default; }
+.card-inner { display: flex; align-items: center; }
+.card-icon { width: 46px; height: 46px; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin-right: 14px; font-size: 22px; color: #fff; }
+.card-value { font-size: 22px; font-weight: bold; color: #333; display: block; }
+.card-label { font-size: 12px; color: #999; }
+.filter-card { padding-bottom: 0; }
+.mb16 { margin-bottom: 16px; }
+</style>