沈阳玫苑物业管理后端
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.

143 lines
4.6 KiB

  1. package models
  2. import (
  3. "lapp_-wy/db"
  4. "lapp_-wy/utils"
  5. "xorm.io/core"
  6. "errors"
  7. )
  8. type Propertytab struct {
  9. Cid int `json:"cid" xorm:"not null pk INT(4)"`
  10. Propertyid string `json:"propertyid" xorm:"not null pk VARCHAR(100)"`
  11. Descr string `json:"descr" xorm:"VARCHAR(255)"`
  12. Buildingid string `json:"buildingid" xorm:"VARCHAR(100)"`
  13. Unit string `json:"unit" xorm:"VARCHAR(40)"`
  14. Isfree string `json:"isfree" xorm:"VARCHAR(10)"`//1.普通业主,2.业主委员会3.空置房
  15. Room string `json:"room" xorm:"VARCHAR(40)"`
  16. Status string `json:"status" xorm:"VARCHAR(40)"`
  17. Ownertype string `json:"ownertype" xorm:"VARCHAR(40)"`
  18. Layout string `json:"layout" xorm:"VARCHAR(255)"`
  19. Orientation string `json:"orientation" xorm:"VARCHAR(255)"`
  20. Constructionarea float64 `json:"constructionarea" xorm:"DECIMAL(10,2)"`
  21. Usearea float64 `json:"usearea" xorm:"DECIMAL(10,2)"`
  22. Contact string `json:"contact" xorm:"VARCHAR(255)"`
  23. Phone1 string `json:"phone1" xorm:"VARCHAR(15)"`
  24. Phone2 string `json:"phone2" xorm:"VARCHAR(15)"`
  25. Createtime string `json:"createtime" xorm:"VARCHAR(14)"`
  26. Lastmodifytime string `json:"lastmodifytime" xorm:"VARCHAR(14)"`
  27. Lastmodifyby string `json:"lastmodifyby" xorm:"VARCHAR(40)"`
  28. Contractid string `json:"contractid" xorm:"VARCHAR(100)"`
  29. }
  30. func (t *Propertytab) TableName() string {
  31. return "propertytab"
  32. }
  33. // 清除string字段的右侧空格
  34. func (t *Propertytab) Clipped() {
  35. utils.TrimStruct(t, *t)
  36. }
  37. //增
  38. func (t *Propertytab) Add() error {
  39. e := db.MasterEngine()
  40. countrole := new(Propertytab)
  41. affw, err := e.Table("propertytab").ID(core.PK{t.Cid, t.Propertyid}).Count(countrole)
  42. if err != nil {
  43. return err
  44. }
  45. if affw > 0 {
  46. return errors.New("数据已经存在!")
  47. }
  48. _, err = e.Table("propertytab").Insert(t)
  49. if err != nil {
  50. return err
  51. }
  52. return nil
  53. }
  54. //删
  55. func (t *Propertytab) Del() bool {
  56. e := db.MasterEngine()
  57. _, err := e.ID(core.PK{t.Cid, t.Propertyid}).Delete(&Propertytab{})
  58. if err != nil {
  59. return false
  60. }
  61. return true
  62. }
  63. //改
  64. func (t *Propertytab) Update() bool {
  65. e := db.MasterEngine()
  66. _, err := e.ID(core.PK{t.Cid, t.Propertyid}).Update(t)
  67. if err != nil {
  68. return false
  69. }
  70. return true
  71. }
  72. //查
  73. func (t *Propertytab) SelectOne() (Propertytab, error) {
  74. e := db.MasterEngine()
  75. var data Propertytab
  76. _, err := e.ID(core.PK{t.Cid, t.Propertyid}).Get(&data)
  77. if err != nil {
  78. return data, err
  79. }
  80. return data, nil
  81. }
  82. //分页
  83. func (t *Propertytab) GetPage(pageSize int, pageIndex int) ([]Propertytab, int, error) {
  84. data := make([]Propertytab, 0)
  85. e := db.MasterEngine()
  86. query := e.Table("propertytab").Where("cid = ? ", t.Cid)
  87. table := e.Table("propertytab").Where("cid = ? ", t.Cid)
  88. if !utils.ValueIsEmpty(t.Propertyid) {
  89. query = query.And("propertyid = ?", t.Propertyid)
  90. table = table.And("propertyid = ?", t.Propertyid)
  91. }
  92. Offset := (pageIndex - 1) * pageSize
  93. err := query.Limit(pageSize, Offset).Desc("createtime").Find(&data)
  94. pcount := new(Propertytab)
  95. count, err := table.Count(pcount)
  96. if err != nil {
  97. return data, 0, err
  98. }
  99. return data, int(count), nil
  100. }
  101. type PropertytabContract struct {
  102. Propertytab `xorm:"extends"`
  103. Buildingtab `xorm:"extends"`
  104. Propertytypetab `xorm:"extends"`
  105. Contracttab `xorm:"extends"`
  106. }
  107. //物业费查询
  108. func (t *Propertytab) Search() (ContractInfo, error) {
  109. data := ContractInfo{}
  110. //联查
  111. var info PropertytabContract
  112. e := db.MasterEngine()
  113. _, err := e.Table("propertytab").Join("LEFT", "buildingtab", "buildingtab.buildingid = propertytab.buildingid and buildingtab.cid = propertytab.cid").Join("LEFT", "propertytypetab", "propertytypetab.propertytypeid=buildingtab.propertytypeid and propertytypetab.cid=buildingtab.cid").Join("LEFT", "contracttab", "propertytab.contractid=contracttab.contractid and propertytab.cid=contracttab.cid").Where("propertytab.cid = ? and propertytab.buildingid = ? and propertytab.unit = ? and propertytab.room =?", t.Cid, t.Buildingid, t.Unit, t.Room).Get(&info)
  114. if err != nil {
  115. return data, err
  116. }
  117. data.Propertyid = info.Propertytab.Propertyid
  118. data.Cid = info.Propertytab.Cid
  119. data.Room = info.Propertytab.Room
  120. data.Unit = info.Unit
  121. data.Buildingid = info.Propertytab.Buildingid
  122. data.Contractid = info.Propertytab.Contractid
  123. data.Descr = info.Propertytab.Descr
  124. data.Contact = info.Propertytab.Contact
  125. data.Phone1 = info.Propertytab.Phone1
  126. data.Phone2 = info.Propertytab.Phone2
  127. data.Constructionarea = info.Propertytab.Constructionarea
  128. data.Unitprice = info.Propertytypetab.Unitprice
  129. data.Contracttab = info.Contracttab
  130. data.Chargetype = 1
  131. return data, err
  132. }