123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- <?php
- namespace common\modules\area\backend\controllers;
- use common\enums\BooleanEnum;
- use common\modules\area\models\Area;
- use common\modules\area\models\Block;
- use Yii;
- use yii\web\Controller;
- use yii\web\NotFoundHttpException;
- /**
- * AreaController implements the CRUD actions for Area model.
- */
- class AreaController extends Controller
- {
- public function actionIndex()
- {
- return $this->render("index", [
- "blocks" => Block::find()->all(),
- "areas" => Area::find()->all()
- ]);
- }
- /**
- * Creates a new Area model.
- * If creation is successful, the browser will be redirected to the 'view' page.
- *
- * @return mixed
- */
- public function actionCreate()
- {
- $model = new Area();
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- return $this->redirect(['index']);
- } else {
- return $this->render('create', [
- 'model' => $model,
- ]);
- }
- }
- /**
- * Updates an existing Area model.
- * If update is successful, the browser will be redirected to the 'view' page.
- *
- * @param int $id
- *
- * @return mixed
- */
- public function actionUpdate($id)
- {
- $model = $this->findModel($id);
- if ($model->load(Yii::$app->request->post()) && $model->save()) {
- return $this->redirect(['index']);
- } else {
- return $this->render('update', [
- 'model' => $model,
- ]);
- }
- }
- /**
- * Deletes an existing Area model.
- * If deletion is successful, the browser will be redirected to the 'index' page.
- *
- * @param int $id
- *
- * @return mixed
- */
- public function actionDelete($id)
- {
- $this->findModel($id)->delete();
- return $this->redirect(['index']);
- }
- public function actionUpdateBlocks()
- {
- Yii::$app->response->format = 'json';
- $id = \Yii::$app->getRequest()->post("id");
- $blocks = \Yii::$app->getRequest()->post("blocks");
- $model = $this->findModel($id);
- $model->blocks = $blocks;
- if($model->save()) {
- return [
- 'status' => true,
- 'msg' => '更新成功'
- ];
- } else {
- return [
- 'status' => false,
- 'msg' => '更新失败'
- ];
- }
- }
- public function actionUpdateBlocksDelete()
- {
- Yii::$app->response->format = 'json';
- $id = \Yii::$app->getRequest()->post("id");
- $blocks = \Yii::$app->getRequest()->post("blocks");
- $block = \Yii::$app->getRequest()->post("block");
- $model = $this->findModel($id);
- $model->blocks = $blocks;
- $block = Block::findOne($block);
- $block->used = BooleanEnum::FLASE;
- if($model->save() && $block->save()) {
- return [
- 'status' => true,
- 'msg' => '更新成功'
- ];
- } else {
- return [
- 'status' => false,
- 'msg' => '更新失败'
- ];
- }
- }
- public function actionUpdateBlocksCreate()
- {
- Yii::$app->response->format = 'json';
- $id = \Yii::$app->getRequest()->post("id");
- $blocks = \Yii::$app->getRequest()->post("blocks");
- $block = \Yii::$app->getRequest()->post("block");
- $model = $this->findModel($id);
- $model->blocks = $blocks;
- $block = Block::findOne($block);
- $block->used = BooleanEnum::TRUE;
- if($model->save() && $block->save()) {
- return [
- 'status' => true,
- 'msg' => '更新成功'
- ];
- } else {
- return [
- 'status' => false,
- 'msg' => '更新失败'
- ];
- }
- }
- /**
- * Finds the Area model based on its primary key value.
- * If the model is not found, a 404 HTTP exception will be thrown.
- *
- * @param integer $id
- * @return Area the loaded model
- * @throws NotFoundHttpException if the model cannot be found
- */
- public function findModel($id)
- {
- if (($model = Area::findOne($id)) !== null) {
- return $model;
- } else {
- throw new NotFoundHttpException('The requested page does not exist.');
- }
- }
- }
|