1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace backend\controllers;
- use common\models\Area;
- use yii;
- use yii\filters\AccessControl;
- /**
- * 城市管理
- * @package backend\controllers
- */
- class AreaController extends BaseController
- {
- public $layout = 'iframe';
- const PAGESIZE = 20;//分页数
- public function behaviors()
- {
- return [
- 'access' => [
- 'class' => AccessControl::className(),
- 'rules' => [
- [
- 'actions' => [],
- 'allow' => true,
- 'roles' => ['@'],
- ],
- ],
- ],
- ];
- }
- /**
- * 列表
- * @return string
- */
- public function actionIndex()
- {
- $search = Yii::$app->request->get();
- $models = Area::find()->where(['type'=>2]);
- if(!empty($search['province']))
- $models->andWhere("father_area_id = :father_area_id",[':father_area_id'=>$search['province']]);
- if(!empty($search['display']))
- $models->andWhere("display = :display",[':display'=>$search['display']]);
- if(!empty($search['name']))
- $models->andWhere("area like :name",[':name'=>"%".$search['name']."%"]);
- $pages = new yii\data\Pagination(["totalCount" => $models->count(), "pageSize" => self::PAGESIZE]);
- $models = $models->offset($pages->offset)->limit($pages->limit)->orderBy("ishot DESC")->all();
- return $this->render('index', ['models' => $models, 'pages' => $pages,'name'=>'城市管理','search'=>$search]);
- }
- /**
- * 更新状态
- * @return string
- */
- public function actionUpdateStatus()
- {
- $id = Yii::$app->request->post('id');
- $model = Area::find()->where(['id'=>$id])->one();
- if($model->display==Area::DISPLAY_YES)
- $model->display = Area::DISPLAY_NO;
- else
- $model->display = Area::DISPLAY_YES;
- if($model->save())
- $result = ['sign'=>1,'msg'=>'修改状态成功'];
- else
- $result = ['sign'=>0,'msg'=>'修改状态失败'];
- return json_encode($result);
- }
- }
|