Commit c1da6a83 authored by 姚书霞's avatar 姚书霞 🐘

修改数据格式

parent 62bd3c6f
......@@ -6,8 +6,7 @@ use Yii;
use backend\controllers\v1\BaseController;
use backend\helpers\Func;
use yii\data\ActiveDataProvider;
use yii\web\BadRequestHttpException;
use yii\web\ServerErrorHttpException;
use yii\web\HttpException;
class CompanyController extends BaseController
{
......@@ -30,6 +29,8 @@ class CompanyController extends BaseController
* DESCRIPTION:描述,
* IS_DEFAULT:是否默认 1是0否
* "),
* @OA\Response(response = 403,description = "权限错误"),
* @OA\Response(response = 500,description = "系统错误"),
* security={{"Authorization": {}}}
* )
*/
......@@ -64,6 +65,8 @@ class CompanyController extends BaseController
* DESCRIPTION:描述,
* IS_DEFAULT:是否默认 1是0否
* "),
* @OA\Response(response = 403,description = "权限错误"),
* @OA\Response(response = 500,description = "系统错误"),
* security={{"Authorization": {}}}
* )
*/
......@@ -71,8 +74,13 @@ class CompanyController extends BaseController
public function actionCompanyDetail()
{
$guid = Yii::$app->request->getQueryparam('guid');
$model = $this->modelClass::findOne($guid);
return $model;
$result = $this->modelClass::findOne($guid)->toArray();
return new ActiveDataProvider(
[
'models' => $result,
'pagination' =>false
]
);
}
/**
......@@ -95,7 +103,10 @@ class CompanyController extends BaseController
* )
* )
* ),
* @OA\Response(response=201,description="success"),
* @OA\Response(response=201,description="添加成功"),
* @OA\Response(response = 403,description = "权限错误"),
* @OA\Response(response = 422,description = "数据验证未通过"),
* @OA\Response(response = 500,description = "系统错误"),
* security={{"Authorization": {}}}
* )
*/
......@@ -105,17 +116,16 @@ class CompanyController extends BaseController
$model->scenario = 'create';//创建的场景
$other_param = array(
'GUID'=>Func::create_guid(),
'ORG_GUID'=>'100',//Yii::$app->user->identity->ORG_GUID,
'ORG_GUID'=>Yii::$app->user->identity->ORG_GUID,
);
$model->setAttributes($other_param);
$model->setAttributes(Yii::$app->request->getBodyparams());
if ($model->save()) {
Yii::$app->getResponse()->setStatusCode(201);
throw new HttpException(201,'添加成功');
} elseif (!$model->hasErrors()) {
throw new ServerErrorHttpException('Failed to create the object for unknown reason.');
throw new HttpException(500,'添加失败');
}
return $model;
}
/**
......@@ -139,26 +149,29 @@ class CompanyController extends BaseController
* )
* )
* ),
* @OA\Response(response=200,description="success"),
* @OA\Response(response = 200,description = "修改成功"),
* @OA\Response(response = 400,description = "失败的请求"),
* @OA\Response(response = 403,description = "权限错误"),
* @OA\Response(response = 422,description = "数据验证未通过"),
* @OA\Response(response = 500,description = "系统错误"),
* security={{"Authorization": {}}}
* )
*/
public function actionCompanyRevise()
{
$guid = Yii::$app->request->getBodyparam('GUID');
// var_dump($guid);die;
$model = $this->modelClass::findOne($guid);
if(!$model){
throw new BadRequestHttpException('没有找到记录');
throw new HttpException(400,'记录不存在');
}
$model->scenario = 'update';//创建的场景
$model->setAttributes(Yii::$app->request->getBodyparams());
if ($model->save() === false && !$model->hasErrors()) {
throw new ServerErrorHttpException('Failed to update the object for unknown reason.');
throw new HttpException(500,'修改失败');
}
return $model;
throw new HttpException(200,'修改成功');
}
/**
......@@ -177,7 +190,10 @@ class CompanyController extends BaseController
* )
* )
* ),
* @OA\Response(response=204,description="success"),
* @OA\Response(response = 204,description = "删除成功"),
* @OA\Response(response = 400,description = "失败的请求"),
* @OA\Response(response = 403,description = "权限错误"),
* @OA\Response(response = 500,description = "系统错误"),
* security={{"Authorization": {}}}
* )
*/
......@@ -186,13 +202,13 @@ class CompanyController extends BaseController
$guid = Yii::$app->request->getBodyparam('GUID');
$model = $this->modelClass::findOne($guid);
if(!$model){
throw new BadRequestHttpException('没有找到记录');
throw new HttpException(400,'记录不存在');
}else if ($model->delete() === false) {
throw new ServerErrorHttpException('Failed to delete the object for unknown reason.');
throw new HttpException(500,'删除失败');
}
Yii::$app->getResponse()->setStatusCode(204);
return $model;
return null;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment