Completed
Push — master ( a107f0...697b33 )
by graychen
12:14 queued 03:42
created

CreateAction::run()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 11
nc 3
nop 0
1
<?php
2
namespace graychen\yii2\jd\deposit\actions;
3
4
use graychen\yii2\jd\deposit\models\OrderDeposit;
5
use Yii;
6
7
class CreateAction extends JdVerifyAction
8
{
9
    public function run()
10
    {
11
        $model = new OrderDeposit();
12
        $data = json_decode(base64_decode(Yii::$app->request->getBodyParam('data')), true);
13
        $model->equipment = $data['gameArea']['name'] ?? '无';
14
        $model->serverinfo = $data['gameServer']['name'] ?? '无';
15
        $model->raw = json_encode($data);
16
        if ($model->load($data, '') && $model->validate() && $model->save()) {
17
            Yii::$app->response->setStatusCode(201);
18
        } elseif (!$model->hasErrors()) {
19
            throw new yii\web\ServerErrorHttpException('Failed to create the object for unknown reason.');
20
        }
21
        return $model;
22
    }
23
}
24