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..76f58b9 100644 --- a/web/controllers/contracttab_controller.go +++ b/web/controllers/contracttab_controller.go @@ -47,8 +47,6 @@ func InsertContracttab(ctx iris.Context) { me.Chargeway = data.Contracttab.Chargeway lengthdate := 0.0 switch data.Chargetype { - case 1: - lengthdate = data.Contracttab.Chargedexpense / data.Unitprice / data.Constructionarea case 2: // lengthdate = data.Contracttab.Chargedexpense / data.Unitprice @@ -72,27 +70,35 @@ 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.Enddate = data.Enddate me.Chargetime = data.Chargetime + if data.Chargetype == 1 { + start, err := time.Parse("2006-01-02", data.Begindate) + if err != nil { + supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil) + return + } + 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 + me.Lengthdate = int(days) + } 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 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..0a67254 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,45 @@ 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 + var carport Carporttab + exist, err := e.Table(t.TableName()).ID(core.PK{t.Cid, t.Carportid}).Get(&carport) + if err != nil { + return data, err + } + if !exist { + return data, errors.New("车位数据不存在,请检查") } - carPortIdList := make([]string, 0) - err = e.Table(t.TableName()).Where("cid = ? and propertyid = ?", t.Cid, t.Propertyid).Cols("carportid").Find(&carPortIdList) + var propertytype Propertytypetab + exist, err = e.Table(propertytype.TableName()).ID(core.PK{t.Cid, carport.Propertytypeid}).Get(&propertytype) if err != nil { return data, err } - data.CarportidList = carPortIdList + 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 + } + } + 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 }