沈阳玫苑物业管理后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

204 lines
5.7 KiB

package controllers
import (
"lapp_-wy/utils"
"lapp_-wy/web/middleware/glog"
"lapp_-wy/web/middleware/jwts"
"lapp_-wy/web/models"
"lapp_-wy/web/supports"
"github.com/kataras/iris"
"time"
)
func GetPropertytabList(ctx iris.Context) {
user, ok := jwts.ParseToken(ctx)
utils.TrimStruct(user, *user)
if !ok {
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
return
}
//日志
logs := new(models.LeitServerLog)
logs.File = "/controllers/Propertytab_controller.go"
logs.Level = "info"
logs.Function = "GetPropertytabList"
logs.Message = "房间列表查看"
logs.Operator = user.Userid
logs.TimeStamp = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss")
logs.InsertRecord()
var data models.Propertytab
var err error
var pageSize = 10
var pageIndex = 1
if size := ctx.URLParam("pageSize"); size != "" {
pageSize = utils.ValueToInt(size, 0)
}
if index := ctx.URLParam("pageIndex"); index != "" {
pageIndex = utils.ValueToInt(index, 0)
}
data.Cid = user.Pid
data.Descr = ctx.URLParam("descr")
data.Propertyid = ctx.URLParam("propertyid")
result, count, err := data.GetPage(pageSize, pageIndex)
if err != nil {
supports.Error(ctx, iris.StatusBadRequest, "抱歉未找到相关信息", nil)
return
}
res := make(map[string]interface{})
res["data"] = result
res["count"] = count
res["pageIndex"] = pageIndex
res["pageSize"] = pageSize
supports.Ok(ctx, supports.OptionSuccess, res)
}
func GetPropertytab(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.Propertytab
me.Cid = user.Pid
me.Propertyid = ctx.URLParam("propertyid")
result, err := me.SelectOne()
if err != nil {
supports.Error(ctx, iris.StatusBadRequest, "抱歉未找到相关信息", nil)
return
}
supports.Ok(ctx, supports.OptionSuccess, result)
}
func InsertPropertytab(ctx iris.Context) {
user, ok := jwts.ParseToken(ctx)
utils.TrimStruct(user, *user)
if !ok {
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
return
}
//日志
logs := new(models.LeitServerLog)
logs.File = "/controllers/Propertytab_controller.go"
logs.Level = "info"
logs.Function = "InsertPropertytab"
logs.Message = "添加房间"
logs.Operator = user.Userid
logs.TimeStamp = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss")
logs.InsertRecord()
data := new(models.Propertytab)
data.Lastmodifyby = user.Userid
data.Createtime = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss")
data.Lastmodifytime = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss")
if err := ctx.ReadJSON(data); err != nil {
logs := new(models.LeitServerLog)
logs.File = "/controllers/Propertytab_controller.go"
logs.Level = "debug"
logs.Function = "InsertPropertytab"
logs.Message = error.Error(err)
logs.Operator = user.Userid
logs.TimeStamp = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss")
logs.InsertRecord()
supports.Error(ctx, iris.StatusBadRequest, "json解析错误", nil)
return
}
data.Cid = user.Pid
err := data.Add()
if err != nil {
supports.Error(ctx, iris.StatusBadRequest, "添加失败!", nil)
return
}
supports.Ok(ctx, supports.OptionSuccess, data)
}
func UpdatePropertytab(ctx iris.Context) {
user, ok := jwts.ParseToken(ctx)
utils.TrimStruct(user, *user)
if !ok {
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
return
}
//日志
logs := new(models.LeitServerLog)
logs.File = "/controllers/Propertytab_controller.go"
logs.Level = "info"
logs.Function = "UpdatePropertytab"
logs.Message = "更新房间"
logs.Operator = user.Userid
logs.TimeStamp = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss")
logs.InsertRecord()
data := new(models.Propertytab)
if err := ctx.ReadJSON(data); err != nil {
supports.Error(ctx, iris.StatusBadRequest, "抱歉未找到相关信息", nil)
return
}
data.Lastmodifyby = user.Userid
data.Cid = user.Pid
res := data.Update()
if !res {
supports.Error(ctx, iris.StatusBadRequest, "更新失败", nil)
return
}
supports.Ok(ctx, "修改成功", "")
}
func DeletePropertytab(ctx iris.Context) {
user, ok := jwts.ParseToken(ctx)
utils.TrimStruct(user, *user)
if !ok {
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
return
}
//日志
logs := new(models.LeitServerLog)
logs.File = "/controllers/Propertytab_controller.go"
logs.Level = "info"
logs.Function = "DeletePropertytab"
logs.Message = "删除房间"
logs.Operator = user.Userid
logs.TimeStamp = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss")
logs.InsertRecord()
me := new(models.Propertytab)
me.Cid = user.Pid
me.Propertyid = ctx.URLParam("propertyid")
res := me.Del()
if !res {
supports.Error(ctx, iris.StatusBadRequest, "删除失败", nil)
return
}
supports.Ok(ctx, "删除成功", "")
}
func SearchPropertytab(ctx iris.Context) {
user, ok := jwts.ParseToken(ctx)
utils.TrimStruct(user, *user)
if !ok {
supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
return
}
//日志
logs := new(models.LeitServerLog)
logs.File = "/controllers/Propertytab_controller.go"
logs.Level = "info"
logs.Function = "SearchPropertytab"
logs.Message = "查询物业费"
logs.Operator = user.Userid
logs.TimeStamp = utils.TimeFormat(time.Now(), "yyyyMMddHHmmss")
logs.InsertRecord()
me := new(models.Propertytab)
me.Cid = user.Pid
me.Propertyid = ctx.URLParam("propertyid")
me.Buildingid = ctx.URLParam("buildingid")
me.Unit = ctx.URLParam("unit")
me.Room = ctx.URLParam("room")
data, err := me.Search()
if err != nil {
glog.InfoExt("缴费","查询物业费:%v",err)
supports.Error(ctx, iris.StatusBadRequest, "查询失败", nil)
return
}
supports.Ok(ctx, "查询成功", data)
}