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 +}