12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- namespace backend\controllers;
- use backend\models\AuthArea;
- use common\models\Comment;
- use yii;
- use yii\filters\AccessControl;
- /**
- * 评论管理
- * @package backend\controllers
- */
- class CommentController 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 =['start'=>'','end'=>'','type_id'=>'','name'=>''];
- $search['start'] = Yii::$app->request->get('start');
- $search['end'] = Yii::$app->request->get('end');
- $search['name'] = Yii::$app->request->get('name');
- //$models = UserMater::find()->where(['u.role'=>User::USER_ROLE_MATER])->from("{{%user_mater}} um")->leftJoin("{{%user}} u","um.uid = u.id");
- $models = Comment::find()->from("{{%comment}} c")->leftJoin("{{%building}} b","c.pid = b.id");
- if(!empty($search['start']))
- $models->andWhere("c.created_at > :start",[':start'=>strtotime($search['start'])]);
- if(!empty($search['end']))
- $models->andWhere("c.update_at < :end",[':end'=>strtotime($search['end'])+(3600*24-1)]);
- if(!empty($search['name']))
- $models->andWhere("b.name like :name ",[':name'=>"%".$search['name']."%"]);
- $citys = AuthArea::queryAuth();
- if($citys=='all')
- $models;
- elseif (!empty($citys))
- $models->andWhere("b.city in ({$citys})");
- else
- $models->andWhere("b.city = -1");
- $pages = new yii\data\Pagination(["totalCount" => $models->count(), "pageSize" => self::PAGESIZE]);
- $models = $models->offset($pages->offset)->limit($pages->limit)->orderBy("c.id 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 = Comment::find()->where(['id'=>$id])->one();
- if($model->status==Comment::STATUS_ACTIVE)
- {
- $title = "关闭评论";
- $model->status = Comment::STATUS_DELETED;
- }
- else{
- $title = "开启评论";
- $model->status = Comment::STATUS_ACTIVE;
- }
- if($model->save())
- $result = ['sign'=>1,'msg'=>$title.'成功'];
- else
- $result = ['sign'=>0,'msg'=>$title.'失败'];
- return json_encode($result);
- }
- }
|