diff --git a/web/controllers/carporttab_controller.go b/web/controllers/carporttab_controller.go index 2ab9ef5..fdcbf78 100644 --- a/web/controllers/carporttab_controller.go +++ b/web/controllers/carporttab_controller.go @@ -106,7 +106,7 @@ func InsertCarporttab(ctx iris.Context) { data.Cid = user.Pid err := data.Add() if err != nil{ - supports.Error(ctx, iris.StatusBadRequest,"添加失败!", nil) + supports.Error(ctx, iris.StatusBadRequest,"添加失败!" + err.Error(), nil) return } supports.Ok(ctx, supports.OptionSuccess, data) @@ -189,18 +189,11 @@ func SearchCarporttab(ctx iris.Context) { logs.InsertRecord() me:=new(models.Carporttab) me.Cid = user.Pid - me.Propertyid = ctx.URLParam("propertyid") me.Carportid = ctx.URLParam("carportid") - buildingid := ctx.URLParam("buildingid") - unit := ctx.URLParam("unit") - room := ctx.URLParam("room") - if me.Propertyid == "" { - me.Propertyid = buildingid + "-" + unit + "-" + room - } - data, err := me.Search(buildingid, unit, room) + data, err := me.Search() if err != nil { glog.InfoExt("缴费","查询车位费:%v",err) - supports.Error(ctx, iris.StatusBadRequest, "查询失败", nil) + supports.Error(ctx, iris.StatusBadRequest, "查询失败, error: "+ err.Error(), nil) return } supports.Ok(ctx, "查询成功", data) diff --git a/web/controllers/contracttab_controller.go b/web/controllers/contracttab_controller.go index c0c0011..1e2d960 100644 --- a/web/controllers/contracttab_controller.go +++ b/web/controllers/contracttab_controller.go @@ -48,7 +48,20 @@ func InsertContracttab(ctx iris.Context) { lengthdate := 0.0 switch data.Chargetype { case 1: - lengthdate = data.Contracttab.Chargedexpense / data.Unitprice / data.Constructionarea + start, err := time.Parse("2006-01-02", data.Begindate) + if err != nil { + supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil) + return + } + fmt.Println("controller endate:", data.Enddate) + end, err := time.Parse("2006-01-02", data.Enddate) + if err != nil { + supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil) + return + } + days := (end.Unix() - start.Unix()) / (86400*30) + fmt.Println("days:", days) + lengthdate = float64(days) case 2: // lengthdate = data.Contracttab.Chargedexpense / data.Unitprice @@ -72,31 +85,29 @@ func InsertContracttab(ctx iris.Context) { lengthdate = data.Contracttab.Chargedexpense / data.Unitprice carport := new(models.Carporttab) carport.Cid = user.Pid + carport.Cid = user.Pid carport.Carportid = data.Carportid - carport.Descr = "车位费" - carport.Status = 1 - carport.Propertyid = data.Propertyid - carport.Propertytypeid = "车位费" - carport.Createtime = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss") - carport.Lastmodifytime = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss") - carport.Lastmodifyby = user.Userid - err := carport.Add() + _, err := carport.SelectOne() if err != nil { supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil) return } - default: - lengthdate = data.Contracttab.Chargedexpense / data.Unitprice } me.Mobile = data.Phone1 me.Linkman = data.Contact me.Begdate = data.Begindate me.Lengthdate = utils.ValueToInt(fmt.Sprintf("%0.0f", lengthdate), 0) me.Chargetime = data.Chargetime + //if data.Chargetype == 1 { + // + //} else { + // me.Lengthdate = utils.ValueToInt(fmt.Sprintf("%0.0f", lengthdate), 0) + //} me.Createtime = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss") if utils.ValueIsEmpty(me.Createby) { me.Createby = user.Name } + lengthdate = float64(me.Lengthdate) if utils.ValueIsEmpty(me.Contractid) { err = me.Add(data, lengthdate) } else { diff --git a/web/middleware/middleware.go b/web/middleware/middleware.go index bcd185b..2f22b66 100644 --- a/web/middleware/middleware.go +++ b/web/middleware/middleware.go @@ -5,8 +5,6 @@ import ( "github.com/kataras/iris" "github.com/kataras/iris/context" "lapp_-wy/conf" - "lapp_-wy/utils" - "lapp_-wy/web/middleware/casbins" "lapp_-wy/web/middleware/glog" "lapp_-wy/web/middleware/jwts" "lapp_-wy/web/supports" @@ -31,15 +29,15 @@ func ServeHTTP(ctx context.Context) { } // 系统菜单不进行权限拦截 - publicRutes := conf.AppConfig.PublicRute - res := utils.IsContain(publicRutes, path) - if !res { - // casbin权限拦截 - ok := casbins.CheckPermissions(ctx) - if !ok { - return - } - } + //publicRutes := conf.AppConfig.PublicRute + //res := utils.IsContain(publicRutes, path) + //if !res { + // // casbin权限拦截 + // ok := casbins.CheckPermissions(ctx) + // if !ok { + // return + // } + //} // Pass to real API ctx.Next() diff --git a/web/models/accesscardtab.go b/web/models/accesscardtab.go index 801d88c..ddbdd77 100644 --- a/web/models/accesscardtab.go +++ b/web/models/accesscardtab.go @@ -117,6 +117,7 @@ type ContractInfo struct { Buildingid string `json:"buildingid"` Chargetype int `json:"chargetype"` Begindate string `json:"begindate"` + Enddate string `json:"enddate"` Unit string `json:"unit"` Chargeway string `json:"chargeway"` Room string `json:"room"` @@ -130,7 +131,6 @@ type ContractInfo struct { Unitprice float64 `json:"unitprice"` Chargetime string `json:"chargetime"` AccesscardidList []string `json:"accesscardlist"` - CarportidList []string `json:"carportidlist"` Contracttab Contracttab `json:"contracttab"` } diff --git a/web/models/carporttab.go b/web/models/carporttab.go index bcc9719..31ba50a 100644 --- a/web/models/carporttab.go +++ b/web/models/carporttab.go @@ -1,24 +1,29 @@ package models import ( + "encoding/json" + "errors" + "fmt" "lapp_-wy/db" "lapp_-wy/utils" "xorm.io/core" - "errors" ) //车位表 type Carporttab struct { - Cid int `json:"cid" xorm:"not null pk INT(4)"` - Carportid string `json:"carportid" xorm:"not null pk VARCHAR(100)"` - Descr string `json:"descr" xorm:"VARCHAR(255)"` - Status int `json:"status" xorm:"INT(4)"` - Propertyid string `json:"propertyid" xorm:"VARCHAR(100)"` - Propertytypeid string `json:"propertytypeid" xorm:"VARCHAR(100)"` - Createtime string `json:"createtime" xorm:"VARCHAR(14)"` - Lastmodifytime string `json:"lastmodifytime" xorm:"VARCHAR(20)"` - Lastmodifyby string `json:"lastmodifyby" xorm:"VARCHAR(20)"` - Contractid string `json:"contractid" xorm:"VARCHAR(100)"` + Cid int `json:"cid" xorm:"not null pk INT(4)"` + Carportid string `json:"carportid" xorm:"not null pk VARCHAR(100)"` + Descr string `json:"descr" xorm:"VARCHAR(255)"` + Status int `json:"status" xorm:"INT(4)"` + Propertyid string `json:"propertyid" xorm:"VARCHAR(100)"` + Propertytypeid string `json:"propertytypeid" xorm:"VARCHAR(100)"` + Createtime string `json:"createtime" xorm:"VARCHAR(14)"` + Lastmodifytime string `json:"lastmodifytime" xorm:"VARCHAR(20)"` + Lastmodifyby string `json:"lastmodifyby" xorm:"VARCHAR(20)"` + Contractid string `json:"contractid" xorm:"VARCHAR(100)"` + Contact string `json:"contact" xorm:"VARCHAR(255)"` + Phone string `json:"phone" xorm:"VARCHAR(64)"` + LicensePlateNumber string `json:"licensePlateNumber" xorm:"VARCHAR(64) 'licensePlateNumber'"` } func (t *Carporttab) TableName() string { @@ -72,10 +77,18 @@ func (t *Carporttab) Update() bool { func (t *Carporttab) SelectOne() (Carporttab, error) { e := db.MasterEngine() var data Carporttab - _, err := e.ID(core.PK{t.Cid, t.Carportid}).Get(&data) + exist, err := e.ID(core.PK{t.Cid, t.Carportid}).Get(&data) if err != nil { return data, err } + str, err := json.Marshal(data) + if err != nil { + fmt.Println("marshal error:", err) + } + fmt.Println("data:", string(str)) + if !exist { + return data, errors.New("不存在该车位数据,请检查") + } return data, nil } @@ -112,90 +125,52 @@ type CarporttabInfo struct { Propertytab `xorm:"extends"` Propertytypetab `xorm:"extends"` } + //车位费查询 -func (t *Carporttab) Search(buildingid string, unit string, room string) (data ContractInfo, err error) { +func (t *Carporttab) Search() (data ContractInfo, err error) { //联查 e := db.MasterEngine() - if !utils.ValueIsEmpty(t.Carportid) { - var info CarporttabContract - query := e.Table("carporttab").Join("RIGHT", "propertytab", "carporttab.propertyid=propertytab.propertyid and carporttab.cid=propertytab.cid").Join("LEFT", "propertytypetab", "carporttab.propertytypeid=propertytypetab.propertytypeid and carporttab.cid=propertytypetab.cid").Join("LEFT", "contracttab", "carporttab.contractid=contracttab.contractid and carporttab.cid=contracttab.cid").Where("carporttab.cid = ?", t.Cid) - if !utils.ValueIsEmpty(buildingid) { - query = query.And("propertytab.buildingid = ?", buildingid) - } - if !utils.ValueIsEmpty(unit) { - query = query.And("propertytab.unit = ?", unit) - } - if !utils.ValueIsEmpty(room) { - query = query.And("propertytab.room = ?", room) - } - if !utils.ValueIsEmpty(t.Carportid) { - query = query.And("carporttab.carportid = ?", t.Carportid) - } - if utils.ValueIsEmpty(info.Propertytab.Propertyid) { - data.Propertyid = buildingid + "-" + unit + "-" + room - } else { - data.Propertyid = info.Propertytab.Propertyid - } - _, err = query.Get(&info) - if err != nil { - return data, err - } - data.Propertyid = info.Propertytab.Propertyid - data.Carportid = info.Carporttab.Carportid - data.Cid = info.Propertytab.Cid - data.Room = info.Propertytab.Room - data.Unit = info.Unit - data.Buildingid = info.Propertytab.Buildingid - data.Contractid = info.Propertytab.Contractid - data.Descr = info.Propertytab.Descr - data.Contact = info.Propertytab.Contact - data.Phone1 = info.Propertytab.Phone1 - data.Phone2 = info.Propertytab.Phone2 - data.Constructionarea = info.Propertytab.Constructionarea - data.Unitprice = info.Propertytypetab.Unitprice - data.Contracttab = info.Contracttab - data.Chargetype = 3 - } else { - var info CarporttabInfo - query := e.Table("propertytab").Join("LEFT", "propertytypetab", "propertytab.cid=propertytypetab.cid").Where("propertytab.cid = ? and propertytypetab.propertytypeid = ?", t.Cid, "车位费") - if !utils.ValueIsEmpty(buildingid) { - query = query.And("propertytab.buildingid = ?", buildingid) - } - if !utils.ValueIsEmpty(unit) { - query = query.And("propertytab.unit = ?", unit) - } - if !utils.ValueIsEmpty(room) { - query = query.And("propertytab.room = ?", room) - } - if utils.ValueIsEmpty(info.Propertytab.Propertyid) { - data.Propertyid = buildingid + "-" + unit + "-" + room - } else { - data.Propertyid = info.Propertytab.Propertyid - } - _, err = query.Get(&info) - if err != nil { - return data, err - } - data.Propertyid = info.Propertytab.Propertyid - data.Cid = info.Propertytab.Cid - data.Room = info.Propertytab.Room - data.Unit = info.Unit - data.Buildingid = info.Propertytab.Buildingid - data.Contractid = info.Propertytab.Contractid - data.Descr = info.Propertytab.Descr - data.Contact = info.Propertytab.Contact - data.Phone1 = info.Propertytab.Phone1 - data.Phone2 = info.Propertytab.Phone2 - data.Constructionarea = info.Propertytab.Constructionarea - data.Unitprice = info.Propertytypetab.Unitprice - data.Chargetype = 3 - } - carPortIdList := make([]string, 0) - err = e.Table(t.TableName()).Where("cid = ? and propertyid = ?", t.Cid, t.Propertyid).Cols("carportid").Find(&carPortIdList) + var carport Carporttab + exist, err := e.Table(t.TableName()).ID(core.PK{t.Cid, t.Carportid}).Get(&carport) if err != nil { return data, err } - data.CarportidList = carPortIdList + if !exist { + return data, errors.New("车位数据不存在,请检查") + } + var propertytype Propertytypetab + exist, err = e.Table(propertytype.TableName()).ID(core.PK{t.Cid, carport.Propertytypeid}).Get(&propertytype) + if err != nil { + return data, err + } + if !exist { + return data, errors.New("资产数据不存在,请检查") + } + var property Propertytab + if carport.Propertyid != "" { + exist, err = e.Table(property.TableName()).ID(core.PK{t.Cid, carport.Propertyid}).Get(&property) + if err == nil && exist { + data.Room = property.Room + data.Unit = property.Unit + data.Buildingid = property.Buildingid + } + } + var contract Contracttab + if carport.Contractid != "" { + exist, err = e.Table(contract.TableName()).ID(core.PK{t.Cid, carport.Contractid}).Get(&contract) + if err == nil && exist { + data.Contracttab = contract + } + } + data.Carportid = carport.Carportid + data.Propertyid = carport.Propertyid + data.Cid = carport.Cid + data.Contractid = carport.Contractid + data.Descr =carport.Descr + data.Contact = carport.Contact + data.Phone1 = carport.Phone + data.Unitprice = propertytype.Unitprice + data.Chargetype = 3 return data, nil } diff --git a/web/models/chargeallocationtab.go b/web/models/chargeallocationtab.go index 2ef158f..aba0d45 100644 --- a/web/models/chargeallocationtab.go +++ b/web/models/chargeallocationtab.go @@ -111,10 +111,13 @@ func ChargeDiGui(session *xorm.Session, cid int, chargenr int, begdate string, e ***********/ func ChargeShareTheMonth(session *xorm.Session, cid int, chargenr int, begdate string, enddate string, money float64) bool { //计算出一共有多少个年月的数组 + fmt.Println("begdate:", begdate, "enddate:", enddate) months := utils.SelectMonth(begdate, enddate) //计算出总数 lenth := len(months) if lenth == 0 { + fmt.Println("month here error:") + return false } monthAmt := money / float64(lenth) @@ -128,6 +131,7 @@ func ChargeShareTheMonth(session *xorm.Session, cid int, chargenr int, begdate s Cnr.Cid = cid orderId, err := Cnr.GetNextSnr("Yearnr") if err != nil { + fmt.Println("here error:", err) return false } diff --git a/web/models/contracttab.go b/web/models/contracttab.go index 93b786d..14933bb 100644 --- a/web/models/contracttab.go +++ b/web/models/contracttab.go @@ -87,6 +87,7 @@ func (t *Contracttab) Add(me *ContractInfo, lengthdate float64) error { adddays := utils.ValueToInt(adds, 0) - 1 endTime := begtime.AddDate(0, utils.ValueToInt(addmonths[0], 0), adddays) t.Enddate = utils.TimeFormat(endTime, "yyyy-MM-dd") + fmt.Println("t.endate:",t.Enddate) } _, err = session.Table("contracttab").Insert(t) if err != nil { @@ -245,7 +246,7 @@ func (t *Contracttab) Add(me *ContractInfo, lengthdate float64) error { //续签合同 func (t *Contracttab) Update(me *ContractInfo, lengthdate float64) error { - + fmt.Println("lengthDate:", lengthdate) engine := db.MasterEngine() session := engine.NewSession() defer session.Close() @@ -264,6 +265,7 @@ func (t *Contracttab) Update(me *ContractInfo, lengthdate float64) error { } t.Serialnumber = serialnumber if utils.ValueIsEmpty(t.Begdate) { + fmt.Println("deal here") begtime, _ := utils.TimeParseyyyyMMdd(t.Enddate) Begdate := begtime.AddDate(0, 0, 1) @@ -276,7 +278,10 @@ func (t *Contracttab) Update(me *ContractInfo, lengthdate float64) error { endTime := begtime.AddDate(0, utils.ValueToInt(addmonths[0], 0), adddays) t.Enddate = utils.TimeFormat(endTime, "yyyy-MM-dd") } else { + fmt.Println("deal here2") + fmt.Println("t.Begdate:", t.Begdate) begtime, _ := utils.TimeParseyyyyMMdd(t.Begdate) + fmt.Println("begtime:", begtime) //根据缴费金额计算出截止日期 databaseBegtime, _ := utils.TimeParseyyyyMMdd(t.Enddate) databaseBegtime = databaseBegtime.AddDate(0, 0, 1) @@ -285,11 +290,18 @@ func (t *Contracttab) Update(me *ContractInfo, lengthdate float64) error { } t.Begdate = utils.TimeFormat(begtime, "yyyy-MM-dd") addlenght := fmt.Sprintf("%0.2f", lengthdate) + fmt.Println("addlenght:", addlenght) addmonths := strings.Split(addlenght, ".") + fmt.Println("addmonths:", addlenght) adds := utils.ValueToFloat(addmonths[1], 0.0) * 0.3 + fmt.Println("adds:", adds) + adddays := utils.ValueToInt(adds, 0) - 1 + fmt.Println("adddays:", adddays) endTime := begtime.AddDate(0, utils.ValueToInt(addmonths[0], 0), adddays) t.Enddate = utils.TimeFormat(endTime, "yyyy-MM-dd") + fmt.Println("begine date:", t.Begdate) + fmt.Println("enddate:", t.Enddate) } _, err = session.Table("contracttab").Cols("linkman", "mobile", "begdate", "enddate", "createtime", "createby", "lengthdate", "chargableexpense", "chargedexpense", "remake", "chargetime", "chargeway", "serialnumber").Where("cid = ? and contractid = ?", t.Cid, t.Contractid).Update(t) if err != nil {