From 717fd8065ccaacf25f0f96a585e19f74ab19079c Mon Sep 17 00:00:00 2001 From: zhangxin Date: Wed, 10 Mar 2021 17:37:39 +0800 Subject: [PATCH 01/12] =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 1 + 1 file changed, 1 insertion(+) diff --git a/main.go b/main.go index 422c6ed..34b0264 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ import ( //基于windows系统服务器,安装成服务 + type program struct{} func (p *program) Start(s service.Service) error { From 06bc87d1507264395b78e4ae30982c18469ff3af Mon Sep 17 00:00:00 2001 From: zhangxin Date: Wed, 10 Mar 2021 19:07:27 +0800 Subject: [PATCH 02/12] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=BC=B4=E8=B4=B9?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E7=9A=84=E8=BF=94=E5=9B=9Edata=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/models/response/chargeallocationtab.go | 21 +++++++++++++++++++++ web/models/response/chargetab.go | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 web/models/response/chargeallocationtab.go create mode 100644 web/models/response/chargetab.go diff --git a/web/models/response/chargeallocationtab.go b/web/models/response/chargeallocationtab.go new file mode 100644 index 0000000..9cd8b33 --- /dev/null +++ b/web/models/response/chargeallocationtab.go @@ -0,0 +1,21 @@ +/****************************************************************************** + * @Function Name : + *----------------------------------------------------------------------------- + * @Description : + * @Function Parameters: + * @Return Value : + * @Author : Zhang Xin + * @Date : 2021/3/3 11:02 + ******************************************************************************/ +package response + +type StatisticData struct { + Type string `json:"type"` + Count float64 `json:"count"` +} + +type ChargeStatisticResponse struct { + Cid int `json:"cid"` + Court string `json:"court"` + Items []*StatisticData `json:"items"` +} diff --git a/web/models/response/chargetab.go b/web/models/response/chargetab.go new file mode 100644 index 0000000..1f7c5e4 --- /dev/null +++ b/web/models/response/chargetab.go @@ -0,0 +1,21 @@ +/****************************************************************************** + * @Function Name : + *----------------------------------------------------------------------------- + * @Description : + * @Function Parameters: + * @Return Value : + * @Author : Zhang Xin + * @Date : 2021/3/3 11:02 + ******************************************************************************/ +package response + +type ChargeTypeStatisticDate struct { + Type int64 `json:"type"` + Count float64 `json:"count"` +} + +type ChargeTypeStatisticResponse struct { + Cid int `json:"cid"` + Court string `json:"court"` + Items []*ChargeTypeStatisticDate `json:"items"` +} From 16dc6a5da0ae9d51b2ee2ea6a95852673a0bd135 Mon Sep 17 00:00:00 2001 From: zhangxin Date: Wed, 10 Mar 2021 19:09:43 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8C=89=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E5=92=8C=E7=BC=B4=E8=B4=B9=E7=B1=BB=E5=9E=8B=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E6=95=B0=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/chargetab.go | 50 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/web/models/chargetab.go b/web/models/chargetab.go index 408400a..6649d9f 100644 --- a/web/models/chargetab.go +++ b/web/models/chargetab.go @@ -9,6 +9,7 @@ import ( "lapp_-wy/db" "lapp_-wy/utils" "lapp_-wy/web/middleware/glog" + "lapp_-wy/web/models/response" "strings" "time" "xorm.io/core" @@ -179,10 +180,10 @@ func (t *Chargetab) ChargeTotalByBuilding(buildingid string, beginyear string, e query = query.And("propertytab.buildingid = ?", buildingid) } if !utils.ValueIsEmpty(beginyear) { - query = query.And("chargeallocationtab.allocateyear = ? and chargeallocationtab.allocatemonth >= ? and chargeallocationtab.cid = ?", beginyear, settledate,t.Cid) + query = query.And("chargeallocationtab.allocateyear = ? and chargeallocationtab.allocatemonth >= ? and chargeallocationtab.cid = ?", beginyear, settledate, t.Cid) } if !utils.ValueIsEmpty(endyear) { - query = query.Or("chargeallocationtab.allocateyear = ? and chargeallocationtab.allocatemonth <= ? and chargeallocationtab.cid = ?", endyear, settledate,t.Cid) + query = query.Or("chargeallocationtab.allocateyear = ? and chargeallocationtab.allocatemonth <= ? and chargeallocationtab.cid = ?", endyear, settledate, t.Cid) } if t.Chargetype > 0 { query = query.And("chargetab.chargetype = ?", t.Chargetype) @@ -199,9 +200,9 @@ func (t *Chargetab) ChargeTotalByBuilding(buildingid string, beginyear string, e sumMoney += v.Money //计算每栋楼的缴费数 p := new(Propertytab) - total, _ := e.Table("propertytab").Join("INNER", "contracttab", "propertytab.contractid=contracttab.contractid and propertytab.cid=contracttab.cid").Where("propertytab.buildingid = ? and contracttab.enddate >? and propertytab.cid = ?", v.Buildingid, startdate,t.Cid).Count(p) + total, _ := e.Table("propertytab").Join("INNER", "contracttab", "propertytab.contractid=contracttab.contractid and propertytab.cid=contracttab.cid").Where("propertytab.buildingid = ? and contracttab.enddate >? and propertytab.cid = ?", v.Buildingid, startdate, t.Cid).Count(p) //计算每栋楼的房间数 - alltotal, _ := e.Table("propertytab").Where("isfree != '3' and propertytab.buildingid = ? and propertytab.cid = ?", v.Buildingid,t.Cid).Count(p) + alltotal, _ := e.Table("propertytab").Where("isfree != '3' and propertytab.buildingid = ? and propertytab.cid = ?", v.Buildingid, t.Cid).Count(p) rate := utils.ValueToFloat(total, 0.0) / utils.ValueToFloat(alltotal, 0.0) * 100 rateMoney += rate data[k].Rate = fmt.Sprintf("%0.0f", rate) + "%" @@ -253,7 +254,7 @@ func (t *Chargetab) ChargeTotalByYear(beginyear string, endyear string, settleda } //计算实收金额 ss := new(SumStruct) - _, err := e.Table("chargeallocationtab").Select("sum(allocateexpense) as paid_in_money").Where("allocateyear =? and allocatemonth >=? and cid = ?", i, settledate,t.Cid).Or("allocateyear =? and allocatemonth <=? and cid = ?", endtime, settledate,t.Cid).Get(ss) + _, err := e.Table("chargeallocationtab").Select("sum(allocateexpense) as paid_in_money").Where("allocateyear =? and allocatemonth >=? and cid = ?", i, settledate, t.Cid).Or("allocateyear =? and allocatemonth <=? and cid = ?", endtime, settledate, t.Cid).Get(ss) //计算实收缴费面积 one := SumStruct{} one.Cid = t.Cid @@ -270,7 +271,7 @@ func (t *Chargetab) ChargeTotalByYear(beginyear string, endyear string, settleda one.PaidInArea = utils.ValueToFloat(area, 0.0) //计算应收金额和面积 buildInfo := new(BuildingInfo) - _, err = e.Table("propertytab").Select("propertytypetab.unitprice as unitprice,(SELECT SUM(constructionarea) FROM propertytab WHERE isfree != '3') as constructionarea").Join("INNER", "buildingtab", "propertytab.buildingid=buildingtab.buildingid and propertytab.cid=buildingtab.cid").Join("INNER", "propertytypetab", "propertytypetab.propertytypeid=buildingtab.propertytypeid and propertytypetab.cid=buildingtab.cid").Where("propertytab.cid = ?",t.Cid).Get(buildInfo) + _, err = e.Table("propertytab").Select("propertytypetab.unitprice as unitprice,(SELECT SUM(constructionarea) FROM propertytab WHERE isfree != '3') as constructionarea").Join("INNER", "buildingtab", "propertytab.buildingid=buildingtab.buildingid and propertytab.cid=buildingtab.cid").Join("INNER", "propertytypetab", "propertytypetab.propertytypeid=buildingtab.propertytypeid and propertytypetab.cid=buildingtab.cid").Where("propertytab.cid = ?", t.Cid).Get(buildInfo) if err != nil { glog.InfoExtln("年缴费测试", "err2 := ", err) continue @@ -1574,3 +1575,40 @@ func (t *Chargetab) Del() error { } return nil } + +// 按日期获取指定缴费类型的缴费额 +func (t *Chargetab) GetChargeTypeStatisticData(cid int, chargeType int, start, end string) (result *response.ChargeTypeStatisticResponse, err error) { + result = new(response.ChargeTypeStatisticResponse) + 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 chargeTypeLi []int64 + // 若使用默认chargeType 则搜索表中所有的chargeType + if chargeType == 0 { + err = engine.Table(t.TableName()).Cols("chargetype").Distinct().Find(&chargeTypeLi) + if err != nil { + return nil, err + } + } else { + chargeTypeLi = append(chargeTypeLi, int64(chargeType)) + } + for _, chargeType := range chargeTypeLi { + var statisticData response.ChargeTypeStatisticDate + count, err := engine.Table(t.TableName()).Where("chargetime >= ? and chargetime <= ? and cid = ? and chargetype = ?", start, end, cid, chargeType).Sum(t, "chargableexpense") + if err != nil { + return nil, err + } + statisticData.Type = chargeType + statisticData.Count = count + result.Items = append(result.Items, &statisticData) + } + result.Cid = cid + result.Court = court.Descr + return result, err +} From 3f3b1a659d462fb38d9c859b1ccb99f029a44545 Mon Sep 17 00:00:00 2001 From: zhangxin Date: Wed, 10 Mar 2021 19:10:29 +0800 Subject: [PATCH 04/12] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BD=93=E5=B9=B4?= =?UTF-8?q?=E5=92=8C=E9=99=88=E6=AC=A0=E7=BC=B4=E8=B4=B9=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E6=95=B0=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 +} From c5879fcc141611a40977e909b2e61a8ef01db39f Mon Sep 17 00:00:00 2001 From: zhangxin Date: Wed, 10 Mar 2021 19:11:43 +0800 Subject: [PATCH 05/12] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8C=89=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E5=92=8C=E7=BC=B4=E8=B4=B9=E7=B1=BB=E5=9E=8B=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E7=BB=9F=E8=AE=A1=E6=95=B0=E6=8D=AE=E6=96=B9=E6=B3=95?= =?UTF-8?q?=20=E5=92=8C=20=E6=9F=A5=E8=AF=A2=E5=BD=93=E5=B9=B4=E5=92=8C?= =?UTF-8?q?=E9=99=88=E6=AC=A0=E7=BC=B4=E8=B4=B9=E6=95=B0=E6=8D=AE=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/controllers/chargetab_controller.go | 128 ++++++++++++++++++++---- 1 file changed, 110 insertions(+), 18 deletions(-) diff --git a/web/controllers/chargetab_controller.go b/web/controllers/chargetab_controller.go index 61041c2..b6fdeef 100644 --- a/web/controllers/chargetab_controller.go +++ b/web/controllers/chargetab_controller.go @@ -93,8 +93,8 @@ func GetChargetabByYear(ctx iris.Context) { beginyear := ctx.URLParam("startYear") endyear := ctx.URLParam("endYear") accountMonth := ctx.URLParam("accountMonth") - settledate := utils.ValueToInt(accountMonth,0) - result, count, err := me.ChargeTotalByYear(beginyear, endyear,settledate) + settledate := utils.ValueToInt(accountMonth, 0) + result, count, err := me.ChargeTotalByYear(beginyear, endyear, settledate) if err != nil { supports.Error(ctx, iris.StatusBadRequest, "抱歉未找到相关信息", nil) return @@ -119,9 +119,9 @@ func GetChargetabByBuilding(ctx iris.Context) { buildingid := ctx.URLParam("building") beginyear := ctx.URLParam("startYear") accountMonth := ctx.URLParam("accountMonth") - settledate := utils.ValueToInt(accountMonth,0) - endyear := utils.ValueToInt(beginyear,0) +1 - result, count,rate, err := me.ChargeTotalByBuilding(buildingid, beginyear,utils.ValueToString(endyear,""),settledate) + settledate := utils.ValueToInt(accountMonth, 0) + endyear := utils.ValueToInt(beginyear, 0) + 1 + result, count, rate, err := me.ChargeTotalByBuilding(buildingid, beginyear, utils.ValueToString(endyear, ""), settledate) if err != nil { supports.Error(ctx, iris.StatusBadRequest, "抱歉未找到相关信息", nil) return @@ -174,7 +174,7 @@ func GetChargetabListPage(ctx iris.Context) { } searchtime := ctx.URLParam("expireDate") startDate := ctx.URLParam("startDate") - result, count,total, err := data.ListPage(pageSize, pageIndex, startDate,searchtime) + result, count, total, err := data.ListPage(pageSize, pageIndex, startDate, searchtime) if err != nil { supports.Error(ctx, iris.StatusBadRequest, "抱歉未找到相关信息", nil) return @@ -211,7 +211,7 @@ func GetChargetabReadExcel(ctx iris.Context) { data.Chargetype = chargetype searchtime := ctx.URLParam("expireDate") startDate := ctx.URLParam("startDate") - _, filename, err := data.ReadExcel(startDate,searchtime) + _, filename, err := data.ReadExcel(startDate, searchtime) if err != nil { fmt.Printf("错误err : %v", err) supports.Error(ctx, iris.StatusBadRequest, "抱歉未找到相关信息", nil) @@ -234,9 +234,9 @@ func GetChargetabReadBuildingExcel(ctx iris.Context) { buildingid := ctx.URLParam("building") beginyear := ctx.URLParam("startYear") accountMonth := ctx.URLParam("accountMonth") - settledate := utils.ValueToInt(accountMonth,0) - endyear := utils.ValueToInt(beginyear,0) +1 - _, filename, err := data.ReadBuildExcel(buildingid, beginyear,utils.ValueToString(endyear,""),settledate) + settledate := utils.ValueToInt(accountMonth, 0) + endyear := utils.ValueToInt(beginyear, 0) + 1 + _, filename, err := data.ReadBuildExcel(buildingid, beginyear, utils.ValueToString(endyear, ""), settledate) if err != nil { fmt.Printf("错误err : %v", err) supports.Error(ctx, iris.StatusBadRequest, "抱歉未找到相关信息", nil) @@ -259,8 +259,8 @@ func GetChargetabReadYearExcel(ctx iris.Context) { beginyear := ctx.URLParam("startYear") endyear := ctx.URLParam("endYear") accountMonth := ctx.URLParam("accountMonth") - settledate := utils.ValueToInt(accountMonth,0) - _, filename, err := me.ReadYearExcel(beginyear, endyear,settledate) + settledate := utils.ValueToInt(accountMonth, 0) + _, filename, err := me.ReadYearExcel(beginyear, endyear, settledate) if err != nil { fmt.Printf("错误err : %v", err) supports.Error(ctx, iris.StatusBadRequest, "抱歉未找到相关信息", nil) @@ -313,12 +313,12 @@ func DelChargetab(ctx iris.Context) { logs.InsertRecord() data := new(models.Chargetab) data.Cid = user.Pid - data.Chargenr,_ = ctx.URLParamInt("chargenr") + data.Chargenr, _ = ctx.URLParamInt("chargenr") data.Lastmodifyby = user.Userid data.Serialnumber = ctx.URLParam("serialnumber") err := data.Del() if err != nil { - glog.InfoExt("删除缴费记录","错误原因:",err) + glog.InfoExt("删除缴费记录", "错误原因:", err) supports.Error(ctx, iris.StatusBadRequest, "删除失败", nil) return } @@ -328,7 +328,7 @@ func DelChargetab(ctx iris.Context) { func GetRecordLogList(ctx iris.Context) { user, ok := jwts.ParseToken(ctx) - utils.TrimStruct(user,*user) + utils.TrimStruct(user, *user) if !ok { supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil) return @@ -340,7 +340,7 @@ func GetRecordLogList(ctx iris.Context) { logs.Function = "GetRecordLogList" logs.Message = "删除记录列表查看" logs.Operator = user.Userid - logs.TimeStamp = utils.TimeFormat(time.Now(),"yyyyMMddHHmmss") + logs.TimeStamp = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss") logs.InsertRecord() var data models.RecordLog var err error @@ -359,7 +359,7 @@ func GetRecordLogList(ctx iris.Context) { startdate := ctx.URLParam("startdate") enddate := ctx.URLParam("enddate") - result, count, err := data.GetPage(pageSize, pageIndex,startdate,enddate) + result, count, err := data.GetPage(pageSize, pageIndex, startdate, enddate) if err != nil { supports.Error(ctx, iris.StatusBadRequest, "抱歉未找到相关信息", nil) return @@ -370,4 +370,96 @@ func GetRecordLogList(ctx iris.Context) { res["pageIndex"] = pageIndex res["pageSize"] = pageSize supports.Ok(ctx, supports.OptionSuccess, res) -} \ No newline at end of file +} + +// 获取当前和陈欠的缴费统计数据 +func GetChargeStatisticData(ctx iris.Context) { + user, ok := jwts.ParseToken(ctx) + utils.TrimStruct(user, *user) + if !ok { + supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil) + return + } + logs := new(models.LeitServerLog) + logs.File = "/controllers/Chargetab_controller.go" + logs.Level = "info" + logs.Function = "GetChargeStatisticData" + logs.Message = "当年及陈欠缴费统计查看" + logs.Operator = user.Userid + logs.TimeStamp = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss") + logs.InsertRecord() + + var cid int + // 如果公司机关部门可以搜索cid + if user.Pid == 110 { + cidStr := ctx.URLParam("cid") + cid = utils.ValueToInt(cidStr, 0) + } else { + cid = user.Pid + } + if cid == 0 { + supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil) + return + } + var chargeTab models.Chargeallocationtab + chargeTab.Cid = user.Pid + year := time.Now().Year() + result, err := chargeTab.GetChargeStatisticData(cid, year) + if err != nil { + supports.Error(ctx, iris.StatusInternalServerError, "抱歉未找到相关信息", nil) + return + } + supports.Ok(ctx, supports.OptionSuccess, result) +} + +// 按日期和缴费类型获取缴费统计数据 +func GetChargeTypeStatisticData(ctx iris.Context) { + user, ok := jwts.ParseToken(ctx) + utils.TrimStruct(user, *user) + if !ok { + supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil) + return + } + logs := new(models.LeitServerLog) + logs.File = "/controllers/Chargetab_controller.go" + logs.Level = "info" + logs.Function = "GetChargeTypeStatisticData" + logs.Message = "按日期和收款类型查看缴费统计" + logs.Operator = user.Userid + logs.TimeStamp = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss") + logs.InsertRecord() + + var cid int + // 如果公司机关部门可以搜索cid + if user.Pid == 110 { + cidStr := ctx.URLParam("cid") + cid = utils.ValueToInt(cidStr, 0) + } else { + cid = user.Pid + } + if cid == 0 { + supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil) + return + } + startDateStr := ctx.URLParam("start") + endDateStr := ctx.URLParam("end") + startDate, err1 := utils.TimeParseyyyyMMdd(startDateStr) + endDate, err2 := utils.TimeParseyyyyMMdd(endDateStr) + if err1 != nil || err2 != nil { + supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil) + return + } + chargeTypeStr := ctx.URLParam("charge_type") + // 如为传入或传入的chargeType 不合规则使用-1 进行所有chargeType的分类统计 + chargeType := utils.ValueToInt(chargeTypeStr, 0) + start := utils.TimeFormat(startDate, "yyyy-MM-dd") + end := utils.TimeFormat(endDate, "yyyy-MM-dd") + var charge models.Chargetab + result, err := charge.GetChargeTypeStatisticData(cid, chargeType, start, end) + if err != nil { + supports.Error(ctx, iris.StatusInternalServerError, "抱歉未找到相关信息", nil) + return + } + supports.Ok(ctx, supports.OptionSuccess, result) + +} From d6f600a33cb2d8d504d7620ebad4561b76db98a0 Mon Sep 17 00:00:00 2001 From: zhangxin Date: Wed, 10 Mar 2021 19:12:38 +0800 Subject: [PATCH 06/12] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8C=89=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E5=92=8C=E7=BC=B4=E8=B4=B9=E7=B1=BB=E5=9E=8B=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E7=BB=9F=E8=AE=A1=E6=95=B0=E6=8D=AE=E6=96=B9=E6=B3=95?= =?UTF-8?q?=20=E5=92=8C=20=E6=9F=A5=E8=AF=A2=E5=BD=93=E5=B9=B4=E5=92=8C?= =?UTF-8?q?=E9=99=88=E6=AC=A0=E7=BC=B4=E8=B4=B9=E6=95=B0=E6=8D=AE=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/routes/routes.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/web/routes/routes.go b/web/routes/routes.go index fa0ec9b..e0b3634 100644 --- a/web/routes/routes.go +++ b/web/routes/routes.go @@ -1,10 +1,10 @@ package routes import ( + "github.com/kataras/iris" "lapp_-wy/web/controllers" "lapp_-wy/web/middleware" "lapp_-wy/web/middleware/cors" - "github.com/kataras/iris" ) // 所有的路由 @@ -168,6 +168,8 @@ func Hub(app *iris.Application) { chargetab.Get("/readdataexcel", controllers.GetChargetabReadDataExcel) chargetab.Delete("/del", controllers.DelChargetab) chargetab.Get("/recordlist", controllers.GetRecordLogList) + chargetab.Get("/statistic", controllers.GetChargeStatisticData) + chargetab.Get("/statistic/type", controllers.GetChargeTypeStatisticData) // 固定资产 assettab := admin.Party("/assettab") From 572972dad24077679a83800e691176afcacdb162 Mon Sep 17 00:00:00 2001 From: zhangxin Date: Thu, 11 Mar 2021 19:08:26 +0800 Subject: [PATCH 07/12] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E9=9C=80=E6=B1=82?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BF=94=E5=9B=9Edata=E7=9A=84=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E4=BD=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/models/response/chargeallocationtab.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/web/models/response/chargeallocationtab.go b/web/models/response/chargeallocationtab.go index 9cd8b33..0411e2d 100644 --- a/web/models/response/chargeallocationtab.go +++ b/web/models/response/chargeallocationtab.go @@ -9,13 +9,9 @@ ******************************************************************************/ package response -type StatisticData struct { +type ChargeStatisticResponse struct { + Cid int `json:"cid"` + Court string `json:"court"` Type string `json:"type"` Count float64 `json:"count"` } - -type ChargeStatisticResponse struct { - Cid int `json:"cid"` - Court string `json:"court"` - Items []*StatisticData `json:"items"` -} From 5aa6ffe33d33f9cce8975998baa866096401e0a2 Mon Sep 17 00:00:00 2001 From: zhangxin Date: Thu, 11 Mar 2021 19:09:16 +0800 Subject: [PATCH 08/12] =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E7=BB=93=E6=9E=84=E4=BD=93=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/models/response/chargetab.go | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 web/models/response/chargetab.go diff --git a/web/models/response/chargetab.go b/web/models/response/chargetab.go deleted file mode 100644 index 1f7c5e4..0000000 --- a/web/models/response/chargetab.go +++ /dev/null @@ -1,21 +0,0 @@ -/****************************************************************************** - * @Function Name : - *----------------------------------------------------------------------------- - * @Description : - * @Function Parameters: - * @Return Value : - * @Author : Zhang Xin - * @Date : 2021/3/3 11:02 - ******************************************************************************/ -package response - -type ChargeTypeStatisticDate struct { - Type int64 `json:"type"` - Count float64 `json:"count"` -} - -type ChargeTypeStatisticResponse struct { - Cid int `json:"cid"` - Court string `json:"court"` - Items []*ChargeTypeStatisticDate `json:"items"` -} From 4f466bf3117a80898a44270778f26906e3fb1a10 Mon Sep 17 00:00:00 2001 From: zhangxin Date: Thu, 11 Mar 2021 19:10:10 +0800 Subject: [PATCH 09/12] =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E7=BB=93=E6=9E=84=E4=BD=93=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/routes/routes.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/web/routes/routes.go b/web/routes/routes.go index e0b3634..8f849f8 100644 --- a/web/routes/routes.go +++ b/web/routes/routes.go @@ -157,7 +157,7 @@ func Hub(app *iris.Application) { //收费记录表 chargetab := admin.Party("/chargetab") - chargetab.Get("/listpage", controllers.GetChargetabList) + chargetab.Get("/listpage", controllers.GetChargeArrearageData) chargetab.Get("/datapage", controllers.GetChargetabListPage) chargetab.Get("/selectinfo", controllers.GetChargetab) chargetab.Get("/totalyear", controllers.GetChargetabByYear) @@ -169,7 +169,8 @@ func Hub(app *iris.Application) { chargetab.Delete("/del", controllers.DelChargetab) chargetab.Get("/recordlist", controllers.GetRecordLogList) chargetab.Get("/statistic", controllers.GetChargeStatisticData) - chargetab.Get("/statistic/type", controllers.GetChargeTypeStatisticData) + chargetab.Get("/type/list", controllers.GetChargeTypeData) + //chargetab.Get("/arrearage/list", controllers.GetChargeArrearageData) // 固定资产 assettab := admin.Party("/assettab") From bdc144aedc1b417443354ad253ac0173f840a95f Mon Sep 17 00:00:00 2001 From: zhangxin Date: Fri, 12 Mar 2021 09:15:55 +0800 Subject: [PATCH 10/12] =?UTF-8?q?=E4=BF=AE=E6=94=B9chargetab/listpage?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=B0=83=E7=94=A8=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/controllers/chargetab_controller.go | 103 ++++++++++++++++++++---- 1 file changed, 87 insertions(+), 16 deletions(-) diff --git a/web/controllers/chargetab_controller.go b/web/controllers/chargetab_controller.go index b6fdeef..36d1c11 100644 --- a/web/controllers/chargetab_controller.go +++ b/web/controllers/chargetab_controller.go @@ -402,9 +402,12 @@ func GetChargeStatisticData(ctx iris.Context) { return } var chargeTab models.Chargeallocationtab - chargeTab.Cid = user.Pid + //chargeTab.Cid = user.Pid year := time.Now().Year() - result, err := chargeTab.GetChargeStatisticData(cid, year) + start := fmt.Sprintf("%d0101", year) + end := fmt.Sprintf("%d1231", year) + selectType := ctx.URLParam("type") + result, err := chargeTab.GetChargeStatisticData(cid, year, start, end, selectType) if err != nil { supports.Error(ctx, iris.StatusInternalServerError, "抱歉未找到相关信息", nil) return @@ -412,8 +415,8 @@ func GetChargeStatisticData(ctx iris.Context) { supports.Ok(ctx, supports.OptionSuccess, result) } -// 按日期和缴费类型获取缴费统计数据 -func GetChargeTypeStatisticData(ctx iris.Context) { +// 按日期和缴费类型获取缴费数据 +func GetChargeTypeData(ctx iris.Context) { user, ok := jwts.ParseToken(ctx) utils.TrimStruct(user, *user) if !ok { @@ -423,12 +426,22 @@ func GetChargeTypeStatisticData(ctx iris.Context) { logs := new(models.LeitServerLog) logs.File = "/controllers/Chargetab_controller.go" logs.Level = "info" - logs.Function = "GetChargeTypeStatisticData" - logs.Message = "按日期和收款类型查看缴费统计" + logs.Function = "GetChargeTypeData" + logs.Message = "按日期和收款类型查看缴费数据" logs.Operator = user.Userid logs.TimeStamp = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss") logs.InsertRecord() + var pageSize = 10 + var pageIndex = 1 + if size := ctx.URLParam("size"); size != "" { + pageSize = utils.ValueToInt(size, 0) + } + + if index := ctx.URLParam("index"); index != "" { + pageIndex = utils.ValueToInt(index, 0) + } + var cid int // 如果公司机关部门可以搜索cid if user.Pid == 110 { @@ -441,21 +454,21 @@ func GetChargeTypeStatisticData(ctx iris.Context) { supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil) return } - startDateStr := ctx.URLParam("start") - endDateStr := ctx.URLParam("end") - startDate, err1 := utils.TimeParseyyyyMMdd(startDateStr) - endDate, err2 := utils.TimeParseyyyyMMdd(endDateStr) - if err1 != nil || err2 != nil { + date := ctx.URLParam("date") + tDate, err1 := utils.TimeParseyyyyMMdd(date) + if err1 != nil { supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil) return } - chargeTypeStr := ctx.URLParam("charge_type") // 如为传入或传入的chargeType 不合规则使用-1 进行所有chargeType的分类统计 - chargeType := utils.ValueToInt(chargeTypeStr, 0) - start := utils.TimeFormat(startDate, "yyyy-MM-dd") - end := utils.TimeFormat(endDate, "yyyy-MM-dd") + date = utils.TimeFormat(tDate, "yyyy-MM-dd") + chargeWay := ctx.URLParam("charge_way") + if chargeWay == "" { + supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil) + return + } var charge models.Chargetab - result, err := charge.GetChargeTypeStatisticData(cid, chargeType, start, end) + result, err := charge.GetChargeTypeData(cid, chargeWay, date, pageIndex, pageSize) if err != nil { supports.Error(ctx, iris.StatusInternalServerError, "抱歉未找到相关信息", nil) return @@ -463,3 +476,61 @@ func GetChargeTypeStatisticData(ctx iris.Context) { supports.Ok(ctx, supports.OptionSuccess, result) } + +// 按日期和缴费类型获取缴费统计数据 +func GetChargeArrearageData(ctx iris.Context) { + user, ok := jwts.ParseToken(ctx) + utils.TrimStruct(user, *user) + if !ok { + supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil) + return + } + logs := new(models.LeitServerLog) + logs.File = "/controllers/Chargetab_controller.go" + logs.Level = "info" + logs.Function = "GetChargeArrearageData" + logs.Message = "按日期查看缴费陈欠数据" + logs.Operator = user.Userid + logs.TimeStamp = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss") + logs.InsertRecord() + + var pageSize = 10 + var pageIndex = 1 + if size := ctx.URLParam("size"); size != "" { + pageSize = utils.ValueToInt(size, 0) + } + + if index := ctx.URLParam("index"); index != "" { + pageIndex = utils.ValueToInt(index, 0) + } + + var cid int + // 如果公司机关部门可以搜索cid + if user.Pid == 110 { + cidStr := ctx.URLParam("cid") + cid = utils.ValueToInt(cidStr, 0) + } else { + cid = user.Pid + } + if cid == 0 { + supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil) + return + } + chargeType, err := ctx.URLParamInt("chargetype") + if err != nil { + chargeType = 0 + } + buildingId := ctx.URLParam("buildingid") + propertyId := ctx.URLParam("propertyid") + year := time.Now().Year() + selectType := ctx.URLParam("type") + arrearageDate := fmt.Sprintf("%d-12-31", year-1) + var charge models.Chargetab + result, err := charge.GetChargeArrearageData(cid, pageIndex, pageSize, year, arrearageDate, selectType, chargeType, buildingId, propertyId) + if err != nil { + fmt.Println("outer error:", err) + supports.Error(ctx, iris.StatusInternalServerError, "抱歉未找到相关信息", nil) + return + } + supports.Ok(ctx, supports.OptionSuccess, result) +} From 9a0d478aadcf86ff45d75c700d7ba49d6d33a704 Mon Sep 17 00:00:00 2001 From: zhangxin Date: Fri, 12 Mar 2021 09:17:00 +0800 Subject: [PATCH 11/12] =?UTF-8?q?=E6=96=B0=E5=A2=9EGetChargeArrearageData?= =?UTF-8?q?=E6=96=B9=E6=B3=95=20=E7=94=A8=E4=BA=8Echargetab/listpage?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=20=E4=BF=AE=E6=94=B9GetChargeTypeData?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/models/chargetab.go | 144 +++++++++++++++++++++++++++++++++++----- 1 file changed, 128 insertions(+), 16 deletions(-) diff --git a/web/models/chargetab.go b/web/models/chargetab.go index 6649d9f..6c3734a 100644 --- a/web/models/chargetab.go +++ b/web/models/chargetab.go @@ -9,7 +9,7 @@ import ( "lapp_-wy/db" "lapp_-wy/utils" "lapp_-wy/web/middleware/glog" - "lapp_-wy/web/models/response" + "math" "strings" "time" "xorm.io/core" @@ -37,6 +37,32 @@ type Chargetab struct { Lastmodifyby string `json:"lastmodifyby" xorm:"VARCHAR(20)"` } +type ChargeArrearage struct { + *Chargetab + Arrearage float64 `json:"arrearage"` + ArrearageDate string `json:"arrearage_date"` +} + +type ChargeTypeResponse struct { + Cid int `json:"cid"` + Court string `json:"court"` + ChargeWay string `json:"charge_way"` + ChargeCount float64 `json:"charge_count"` + Items []*Chargetab `json:"items"` + Total int64 `json:"total"` + TotalPage int `json:"total_page"` + CurrentPage int `json:"current_page"` +} + +type ChargeArrearageResponse struct { + Cid int `json:"cid"` + Court string `json:"court"` + Items []*ChargeArrearage `json:"items"` + Total int64 `json:"total"` + TotalPage int `json:"total_page"` + CurrentPage int `json:"current_page"` +} + func (t *Chargetab) TableName() string { return "chargetab" } @@ -1577,8 +1603,8 @@ func (t *Chargetab) Del() error { } // 按日期获取指定缴费类型的缴费额 -func (t *Chargetab) GetChargeTypeStatisticData(cid int, chargeType int, start, end string) (result *response.ChargeTypeStatisticResponse, err error) { - result = new(response.ChargeTypeStatisticResponse) +func (t *Chargetab) GetChargeTypeData(cid int, chargeWay string, date string, pageIndex, pageSize int) (result *ChargeTypeResponse, err error) { + result = new(ChargeTypeResponse) engine := db.MasterEngine() var court Courttab exist, err := engine.Table(court.TableName()).ID(cid).Get(&court) @@ -1588,27 +1614,113 @@ func (t *Chargetab) GetChargeTypeStatisticData(cid int, chargeType int, start, e if !exist { return result, errors.New("data not exist") } - var chargeTypeLi []int64 - // 若使用默认chargeType 则搜索表中所有的chargeType - if chargeType == 0 { - err = engine.Table(t.TableName()).Cols("chargetype").Distinct().Find(&chargeTypeLi) + var totalMoney float64 + // 扫码包含 微信 支付宝 和 扫码 + if chargeWay == "扫码" { + totalMoney, err = engine.Table(t.TableName()).Where(`cid = ? and (chargeway = "扫码" or chargeway = "微信" or chargeway = "支付宝") and chargetime = ?`, cid, date).Sum(t, "chargableexpense") + } else { + totalMoney, err = engine.Table(t.TableName()).Where("cid = ? and chargeway = ? and chargetime = ?", cid, chargeWay, date).Sum(t, "chargableexpense") + } + if err != nil { + fmt.Println("error here1:", err) + return nil, err + } + offset := (pageIndex - 1) * pageSize + var count int64 + var chargeLi []*Chargetab + if chargeWay == "扫码" { + err = engine.Table(t.TableName()).Where("cid = ? and (chargeway = \"扫码\" or chargeway = \"微信\" or chargeway = \"支付宝\") and chargetime = ?", cid, date).Limit(pageSize, offset).Find(&chargeLi) if err != nil { return nil, err } - } else { - chargeTypeLi = append(chargeTypeLi, int64(chargeType)) - } - for _, chargeType := range chargeTypeLi { - var statisticData response.ChargeTypeStatisticDate - count, err := engine.Table(t.TableName()).Where("chargetime >= ? and chargetime <= ? and cid = ? and chargetype = ?", start, end, cid, chargeType).Sum(t, "chargableexpense") + count, err = engine.Table(t.TableName()).Where("cid = ? and (chargeway = \"扫码\" or chargeway = \"微信\" or chargeway = \"支付宝\") and chargetime = ?", cid, date).Count() if err != nil { + fmt.Println("error:", err) return nil, err } - statisticData.Type = chargeType - statisticData.Count = count - result.Items = append(result.Items, &statisticData) + } else { + err = engine.Table(t.TableName()).Where("cid = ? and chargeway = ? and chargetime = ?", cid, chargeWay, date).Limit(pageSize, offset).Find(&chargeLi) + count, err = engine.Table(t.TableName()).Where("cid = ? and chargeway = ? and chargetime = ?", cid, chargeWay, date).Count() + } + if err != nil { + return nil, err } result.Cid = cid result.Court = court.Descr + result.ChargeCount = totalMoney + result.ChargeWay = chargeWay + result.Items = chargeLi + result.Total = count + result.TotalPage = int(math.Ceil(float64(result.Total) / float64(pageSize))) + result.CurrentPage = pageIndex return result, err } + +// 缴费台账接口 +func (t *Chargetab) GetChargeArrearageData(cid int, pageIndex, pageSize int, year int, arrearageDate string, selectType string, chargeType int, buildingId string, propertyId string) (result *ChargeArrearageResponse, err error) { + result = new(ChargeArrearageResponse) + 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 chargeLi []*Chargetab + + query := engine.Table(t.TableName()) + table := engine.Table(t.TableName()) + // 若搜索楼栋id则与物业表连表 + if !utils.ValueIsEmpty(buildingId) { + query = query.Join("LEFT", "propertytab", "propertytab.propertyid = chargetab.propertyid and propertytab.cid = chargetab.cid").Where("chargetab.cid = ?", cid).And("propertytab.buildingid = ?", buildingId) + table = table.Join("LEFT", "propertytab", "propertytab.propertyid = chargetab.propertyid and propertytab.cid = chargetab.cid").Where("chargetab.cid = ?", cid).And("propertytab.buildingid = ?", buildingId) + } + // arrearage 陈欠 current 当年 + if selectType == "arrearage" { + query = query.Where("chargetab.chargetime <= ?", arrearageDate) + table = table.Where("chargetab.chargetime <= ?", arrearageDate) + } else if selectType == "current" { + query = query.Where("chargetab.chargetime > ?", arrearageDate) + table = table.Where("chargetab.chargetime > ?", arrearageDate) + } + if chargeType != 0 { + query = query.And("chargetab.chargetype = ?", chargeType) + table = table.And("chargetab.chargetype = ?", chargeType) + } + if !utils.ValueIsEmpty(propertyId) { + query = query.And("chargetab.propertyid = ?", propertyId) + table = table.And("chargetab.propertyid = ?", propertyId) + } + offset := pageSize * (pageIndex - 1) + err = query.Limit(pageSize, offset).Find(&chargeLi) + if err != nil { + return nil, err + } + count, err := table.Count() + if err != nil { + return nil, err + } + // 在chargetab上拼接两个字段 一个陈欠日期 一个陈欠金额 + var chargeArrearageLi []*ChargeArrearage + for _, charge := range chargeLi { + var chargeallocation Chargeallocationtab + var chargeArrearage ChargeArrearage + chargeArrearage.Chargetab = charge + chargeCount, err := engine.Table(chargeallocation.TableName()).Where("chargenr = ? and allocateyear < ?", charge.Chargenr, year).Sum(chargeallocation, "allocateexpense") + if err != nil { + return nil, err + } + chargeArrearage.Arrearage = chargeCount + chargeArrearage.ArrearageDate = arrearageDate + chargeArrearageLi = append(chargeArrearageLi, &chargeArrearage) + } + result.Court = court.Descr + result.Items = chargeArrearageLi + result.CurrentPage = pageIndex + result.Total = count + result.TotalPage = int(math.Ceil(float64(count) / float64(pageSize))) + return result, nil + +} From 8400698dc603097056b3a0c1ba297127ac7954e5 Mon Sep 17 00:00:00 2001 From: zhangxin Date: Fri, 12 Mar 2021 09:17:45 +0800 Subject: [PATCH 12/12] =?UTF-8?q?=E4=BF=AE=E6=94=B9GetChargeStatisticData?= =?UTF-8?q?=E4=B8=9A=E5=8A=A1=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/models/chargeallocationtab.go | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/web/models/chargeallocationtab.go b/web/models/chargeallocationtab.go index 8c5b03c..f88bb7c 100644 --- a/web/models/chargeallocationtab.go +++ b/web/models/chargeallocationtab.go @@ -1,6 +1,7 @@ package models import ( + "errors" "fmt" "github.com/go-xorm/xorm" "lapp_-wy/db" @@ -152,7 +153,7 @@ func ChargeShareTheMonth(session *xorm.Session, cid int, chargenr int, begdate s } // 获取当年物业费和陈欠物业费统计数据 -func (t *Chargeallocationtab) GetChargeStatisticData(cid int, year int) (result *response.ChargeStatisticResponse, err error) { +func (t *Chargeallocationtab) GetChargeStatisticData(cid int, year int, start string, end string, selectType string) (result *response.ChargeStatisticResponse, err error) { result = new(response.ChargeStatisticResponse) engine := db.MasterEngine() var court Courttab @@ -165,28 +166,24 @@ func (t *Chargeallocationtab) GetChargeStatisticData(cid int, year int) (result } // 获取当年物业费统计 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 + var count float64 + if selectType == "arrearage" { + count, err = engine.Table(charge.TableName()).Where("cid = ? and allocateyear < ? and createtime >= ? and createtime <= ?", cid, year, start, end).Sum(charge, "allocateexpense") + } else if selectType == "current" { + count, err = engine.Table(charge.TableName()).Where("cid = ? and allocateyear >= ? and createtime >= ? and createtime <= ?", cid, year, start, end).Sum(charge, "allocateexpense") + } else { + count, err = engine.Table(charge.TableName()).Where("cid = ? and createtime >= ? and createtime <= ?", cid, start, end).Sum(charge, "allocateexpense") } - 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 { + fmt.Println("error1:", err) return result, err } - oldStatistic := &response.StatisticData{ - Type: "old", - Count: oldCount, + if selectType != "current" && selectType != "arrearage" { + selectType = "total" } result.Cid = cid result.Court = court.Descr - result.Items = append(result.Items, currentYearStatistic, oldStatistic) + result.Type = selectType + result.Count = count return result, nil }