[ 'class' => LoginBehavior::className(), ], ]); } public function actionIndex() { if(\Yii::$app->request->isAjax){ $form = new CommonPostListForm(); $form->attributes = \Yii::$app->request->get(); $form->cx_mch_id = $this->cx_mch_id; $form->scene = Post::SCENE_DEFAULT; $data = $form->search(); return $this->responseHandler($data); } $cat_list = Cat::find() ->where([ 'cx_mch_id' => $this->cx_mch_id, 'is_delete' => 0, 'type' => Cat::TYPE_POST_DEFAULT, ]) ->orderBy(['sort' => SORT_ASC, 'created_at' => SORT_DESC]) ->select('id,name')->asArray()->all(); return $this->render('index',[ 'cat_list' => $cat_list ]); } public function actionEdit($id = 0) { $model = Post::findOne([ 'cx_mch_id' => $this->cx_mch_id, 'is_delete' => 0, 'id' => $id, 'scene' => Post::SCENE_DEFAULT ]); if($model == null) $model = new Post(); if(\Yii::$app->request->isPost){ $form = new CommonPostEditForm(); $form->attributes = \Yii::$app->request->post(); $form->cx_mch_id = $this->cx_mch_id; $form->scene = Post::SCENE_DEFAULT; $form->model = $model; $data = $form->save(); return $this->responseHandler($data); } $cat_list = Cat::find() ->where([ 'cx_mch_id' => $this->cx_mch_id, 'is_delete' => 0, 'type' => Cat::TYPE_POST_DEFAULT, ]) ->select('id,name')->asArray()->all(); $cat_list = Cat::getTagTreeArray(0, Cat::TYPE_POST_DEFAULT, $this->cx_mch_id); foreach($cat_list as $index => $item){ $checked = false; $temp = PostMeta::findOne([ 'cx_mch_id' => $this->cx_mch_id, 'post_id' => $model->isNewRecord ? 0 : $model->id, 'type' => PostMeta::TYPE_CAT, 'value' => $item['id'], 'is_delete' => 0 ]); $checked = $temp == null ? false : true; $item['checked'] = $checked; $item['prefix'] = str_repeat("-", 2 * $item['level']); $cat_list[$index] = $item; } $return_url = \Yii::$app->request->referrer; return $this->render('edit', [ 'model' => $model, 'return_url' => $return_url, 'cat_list' => $cat_list, ]); } public function actionDelete() { if(!\Yii::$app->request->isPost){ $data = $this->invaildRequest(); return $this->responseHandler($data); } $form = new CommonPostActionForm(); $form->attributes = \Yii::$app->request->post(); $form->cx_mch_id = $this->cx_mch_id; $form->scene = Post::SCENE_DEFAULT; $data = $form->delete(); return $this->responseHandler($data); } public function actionPublish() { if(!\Yii::$app->request->isPost){ $data = $this->invaildRequest(); return $this->responseHandler($data); } $form = new CommonPostActionForm(); $form->attributes = \Yii::$app->request->post(); $form->cx_mch_id = $this->cx_mch_id; $form->scene = Post::SCENE_DEFAULT; $data = $form->publish(); return $this->responseHandler($data); } public function actionTrash() { if(!\Yii::$app->request->isPost){ $data = $this->invaildRequest(); return $this->responseHandler($data); } $form = new CommonPostActionForm(); $form->attributes = \Yii::$app->request->post(); $form->cx_mch_id = $this->cx_mch_id; $form->scene = Post::SCENE_DEFAULT; $data = $form->trash(); return $this->responseHandler($data); } public function actionCancelTrash() { if(!\Yii::$app->request->isPost){ $data = $this->invaildRequest(); return $this->responseHandler($data); } $form = new CommonPostActionForm(); $form->attributes = \Yii::$app->request->post(); $form->cx_mch_id = $this->cx_mch_id; $form->scene = Post::SCENE_DEFAULT; $data = $form->cancel_trash(); return $this->responseHandler($data); } public function actionCancelTop() { if(!\Yii::$app->request->isPost){ $data = $this->invaildRequest(); return $this->responseHandler($data); } $form = new CommonPostActionForm(); $form->attributes = \Yii::$app->request->post(); $form->cx_mch_id = $this->cx_mch_id; $form->scene = Post::SCENE_DEFAULT; $data = $form->cancel_top(); return $this->responseHandler($data); } public function actionTop() { if(!\Yii::$app->request->isPost){ $data = $this->invaildRequest(); return $this->responseHandler($data); } $form = new CommonPostActionForm(); $form->attributes = \Yii::$app->request->post(); $form->cx_mch_id = $this->cx_mch_id; $form->scene = Post::SCENE_DEFAULT; $data = $form->top(); return $this->responseHandler($data); } public function actionCat() { if(\Yii::$app->request->isAjax){ $form = new CommonCatListForm(); $form->attributes = \Yii::$app->request->get(); $form->cx_mch_id = $this->cx_mch_id; $form->type = Cat::TYPE_POST_DEFAULT; $data = $form->search(); return $this->responseHandler($data); } return $this->render('cat'); } public function actionCatEdit($id = 0) { $model = Cat::findOne([ 'cx_mch_id' => $this->cx_mch_id, 'is_delete' => 0, 'id' => $id, 'type' => Cat::TYPE_POST_DEFAULT, ]); if($model == null){ $model = new Cat(); $model->status = 1; } if(\Yii::$app->request->isPost){ $form = new CommonCatEditForm(); $form->attributes = \Yii::$app->request->post(); $form->cx_mch_id = $this->cx_mch_id; $form->model = $model; $form->type = Cat::TYPE_POST_DEFAULT; $data = $form->save(); return $this->responseHandler($data); } $cat_ids = []; $cat_ids[] = $model->isNewRecord ? 0 : $model->id; $parent_list = Cat::find() ->where([ 'cx_mch_id' => $this->cx_mch_id, 'is_delete' => 0, 'type' => Cat::TYPE_POST_DEFAULT, ]) ->andWhere([ 'NOT IN', 'id', $cat_ids ]) ->select('id,name')->asArray()->all(); $is_has_parent = true;//开启是否有父节点 $parent_list = $is_has_parent ? $parent_list : []; array_unshift($parent_list,['id' => 0, 'name' => '无父节点']); $return_url = \Yii::$app->request->referrer; return $this->render('cat-edit', [ 'model' => $model, 'return_url' => $return_url, 'parent_list' => $parent_list ]); } public function actionCatDelete() { if(!\Yii::$app->request->isPost){ $data = $this->invaildRequest(); return $this->responseHandler($data); } $form = new CommonCatActionForm(); $form->attributes = \Yii::$app->request->post(); $form->cx_mch_id = $this->cx_mch_id; $form->type = Cat::TYPE_POST_DEFAULT; $data = $form->delete(); return $this->responseHandler($data); } public function actionCatShow() { if(!\Yii::$app->request->isPost){ $data = $this->invaildRequest(); return $this->responseHandler($data); } $form = new CommonCatActionForm(); $form->attributes = \Yii::$app->request->post(); $form->cx_mch_id = $this->cx_mch_id; $form->type = Cat::TYPE_POST_DEFAULT; $data = $form->show(); return $this->responseHandler($data); } public function actionCatHide() { if(!\Yii::$app->request->isPost){ $data = $this->invaildRequest(); return $this->responseHandler($data); } $form = new CommonCatActionForm(); $form->attributes = \Yii::$app->request->post(); $form->cx_mch_id = $this->cx_mch_id; $form->type = Cat::TYPE_POST_DEFAULT; $data = $form->hide(); return $this->responseHandler($data); } public function actionCatOpen() { if(!\Yii::$app->request->isPost){ $data = $this->invaildRequest(); return $this->responseHandler($data); } $form = new CommonCatActionForm(); $form->attributes = \Yii::$app->request->post(); $form->cx_mch_id = $this->cx_mch_id; $form->type = Cat::TYPE_POST_DEFAULT; $data = $form->open(); return $this->responseHandler($data); } public function actionCatClose() { if(!\Yii::$app->request->isPost){ $data = $this->invaildRequest(); return $this->responseHandler($data); } $form = new CommonCatActionForm(); $form->attributes = \Yii::$app->request->post(); $form->cx_mch_id = $this->cx_mch_id; $form->type = Cat::TYPE_POST_DEFAULT; $data = $form->close(); return $this->responseHandler($data); } }