PushCity.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/5/21
  6. * Time: 下午5:18
  7. */
  8. namespace common\models;
  9. class PushCity extends Common
  10. {
  11. public function rules()
  12. {
  13. return [
  14. // ['city_id', 'unique', 'targetClass' => 'common\models\PushCity','on'=>['add'],'message'=>'该楼盘已存在','filter'=>function($query){
  15. // return $query->andWhere(['del'=>$this->setDel]);
  16. // }],
  17. // ['city_id','number','message'=>'请选择区域'],
  18. ['city_id','each','rule'=>['integer'],'message'=>'请输入正确的区域信息'],
  19. ['sort','number','message'=>'排序只能是数字'],
  20. ['sort','number','max'=>10000],
  21. ];
  22. }
  23. public function attributeLabels()
  24. {
  25. return [
  26. 'hid'=>'楼盘名称',
  27. 'sort'=>'排序',
  28. ];
  29. }
  30. public function Authenticator($input)
  31. {
  32. $this->load($input,'');
  33. if(!$this->validate()) return $this->errors;
  34. return $this;
  35. }
  36. public function FindById($id)
  37. {
  38. return self::findOne($id);
  39. }
  40. public function getList($input)
  41. {
  42. $query = self::find();
  43. $query->select(['pfg_category_city.id','pfg_category_city.city_name','pfg_push_city.create_at','pfg_push_city.is_show','pfg_push_city.sort']);
  44. $query->andWhere(['pfg_push_city.del'=>$this->setDel]);
  45. if(!empty($input['city_name']))
  46. {
  47. $query->andWhere(['like','pfg_category_city.city_name',$input['city_name']]);
  48. }
  49. if(!empty($input['city_id']))
  50. {
  51. $query->andWhere(['pfg_push_city.city_id'=>$input['city_id']]);
  52. }
  53. $query->leftJoin('pfg_category_city','pfg_push_city.city_id=pfg_category_city.id');
  54. if(!empty($input['page']))
  55. {
  56. $query->limit = $input['limit'];
  57. $query->offset = ($input['page']-1 )* $input['limit'];
  58. }
  59. return $query->orderBy(['pfg_push_city.create_at'=>SORT_DESC])->asArray()->all();
  60. }
  61. public function WhereColumn($query)
  62. {
  63. }
  64. public function Total()
  65. {
  66. $query = self::find();
  67. $query->andWhere(['pfg_push_city.del'=>$this->setDel]);
  68. $query->leftJoin('pfg_category_city','pfg_push_city.city_id=pfg_category_city.id');
  69. return $query->count();
  70. }
  71. public function Homegetlist()
  72. {
  73. // $query = self::find();
  74. // $query->select(['pfg_category_city.id','pfg_category_city.city_name','pfg_push_city.create_at','pfg_push_city.is_show','pfg_push_city.sort']);
  75. // $query->andWhere(['pfg_push_city.del'=>$this->setDel]);
  76. // if(!empty($input['city_name']))
  77. // {
  78. // $query->andWhere(['like','pfg_category_city.city_name',$input['city_name']]);
  79. // }
  80. // if(!empty($input['city_id']))
  81. // {
  82. // $query->andWhere(['pfg_push_city.city_id'=>$input['city_id']]);
  83. // }
  84. // $query->leftJoin('pfg_category_city','pfg_push_city.city_id=pfg_category_city.id');
  85. // if(!empty($input['page']))
  86. // {
  87. // $query->limit = $input['limit'];
  88. // $query->offset = ($input['page']-1 )* $input['limit'];
  89. // }
  90. // return $query->orderBy(['pfg_push_city.create_at'=>SORT_DESC])->asArray()->all();
  91. $query = self::find();
  92. $query->select(['pfg_category_city.id','pfg_category_city.city_name','pfg_push_city.create_at','pfg_push_city.is_show','pfg_push_city.sort']);
  93. $query->andWhere(['pfg_push_city.del'=>$this->setDel]);
  94. $query->andWhere(['pfg_push_city.is_show'=>1]);
  95. $query->leftJoin('pfg_category_city','pfg_push_city.city_id=pfg_category_city.id');
  96. $query->orderBy(['pfg_push_city.sort'=>SORT_ASC]);
  97. $query->limit = 18;
  98. return $query->asArray()->all();
  99. }
  100. }