From fbe5a3686b53295bbe99f4e4390fe8b32abebba2 Mon Sep 17 00:00:00 2001 From: zhangxin Date: Tue, 6 Apr 2021 17:15:10 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E8=BD=A6=E4=BD=8D=E8=B4=B9=E8=BF=94=E5=9B=9E=E8=AF=A5=E4=B8=9A?= =?UTF-8?q?=E4=B8=BB=E6=89=80=E6=9C=89=E8=BD=A6=E4=BD=8Did=E7=9A=84?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/controllers/carporttab_controller.go | 3 + web/controllers/contracttab_controller.go | 16 +++ web/models/accesscardtab.go | 1 + web/models/carporttab.go | 118 +++++++++++++++------- 4 files changed, 104 insertions(+), 34 deletions(-) diff --git a/web/controllers/carporttab_controller.go b/web/controllers/carporttab_controller.go index 963a970..2ab9ef5 100644 --- a/web/controllers/carporttab_controller.go +++ b/web/controllers/carporttab_controller.go @@ -194,6 +194,9 @@ func SearchCarporttab(ctx iris.Context) { 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) if err != nil { glog.InfoExt("缴费","查询车位费:%v",err) diff --git a/web/controllers/contracttab_controller.go b/web/controllers/contracttab_controller.go index bc17e65..c0c0011 100644 --- a/web/controllers/contracttab_controller.go +++ b/web/controllers/contracttab_controller.go @@ -62,6 +62,7 @@ func InsertContracttab(ctx iris.Context) { access.Createtime = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss") access.Lastmodifytime = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss") access.Descr = "电梯卡费" + access.Lastmodifyby = user.Userid err := access.Add() if err != nil { supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil) @@ -69,6 +70,21 @@ func InsertContracttab(ctx iris.Context) { } case 3: lengthdate = data.Contracttab.Chargedexpense / data.Unitprice + carport := new(models.Carporttab) + 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() + if err != nil { + supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil) + return + } default: lengthdate = data.Contracttab.Chargedexpense / data.Unitprice } diff --git a/web/models/accesscardtab.go b/web/models/accesscardtab.go index 239881d..801d88c 100644 --- a/web/models/accesscardtab.go +++ b/web/models/accesscardtab.go @@ -130,6 +130,7 @@ 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 30488d6..bcc9719 100644 --- a/web/models/carporttab.go +++ b/web/models/carporttab.go @@ -92,7 +92,7 @@ func (t *Carporttab) GetPage(pageSize int, pageIndex int) ([]Carporttab, int, er table = table.And("descr like ?", descr) } Offset := (pageIndex - 1) * pageSize - err := query.Limit(pageSize,Offset).Desc("createtime").Find(&data) + err := query.Limit(pageSize, Offset).Desc("createtime").Find(&data) pcount := new(Carporttab) count, err := table.Count(pcount) @@ -108,44 +108,94 @@ type CarporttabContract struct { Propertytypetab `xorm:"extends"` Contracttab `xorm:"extends"` } - +type CarporttabInfo struct { + Propertytab `xorm:"extends"` + Propertytypetab `xorm:"extends"` +} //车位费查询 -func (t *Carporttab) Search(buildingid string, unit string, room string) (ContractInfo, error) { +func (t *Carporttab) Search(buildingid string, unit string, room string) (data ContractInfo, err error) { //联查 - data := ContractInfo{} - var info CarporttabContract + e := db.MasterEngine() - query := e.Table("carporttab").Join("LEFT", "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(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 } - 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) - } - _, err := query.Get(&info) + carPortIdList := make([]string, 0) + err = e.Table(t.TableName()).Where("cid = ? and propertyid = ?", t.Cid, t.Propertyid).Cols("carportid").Find(&carPortIdList) 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 - return data, err + data.CarportidList = carPortIdList + return data, nil } -- 2.30.1.windows.1 From 8c4501166e98b6db4bcf71c161247eb509195bba Mon Sep 17 00:00:00 2001 From: zhangxin Date: Thu, 22 Apr 2021 09:41:24 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=89=A9=E4=B8=9A?= =?UTF-8?q?=E8=B4=B9=E7=BC=B4=E8=B4=B9=E7=B2=BE=E5=BA=A6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/controllers/carporttab_controller.go | 13 +- web/controllers/contracttab_controller.go | 32 +++-- web/middleware/middleware.go | 20 ++- web/models/accesscardtab.go | 2 +- web/models/carporttab.go | 146 +++++++++------------- 5 files changed, 89 insertions(+), 124 deletions(-) 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 } -- 2.30.1.windows.1 From fa0f83ab830cef230622f5e8c2e802883c320839 Mon Sep 17 00:00:00 2001 From: zhangxin Date: Sun, 25 Apr 2021 09:02:56 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=BC=B4=E8=B4=B9?= =?UTF-8?q?=E7=B2=BE=E5=BA=A6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/controllers/contracttab_controller.go | 39 +++++++++++++---------- web/models/chargeallocationtab.go | 4 +++ web/models/contracttab.go | 14 +++++++- 3 files changed, 39 insertions(+), 18 deletions(-) diff --git a/web/controllers/contracttab_controller.go b/web/controllers/contracttab_controller.go index 76f58b9..75db8ac 100644 --- a/web/controllers/contracttab_controller.go +++ b/web/controllers/contracttab_controller.go @@ -47,6 +47,21 @@ func InsertContracttab(ctx iris.Context) { me.Chargeway = data.Contracttab.Chargeway lengthdate := 0.0 switch data.Chargetype { + case 1: + 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 + fmt.Println("days:", days) + lengthdate = float64(days) case 2: // lengthdate = data.Contracttab.Chargedexpense / data.Unitprice @@ -81,28 +96,18 @@ func InsertContracttab(ctx iris.Context) { me.Mobile = data.Phone1 me.Linkman = data.Contact me.Begdate = data.Begindate - me.Enddate = data.Enddate + me.Lengthdate = utils.ValueToInt(fmt.Sprintf("%0.0f", lengthdate), 0) 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) - } + //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/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 { -- 2.30.1.windows.1 From 661d29e21f6e7c9670dde3f1e91b8e8ab428964a Mon Sep 17 00:00:00 2001 From: louwenzhi Date: Sun, 25 Apr 2021 10:02:06 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E6=97=A5=E6=9C=9F=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/controllers/contracttab_controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/controllers/contracttab_controller.go b/web/controllers/contracttab_controller.go index 75db8ac..1e2d960 100644 --- a/web/controllers/contracttab_controller.go +++ b/web/controllers/contracttab_controller.go @@ -59,7 +59,7 @@ func InsertContracttab(ctx iris.Context) { supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil) return } - days := (end.Unix() - start.Unix()) / 86400 + days := (end.Unix() - start.Unix()) / (86400*30) fmt.Println("days:", days) lengthdate = float64(days) case 2: -- 2.30.1.windows.1 From afeb206109c146ef7d6ff0cd3f3f4f8fc862d281 Mon Sep 17 00:00:00 2001 From: zhangxin Date: Sun, 25 Apr 2021 14:11:43 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=90=88=E5=90=8C=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/models/carporttab.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/web/models/carporttab.go b/web/models/carporttab.go index 0a67254..31ba50a 100644 --- a/web/models/carporttab.go +++ b/web/models/carporttab.go @@ -156,6 +156,13 @@ func (t *Carporttab) Search() (data ContractInfo, err error) { 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 -- 2.30.1.windows.1