CategoryLabel.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/3/4
  6. * Time: 上午9:28
  7. */
  8. namespace common\models;
  9. //use yii\db\ActiveRecord;
  10. //use yii\behaviors\TimestampBehavior;
  11. /*
  12. * type = 2 表示建筑类别
  13. * */
  14. class CategoryLabel extends Common
  15. {
  16. public function rules()
  17. {
  18. return [
  19. ['name','required','message'=>'不能为空'],
  20. ['type','in','range'=>[1,2,3,4]],
  21. ['del','in','range'=>[1,2]],
  22. ['sort','number'],
  23. // ['name', 'unique', 'targetClass' => 'common\models\CategoryCity','on'=>['add'],'message'=>'该城市名称已经存在'],
  24. ];
  25. }
  26. public function FindById($id)
  27. {
  28. return self::findOne($id);
  29. }
  30. public function getList($page,$select = null)
  31. {
  32. $query = self::find();
  33. $query->select($select);
  34. $query = $this->WhereColumn($query);
  35. if(!empty($page['page']))
  36. {
  37. $query->offset = ($page['page'] - 1) * $page['limit'];
  38. $query->limit = $page['limit'];
  39. }
  40. return $query->orderBy(['create_at'=>SORT_DESC])->asArray()->all();
  41. }
  42. private function WhereColumn($query)
  43. {
  44. $query->andFilterWhere(['name'=>$this->name]);
  45. $query->andFilterWhere(['type'=>$this->type]);
  46. $query->andFilterWhere(['id'=>$this->id]);
  47. $query->andWhere(['del'=>1]);
  48. return $query;
  49. }
  50. public function Total()
  51. {
  52. $query = self::find();
  53. $query = $this->WhereColumn($query);
  54. return $query->count();
  55. }
  56. public function CityAdd()
  57. {
  58. // $this->()
  59. }
  60. }