HousePermit.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/3/4
  6. * Time: 上午9:25
  7. * 楼盘预售证号
  8. */
  9. namespace common\models;
  10. class HousePermit extends Common
  11. {
  12. public function rules()
  13. {
  14. return [
  15. ['permit','required','message'=>'{attribute}不能为空'],
  16. ['hid','required','message'=>'请刷新重试'],
  17. ['time','string','max'=>30],
  18. ['building_num','string','max'=>200],
  19. ];
  20. }
  21. public function attributeLabels()
  22. {
  23. return [
  24. 'permit'=>'预售证号',
  25. 'time'=>'发证时间',
  26. 'building_num'=>'楼栋数',
  27. ];
  28. }
  29. public function Authenticator($input)
  30. {
  31. $this->load($input,'');
  32. if(!$this->validate()) return $this->errors;
  33. return $this;
  34. }
  35. public function FindById($id)
  36. {
  37. return self::findOne($id);
  38. }
  39. public function getList($input)
  40. {
  41. $query = self::find();
  42. $query->andWhere(['del'=>$this->setDel]);
  43. if(!empty($input['hid']))
  44. {
  45. $query->andWhere(['hid'=>$input['hid']]);
  46. }
  47. if(!empty($input['page']))
  48. {
  49. $query->limit = $input['limit'];
  50. $query->offset = ($input['page']-1 )* $input['limit'];
  51. }
  52. return $query->orderBy(['create_at'=>SORT_DESC])->asArray()->all();
  53. }
  54. public function Total()
  55. {
  56. $query = self::find();
  57. $query->andWhere(['del'=>$this->setDel]);
  58. $query->andFilterWhere(['hid'=>$this->hid]);
  59. return $query->count();
  60. }
  61. public function FindNewest()
  62. {
  63. $query = self::find();
  64. $query->select(['permit','building_num','time']);
  65. $query->andWhere(['hid'=>$this->hid]);
  66. $query->andWhere(['del'=>$this->setDel]);
  67. return $query->orderBy(['create_at'=>SORT_DESC])->asArray()->one();
  68. }
  69. //楼盘分组查询统计
  70. public function HidTotal()
  71. {
  72. $query = self::find();
  73. $query->select(["count('hid') as num",'hid']);
  74. $query->andFilterWhere(['hid'=>$this->hid]);
  75. $query->andWhere(['del'=>$this->setDel]);
  76. return $query->groupBy('hid')->asArray()->all();
  77. }
  78. }