-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jianyan74
committed
Mar 7, 2018
1 parent
41e3da5
commit 9c10e41
Showing
102 changed files
with
1,021 additions
and
824 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('请求的数据不存在.'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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('请求的数据失败.'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.