Skip to content

Commit

Permalink
修复几个bug 增加个性化菜单 解耦websocket
Browse files Browse the repository at this point in the history
  • Loading branch information
jianyan74 committed Mar 7, 2018
1 parent 41e3da5 commit 9c10e41
Show file tree
Hide file tree
Showing 102 changed files with 1,021 additions and 824 deletions.
1 change: 1 addition & 0 deletions api/config/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
* http://当前域名/api/site/login?group=1
*/
'site',
'room',
'file',
/** ------ 业务相关 ------ **/
'v1/default',
Expand Down
9 changes: 7 additions & 2 deletions api/controllers/AController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public function actionIndex()
public function actionCreate()
{
$model = new $this->modelClass();
$model->member_id = Yii::$app->user->identity->user_id;
$model->attributes = Yii::$app->request->post();

if (!$model->save())
{
// 返回数据验证失败
Expand All @@ -61,7 +63,8 @@ public function actionCreate()
* 更新
*
* @param $id
* @return mixed
* @return mixed|void
* @throws NotFoundHttpException
*/
public function actionUpdate($id)
{
Expand All @@ -81,17 +84,19 @@ public function actionUpdate($id)
*
* @param $id
* @return mixed
* @throws NotFoundHttpException
*/
public function actionDelete($id)
{
return $this->findModel($id)->delete();
}

/**
* 显示单个
* 详情
*
* @param $id
* @return mixed
* @throws NotFoundHttpException
*/
public function actionView($id)
{
Expand Down
132 changes: 132 additions & 0 deletions api/controllers/MController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
<?php
namespace api\controllers;

use Yii;
use yii\data\ActiveDataProvider;
use yii\web\NotFoundHttpException;
use common\enums\StatusEnum;
use common\controllers\ActiveController;

/**
* 用户信息基类
*
* Class MController
* @package api\controllers
*/
class MController extends ActiveController
{
public function actions()
{
$actions = parent::actions();
// 注销系统自带的实现方法
unset($actions['index'], $actions['update'], $actions['create'], $actions['delete'], $actions['view']);
// 自定义数据indexDataProvider覆盖IndexAction中的prepareDataProvider()方法
// $actions['index']['prepareDataProvider'] = [$this, 'indexDataProvider'];
return $actions;
}

/**
* 首页
*
* @return ActiveDataProvider
*/
public function actionIndex()
{
$modelClass = $this->modelClass;
$query = $modelClass::find()
->where(['status' => StatusEnum::ENABLED, 'member_id' => Yii::$app->user->identity->user_id])
->offset($this->_offset)
->limit($this->_limit)
->asArray()
->all();

return $query;
}

/**
* 创建
*
* @return bool
*/
public function actionCreate()
{
$model = new $this->modelClass();
$model->attributes = Yii::$app->request->post();
$model->member_id = Yii::$app->user->identity->user_id;
if (!$model->save())
{
// 返回数据验证失败
return $this->setResponse($this->analysisError($model->getFirstErrors()));
}

return $model;
}

/**
* 更新
*
* @param $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
$model->attributes = Yii::$app->request->post();
if (!$model->save())
{
// 返回数据验证失败
return $this->setResponse($this->analysisError($model->getFirstErrors()));
}

return $model;
}

/**
* 删除
*
* @param $id
* @return mixed
*/
public function actionDelete($id)
{
$model = $this->findModel($id);
$model->status = StatusEnum::DELETE;
return $model->save();
}

/**
* 显示单个
*
* @param $id
* @return mixed
*/
public function actionView($id)
{
return $this->findModel($id);
}

/**
* 返回模型
*
* @param $id
* @return mixed
* @throws NotFoundHttpException
*/
protected function findModel($id)
{
if (empty($id))
{
throw new NotFoundHttpException('请求的数据不存在.');
}

$modelClass = $this->modelClass;
if ($model = $modelClass::find()->where(['id' => $id, 'status' => StatusEnum::ENABLED, 'member_id' => Yii::$app->user->identity->user_id])->one())
{
return $model->loadDefaultValues();
}
else
{
throw new NotFoundHttpException('请求的数据不存在.');
}
}
}
121 changes: 121 additions & 0 deletions api/controllers/RoomController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php
namespace api\controllers;

use Yii;
use yii\data\ActiveDataProvider;
use yii\web\NotFoundHttpException;

/**
* 直播间
*
* Class RoomController
* @package api\controllers
*/
class RoomController extends AController
{
public $modelClass = 'common\models\live\Room';

/**
* 首页
*
* @return ActiveDataProvider
*/
public function actionIndex()
{
$modelClass = $this->modelClass;
$query = $modelClass::find();

return new ActiveDataProvider([
'query' => $query,
]);
}

/**
* 创建
*
* @return bool
*/
public function actionCreate()
{
$model = new $this->modelClass();
$model->member_id = Yii::$app->user->identity->user_id;
$model->attributes = Yii::$app->request->post();

if (!$model->save())
{
// 返回数据验证失败
return $this->setResponse($this->analysisError($model->getFirstErrors()));
}

return $model;
}

/**
* 更新
*
* @param $id
* @return mixed|void
* @throws NotFoundHttpException
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
$model->attributes = Yii::$app->request->post();
if (!$model->save())
{
// 返回数据验证失败
return $this->setResponse($this->analysisError($model->getFirstErrors()));
}

return $model;
}

/**
* 删除
*
* @param $id
* @return mixed
* @throws NotFoundHttpException
*/
public function actionDelete($id)
{
return $this->findModel($id)->delete();
}

/**
* 详情
*
* @param $id
* @return mixed
* @throws NotFoundHttpException
*/
public function actionView($id)
{
return $this->findModel($id);
}

/**
* 返回模型
*
* @param $id
* @return mixed
* @throws NotFoundHttpException
*/
protected function findModel($id)
{
if (empty($id))
{
throw new NotFoundHttpException('请求的数据失败.');
}

$modelClass = $this->modelClass;
if ($model = $modelClass::findOne($id))
{
return $model->loadDefaultValues();
}
else
{
throw new NotFoundHttpException('请求的数据失败.');
}
}
}
3 changes: 2 additions & 1 deletion api/controllers/SiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ public function actionLogin($group = 1)
/**
* 重置令牌
*
* @param string$refresh_token 重置token
* @param $refresh_token
* @return array
* @throws NotFoundHttpException
* @throws \yii\base\Exception
*/
public function actionRefresh($refresh_token)
{
Expand Down
10 changes: 10 additions & 0 deletions backend/controllers/TestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ public function actionUploadImg()
]);
}

/**
* @return string
*/
public function actionWebsocket()
{
return $this->render('websocket', [

]);
}

/**
* 上传文件测试
*
Expand Down
2 changes: 1 addition & 1 deletion backend/controllers/UeditorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class UeditorController extends \crazydb\ueditor\UEditorController
{
public $config = [
//server config @see http://fex-team.github.io/ueditor/#server-config
// server config @see http://fex-team.github.io/ueditor/#server-config
'imagePathFormat' => '/upload/image/{yyyy}/{mm}/{dd}/{time}_{rand:6}',
'scrawlPathFormat' => '/upload/image/{yyyy}/{mm}/{dd}/{time}_{rand:6}',
'snapscreenPathFormat' => '/upload/image/{yyyy}/{mm}{dd}/{time}_{rand:6}',
Expand Down
19 changes: 0 additions & 19 deletions backend/modules/member/controllers/DefaultController.php

This file was deleted.

10 changes: 7 additions & 3 deletions backend/modules/member/controllers/MemberController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public function actionIndex()
/**
* 编辑/新增
*
* @return string|\yii\web\Response
* @return string|yii\web\Response
* @throws yii\base\Exception
*/
public function actionEdit()
{
Expand Down Expand Up @@ -92,6 +93,9 @@ public function actionEdit()
*
* @param $id
* @return mixed
* @throws \Exception
* @throws \Throwable
* @throws yii\db\StaleObjectException
*/
public function actionDelete($id)
{
Expand Down Expand Up @@ -131,7 +135,7 @@ public function actionPersonal()
* 返回模型
*
* @param $id
* @return Member|static
* @return Member|null|static
*/
protected function findModel($id)
{
Expand All @@ -140,7 +144,7 @@ protected function findModel($id)
return new Member;
}

if (empty(($model = Member::findOne($id))))
if (empty($model = Member::findOne($id)))
{
return new Member;
}
Expand Down
Loading

0 comments on commit 9c10e41

Please sign in to comment.