1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/5/21
- * Time: 下午5:18
- */
- namespace common\models;
- class PushFreshcity extends Common
- {
- public function rules()
- {
- return [
- ['city_id','number','message'=>'请输入正确的区域信息'],
- ['sort','number','message'=>'排序只能是数字'],
- ['sort','number','max'=>10000],
- ];
- }
- public function attributeLabels()
- {
- return [
- 'city_id'=>'区域',
- ];
- }
- public function Authenticator($input)
- {
- $this->load($input,'');
- if(!$this->validate()) return $this->errors;
- return $this;
- }
- public function FindById($id)
- {
- return self::findOne($id);
- }
- public function getList($input)
- {
- $query = self::find();
- $query->select(['pfg_push_freshcity.img','pfg_push_freshcity.city_id','pfg_push_freshcity.id','pfg_category_city.city_name','pfg_push_freshcity.create_at','pfg_push_freshcity.is_show','pfg_push_freshcity.sort']);
- $query->andWhere(['pfg_push_freshcity.del'=>$this->setDel]);
- if(!empty($input['city_name']))
- {
- $query->andWhere(['like','pfg_category_city.city_name',$input['city_name']]);
- }
- if(!empty($input['city_id']))
- {
- $query->andWhere(['pfg_push_city.city_id'=>$input['city_id']]);
- }
- $query->leftJoin('pfg_category_city','pfg_push_freshcity.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_push_freshcity.create_at'=>SORT_DESC])->asArray()->all();
- }
- public function WhereColumn($query)
- {
- }
- public function Total()
- {
- $query = self::find();
- $query->andWhere(['pfg_push_freshcity.del'=>$this->setDel]);
- $query->leftJoin('pfg_category_city','pfg_push_freshcity.city_id=pfg_category_city.id');
- return $query->count();
- }
- public function Homegetlist()
- {
- $query = self::find();
- $query->select(['pfg_category_city.id','pfg_category_city.city_name','pfg_push_freshcity.img']);
- $query->andWhere(['pfg_push_freshcity.del'=>$this->setDel]);
- $query->andWhere(['pfg_push_freshcity.is_show'=>1]);
- $query->leftJoin('pfg_category_city','pfg_push_freshcity.city_id=pfg_category_city.id');
- $query->orderBy(['pfg_push_freshcity.sort'=>SORT_ASC]);
- $query->limit = 10;
- return $query->asArray()->all();
- }
- }
|