From 3f3b1a659d462fb38d9c859b1ccb99f029a44545 Mon Sep 17 00:00:00 2001 From: zhangxin Date: Wed, 10 Mar 2021 19:10:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BD=93=E5=B9=B4=E5=92=8C?= =?UTF-8?q?=E9=99=88=E6=AC=A0=E7=BC=B4=E8=B4=B9=E7=BB=9F=E8=AE=A1=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/models/chargeallocationtab.go | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/web/models/chargeallocationtab.go b/web/models/chargeallocationtab.go index 9eef3d9..8c5b03c 100644 --- a/web/models/chargeallocationtab.go +++ b/web/models/chargeallocationtab.go @@ -3,7 +3,9 @@ package models import ( "fmt" "github.com/go-xorm/xorm" + "lapp_-wy/db" "lapp_-wy/utils" + "lapp_-wy/web/models/response" "strings" "time" ) @@ -148,3 +150,43 @@ func ChargeShareTheMonth(session *xorm.Session, cid int, chargenr int, begdate s } return true } + +// 获取当年物业费和陈欠物业费统计数据 +func (t *Chargeallocationtab) GetChargeStatisticData(cid int, year int) (result *response.ChargeStatisticResponse, err error) { + result = new(response.ChargeStatisticResponse) + engine := db.MasterEngine() + var court Courttab + exist, err := engine.Table(court.TableName()).ID(cid).Get(&court) + if err != nil { + return result, err + } + if !exist { + return result, errors.New("data not exist") + } + // 获取当年物业费统计 + var charge Chargeallocationtab + var currentYearCount float64 + currentYearCount, err = engine.Table(charge.TableName()).Where("cid = ? and allocateyear >= ?", cid, year).Sum(charge, "allocateexpense") + if err != nil { + return result, err + } + currentYearStatistic := &response.StatisticData{ + Type: "current", + Count: currentYearCount, + } + // 获取陈欠物业费 + var oldCount float64 + + oldCount, err = engine.Table(charge.TableName()).Where("cid = ? and allocateyear < ?", cid, year).Sum(charge, "allocateexpense") + if err != nil { + return result, err + } + oldStatistic := &response.StatisticData{ + Type: "old", + Count: oldCount, + } + result.Cid = cid + result.Court = court.Descr + result.Items = append(result.Items, currentYearStatistic, oldStatistic) + return result, nil +}