HousePriceRecord.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/3/28
  6. * Time: 下午2:47
  7. */
  8. namespace common\models;
  9. //use yii\db\ActiveRecord;
  10. //use yii\behaviors\TimestampBehavior;
  11. class HousePriceRecord extends Common
  12. {
  13. // public $setDel = 1;
  14. // public function behaviors()
  15. // {
  16. // return [
  17. // [
  18. // 'class' => TimestampBehavior::className(),
  19. // 'attributes' => [
  20. // # 创建之前
  21. // ActiveRecord::EVENT_BEFORE_INSERT => ['create_at', 'update_at'],
  22. // # 修改之前
  23. // ActiveRecord::EVENT_BEFORE_UPDATE => ['update_at']
  24. // ],
  25. // #设置默认值
  26. // 'value' => $_SERVER['REQUEST_TIME']
  27. // ]
  28. // ];
  29. // }
  30. public function rules()
  31. {
  32. return [
  33. [['create_time','price'],'required','message'=>'{attribute}不能为空'],
  34. ['create_time','date', 'format'=>'yyyy-mm-dd'],
  35. ['min_price','string','max'=>30],
  36. ['explain','string','max'=>200],
  37. ['hid','number'],
  38. ['price','number'],
  39. ];
  40. }
  41. public function attributeLabels()
  42. {
  43. return [
  44. 'price'=>'价格',
  45. 'create_time'=>'添加时间',
  46. 'min_price'=>'最低价格',
  47. 'explain'=>'价格说明',
  48. ];
  49. }
  50. public function Authenticator($input)
  51. {
  52. $this->load($input,'');
  53. if(!$this->validate()) return $this->errors;
  54. return $this;
  55. }
  56. public function getList($page)
  57. {
  58. $query = self::find();
  59. $query = $this->SetWheres($query);
  60. if(!empty($page['page']))
  61. {
  62. $query->offset = ($page['page'] - 1) * $page['limit'];
  63. $query->limit = $page['limit'];
  64. }
  65. return $query->orderBy(['create_time'=>SORT_DESC])->asArray()->all();
  66. }
  67. public function Total()
  68. {
  69. $query = self::find();
  70. $query = $this->SetWheres($query);
  71. return $query->count();
  72. }
  73. private function SetWheres($query)
  74. {
  75. $query->andWhere(['del'=>$this->setDel]);
  76. $query->andFilterWhere(['hid'=>$this->hid]);
  77. return $query;
  78. }
  79. // public function FindOneRecord()
  80. // {
  81. // $query = $this->newFind();
  82. // $query = $this->SetWheres($query);
  83. // return $query->one();
  84. // }
  85. private function newFind()
  86. {
  87. return self::find();
  88. }
  89. public function FindById($id)
  90. {
  91. return self::findOne($id);
  92. }
  93. public function GetPrice($Id)
  94. {
  95. $query = self::find();
  96. $query->andWhere(['del'=>$this->setDel]);
  97. $query->andFilterWhere(['hid'=>$Id]);
  98. return $query->orderBy('create_time')->asArray()->all();
  99. }
  100. }