DepositController::actionIndex()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
namespace backend\controllers;
4
5
use Yii;
6
use common\models\OrderDeposit;
7
use common\models\Order;
8
use yii\web\Controller;
9
use yii\web\NotFoundHttpException;
10
use yii\filters\VerbFilter;
11
use backend\models\SearchDeposit;
12
use GuzzleHttp\Client;
13
14
/**
15
 * OrderController implements the CRUD actions for Order model.
16
 */
17
class DepositController extends Controller
18
{
19
    /**
20
     * @inheritdoc
21
     */
22
    public function behaviors()
23
    {
24
        return [
25
            'verbs' => [
26
                'class' => VerbFilter::className(),
0 ignored issues
show
Deprecated Code introduced by
The method yii\base\BaseObject::className() has been deprecated with message: since 2.0.14. On PHP >=5.5, use `::class` instead.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
27
                'actions' => [
28
                    'delete' => ['POST'],
29
                ],
30
            ],
31
        ];
32
    }
33
34
    public function actionGame()
35
    {
36
        $params = Yii::$app->request->getBodyParams();
37
        $client = new Client();
38
        $data = base64_encode(json_encode(['orderId' =>$params['orderId'],'orderStatus'=>$params['orderStatus']]));
39
        $allData = [
40
            'customerId' => getenv('JINDONG_API_CUSTOMERID'),
41
            'timestamp'=>date("YmdHis"),
42
            'sign'=>$this->createSign($data),
0 ignored issues
show
Documentation introduced by
$data is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
43
            'data'=>$data
44
        ];
45
        $res = $client->request('POST', 'http://card.jd.com/api/gameApi.action', $allData);
46
        $body=$res->getBody();
47
        $arrBody=json_decode($body, true);
48
        if ($arrBody['retCode']==100) {
49
            $orderDeposit=OrderDeposit::find()->where(['sn'=>'JD'.$params['orderId']])->one();
50
            $orderDeposit->status=$params['orderStatus'];
51
            $orderDeposit->save();
52
        }
53
        return $body;
54
    }
55
56
    /**
57
     * 生成签名验证串sign
58
     * @param array $params post或get请求的请求参数数组
59
     * @return string sign签名验证串
60
     */
61
    public function createSign($params)
62
    {
63
        $data = $params;
64
        $signStr="customerId=".getenv('JINDONG_API_CUSTOMERID')."&data=".$data."&timestamp=".date("YmdHis")."&".getenv('JINDONG_API_PRIVATEKEY');
65
        $sign = md5($signStr);
66
        return $sign;
67
    }
68
69
    /**
70
     * Lists all Order models.
71
     * @return mixed
72
     */
73
    public function actionIndex()
74
    {
75
        $searchModel = new SearchDeposit();
76
        $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
77
        $total=Order::getOrderTotal();
78
79
        return $this->render('index', [
80
            'searchModel' => $searchModel,
81
            'dataProvider' => $dataProvider,
82
            'total'=>$total
83
        ]);
84
    }
85
86
    /**
87
     * Displays a single Order model.
88
     * @param integer $id
89
     * @return mixed
90
     */
91
    public function actionView($id)
92
    {
93
        return $this->render('view', [
94
            'model' => $this->findModel($id),
95
        ]);
96
    }
97
98
    /**
99
     * Deletes an existing Order model.
100
     * If deletion is successful, the browser will be redirected to the 'index' page.
101
     * @param integer $id
102
     * @return mixed
103
     */
104
    public function actionDelete($id)
105
    {
106
        $this->findModel($id)->delete();
107
108
        return $this->redirect(['index']);
109
    }
110
111
    /**
112
     * Finds the Order model based on its primary key value.
113
     * If the model is not found, a 404 HTTP exception will be thrown.
114
     * @param integer $id
115
     * @return Order the loaded model
116
     * @throws NotFoundHttpException if the model cannot be found
117
     */
118
    protected function findModel($id)
119
    {
120
        if (($model = Order::findOne($id)) !== null) {
121
            return $model;
122
        } else {
123
            throw new NotFoundHttpException('The requested page does not exist.');
124
        }
125
    }
126
}
127