Browse Source

添加按日期和缴费类型统计数据方法

pull/2/head
zhangxin 4 years ago
parent
commit
16dc6a5da0
1 changed files with 44 additions and 6 deletions
  1. +44
    -6
      web/models/chargetab.go

+ 44
- 6
web/models/chargetab.go View File

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

Loading…
Cancel
Save