123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/4/26
- * Time: 上午11:57
- */
- namespace common\models;
- class CityDetails extends Common
- {
- public function rules()
- {
- return [
- ['del','in','range'=>[1,2]],
- ['city_id','number'],
- [['title','introduce','thumb','background_img','pinyin','video'],'string'],
- ];
- }
- public function attributeLabels()
- {
- return [
- 'title'=>'标题',
- 'introduce'=>'简介',
- 'thumb'=>'缩略图',
- 'background_img'=>'图集',
- ];
- }
- /*
- * 调用里面的验证,错误返回数组,正确返回对象
- * */
- public function Authenticator($input)
- {
- $this->load($input,'');
- if(!$this->validate()) return $this->errors;
- return $this;
- }
- public function getList($input)
- {
- $query = self::find();
- $query->select(['pfg_category_city.city_name','pfg_city_details.title',
- 'pfg_city_details.id','pfg_city_details.introduce','pfg_city_details.pinyin']);
- $query->andWhere(['pfg_city_details.del'=>$this->setDel]);
- if(!empty($this->city_id))
- {
- $query->andWhere(['pfg_city_details.city_id'=>$this->city_id]);
- }
- $query->leftJoin('pfg_category_city','pfg_city_details.city_id=pfg_category_city.id');
- if(!empty($input['page']))
- {
- $query->limit = $input['limit'];
- $query->offset = ($input['page']-1 )* $input['limit'];
- }
- return $query->orderBy(['pfg_city_details.create_at'=>SORT_DESC])->asArray()->all();
- }
- public function FingById($id)
- {
- return self::findOne($id);
- }
- public function FingByName($id)
- {
- $query = self::find();
- $query->andWhere(['pfg_city_details.del'=>$this->setDel]);
- $query->andWhere(['pfg_city_details.is_view'=>1]);
- $query->andWhere(['pfg_city_details.id'=>$id]);
- $query->select(['pfg_category_city.city_name','pfg_city_details.*']);
- $query->leftJoin('pfg_category_city','pfg_city_details.city_id = pfg_category_city.id');
- return $query->asArray()->one();
- }
- public function Total()
- {
- $query = self::find();
- $query->andWhere(['pfg_city_details.del'=>$this->setDel]);
- $query->leftJoin('pfg_category_city','pfg_city_details.city_id=pfg_category_city.id');
- return $query->count();
- }
- public function Homegetlist()
- {
- $query = self::find();
- $query->andWhere(['pfg_city_details.del'=>$this->setDel]);
- $query->andWhere(['pfg_city_details.is_view'=>1]);
- $query->select(['pfg_category_city.city_name','pfg_city_details.introduce','pfg_city_details.thumb']);
- $query->leftJoin('pfg_category_city','pfg_city_details.city_id = pfg_category_city.id');
- $query->orderBy(['pfg_city_details.sort'=>SORT_ASC]);
- $query->limit = 5;
- return $query->asArray()->all();
- }
- /**
- * 返回区域信息
- */
- public function CityInfo()
- {
- $query = self::find();
- $query->andWhere(['pfg_city_details.del'=>$this->setDel]);
- $query->andWhere(['pfg_city_details.is_view'=>1]);
- $query->select(['pfg_category_city.city_name','pfg_city_details.thumb','pfg_city_details.id']);
- $query->leftJoin('pfg_category_city','pfg_city_details.city_id = pfg_category_city.id');
- $query->orderBy(['pfg_city_details.sort'=>SORT_ASC]);
- return $query->asArray()->all();
- }
- }
|