From 15ade1367f7750b0f7b734d75d54f5b34a90433f Mon Sep 17 00:00:00 2001 From: zhangxin Date: Wed, 17 Mar 2021 10:29:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B9=B4=E7=BC=B4=E8=B4=B9?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E6=8E=A5=E5=8F=A3=20=20=E5=AF=BC=E5=87=BA?= =?UTF-8?q?=E6=8A=A5=E8=A1=A8=E4=B8=8D=E5=86=8D=E4=BD=BF=E7=94=A8=E5=88=86?= =?UTF-8?q?=E9=A1=B5=20=E7=BC=B4=E8=B4=B9=E5=8F=B0=E8=B4=A6=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E8=BF=94=E5=9B=9E=E5=80=BC=E6=B7=BB=E5=8A=A0user?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=20=E4=BC=98=E5=8C=96=E7=BC=B4=E8=B4=B9?= =?UTF-8?q?=E5=8F=B0=E8=B4=A6=E7=BB=9F=E8=AE=A1=E9=87=91=E9=A2=9D=E7=9A=84?= =?UTF-8?q?sql?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/controllers/chargetab_controller.go | 55 +++++---- web/models/chargetab.go | 154 +++++++++++++++++++----- 2 files changed, 155 insertions(+), 54 deletions(-) diff --git a/web/controllers/chargetab_controller.go b/web/controllers/chargetab_controller.go index 0e83b48..49b3e80 100644 --- a/web/controllers/chargetab_controller.go +++ b/web/controllers/chargetab_controller.go @@ -429,6 +429,9 @@ func GetChargeStatisticData(ctx iris.Context) { year = 0 } selectType := ctx.URLParam("type") + if selectType != "arrearage" && selectType != "current" { + selectType = "total" + } var charge models.Chargetab result, err := charge.GetChargeStatisticData(cid, year, selectType, chargeType, buildingId, propertyId, start, end, currentYear) if err != nil { @@ -512,6 +515,7 @@ func GetChargeArrearageData(ctx iris.Context) { supports.Error(ctx, iris.StatusInternalServerError, "抱歉未找到相关信息", nil) return } + result.User = user.Role supports.Ok(ctx, supports.OptionSuccess, result) } @@ -594,16 +598,6 @@ func ExportChargeArrearageExcel(ctx iris.Context) { 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 { @@ -645,7 +639,7 @@ func ExportChargeArrearageExcel(ctx iris.Context) { } arrearageDate := fmt.Sprintf("%d-12-31", currentYear-1) var charge models.Chargetab - result, err := charge.GetChargeArrearageExcelData(cid, pageIndex, pageSize, year, arrearageDate, chargeType, buildingId, propertyId, start, end, currentYear) + result, err := charge.GetChargeArrearageExcelData(cid, year, arrearageDate, chargeType, buildingId, propertyId, start, end, currentYear) if err != nil { supports.Error(ctx, iris.StatusInternalServerError, "抱歉未找到相关信息", nil) return @@ -678,16 +672,6 @@ func ExportChargeWayDataListExcel(ctx iris.Context) { 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 { @@ -715,7 +699,7 @@ func ExportChargeWayDataListExcel(ctx iris.Context) { chargeWay := ctx.URLParam("chargeWay") chargeType := ctx.URLParam("chargeType") var charge models.Chargetab - result, err := charge.GetExcelChargeWayDataList(cid, chargeWay, chargeType, start, end, pageIndex, pageSize) + result, err := charge.GetExcelChargeWayDataList(cid, chargeWay, chargeType, start, end) if err != nil { fmt.Println("error1:", err) supports.Error(ctx, iris.StatusInternalServerError, "抱歉未找到相关信息", nil) @@ -731,3 +715,30 @@ func ExportChargeWayDataListExcel(ctx iris.Context) { supports.Ok(ctx, supports.OptionSuccess, strUrl) } + +func GetChargetabStatisticByYear(ctx iris.Context) { + user, ok := jwts.ParseToken(ctx) + utils.TrimStruct(user, *user) + if !ok { + supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil) + return + } + var me models.Chargetab + me.Cid = user.Pid + me.Chargetype, _ = ctx.URLParamInt("chargetype") + year, err := ctx.URLParamInt("year") + if err != nil { + supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil) + return + } + selectType := ctx.URLParam("type") + result, count, err := me.ChargeTotalStatisticData(year, selectType) + if err != nil { + supports.Error(ctx, iris.StatusBadRequest, "抱歉未找到相关信息", nil) + return + } + res := make(map[string]interface{}) + res["data"] = result + res["count"] = count + supports.Ok(ctx, supports.OptionSuccess, res) +} diff --git a/web/models/chargetab.go b/web/models/chargetab.go index 9c87ef3..306ed91 100644 --- a/web/models/chargetab.go +++ b/web/models/chargetab.go @@ -4,6 +4,7 @@ import ( "encoding/json" "errors" "fmt" + "github.com/go-xorm/xorm" uuid "github.com/iris-contrib/go.uuid" "github.com/tealeg/xlsx" "lapp_-wy/db" @@ -74,6 +75,7 @@ type ChargeArrearageResponse struct { Total int64 `json:"total"` TotalPage int `json:"total_page"` CurrentPage int `json:"current_page"` + User string `json:"user"` } type ExcelChargeWayData struct { @@ -264,6 +266,8 @@ type SumStruct struct { PaidInArea float64 `json:"paid_in_area"` ReceivableMoney float64 `json:"receivable_money"` PaidInMoney float64 `json:"paid_in_money"` + CurrentPercent float64 `json:"current_percent"` + ArrearagePercent float64 `json:"arrearage_percent"` } type BuildingInfo struct { @@ -1637,6 +1641,7 @@ func (t *Chargetab) GetChargeWayDataList(cid int, chargeWay, chargeType, start, query := engine.Table(t.TableName()).Where(`cid = ?`, cid) table := engine.Table(t.TableName()).Where(`cid = ?`, cid) sumQuery := engine.Table(t.TableName()).Where(`cid = ?`, cid) + fmt.Println("chargeWay:", chargeWay) if chargeWay != "" { if chargeWay == "扫码" { query = query.And("chargeway = \"扫码\" or chargeway = \"微信\" or chargeway = \"支付宝\"") @@ -1757,34 +1762,51 @@ func (t *Chargetab) GetChargeArrearageData(cid int, pageIndex, pageSize int, yea func (t *Chargetab) GetChargeStatisticData(cid, year int, selectType string, chargeType int, buildingId string, propertyId string, start string, end string, currentYear int) (result *response.ChargeStatisticResponse, err error) { result = new(response.ChargeStatisticResponse) engine := db.MasterEngine() - query := engine.Table(t.TableName()).Where("chargetab.cid = ?", cid) - // 若搜索楼栋id则与物业表连表 + var query *xorm.Session var chargeAllocation Chargeallocationtab - if !utils.ValueIsEmpty(buildingId) { - query = query.Join("LEFT", "propertytab", "propertytab.propertyid = chargetab.propertyid and propertytab.cid = chargetab.cid").And("propertytab.buildingid = ?", buildingId) - } - if chargeType != 0 { - query = query.And("chargetab.chargetype = ?", chargeType) - } - if !utils.ValueIsEmpty(propertyId) { - query = query.And("chargetab.propertyid = ?", propertyId) - } - if start != "" { - query = query.And("chargetab.chargetime >= ? and chargetab.chargetime <= ?", start, end) + if chargeType == 0 && buildingId == "" && start == "" && end == "" && year == 0{ + query = engine.Table(chargeAllocation.TableName()).Where("cid = ?", cid) + } else { - if year != 0 { - start := fmt.Sprintf("%d-01-01", year) - end := fmt.Sprintf("%d-01-01", year+1) - query = query.And("chargetab.chargetime >= ? and chargetab.chargetime < ?", start, end) + chargeLi := make([]Chargetab, 0) + query = engine.Table(t.TableName()).Where("chargetab.cid = ?", cid) + // 若搜索楼栋id则与物业表连表 + if !utils.ValueIsEmpty(buildingId) { + query = query.Join("LEFT", "propertytab", "propertytab.propertyid = chargetab.propertyid and propertytab.cid = chargetab.cid").And("propertytab.buildingid = ?", buildingId) + } + if chargeType != 0 { + query = query.And("chargetab.chargetype = ?", chargeType) + } + if !utils.ValueIsEmpty(propertyId) { + query = query.And("chargetab.propertyid = ?", propertyId) + } + if start != "" { + query = query.And("chargetab.chargetime >= ? and chargetab.chargetime <= ?", start, end) + } else { + if year != 0 { + start := fmt.Sprintf("%d-01-01", year) + end := fmt.Sprintf("%d-01-01", year+1) + query = query.And("chargetab.chargetime >= ? and chargetab.chargetime < ?", start, end) + } + } + err = query.Find(&chargeLi) + if err != nil { + return nil, err + } + chargeNrLi := make([]int, 0) + for _, charge := range chargeLi { + chargeNrLi = append(chargeNrLi, charge.Chargenr) } + query = engine.Table(chargeAllocation.TableName()).Where("cid = ?", cid).In("chargenr", chargeNrLi) } - query = query.Join("LEFT", "chargeallocationtab", "chargetab.chargenr = chargeallocationtab.chargenr") + // arrearage 陈欠 current 当年 if selectType == "arrearage" { query = query.Where("chargeallocationtab.allocateyear < ?", currentYear) } else if selectType == "current" { query = query.Where("chargeallocationtab.allocateyear >= ?", currentYear) } + count, err := query.Sum(chargeAllocation, "chargeallocationtab.allocateexpense") result.Cid = cid result.Count = utils.Round(count) @@ -1792,7 +1814,7 @@ func (t *Chargetab) GetChargeStatisticData(cid, year int, selectType string, cha return result, nil } -func (t *Chargetab) GetChargeArrearageExcelData(cid int, pageIndex, pageSize int, year int, arrearageDate string, chargeType int, buildingId string, propertyId string, start string, end string, currentYear int) (result []*ChargeArrearageExcelData, err error) { +func (t *Chargetab) GetChargeArrearageExcelData(cid int, year int, arrearageDate string, chargeType int, buildingId string, propertyId string, start string, end string, currentYear int) (result []*ChargeArrearageExcelData, err error) { engine := db.MasterEngine() chargeLi := make([]*ChargeContactData, 0) @@ -1816,8 +1838,7 @@ func (t *Chargetab) GetChargeArrearageExcelData(cid int, pageIndex, pageSize int query = query.And("chargetab.chargetime >= ? and chargetab.chargetime < ?", start, end) } } - offset := pageSize * (pageIndex - 1) - err = query.Desc("chargetab.createtime").Limit(pageSize, offset).Find(&chargeLi) + err = query.Desc("chargetab.createtime").Find(&chargeLi) if err != nil { return nil, err } @@ -1846,20 +1867,13 @@ func (t *Chargetab) GetChargeArrearageExcelData(cid int, pageIndex, pageSize int } // 获取缴费方式数据列表 -func (t *Chargetab) GetExcelChargeWayDataList(cid int, chargeWay, chargeType, start, end string, pageIndex, pageSize int) (result []*ExcelChargeWayData, err error) { +func (t *Chargetab) GetExcelChargeWayDataList(cid int, chargeWay, chargeType, start, end string) (result []*ExcelChargeWayData, err error) { result = make([]*ExcelChargeWayData, 0) tempLi := make([]*ChargeContactData, 0) 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") - //} // 扫码包含 微信 支付宝 和 扫码 query := engine.Table(t.TableName()).Where(`chargetab.cid = ?`, cid).Join("LEFT", "propertytab", "propertytab.propertyid = chargetab.propertyid and propertytab.cid = chargetab.cid") + fmt.Println("chargeWay:", chargeWay) if chargeWay != "" { if chargeWay == "扫码" { query = query.And("chargetab.chargeway = \"扫码\" or chargetab.chargeway = \"微信\" or chargetab.chargeway = \"支付宝\"") @@ -1873,8 +1887,7 @@ func (t *Chargetab) GetExcelChargeWayDataList(cid int, chargeWay, chargeType, st if start != "" { query = query.And("chargetab.chargetime >= ? and chargetab.chargetime <= ?", start, end) } - offset := (pageIndex - 1) * pageSize - err = query.Desc("chargetab.createtime").Limit(pageSize, offset).Find(&tempLi) + err = query.Desc("chargetab.createtime").Find(&tempLi) if err != nil { return nil, err } @@ -2083,9 +2096,86 @@ func (t *Chargetab) ExportChargeWayExcel(datalist []*ExcelChargeWayData) (excelf exceldir, _ := utils.GetCurrentPath("web/public/uploadxlsx") // 目录+文件名 excelfile = exceldir + "/" + filename + fmt.Println("excelfile:", excelfile) err = file.Save(excelfile) if err != nil { return "", "", err } return excelfile, filename, nil } + +//按年统计 +func (t *Chargetab) ChargeTotalStatisticData(year int, selectType string) ([]SumStruct, int, error) { + e := db.MasterEngine() + datalist := make([]SumStruct, 0) + currentYear := time.Now().Year() + var startDate string + var endDate string + if selectType == "current" { + if year < currentYear { + year = currentYear + } + startDate = fmt.Sprintf("%d-01-01", year) + endDate = fmt.Sprintf("%d-01-01", 2099) + } else if selectType == "arrearage" { + startDate = fmt.Sprintf("%d-01-01", 2000) + if year >= currentYear { + year = currentYear - 1 + } + endDate = fmt.Sprintf("%d-01-01", year+1) + } else { + startDate = fmt.Sprintf("%d-01-01", year) + endDate = fmt.Sprintf("%d-01-01", year+1) + } + //计算实收金额 + ss := new(SumStruct) + _, err := e.Table("chargeallocationtab").Select("sum(allocateexpense) as paid_in_money").Where("cid = ? and allocateyear =? ", t.Cid, year).Get(ss) + //计算实收缴费面积 + one := SumStruct{} + one.Cid = t.Cid + one.Allocateyear = year + PaidInMoney := fmt.Sprintf("%0.0f", ss.PaidInMoney) + one.PaidInMoney = utils.ValueToFloat(PaidInMoney, 0.0) + info := new(SumStruct) + _, err = e.Table("chargetab").Select("sum(propertytab.constructionarea) as paid_in_area").Join("INNER", "propertytab", "propertytab.propertyid = chargetab.propertyid and propertytab.cid = chargetab.cid").Where("chargetab.cid = ? and chargetab.chargeenddate >= ? and chargetab.chargeenddate < ?", t.Cid, startDate, endDate).Get(info) + if err != nil { + glog.InfoExtln("年缴费测试", "err1 := ", err) + return nil, 0, err + } + area := fmt.Sprintf("%0.2f", info.PaidInArea) + 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) + if err != nil { + glog.InfoExtln("年缴费测试", "err2 := ", err) + return nil, 0, err + } + ReceivableArea := fmt.Sprintf("%0.2f", buildInfo.Constructionarea) + one.ReceivableArea = utils.ValueToFloat(ReceivableArea, 0.0) + money := fmt.Sprintf("%0.0f", buildInfo.Constructionarea*buildInfo.Unitprice*12) + one.ReceivableMoney = utils.ValueToFloat(money, 0.0) + if selectType == "current" { + one.CurrentPercent = 1 + one.ArrearagePercent = 0 + } else if selectType == "arrearage" { + one.CurrentPercent = 0 + one.ArrearagePercent = 1 + } else { + if year >= currentYear { + one.CurrentPercent = 1 + one.ArrearagePercent = 0 + } else { + one.CurrentPercent = 0 + one.ArrearagePercent = 1 + } + } + glog.InfoExtln("年缴费测试", "one := ", one) + datalist = append(datalist, one) + sumMoney := 0.0 + for _, v := range datalist { + sumMoney += v.PaidInMoney + } + total := utils.ValueToInt(sumMoney, 0) + return datalist, total, nil +} \ No newline at end of file