HousesPrice.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/3/4
  6. * Time: 上午9:40
  7. */
  8. namespace common\models;
  9. //use yii\db\ActiveRecord;
  10. //use yii\behaviors\TimestampBehavior;
  11. class HousesPrice extends Common
  12. {
  13. // public function behaviors()
  14. // {
  15. // return [
  16. // [
  17. // 'class' => TimestampBehavior::className(),
  18. // 'attributes' => [
  19. // # 创建之前
  20. // ActiveRecord::EVENT_BEFORE_INSERT => ['create_at', 'update_at'],
  21. // # 修改之前
  22. // ActiveRecord::EVENT_BEFORE_UPDATE => ['update_at']
  23. // ],
  24. // #设置默认值
  25. // 'value' => $_SERVER['REQUEST_TIME']
  26. // ]
  27. // ];
  28. // }
  29. public function rules()
  30. {
  31. return [
  32. ['price','required','message'=>'价格不能为空'],
  33. ['price_short','required','message'=>'短标不能为空'],
  34. ['state','in','range'=>[1,2]],
  35. ['del','in','range'=>[1,2]],
  36. ];
  37. }
  38. public function FindById($id)
  39. {
  40. return self::findOne($id);
  41. }
  42. public function getList($input,$arr = null)
  43. {
  44. $query = self::find();
  45. $query->select($arr);
  46. $query = $this->WhereFouse($query);
  47. if(!empty($input['page']))
  48. {
  49. $query->offset = ($input['page'] -1 ) * $input['limit'];
  50. $query->limit = $input['limit'];
  51. }
  52. return $query->orderBy(['create_at'=>SORT_DESC])->asArray()->all();
  53. }
  54. public function WhereFouse($query)
  55. {
  56. $query->andFilterWhere(['del'=>$this->setDel]);
  57. $query->andFilterWhere(['price'=>$this->price]);
  58. return $query;
  59. }
  60. public function Total()
  61. {
  62. $query = self::find();
  63. $query = $this->WhereFouse($query);
  64. return $query->count();
  65. }
  66. }