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(), |
|
|
|
|
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), |
|
|
|
|
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."×tamp=".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
|
|
|
|
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.