diff --git a/conf/db.go b/conf/db.go index 42761f1..9e442fd 100644 --- a/conf/db.go +++ b/conf/db.go @@ -13,15 +13,14 @@ type DbConf struct { //线上服务器配置 var MasterDbConfig DbConf = DbConf{ - Host: "127.0.0.1", - Port: 3306, - User: "root", - Pwd: "Leit2020", + Host: "127.0.0.1", + Port: 3306, + User: "root", + Pwd: "123456", DbName: "lappserver", BackUp: "C:\\lapp_-wy\\dblog", } - //var MasterDbConfig DbConf = DbConf{ // Host: "127.0.0.1", // Port: 3306, @@ -40,6 +39,3 @@ var MasterDbConfig DbConf = DbConf{ // DbName: "wyserver8094", // BackUp: "C:\\ruifeng_wy\\dblog", //} - - - diff --git a/utils/value.go b/utils/value.go index 0734cdb..051ca11 100644 --- a/utils/value.go +++ b/utils/value.go @@ -156,7 +156,9 @@ func ValueToFloat(in interface{}, def float64) float64 { func ValueToString(in interface{}, def string) string { return ValueToStringIn(in, def, 0) } - +func ValueToStringTwo(in interface{}, def string) string { + return ValueToStringIn(in, def, 2) +} func ValueToStringIn(in interface{}, def string, fixed int) string { if in == nil { return def @@ -352,4 +354,4 @@ func IDsToString(ids []int) string { str = str + "')" } return str -} \ No newline at end of file +} diff --git a/web/controllers/chargetab_controller.go b/web/controllers/chargetab_controller.go index 07f0195..cec8152 100644 --- a/web/controllers/chargetab_controller.go +++ b/web/controllers/chargetab_controller.go @@ -893,6 +893,10 @@ func GetChargetabListPage(ctx iris.Context) { } data.Cid = user.Pid chargetype, _ := ctx.URLParamInt("chargetype") + cid, _ := ctx.URLParamInt("cid") + if cid > 0 { + data.Cid = cid + } data.Chargetype = chargetype switch chargetype { case 1: diff --git a/web/controllers/user_controller.go b/web/controllers/user_controller.go index 11777ef..0c843f4 100644 --- a/web/controllers/user_controller.go +++ b/web/controllers/user_controller.go @@ -1,6 +1,8 @@ package controllers import ( + "github.com/kataras/iris" + "io" "lapp_-wy/conf" "lapp_-wy/utils" "lapp_-wy/web/middleware/glog" @@ -8,8 +10,6 @@ import ( "lapp_-wy/web/models" "lapp_-wy/web/supports" "lapp_-wy/web/supports/vo" - "github.com/kataras/iris" - "io" "log" "net/http" "strings" @@ -28,11 +28,11 @@ func Login(ctx iris.Context) { log.Operator = user.Userid log.TimeStamp = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss") log.InsertRecord() - supports.Error(ctx, iris.StatusPaymentRequired, supports.LoginFailur, nil) + supports.Error(ctx, iris.StatusPaymentRequired, supports.LoginFailur, err.Error()) return } //日志 - glog.InfoExt("日志测试","开始1") + glog.InfoExt("日志测试", "开始1") mUser := new(models.Usertab) mUser.Pid = user.Pid mUser.Userid = user.Userid @@ -47,7 +47,7 @@ func Login(ctx iris.Context) { log.Operator = user.Userid log.TimeStamp = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss") log.InsertRecord() - supports.Error(ctx, iris.StatusPaymentRequired, supports.LoginFailur, nil) + supports.Error(ctx, iris.StatusPaymentRequired, supports.LoginFailur, err.Error()) return } @@ -426,7 +426,7 @@ func InsetSysUserAvatar(ctx iris.Context) { for _, file := range files { // 上传文件至指定目录 - savePath,_ := utils.GetCurrentPath(savePath) + savePath, _ := utils.GetCurrentPath(savePath) err := utils.SaveUploadedFile(file, savePath) if err != nil { log.Printf("上传图片错误:%v", err) diff --git a/web/models/carporttab.go b/web/models/carporttab.go index 31ba50a..d1db109 100644 --- a/web/models/carporttab.go +++ b/web/models/carporttab.go @@ -17,6 +17,7 @@ type Carporttab struct { Status int `json:"status" xorm:"INT(4)"` Propertyid string `json:"propertyid" xorm:"VARCHAR(100)"` Propertytypeid string `json:"propertytypeid" xorm:"VARCHAR(100)"` + Rentouttypeid string `json:"rentouttypeid" xorm:"VARCHAR(255)"` Createtime string `json:"createtime" xorm:"VARCHAR(14)"` Lastmodifytime string `json:"lastmodifytime" xorm:"VARCHAR(20)"` Lastmodifyby string `json:"lastmodifyby" xorm:"VARCHAR(20)"` @@ -167,7 +168,7 @@ func (t *Carporttab) Search() (data ContractInfo, err error) { data.Propertyid = carport.Propertyid data.Cid = carport.Cid data.Contractid = carport.Contractid - data.Descr =carport.Descr + data.Descr = carport.Descr data.Contact = carport.Contact data.Phone1 = carport.Phone data.Unitprice = propertytype.Unitprice diff --git a/web/models/chargetab.go b/web/models/chargetab.go index f77ce75..d9b70c0 100644 --- a/web/models/chargetab.go +++ b/web/models/chargetab.go @@ -18,6 +18,10 @@ import ( "xorm.io/core" ) +type ChargetabCount struct { + Count int `json:"count"` +} + type Chargetab struct { Cid int `json:"cid" xorm:"not null pk INT(4)"` Chargenr int `json:"chargenr" xorm:"not null pk INT(4)"` @@ -345,6 +349,8 @@ type ChargeUsers struct { Cid int `json:"cid"` //项目号 Chargetype int `json:"chargetype"` //缴费类型 Propertyid string `json:"propertyid"` //物业编号 + Accesscardid string `json:"accesscardid"` //电梯卡 + Carportid string `json:"carportid"` //车位卡 Begdate string `json:"begdate"` //起始日期 Enddate string `json:"enddate"` //结束日期 Chargableexpense float64 `json:"chargableexpense"` //缴费金额 @@ -356,21 +362,23 @@ type ChargeUsers struct { NowEnddate string `json:"nowEnddate"` //当期结束时间 Constructionarea float64 `json:"constructionarea"` //建筑面积 Unitprice float64 `json:"unitprice"` //单价 - OweMoney float64 `json:"oweMoney"` //陈欠收费 - NowMoney float64 `json:"NowMoney"` //当期收费 - PrepayMoney float64 `json:"prepayMoney"` //预缴收费 - RealMoney float64 `json:"realMoney"` //实缴金额 + Rentoutprice float64 `json:"rentoutprice"` + OweMoney float64 `json:"oweMoney"` //陈欠收费 + NowMoney float64 `json:"NowMoney"` //当期收费 + PrepayMoney float64 `json:"prepayMoney"` //预缴收费 + RealMoney float64 `json:"realMoney"` //实缴金额 Linkman string `json:"linkman"` Phone1 string `json:"phone1"` Phone2 string `json:"phone2"` Createby string `json:"createby"` + Owetime string `json:"owetime" xorm:"-"` } //分页 func (t *Chargetab) ListPage(pageSize int, pageIndex int, starttime string, searchtime string) ([]ChargeUsers, int, float64, error) { data := make([]ChargeUsers, 0) e := db.MasterEngine() - + _starttime, _ := time.Parse("2006-01-02", starttime) switch t.Chargetype { case 1: query := e.Table("propertytab") @@ -385,40 +393,42 @@ func (t *Chargetab) ListPage(pageSize int, pageIndex int, starttime string, sear table = table.And("propertytab.propertyid = ?", t.Propertyid) total = total.And("propertytab.propertyid = ?", t.Propertyid) } - if !utils.ValueIsEmpty(searchtime) { - query = query.And("contracttab.enddate < ?", searchtime) - table = table.And("contracttab.enddate < ?", searchtime) - total = total.And("contracttab.enddate < ?", searchtime) - } + if !utils.ValueIsEmpty(starttime) { - query = query.And("contracttab.enddate > ?", starttime) - table = table.And("contracttab.enddate > ?", starttime) - total = total.And("contracttab.enddate > ?", starttime) + query = query.And("contracttab.enddate < ?", starttime) + table = table.And("contracttab.enddate < ?", starttime) + total = total.And("contracttab.enddate < ?", starttime) } query = query.And("contracttab.chargetype = ?", 1) table = table.And("contracttab.chargetype = ?", 1) total = total.And("contracttab.chargetype = ?", 1) Offset := (pageIndex - 1) * pageSize - err := query.Limit(pageSize, Offset).Asc("contracttab.lengthdate").Desc("propertytab.propertyid").Find(&data) + err := query.Limit(pageSize, Offset).Desc("contracttab.enddate").Desc("propertytab.propertyid").Find(&data) + //循环date + for k, v := range data { + //将结束时间转时间类型 + _endtime, _ := time.Parse("2006-01-02", v.Enddate) + lengthdate := SubMonth(_starttime, _endtime) + 1 + + data[k].Lengthdate = utils.ValueToString(lengthdate, "") + data[k].Owetime = starttime + data[k].Chargetime = v.Enddate + data[k].Chargableexpense = utils.Decimal(float64(lengthdate)*v.Unitprice*v.Constructionarea, 2) + } pcount := new(Chargetab) count, err := table.Count(pcount) if err != nil { return data, 0, 0, err } - ss := new(Chargetab) - _, err = total.Select("sum(chargedexpense) as chargedexpense").Get(ss) - if err != nil { - return data, 0, 0, err - } - return data, int(count), ss.Chargedexpense, nil + return data, int(count), 0, nil case 2: query := e.Table("accesscardtab") table := e.Table("accesscardtab") total := e.Table("accesscardtab") //电梯费 - query = query.Join("LEFT", "contracttab", "accesscardtab.contractid = contracttab.contractid and accesscardtab.cid = contracttab.cid").Where("accesscardtab.cid = ?", t.Cid) + query = query.Join("LEFT", "contracttab", "accesscardtab.contractid = contracttab.contractid and accesscardtab.cid = contracttab.cid").Join("LEFT", "propertytypetab", "accesscardtab.propertytypeid = propertytypetab.propertytypeid and accesscardtab.cid = propertytypetab.cid").Where("accesscardtab.cid = ?", t.Cid) table = table.Join("LEFT", "contracttab", "accesscardtab.contractid = contracttab.contractid and accesscardtab.cid = contracttab.cid").Where("accesscardtab.cid = ?", t.Cid) total = total.Join("LEFT", "contracttab", "accesscardtab.contractid = contracttab.contractid and accesscardtab.cid = contracttab.cid").Where("accesscardtab.cid = ?", t.Cid) if !utils.ValueIsEmpty(t.Accesscardid) { @@ -426,73 +436,75 @@ func (t *Chargetab) ListPage(pageSize int, pageIndex int, starttime string, sear table = table.And("accesscardtab.accesscardid = ?", t.Accesscardid) total = total.And("accesscardtab.accesscardid = ?", t.Accesscardid) } - if !utils.ValueIsEmpty(searchtime) { - query = query.And("contracttab.enddate < ?", searchtime) - table = table.And("contracttab.enddate < ?", searchtime) - total = total.And("contracttab.enddate < ?", searchtime) - } if !utils.ValueIsEmpty(starttime) { - query = query.And("contracttab.enddate > ?", starttime) - table = table.And("contracttab.enddate > ?", starttime) - total = total.And("contracttab.enddate > ?", starttime) + query = query.And("contracttab.enddate < ?", starttime) + table = table.And("contracttab.enddate < ?", starttime) + total = total.And("contracttab.enddate < ?", starttime) } query = query.And("contracttab.chargetype = ?", 2) table = table.And("contracttab.chargetype = ?", 2) total = total.And("contracttab.chargetype = ?", 2) Offset := (pageIndex - 1) * pageSize - err := query.Limit(pageSize, Offset).Desc("accesscardtab.accesscardid").Find(&data) + err := query.Limit(pageSize, Offset).Desc("contracttab.enddate").Find(&data) + //循环date + for k, v := range data { + //将结束时间转时间类型 + _endtime, _ := time.Parse("2006-01-02", v.Enddate) + lengthdate := SubMonth(_starttime, _endtime) + 1 + + data[k].Lengthdate = utils.ValueToString(lengthdate, "") + data[k].Owetime = starttime + data[k].Chargetime = v.Enddate + data[k].Chargableexpense = utils.Decimal(float64(lengthdate)*v.Unitprice, 2) + } pcount := new(Chargetab) count, err := table.Count(pcount) if err != nil { return data, 0, 0, err } - ss := new(Chargetab) - _, err = total.Select("sum(chargedexpense) as chargedexpense").Get(ss) - if err != nil { - return data, 0, 0, err - } - return data, int(count), ss.Chargedexpense, nil + return data, int(count), 0, nil case 3: - query := e.Table("carporttab") + query := e.Table("carporttab").Select("carporttab.*,contracttab.*,propertytypetab.*,l.unitprice rentoutprice") table := e.Table("carporttab") total := e.Table("carporttab") //车位费 - query = query.Join("LEFT", "contracttab", "carporttab.contractid = contracttab.contractid and carporttab.cid = contracttab.cid").Where("carporttab.cid = ?", t.Cid) + query = query.Join("LEFT", "contracttab", "carporttab.contractid = contracttab.contractid and carporttab.cid = contracttab.cid").Join("LEFT", "propertytypetab", "carporttab.propertytypeid = propertytypetab.propertytypeid and carporttab.cid = propertytypetab.cid").Join("LEFT", "propertytypetab l", "carporttab.rentouttypeid = l.propertytypeid and carporttab.cid = l.cid").Where("carporttab.cid = ?", t.Cid) table = table.Join("LEFT", "contracttab", "carporttab.contractid = contracttab.contractid and carporttab.cid = contracttab.cid").Where("carporttab.cid = ?", t.Cid) total = total.Join("LEFT", "contracttab", "carporttab.contractid = contracttab.contractid and carporttab.cid = contracttab.cid").Where("carporttab.cid = ?", t.Cid) + if !utils.ValueIsEmpty(t.Accesscardid) { query = query.And("carporttab.carportid = ?", t.Carportid) table = table.And("carporttab.carportid = ?", t.Carportid) total = total.And("carporttab.carportid = ?", t.Carportid) } - if !utils.ValueIsEmpty(searchtime) { - query = query.And("contracttab.enddate < ?", searchtime) - table = table.And("contracttab.enddate < ?", searchtime) - total = total.And("contracttab.enddate < ?", searchtime) - } if !utils.ValueIsEmpty(starttime) { - query = query.And("contracttab.enddate > ?", starttime) - table = table.And("contracttab.enddate > ?", starttime) - total = total.And("contracttab.enddate > ?", starttime) + query = query.And("contracttab.enddate < ?", starttime) + table = table.And("contracttab.enddate < ?", starttime) + total = total.And("contracttab.enddate < ?", starttime) } query = query.And("contracttab.chargetype = ?", 3) table = table.And("contracttab.chargetype = ?", 3) total = total.And("contracttab.chargetype = ?", 3) Offset := (pageIndex - 1) * pageSize - err := query.Limit(pageSize, Offset).Desc("carporttab.carportid").Find(&data) + err := query.Limit(pageSize, Offset).Desc("contracttab.enddate").Find(&data) + //循环date + for k, v := range data { + //将结束时间转时间类型 + _endtime, _ := time.Parse("2006-01-02", v.Enddate) + lengthdate := SubMonth(_starttime, _endtime) + 1 + + data[k].Lengthdate = utils.ValueToString(lengthdate, "") + data[k].Owetime = starttime + data[k].Chargetime = v.Enddate + data[k].Chargableexpense = utils.Decimal(float64(lengthdate)*(v.Unitprice+v.Rentoutprice), 2) + } pcount := new(Chargetab) count, err := table.Count(pcount) if err != nil { return data, 0, 0, err } - ss := new(Chargetab) - _, err = total.Select("sum(chargedexpense) as chargedexpense").Get(ss) - if err != nil { - return data, 0, 0, err - } - - return data, int(count), ss.Chargedexpense, nil + return data, int(count), 0, nil case 4: //其他费用 query := e.Table("chargetab").Where("chargetab.cid = ?", t.Cid) @@ -569,6 +581,30 @@ func (t *Chargetab) ListPage(pageSize int, pageIndex int, starttime string, sear } +// 计算日期相差多少月 +func SubMonth(t1, t2 time.Time) (month int) { + y1 := t1.Year() + y2 := t2.Year() + m1 := int(t1.Month()) + m2 := int(t2.Month()) + d1 := t1.Day() + d2 := t2.Day() + + yearInterval := y1 - y2 + // 如果 d1的 月-日 小于 d2的 月-日 那么 yearInterval-- 这样就得到了相差的年数 + if m1 < m2 || m1 == m2 && d1 < d2 { + yearInterval-- + } + // 获取月数差值 + monthInterval := (m1 + 12) - m2 + if d1 < d2 { + monthInterval-- + } + monthInterval %= 12 + month = yearInterval*12 + monthInterval + return +} + //导出 func (t *Chargetab) ReadData(startDate string, searchtime string) ([]ChargeUsers, error) { data := make([]ChargeUsers, 0) @@ -2288,10 +2324,26 @@ type PropertyFeeTwo struct { Twelve float64 `json:"twelve"` All float64 `json:"all"` } +type PropertyFeeThree struct { + Name string `json:"name"` + One string `json:"one"` + Two string `json:"two"` + Three string `json:"three"` + Four string `json:"four"` + Five string `json:"five"` + Six string `json:"six"` + Seven string `json:"seven"` + Eight string `json:"eight"` + Nine string `json:"nine"` + Ten string `json:"ten"` + Eleven string `json:"eleven"` + Twelve string `json:"twelve"` + All string `json:"all"` +} type CatPropertytabData struct { - ParkStatistics []PropertyFeeTwo `json:"park_statistics"` - BuildingStatistics []PropertyFeeTwo `json:"building_statistics"` - BuildArr []PropertyFee `json:"build_arr"` + ParkStatistics []PropertyFeeThree `json:"park_statistics"` + BuildingStatistics []PropertyFeeThree `json:"building_statistics"` + BuildArr []PropertyFee `json:"build_arr"` } /**** @@ -2318,6 +2370,7 @@ func (t *Chargetab) PropertyFeeData(startDate string) (datalist CatPropertytabDa rateMap := make(map[string][]string) rateMap2 := make(map[string]float64) shopMap := make(map[string]int) + rateId2 := "'0'" for _, v := range rate { rateId = append(rateId, v.Propertytypeid) rateMap[v.Propertycate] = append(rateMap[v.Propertycate], v.Propertytypeid) @@ -2325,6 +2378,7 @@ func (t *Chargetab) PropertyFeeData(startDate string) (datalist CatPropertytabDa if v.Propertycate == "商业" { shopMap[v.Propertytypeid] = 1 } + rateId2 += ",'" + v.Propertytypeid + "'" } //查出楼层 var building []Buildingtab @@ -2344,13 +2398,13 @@ func (t *Chargetab) PropertyFeeData(startDate string) (datalist CatPropertytabDa }) } //查询楼层统计 - var proper []Propertytab + var proper []PropertytabTemporary //查询住户统计 err = e.Table("propertytab").Select("buildingid,count(1) count,sum(constructionarea) constructionarea").In("propertytypeid", rateMap["住宅"]).In("buildingid", buildingId).Where("cid=?", t.Cid).GroupBy("buildingid").Find(&proper) if err != nil { return datalist, err } - properMap := make(map[string]Propertytab) + properMap := make(map[string]PropertytabTemporary) for _, v := range proper { properMap[v.Buildingid] = v } @@ -2362,13 +2416,15 @@ func (t *Chargetab) PropertyFeeData(startDate string) (datalist CatPropertytabDa allBuildMap := make(map[string]float64) for k, v := range datalist.BuildArr { if _info, ok := properMap[v.Buildingid]; ok { + buildPrice := _info.Constructionarea * v.Unitprice allCount += _info.Count allConstructionarea += _info.Constructionarea datalist.BuildArr[k].Totalhouseholds = _info.Count datalist.BuildArr[k].Constructionarea = utils.Decimal(_info.Constructionarea, 2) - datalist.BuildArr[k].ExpectMoney = utils.Decimal(_info.Constructionarea*v.Unitprice*12, 2) - allExpectMoney += datalist.BuildArr[k].ExpectMoney - allBuildMap[v.Buildingid] = _info.Constructionarea * v.Unitprice + datalist.BuildArr[k].ExpectMoney = utils.Decimal(buildPrice*12, 2) + datalist.BuildArr[k].Totalhouseholds = _info.Count + allExpectMoney += buildPrice + allBuildMap[v.Buildingid] = buildPrice } } allBuildMap["-1"] = allExpectMoney @@ -2385,28 +2441,34 @@ func (t *Chargetab) PropertyFeeData(startDate string) (datalist CatPropertytabDa if err != nil { return datalist, err } + shopUnitprice := 0.00 + if len(rateMap["商业"]) > 0 { + shopUnitprice = rateMap2[rateMap["商业"][0]] + } if ok { datalist.BuildArr = append(datalist.BuildArr, PropertyFee{ Cid: -1, Buildingname: "园区商铺总计", Totalhouseholds: properShop.Count, Constructionarea: utils.Decimal(properShop.Constructionarea, 2), - ExpectMoney: utils.Decimal(properShop.Constructionarea*rateMap2[rateMap["商业"][0]], 2), + ExpectMoney: utils.Decimal(properShop.Constructionarea*shopUnitprice, 2), + Unitprice: shopUnitprice, }) } else { datalist.BuildArr = append(datalist.BuildArr, PropertyFee{ Cid: -1, Buildingname: "园区商铺总计", + Unitprice: shopUnitprice, }) } - sql := "SELECT c.buildingid, b.allocatemonth,sum( b.allocateexpense ) money, c.propertytypeid FROM chargetab a RIGHT JOIN chargeallocationtab b ON a.cid = b.cid AND a.chargenr = b.chargenr AND a.chargetype = 1 LEFT JOIN propertytab c ON a.propertyid = c.propertyid AND c.cid = a.cid AND c.propertytypeid IN ( \"门市\", \"住宅\", \"物业费\" ) WHERE b.allocateyear = ? AND b.cid = ? GROUP BY c.buildingid, b.allocatemonth,c.propertytypeid" + sql := "SELECT c.buildingid, b.allocatemonth,sum( b.allocateexpense ) money, c.propertytypeid FROM chargetab a RIGHT JOIN chargeallocationtab b ON a.cid = b.cid AND a.chargenr = b.chargenr LEFT JOIN propertytab c ON a.propertyid = c.propertyid AND c.cid = a.cid AND c.propertytypeid IN ( " + rateId2 + " ) WHERE b.allocateyear = ? AND b.cid = ? AND a.chargetype = 1 GROUP BY c.buildingid, b.allocatemonth,c.propertytypeid" //查询园区每月住宅收入 当期实缴 info, err := e.Query(sql, startDate, t.Cid) if err != nil { return datalist, err } //组合成map [楼号] - listFell := make(map[string]*PropertyFeeTwo) + listFell := make(map[string]PropertyFeeTwo) shopFell := PropertyFeeTwo{} var errFell *PropertyFeeTwo for _, v := range info { @@ -2426,9 +2488,9 @@ func (t *Chargetab) PropertyFeeData(startDate string) (datalist CatPropertytabDa //全部化为住宅用户 info, ok := listFell[string(v["buildingid"])] if !ok { - info = new(PropertyFeeTwo) + info = PropertyFeeTwo{} } - loadData(string(v["allocatemonth"]), info, money) + loadData(string(v["allocatemonth"]), &info, money) listFell[string(v["buildingid"])] = info } } @@ -2447,141 +2509,103 @@ func (t *Chargetab) PropertyFeeData(startDate string) (datalist CatPropertytabDa allFell.Ten = allFell.Ten + _info.Ten allFell.Eleven = allFell.Eleven + _info.Eleven allFell.Twelve = allFell.Twelve + _info.Twelve - allMoney := _info.One + _info.Two + _info.Three + _info.Four + _info.Five + _info.Six + _info.Seven + _info.Eight + _info.Nine + _info.Ten + _info.Eleven + _info.Twelve - datalist.BuildingStatistics = append(datalist.BuildingStatistics, PropertyFeeTwo{ - Name: v.Descr + "月收入", - One: utils.Decimal(_info.One, 2), - Two: utils.Decimal(_info.Two, 2), - Three: utils.Decimal(_info.Three, 2), - Four: utils.Decimal(_info.Four, 2), - Five: utils.Decimal(_info.Five, 2), - Six: utils.Decimal(_info.Six, 2), - Seven: utils.Decimal(_info.Seven, 2), - Eight: utils.Decimal(_info.Eight, 2), - Nine: utils.Decimal(_info.Nine, 2), - Ten: utils.Decimal(_info.Ten, 2), - Eleven: utils.Decimal(_info.Eleven, 2), - Twelve: utils.Decimal(_info.Twelve, 2), - All: utils.Decimal(allMoney, 2), - }) + allFell.All = allFell.All + _info.All + _info.Name = v.Descr + "月收入" + datalist.BuildingStatistics = append(datalist.BuildingStatistics, loadDataFell(_info)) if allBuildMap[v.Buildingid] == 0.00 { - datalist.BuildingStatistics = append(datalist.BuildingStatistics, PropertyFeeTwo{ - Name: v.Descr + "单月收费率", - }) + datalist.BuildingStatistics = append(datalist.BuildingStatistics, loadDataFellProportionDef(v.Descr+"单月收费率")) } else { - datalist.BuildingStatistics = append(datalist.BuildingStatistics, PropertyFeeTwo{ - Name: v.Descr + "单月收费率", - One: utils.Decimal(_info.One/allBuildMap[v.Buildingid]*100, 2), - Two: utils.Decimal(_info.Two/allBuildMap[v.Buildingid]*100, 2), - Three: utils.Decimal(_info.Three/allBuildMap[v.Buildingid]*100, 2), - Four: utils.Decimal(_info.Four/allBuildMap[v.Buildingid]*100, 2), - Five: utils.Decimal(_info.Five/allBuildMap[v.Buildingid]*100, 2), - Six: utils.Decimal(_info.Six/allBuildMap[v.Buildingid]*100, 2), - Seven: utils.Decimal(_info.Seven/allBuildMap[v.Buildingid]*100, 2), - Eight: utils.Decimal(_info.Eight/allBuildMap[v.Buildingid]*100, 2), - Nine: utils.Decimal(_info.Nine/allBuildMap[v.Buildingid]*100, 2), - Ten: utils.Decimal(_info.Ten/allBuildMap[v.Buildingid]*100, 2), - Eleven: utils.Decimal(_info.Eleven/allBuildMap[v.Buildingid]*100, 2), - Twelve: utils.Decimal(_info.Twelve/allBuildMap[v.Buildingid]*100, 2), - All: utils.Decimal(allMoney/12/allBuildMap[v.Buildingid]*100, 2), - }) + _info.Name = v.Descr + "单月收费率" + datalist.BuildingStatistics = append(datalist.BuildingStatistics, loadDataFellProportion(_info, allBuildMap[v.Buildingid])) } } else { - datalist.BuildingStatistics = append(datalist.BuildingStatistics, PropertyFeeTwo{ + datalist.BuildingStatistics = append(datalist.BuildingStatistics, PropertyFeeThree{ Name: v.Descr, }) - datalist.BuildingStatistics = append(datalist.BuildingStatistics, PropertyFeeTwo{ + datalist.BuildingStatistics = append(datalist.BuildingStatistics, PropertyFeeThree{ Name: v.Descr + "单月收费率", }) } } - allMoney := allFell.One + allFell.Two + allFell.Three + allFell.Four + allFell.Five + allFell.Six + allFell.Seven + allFell.Eight + allFell.Nine + allFell.Ten + allFell.Eleven + allFell.Twelve - datalist.ParkStatistics = append(datalist.ParkStatistics, PropertyFeeTwo{ - Name: "住宅物业费月收入", - One: utils.Decimal(allFell.One, 2), - Two: utils.Decimal(allFell.Two, 2), - Three: utils.Decimal(allFell.Three, 2), - Four: utils.Decimal(allFell.Four, 2), - Five: utils.Decimal(allFell.Five, 2), - Six: utils.Decimal(allFell.Six, 2), - Seven: utils.Decimal(allFell.Seven, 2), - Eight: utils.Decimal(allFell.Eight, 2), - Nine: utils.Decimal(allFell.Nine, 2), - Ten: utils.Decimal(allFell.Ten, 2), - Eleven: utils.Decimal(allFell.Eleven, 2), - Twelve: utils.Decimal(allFell.Twelve, 2), - All: utils.Decimal(allMoney, 2), - }) - if allFell.One/allBuildMap["-1"] == 0.00 { - datalist.ParkStatistics = append(datalist.ParkStatistics, PropertyFeeTwo{ - Name: "住宅物业费单月收费率", - }) + allFell.Name = "住宅物业费月收入" + datalist.ParkStatistics = append(datalist.ParkStatistics, loadDataFell(allFell)) + allFell.Name = "住宅物业费单月收费率" + if allFell.One/allBuildMap["-1"] == 0.00 || len(allBuildMap) <= 1 { + datalist.ParkStatistics = append(datalist.ParkStatistics, loadDataFellProportionDef("住宅物业费单月收费率")) } else { - datalist.ParkStatistics = append(datalist.ParkStatistics, PropertyFeeTwo{ - Name: "住宅物业费单月收费率", - One: utils.Decimal(allFell.One/allBuildMap["-1"]*100, 2), - Two: utils.Decimal(allFell.Two/allBuildMap["-1"]*100, 2), - Three: utils.Decimal(allFell.Three/allBuildMap["-1"]*100, 2), - Four: utils.Decimal(allFell.Four/allBuildMap["-1"]*100, 2), - Five: utils.Decimal(allFell.Five/allBuildMap["-1"]*100, 2), - Six: utils.Decimal(allFell.Six/allBuildMap["-1"]*100, 2), - Seven: utils.Decimal(allFell.Seven/allBuildMap["-1"]*100, 2), - Eight: utils.Decimal(allFell.Eight/allBuildMap["-1"]*100, 2), - Nine: utils.Decimal(allFell.Nine/allBuildMap["-1"]*100, 2), - Ten: utils.Decimal(allFell.Ten/allBuildMap["-1"]*100, 2), - Eleven: utils.Decimal(allFell.Eleven/allBuildMap["-1"]*100, 2), - Twelve: utils.Decimal(allFell.Twelve/allBuildMap["-1"]*100, 2), - All: utils.Decimal(allMoney/12/allBuildMap["-1"]*100, 2), - }) + datalist.ParkStatistics = append(datalist.ParkStatistics, loadDataFellProportion(allFell, allBuildMap["-1"])) } - shopAllFell := properShop.Constructionarea * rateMap2[rateMap["商业"][0]] - shopAllMoney := shopFell.One + shopFell.Two + shopFell.Three + shopFell.Four + shopFell.Five + shopFell.Six + shopFell.Seven + shopFell.Eight + shopFell.Nine + shopFell.Ten + shopFell.Eleven + shopFell.Twelve - datalist.ParkStatistics = append(datalist.ParkStatistics, PropertyFeeTwo{ - Name: "商铺物业费月收入", - One: utils.Decimal(shopFell.One, 2), - Two: utils.Decimal(shopFell.Two, 2), - Three: utils.Decimal(shopFell.Three, 2), - Four: utils.Decimal(shopFell.Four, 2), - Five: utils.Decimal(shopFell.Five, 2), - Six: utils.Decimal(shopFell.Six, 2), - Seven: utils.Decimal(shopFell.Seven, 2), - Eight: utils.Decimal(shopFell.Eight, 2), - Nine: utils.Decimal(shopFell.Nine, 2), - Ten: utils.Decimal(shopFell.Ten, 2), - Eleven: utils.Decimal(shopFell.Eleven, 2), - Twelve: utils.Decimal(shopFell.Twelve, 2), - All: utils.Decimal(shopAllMoney, 2), - }) + shopAllFell := properShop.Constructionarea * shopUnitprice + shopFell.Name = "商铺物业费月收入" + datalist.ParkStatistics = append(datalist.ParkStatistics, loadDataFell(shopFell)) + shopFell.Name = "商铺物业费单月收费率" if shopAllFell == 0.00 { - datalist.ParkStatistics = append(datalist.ParkStatistics, PropertyFeeTwo{ - Name: "商铺物业费单月收费率", - }) + datalist.ParkStatistics = append(datalist.ParkStatistics, loadDataFellProportionDef("商铺物业费单月收费率")) } else { - datalist.ParkStatistics = append(datalist.ParkStatistics, PropertyFeeTwo{ - Name: "商铺物业费单月收费率", - One: utils.Decimal(allFell.One/shopAllFell*100, 2), - Two: utils.Decimal(allFell.Two/shopAllFell*100, 2), - Three: utils.Decimal(allFell.Three/shopAllFell*100, 2), - Four: utils.Decimal(allFell.Four/shopAllFell*100, 2), - Five: utils.Decimal(allFell.Five/shopAllFell*100, 2), - Six: utils.Decimal(allFell.Six/shopAllFell*100, 2), - Seven: utils.Decimal(allFell.Seven/shopAllFell*100, 2), - Eight: utils.Decimal(allFell.Eight/shopAllFell*100, 2), - Nine: utils.Decimal(allFell.Nine/shopAllFell*100, 2), - Ten: utils.Decimal(allFell.Ten/shopAllFell*100, 2), - Eleven: utils.Decimal(allFell.Eleven/shopAllFell*100, 2), - Twelve: utils.Decimal(allFell.Twelve/shopAllFell*100, 2), - All: utils.Decimal(shopAllMoney/12/shopAllFell*100, 2), - }) + datalist.ParkStatistics = append(datalist.ParkStatistics, loadDataFellProportion(shopFell, shopAllFell)) } if errFell != nil { errFell.Name = "异常收费" - datalist.ParkStatistics = append(datalist.ParkStatistics, *errFell) + datalist.ParkStatistics = append(datalist.ParkStatistics, loadDataFell(*errFell)) } return datalist, nil } +func loadDataFellProportionDef(name string) PropertyFeeThree { + return PropertyFeeThree{ + Name: name, + One: "0.00%", + Two: "0.00%", + Three: "0.00%", + Four: "0.00%", + Five: "0.00%", + Six: "0.00%", + Seven: "0.00%", + Eight: "0.00%", + Nine: "0.00%", + Ten: "0.00%", + Eleven: "0.00%", + Twelve: "0.00%", + All: "0.00%", + } +} +func loadDataFellProportion(propertyFeeTwo PropertyFeeTwo, money float64) PropertyFeeThree { + return PropertyFeeThree{ + Name: propertyFeeTwo.Name, + One: utils.ValueToStringTwo(propertyFeeTwo.One/money*100, "") + "%", + Two: utils.ValueToStringTwo(propertyFeeTwo.Two/money*100, "") + "%", + Three: utils.ValueToStringTwo(propertyFeeTwo.Three/money*100, "") + "%", + Four: utils.ValueToStringTwo(propertyFeeTwo.Four/money*100, "") + "%", + Five: utils.ValueToStringTwo(propertyFeeTwo.Five/money*100, "") + "%", + Six: utils.ValueToStringTwo(propertyFeeTwo.Six/money*100, "") + "%", + Seven: utils.ValueToStringTwo(propertyFeeTwo.Seven/money*100, "") + "%", + Eight: utils.ValueToStringTwo(propertyFeeTwo.Eight/money*100, "") + "%", + Nine: utils.ValueToStringTwo(propertyFeeTwo.Nine/money*100, "") + "%", + Ten: utils.ValueToStringTwo(propertyFeeTwo.Ten/money*100, "") + "%", + Eleven: utils.ValueToStringTwo(propertyFeeTwo.Eleven/money*100, "") + "%", + Twelve: utils.ValueToStringTwo(propertyFeeTwo.Twelve/money*100, "") + "%", + All: utils.ValueToStringTwo(propertyFeeTwo.All/12/money*100, "") + "%", + } +} +func loadDataFell(propertyFeeTwo PropertyFeeTwo) PropertyFeeThree { + return PropertyFeeThree{ + Name: propertyFeeTwo.Name, + One: utils.ValueToStringTwo(propertyFeeTwo.One, ""), + Two: utils.ValueToStringTwo(propertyFeeTwo.Two, ""), + Three: utils.ValueToStringTwo(propertyFeeTwo.Three, ""), + Four: utils.ValueToStringTwo(propertyFeeTwo.Four, ""), + Five: utils.ValueToStringTwo(propertyFeeTwo.Five, ""), + Six: utils.ValueToStringTwo(propertyFeeTwo.Six, ""), + Seven: utils.ValueToStringTwo(propertyFeeTwo.Seven, ""), + Eight: utils.ValueToStringTwo(propertyFeeTwo.Eight, ""), + Nine: utils.ValueToStringTwo(propertyFeeTwo.Nine, ""), + Ten: utils.ValueToStringTwo(propertyFeeTwo.Ten, ""), + Eleven: utils.ValueToStringTwo(propertyFeeTwo.Eleven, ""), + Twelve: utils.ValueToStringTwo(propertyFeeTwo.Twelve, ""), + All: utils.ValueToStringTwo(propertyFeeTwo.All, ""), + } +} func loadData(allocatemonth string, fell *PropertyFeeTwo, money float64) { switch string(allocatemonth) { case "1": @@ -2625,28 +2649,32 @@ func loadData(allocatemonth string, fell *PropertyFeeTwo, money float64) { } type ChargeTotal struct { - Cid int `json:"cid"` //项目号 - Chargetype int `json:"chargetype"` //缴费类型 - Propertyid string `json:"propertyid"` //物业编号 - Accesscardid string `json:"accesscardid"` //电梯卡 - Carportid string `json:"carportid"` //车位卡 - Begdate string `json:"begdate"` //起始日期 - Enddate string `json:"enddate"` //结束日期 - Chargableexpense float64 `json:"chargableexpense"` //缴费金额 - Chargedexpense float64 `json:"chargedexpense"` //金额 - Lengthdate string `json:"lengthdate"` //时长 - Chargetime string `json:"chargetime"` //收费时间 - StatisticalDate string `json:"statisticalDate"` //统计时间 - NowBegdate string `json:"nowBegdate"` //当期起始时间 - NowEnddate string `json:"nowEnddate"` //当期结束时间 - Constructionarea float64 `json:"constructionarea"` //建筑面积 - Unitprice float64 `json:"unitprice"` //单价 - OweMoney float64 `json:"oweMoney"` //陈欠收费 - NowMoney float64 `json:"NowMoney"` //当期收费 - PrepayMoney float64 `json:"prepayMoney"` //预缴收费 - RealMoney float64 `json:"realMoney"` //实缴金额 - Propertytypeid string `xorm:"-" json:"-"` //费率类型 - Contractid string `xorm:"-" json:"-"` //费率类型 + Cid int `json:"cid"` //项目号 + Chargetype int `json:"chargetype"` //缴费类型 + Propertyid string `json:"propertyid"` //物业编号 + Accesscardid string `json:"accesscardid"` //电梯卡 + Carportid string `json:"carportid"` //车位卡 + Begdate string `json:"begdate"` //起始日期 + Enddate string `json:"enddate"` //结束日期 + Chargableexpense float64 `json:"chargableexpense"` //缴费金额 + Chargedexpense float64 `json:"chargedexpense"` //金额 + Lengthdate string `json:"lengthdate"` //时长 + Chargetime string `json:"chargetime"` //收费时间 + StatisticalDate string `json:"statisticalDate"` //统计时间 + NowBegdate string `json:"nowBegdate"` //当期起始时间 + NowEnddate string `json:"nowEnddate"` //当期结束时间 + Constructionarea float64 `json:"constructionarea"` //建筑面积 + Unitprice float64 `json:"unitprice"` //单价 + OweMoney float64 `json:"oweMoney"` //陈欠收费 + NowMoney float64 `json:"NowMoney"` //当期收费 + PrepayMoney float64 `json:"prepayMoney"` //预缴收费 + RealMoney float64 `json:"realMoney"` //实缴金额 + Propertytypeid string `xorm:"-" json:"-"` //费率类型 + AllUnitprice float64 `xorm:"-" json:"allUnitprice"` //费用总计 + Rentouttypeid string `xorm:"-" json:"-"` //租赁费用类型 + RentoutPrice float64 `xorm:"-" json:"rentoutPrice"` //租赁费用单价 + AllRentoutPrice float64 `xorm:"-" json:"allRentoutPrice"` //费用总计 + Contractid string `xorm:"-" json:"-"` //费率类型 } type ChargeTotalSum struct { @@ -2663,34 +2691,83 @@ func (t *Chargetab) ChargeTotalPage(pageSize int, pageIndex int, startDate strin if utils.ValueIsEmpty(t.Cid) { return data, 0, ChargeTotalSum{}, fmt.Errorf("请选择园区") } + //需要查询的实体 + var nowEndDate time.Time + var nowEndDateFormat string + var nowStartDate time.Time + var nowStartDateFormat string + if utils.ValueIsEmpty(startDate) { + endTime := time.Now() + nowEndDate = endTime.AddDate(0, 1, -endTime.Day()) + nowEndDateFormat = utils.TimeFormat(nowEndDate, "yyyy-MM-dd") + //获取统计时间的第一天 + nowStartDate = nowEndDate.AddDate(0, -1, 0) + nowStartDateFormat = utils.TimeFormat(nowStartDate, "yyyy-MM-dd") + } else { + nowStartDate, _ = time.Parse("2006-01-02", startDate+"-01") + nowEndDate = nowStartDate.AddDate(0, 1, -1) + nowEndDateFormat = utils.TimeFormat(nowEndDate, "yyyy-MM-dd") + nowStartDateFormat = utils.TimeFormat(nowStartDate, "yyyy-MM-dd") + } + + //查询出此次查询的楼号 + Offset := (pageIndex - 1) * pageSize + //查询缴费主记录 + field := "" + switch t.Chargetype { + case 1: + field = "propertyid" + break + case 2: + field = "accesscardid" + break + case 3: + field = "carportid" + break + } + var feeData []Chargetab + feeDataDb := e.Table("chargetab").Select("propertyid,accesscardid,carportid").Where("cid=?", t.Cid).Where("chargetype = ?", t.Chargetype) + feeDataDb.Where("chargetime BETWEEN ? and ?", nowStartDateFormat, nowEndDateFormat).GroupBy(field).Limit(pageSize, Offset) + err := feeDataDb.Find(&feeData) + if err != nil { + return data, 0, ChargeTotalSum{}, err + } + pcount := new(ChargetabCount) + _, err = e.Table("chargetab").Select("count(DISTINCT(propertyid)) count").Where("cid=?", t.Cid).And("chargetype = ?", t.Chargetype).And("chargetime BETWEEN ? and ?", nowStartDateFormat, nowEndDateFormat).Get(pcount) + count := pcount.Count + if err != nil { + return data, 0, ChargeTotalSum{}, err + } + + var propertyid []string + var accesscardid []string + var carportid []string + for _, v := range feeData { + propertyid = append(propertyid, v.Propertyid) + accesscardid = append(accesscardid, v.Accesscardid) + carportid = append(carportid, v.Carportid) + } switch t.Chargetype { case 1: chargeTotalSum := ChargeTotalSum{} propertytab := make([]Propertytab, 0) //首先需要根据楼号进行分页查询 - query := e.Table("propertytab").Where("cid = ?", t.Cid) - table := e.Table("propertytab").Where("cid = ?", t.Cid) + query := e.Table("propertytab").Where("cid = ?", t.Cid).In("propertyid", propertyid) + table := e.Table("propertytab").Where("cid = ?", t.Cid).In("propertyid", propertyid) if !utils.ValueIsEmpty(t.Propertyid) { query = query.And("propertyid = ?", t.Propertyid) table = table.And("propertyid = ?", t.Propertyid) } - //查询出此次查询的楼号 - Offset := (pageIndex - 1) * pageSize - err := query.Limit(pageSize, Offset).Desc("propertyid").Find(&propertytab) - if err != nil { - return data, 0, chargeTotalSum, err - } - pcount := new(Propertytab) - count, err := table.Count(pcount) + + err := query.Desc("propertyid").Find(&propertytab) if err != nil { return data, 0, chargeTotalSum, err } + //整理出要查询的费率 - var cid []int var propertytypeid []string var propertyid []string for _, v := range propertytab { - cid = append(cid, v.Cid) propertytypeid = append(propertytypeid, v.Propertytypeid) propertyid = append(propertyid, v.Propertyid) data = append(data, ChargeTotal{ @@ -2704,34 +2781,20 @@ func (t *Chargetab) ChargeTotalPage(pageSize int, pageIndex int, startDate strin } //查询费率 rate := make([]Propertytypetab, 0) - err = e.Table("propertytypetab").In("cid", cid).In("propertytypeid", propertytypeid).Find(&rate) + err = e.Table("propertytypetab").Where("cid=?", t.Cid).In("propertytypeid", propertytypeid).Find(&rate) if err != nil { return data, 0, chargeTotalSum, err } rateMap := make(map[string]Propertytypetab) + for _, v := range rate { rateMap[utils.ValueToString(v.Cid, "")+"[|]"+v.Propertytypeid] = v - } - //查询物业缴费记录 - //获取统计时间的最后一天 - var nowEndDate time.Time - if utils.ValueIsEmpty(startDate) { - endTime := time.Now() - nowEndDate = endTime.AddDate(0, 1, -endTime.Day()) - } else { - endTime, _ := time.Parse("2006-01", startDate) - nowEndDate = endTime.AddDate(0, 1, -1) } - nowEndDateFormat := utils.TimeFormat(nowEndDate, "yyyy-MM-dd") - - //获取统计时间的第一天 - nowStartDate := nowEndDate.AddDate(0, -1, 0) - nowStartDateFormat := utils.TimeFormat(nowStartDate, "yyyy-MM-dd") //查询缴费主记录 var feeLog []Chargetab - feeDb := e.Table("chargetab").In("propertyid", propertyid).In("cid", cid).Where("chargetype = ?", 1) + feeDb := e.Table("chargetab").In("propertyid", propertyid).Where("cid=?", t.Cid).Where("chargetype = ?", 1) feeDb.Where("chargetime BETWEEN ? and ?", nowStartDateFormat, nowEndDateFormat) err = feeDb.Find(&feeLog) if err != nil { @@ -2761,7 +2824,7 @@ func (t *Chargetab) ChargeTotalPage(pageSize int, pageIndex int, startDate strin } //查询缴费子记录 (按年 月区分) var feeSonLog []Chargeallocationtab - err = e.Table("chargeallocationtab").In("chargenr", feeID).Find(&feeSonLog) + err = e.Table("chargeallocationtab").In("chargenr", feeID).Where("cid=?", t.Cid).Find(&feeSonLog) if err != nil { return data, 0, chargeTotalSum, err } @@ -2771,6 +2834,7 @@ func (t *Chargetab) ChargeTotalPage(pageSize int, pageIndex int, startDate strin lengthDate := make(map[string]int) nowStartDateMap := make(map[string]time.Time) nowEndDateMap := make(map[string]time.Time) + for _, v := range feeSonLog { //获取楼层id if info, ok := feeMap[v.Chargenr]; ok { @@ -2825,6 +2889,7 @@ func (t *Chargetab) ChargeTotalPage(pageSize int, pageIndex int, startDate strin } } + //组合数据 for k, v := range data { //加载费率 @@ -2852,14 +2917,20 @@ func (t *Chargetab) ChargeTotalPage(pageSize int, pageIndex int, startDate strin data[k].Chargetime = startDate data[k].StatisticalDate = startDate //加载开始时间 - data[k].Begdate = utils.ValueToString(begDate[v.Propertyid], "") + //data[k].Begdate = utils.ValueToString(begDate[v.Propertyid], "") //加载结束时间 - data[k].Enddate = utils.ValueToString(endDate[v.Propertyid], "") + //data[k].Enddate = utils.ValueToString(endDate[v.Propertyid], "") + //当期开始时间 - data[k].NowBegdate = utils.ValueToString(nowStartDateMap[v.Propertyid], "") + if _info, ok := nowStartDateMap[v.Propertyid]; ok { + data[k].Begdate = utils.TimeFormat(_info, "yyyy-MM-dd") + } //当期结束时间 - data[k].NowEnddate = utils.ValueToString(nowEndDateMap[v.Propertyid], "") + if _info, ok := nowEndDateMap[v.Propertyid]; ok { + data[k].Enddate = utils.TimeFormat(_info, "yyyy-MM-dd") + } } + //查询当期 info, err := e.Query("SELECT sum(a.allocateexpense) now_money_total from chargeallocationtab a join chargetab b on a.cid = ? AND a.cid = b.cid AND b.chargetime BETWEEN ? AND ? and b.chargetype=1 and b.chargenr = a.chargenr WHERE a.allocateyear=? ", t.Cid, utils.TimeFormat(nowStartDate, "yyyy-MM-dd"), utils.TimeFormat(nowEndDate, "yyyy-MM-dd"), nowEndDate.Year()) if err != nil { @@ -2894,31 +2965,20 @@ func (t *Chargetab) ChargeTotalPage(pageSize int, pageIndex int, startDate strin chargeTotalSum := ChargeTotalSum{} propertytab := make([]Accesscardtab, 0) //首先需要根据楼号进行分页查询 - query := e.Table("accesscardtab").Where("cid = ?", t.Cid) - table := e.Table("accesscardtab").Where("cid = ?", t.Cid) + query := e.Table("accesscardtab").Where("cid = ?", t.Cid).In("accesscardid", accesscardid) if !utils.ValueIsEmpty(t.Accesscardid) { query = query.And("accesscardid = ?", t.Accesscardid) - table = table.And("accesscardid = ?", t.Accesscardid) } - //查询出此次查询的楼号 - Offset := (pageIndex - 1) * pageSize - err := query.Limit(pageSize, Offset).Desc("accesscardid").Find(&propertytab) - if err != nil { - return data, 0, chargeTotalSum, err - } - pcount := new(Accesscardtab) - count, err := table.Count(pcount) + err := query.Desc("accesscardid").Find(&propertytab) if err != nil { return data, 0, chargeTotalSum, err } + //整理出要查询的费率 - var cid []int + var propertytypeid []string - var accesscardid []string for _, v := range propertytab { - cid = append(cid, v.Cid) propertytypeid = append(propertytypeid, v.Propertytypeid) - accesscardid = append(accesscardid, v.Accesscardid) data = append(data, ChargeTotal{ Cid: v.Cid, Propertyid: v.Propertyid, @@ -2930,7 +2990,7 @@ func (t *Chargetab) ChargeTotalPage(pageSize int, pageIndex int, startDate strin } //查询费率 rate := make([]Propertytypetab, 0) - err = e.Table("propertytypetab").In("cid", cid).In("propertytypeid", propertytypeid).Find(&rate) + err = e.Table("propertytypetab").Where("cid=?", t.Cid).In("propertytypeid", propertytypeid).Find(&rate) if err != nil { return data, 0, chargeTotalSum, err } @@ -2938,26 +2998,9 @@ func (t *Chargetab) ChargeTotalPage(pageSize int, pageIndex int, startDate strin for _, v := range rate { rateMap[utils.ValueToString(v.Cid, "")+"[|]"+v.Propertytypeid] = v } - - //查询物业缴费记录 - //获取统计时间的最后一天 - var nowEndDate time.Time - if utils.ValueIsEmpty(startDate) { - endTime := time.Now() - nowEndDate = endTime.AddDate(0, 1, -endTime.Day()) - } else { - endTime, _ := time.Parse("2006-01", startDate) - nowEndDate = endTime.AddDate(0, 1, -1) - } - nowEndDateFormat := utils.TimeFormat(nowEndDate, "yyyy-MM-dd") - - //获取统计时间的第一天 - nowStartDate := nowEndDate.AddDate(0, -1, 0) - nowStartDateFormat := utils.TimeFormat(nowStartDate, "yyyy-MM-dd") - //查询缴费主记录 var feeLog []Chargetab - feeDb := e.Table("chargetab").In("accesscardid", accesscardid).In("cid", cid).Where("chargetype = ?", 2) + feeDb := e.Table("chargetab").In("accesscardid", accesscardid).Where("cid=?", t.Cid).Where("chargetype = ?", 2) feeDb.Where("chargetime BETWEEN ? and ?", nowStartDateFormat, nowEndDateFormat) err = feeDb.Find(&feeLog) if err != nil { @@ -2987,7 +3030,7 @@ func (t *Chargetab) ChargeTotalPage(pageSize int, pageIndex int, startDate strin } //查询缴费子记录 (按年 月区分) var feeSonLog []Chargeallocationtab - err = e.Table("chargeallocationtab").In("chargenr", feeID).Find(&feeSonLog) + err = e.Table("chargeallocationtab").In("chargenr", feeID).Where("cid=?", t.Cid).Find(&feeSonLog) if err != nil { return data, 0, chargeTotalSum, err } @@ -3121,11 +3164,9 @@ func (t *Chargetab) ChargeTotalPage(pageSize int, pageIndex int, startDate strin chargeTotalSum := ChargeTotalSum{} propertytab := make([]Carporttab, 0) //首先需要根据楼号进行分页查询 - query := e.Table("carporttab").Where("cid = ?", t.Cid) - table := e.Table("carporttab").Where("cid = ?", t.Cid) + query := e.Table("carporttab").Where("cid = ?", t.Cid).In("carportid", carportid) if !utils.ValueIsEmpty(t.Carportid) { query = query.And("carportid = ?", t.Carportid) - table = table.And("carportid = ?", t.Carportid) } //查询出此次查询的楼号 Offset := (pageIndex - 1) * pageSize @@ -3133,19 +3174,14 @@ func (t *Chargetab) ChargeTotalPage(pageSize int, pageIndex int, startDate strin if err != nil { return data, 0, chargeTotalSum, err } - pcount := new(Carporttab) - count, err := table.Count(pcount) - if err != nil { - return data, 0, chargeTotalSum, err - } + //整理出要查询的费率 - var cid []int + var propertytypeid []string - var carportid []string for _, v := range propertytab { - cid = append(cid, v.Cid) + propertytypeid = append(propertytypeid, v.Propertytypeid) - carportid = append(carportid, v.Carportid) + propertytypeid = append(propertytypeid, v.Rentouttypeid) data = append(data, ChargeTotal{ Cid: v.Cid, Propertyid: v.Propertyid, @@ -3153,11 +3189,12 @@ func (t *Chargetab) ChargeTotalPage(pageSize int, pageIndex int, startDate strin Propertytypeid: v.Propertytypeid, Contractid: v.Contractid, Chargetype: 3, + Rentouttypeid: v.Rentouttypeid, }) } //查询费率 rate := make([]Propertytypetab, 0) - err = e.Table("propertytypetab").In("cid", cid).In("propertytypeid", propertytypeid).Find(&rate) + err = e.Table("propertytypetab").Where("cid=?", t.Cid).In("propertytypeid", propertytypeid).Find(&rate) if err != nil { return data, 0, chargeTotalSum, err } @@ -3166,25 +3203,9 @@ func (t *Chargetab) ChargeTotalPage(pageSize int, pageIndex int, startDate strin rateMap[utils.ValueToString(v.Cid, "")+"[|]"+v.Propertytypeid] = v } - //查询物业缴费记录 - //获取统计时间的最后一天 - var nowEndDate time.Time - if utils.ValueIsEmpty(startDate) { - endTime := time.Now() - nowEndDate = endTime.AddDate(0, 1, -endTime.Day()) - } else { - endTime, _ := time.Parse("2006-01", startDate) - nowEndDate = endTime.AddDate(0, 1, -1) - } - nowEndDateFormat := utils.TimeFormat(nowEndDate, "yyyy-MM-dd") - - //获取统计时间的第一天 - nowStartDate := nowEndDate.AddDate(0, -1, 0) - nowStartDateFormat := utils.TimeFormat(nowStartDate, "yyyy-MM-dd") - //查询缴费主记录 var feeLog []Chargetab - feeDb := e.Table("chargetab").In("carportid", carportid).In("cid", cid).Where("chargetype = ?", 3) + feeDb := e.Table("chargetab").In("carportid", carportid).Where("cid=?", t.Cid).Where("chargetype = ?", 3) feeDb.Where("chargetime BETWEEN ? and ?", nowStartDateFormat, nowEndDateFormat) err = feeDb.Find(&feeLog) if err != nil { @@ -3214,7 +3235,7 @@ func (t *Chargetab) ChargeTotalPage(pageSize int, pageIndex int, startDate strin } //查询缴费子记录 (按年 月区分) var feeSonLog []Chargeallocationtab - err = e.Table("chargeallocationtab").In("chargenr", feeID).Find(&feeSonLog) + err = e.Table("chargeallocationtab").In("chargenr", feeID).Where("cid=?", t.Cid).Find(&feeSonLog) if err != nil { return data, 0, chargeTotalSum, err } @@ -3280,9 +3301,22 @@ func (t *Chargetab) ChargeTotalPage(pageSize int, pageIndex int, startDate strin } //组合数据 for k, v := range data { + //加载时长 + if info, ok := lengthDate[v.Carportid]; ok { + data[k].Lengthdate = utils.ValueToString(info, "") + } //加载费率 if info, ok := rateMap[utils.ValueToString(v.Cid, "")+"[|]"+v.Propertytypeid]; ok { - data[k].Unitprice = info.Unitprice + data[k].Unitprice = utils.Decimal(info.Unitprice, 2) + if _info, _ok := lengthDate[v.Carportid]; _ok { + data[k].AllUnitprice = utils.Decimal(info.Unitprice*float64(_info), 2) + } + } + if info, ok := rateMap[utils.ValueToString(v.Cid, "")+"[|]"+v.Rentouttypeid]; ok { + data[k].RentoutPrice = info.Unitprice + if _info, _ok := lengthDate[v.Carportid]; _ok { + data[k].AllRentoutPrice = utils.Decimal(info.Unitprice*float64(_info), 2) + } } //加载陈欠 if info, ok := oweMoney[v.Carportid]; ok { @@ -3298,10 +3332,7 @@ func (t *Chargetab) ChargeTotalPage(pageSize int, pageIndex int, startDate strin } //计算实收 data[k].RealMoney = data[k].OweMoney + data[k].NowMoney + data[k].PrepayMoney - //加载时长 - if info, ok := lengthDate[v.Carportid]; ok { - data[k].Lengthdate = utils.ValueToString(info, "") - } + data[k].Chargetime = startDate data[k].StatisticalDate = startDate //加载开始时间 @@ -3313,8 +3344,10 @@ func (t *Chargetab) ChargeTotalPage(pageSize int, pageIndex int, startDate strin //当期结束时间 data[k].NowEnddate = utils.ValueToString(nowEndDateMap[v.Carportid], "") } + nowStartDateStr := utils.TimeFormat(nowStartDate, "yyyy-MM-dd") + nowEndDateStr := utils.TimeFormat(nowEndDate, "yyyy-MM-dd") //查询当期 - info, err := e.Query("SELECT sum(a.allocateexpense) now_money_total from chargeallocationtab a join chargetab b on a.cid = ? AND a.cid = b.cid AND b.chargetime BETWEEN ? AND ? and b.chargetype=3 and b.chargenr = a.chargenr WHERE a.allocateyear=? ", t.Cid, utils.TimeFormat(nowStartDate, "yyyy-MM-dd"), utils.TimeFormat(nowEndDate, "yyyy-MM-dd"), nowEndDate.Year()) + info, err := e.Query("SELECT sum(a.allocateexpense) now_money_total from chargeallocationtab a join chargetab b on a.cid = ? AND a.cid = b.cid AND b.chargetime BETWEEN ? AND ? and b.chargetype=3 and b.chargenr = a.chargenr WHERE a.allocateyear=? ", t.Cid, nowStartDateStr, nowEndDateStr, nowEndDate.Year()) if err != nil { return data, 0, chargeTotalSum, err } @@ -3323,7 +3356,7 @@ func (t *Chargetab) ChargeTotalPage(pageSize int, pageIndex int, startDate strin chargeTotalSum.NowMoneyTotal = utils.Decimal(_info, 2) } //查询陈欠 - info, err = e.Query("SELECT sum(a.allocateexpense) owe_money_total from chargeallocationtab a join chargetab b on a.cid = ? AND a.cid = b.cid AND b.chargetime BETWEEN ? AND ? and b.chargetype=3 and b.chargenr = a.chargenr WHERE a.allocateyear? ", t.Cid, utils.TimeFormat(nowStartDate, "yyyy-MM-dd"), utils.TimeFormat(nowEndDate, "yyyy-MM-dd"), nowEndDate.Year()) + info, err = e.Query("SELECT sum(a.allocateexpense) prepay_money_total from chargeallocationtab a join chargetab b on a.cid = ? AND a.cid = b.cid AND b.chargetime BETWEEN ? AND ? and b.chargetype=3 and b.chargenr = a.chargenr WHERE a.allocateyear>? ", t.Cid, nowStartDateStr, nowEndDateStr, nowEndDate.Year()) if err != nil { return data, 0, chargeTotalSum, err } diff --git a/web/models/propertytab.go b/web/models/propertytab.go index f3486df..990172f 100644 --- a/web/models/propertytab.go +++ b/web/models/propertytab.go @@ -7,6 +7,11 @@ import ( "xorm.io/core" ) +type PropertytabTemporary struct { + Buildingid string `json:"buildingid" xorm:"VARCHAR(100)"` + Count int `json:"-" xorm:"count"` + Constructionarea float64 `json:"constructionarea" xorm:"DECIMAL(10,2)"` +} type Propertytab struct { Cid int `json:"cid" xorm:"not null pk INT(4)"` Propertyid string `json:"propertyid" xorm:"not null pk VARCHAR(100)"`