Просмотр исходного кода

feat: 收费记录页新增当日汇总统计——总额/现金/免密/笔数

lq 1 месяц назад
Родитель
Сommit
05f6612c84

+ 8 - 0
frontend/src/api/payment.js

@@ -8,3 +8,11 @@ export const getPaymentList = (params) => {
     params
   })
 }
+
+// 当日收费汇总
+export const getTodaySummary = () => {
+  return service({
+    url: '/payment/today-summary',
+    method: 'get'
+  })
+}

+ 30 - 3
frontend/src/view/report/paymentRecord.vue

@@ -1,6 +1,21 @@
 <template>
   <div>
-    <el-form inline>
+    <el-row :gutter="16" class="summary-row">
+      <el-col :span="6">
+        <el-statistic title="今日收款总额" :value="summary.total_amount" prefix="¥" :precision="2" />
+      </el-col>
+      <el-col :span="6">
+        <el-statistic title="现金收款" :value="summary.cash_amount" prefix="¥" :precision="2" />
+      </el-col>
+      <el-col :span="6">
+        <el-statistic title="免密放行" :value="summary.free_amount" prefix="¥" :precision="2" />
+      </el-col>
+      <el-col :span="6">
+        <el-statistic title="收款笔数" :value="summary.total_count" />
+      </el-col>
+    </el-row>
+
+    <el-form inline style="margin-top:16px">
       <el-form-item :label="$t.value.LicensePlateNo">
         <el-input v-model="queryForm.plate_number" :placeholder="$t.value.carPlateInput" clearable />
       </el-form-item>
@@ -61,14 +76,21 @@
 
 <script setup>
 import { ref, reactive, onMounted } from 'vue'
-import { getPaymentList } from '@/api/payment'
+import { getPaymentList, getTodaySummary } from '@/api/payment'
 
 const queryForm = reactive({ plate_number: '', payment_method: '', page: 1, page_size: 10, start_date: '', end_date: '' })
 const dateRange = ref([])
 const list = ref([])
 const total = ref(0)
+const summary = reactive({ total_amount: 0, cash_amount: 0, free_amount: 0, total_count: 0 })
 
-onMounted(() => fetchList())
+onMounted(() => { fetchList(); fetchSummary() })
+
+function fetchSummary() {
+  getTodaySummary().then(res => {
+    if (res.code === 0) Object.assign(summary, res.data)
+  })
+}
 
 function fetchList() {
   if (dateRange.value && dateRange.value.length === 2) {
@@ -94,3 +116,8 @@ function resetQuery() {
   fetchList()
 }
 </script>
+
+<style scoped>
+.summary-row { margin-bottom: 16px; }
+.summary-row .el-statistic { background: #f5f7fa; padding: 16px; border-radius: 8px; }
+</style>

+ 11 - 0
internal/modules/payment/api.go

@@ -63,11 +63,22 @@ func ListPayments(c *gin.Context) {
 	}, "查询成功", c)
 }
 
+// TodaySummary 当日收费汇总
+func TodaySummary(c *gin.Context) {
+	s, err := paymentSvc.GetTodaySummary()
+	if err != nil {
+		response.FailWithMessage(err.Error(), c)
+		return
+	}
+	response.OkWithData(s, c)
+}
+
 // SetupPaymentRouter 注册支付相关路由
 func SetupPaymentRouter(router *gin.RouterGroup) {
 	pg := router.Group("/payment")
 	{
 		pg.GET("/list", ListPayments)
+		pg.GET("/today-summary", TodaySummary)
 	}
 	eg := router.Group("/vehicle")
 	{

+ 23 - 0
internal/modules/payment/repository/repo.go

@@ -1,6 +1,7 @@
 package repository
 
 import (
+	"time"
 	"wails-app/internal/dao"
 	"wails-app/internal/global"
 )
@@ -78,3 +79,25 @@ func (r *PaymentRepository) List(q PaymentListQuery) ([]PaymentListResult, int64
 	err := db.Order("payment_record.paid_at DESC").Offset(offset).Limit(q.PageSize).Scan(&results).Error
 	return results, total, err
 }
+
+// TodaySummary 当日收费汇总
+type TodaySummary struct {
+	TotalAmount float64 `json:"total_amount"`
+	CashAmount  float64 `json:"cash_amount"`
+	FreeAmount  float64 `json:"free_amount"`
+	TotalCount  int64   `json:"total_count"`
+}
+
+// GetTodaySummary 获取当日收费汇总
+func (r *PaymentRepository) GetTodaySummary() (TodaySummary, error) {
+	var s TodaySummary
+	today := time.Now().Format("2006-01-02")
+	err := global.GVA_DB.Table("payment_record").
+		Select(`COALESCE(SUM(amount), 0) as total_amount,
+			COALESCE(SUM(CASE WHEN payment_method = 'cash' THEN amount ELSE 0 END), 0) as cash_amount,
+			COALESCE(SUM(CASE WHEN payment_method = 'free' THEN amount ELSE 0 END), 0) as free_amount,
+			COUNT(*) as total_count`).
+		Where("paid_at >= ? AND paid_at < ?", today, today+" 23:59:59").
+		Scan(&s).Error
+	return s, err
+}

+ 5 - 0
internal/modules/payment/service/service.go

@@ -60,3 +60,8 @@ func (s *PaymentService) ProcessPayment(recordID uint, paymentMethod string, amo
 func (s *PaymentService) QueryPayments(q repository.PaymentListQuery) ([]repository.PaymentListResult, int64, error) {
 	return s.repo.List(q)
 }
+
+// GetTodaySummary 获取当日收费汇总
+func (s *PaymentService) GetTodaySummary() (repository.TodaySummary, error) {
+	return s.repo.GetTodaySummary()
+}