Commit e5a695f11bd72ae017aec6e0749b0e81a76dd619
1 parent
d1ded260
Exists in
master
1. F 授权接口返回码调整
2. F 序列号生成数量不能填小于等于0的数
Showing
5 changed files
with
46 additions
and
40 deletions
Show diff stats
app-api/controllers/AuthDeviceController.php
@@ -52,8 +52,8 @@ class AuthDeviceController extends BaseController | @@ -52,8 +52,8 @@ class AuthDeviceController extends BaseController | ||
52 | $getPostData = file_get_contents('php://input', 'r'); | 52 | $getPostData = file_get_contents('php://input', 'r'); |
53 | self::myLog('actionIndex postData:'.$getPostData); | 53 | self::myLog('actionIndex postData:'.$getPostData); |
54 | if (!$getPostData) { | 54 | if (!$getPostData) { |
55 | - $e->status = 2; | ||
56 | - $e->message = '数据为空'; | 55 | + $e->status = 1; |
56 | + $e->message = '传入的数据为空'; | ||
57 | return $e; | 57 | return $e; |
58 | } | 58 | } |
59 | $getPostData = json_decode($getPostData, true); | 59 | $getPostData = json_decode($getPostData, true); |
@@ -68,26 +68,20 @@ class AuthDeviceController extends BaseController | @@ -68,26 +68,20 @@ class AuthDeviceController extends BaseController | ||
68 | $salt = self::SIGN_SALT; | 68 | $salt = self::SIGN_SALT; |
69 | $makeSign = md5($manufactureNo . $projectNo. $modelNo . $productionNo . $timestamp . $deviceId. $salt); | 69 | $makeSign = md5($manufactureNo . $projectNo. $modelNo . $productionNo . $timestamp . $deviceId. $salt); |
70 | if ($sign != $makeSign) { | 70 | if ($sign != $makeSign) { |
71 | - $e->status = 3; | ||
72 | - $e->message = '签名有误'; | 71 | + $e->status = 2; |
72 | + $e->message = '签名出错'; | ||
73 | return $e; | 73 | return $e; |
74 | } | 74 | } |
75 | 75 | ||
76 | $authResult = Device::authDevice($deviceId, $manufactureNo, $projectNo, $modelNo, $productionNo); | 76 | $authResult = Device::authDevice($deviceId, $manufactureNo, $projectNo, $modelNo, $productionNo); |
77 | 77 | ||
78 | + $e->status = $authResult->status; | ||
79 | + $e->message = $authResult->message; | ||
78 | if ($authResult->success) { | 80 | if ($authResult->success) { |
79 | $e->mac = $authResult->mac; | 81 | $e->mac = $authResult->mac; |
80 | $e->serial_no = $authResult->serial_no; | 82 | $e->serial_no = $authResult->serial_no; |
81 | - $e->message = $authResult->message; | ||
82 | - $e->status = 0; | ||
83 | - } else { | ||
84 | - $e->status = 4; | ||
85 | - $e->message = $authResult->message; | ||
86 | } | 83 | } |
87 | - if ($authResult->status > 0) { | ||
88 | - $e->status = $authResult->status; | ||
89 | - } | ||
90 | - | 84 | + |
91 | return $e; | 85 | return $e; |
92 | } | 86 | } |
93 | } | 87 | } |
94 | \ No newline at end of file | 88 | \ No newline at end of file |
app-ht/modules/device/controllers/DeviceController.php
@@ -260,11 +260,15 @@ class DeviceController extends BaseController | @@ -260,11 +260,15 @@ class DeviceController extends BaseController | ||
260 | $e->success = false; | 260 | $e->success = false; |
261 | $e->message = 'fail'; | 261 | $e->message = 'fail'; |
262 | if (empty($num)) { | 262 | if (empty($num)) { |
263 | - $e->message = '数量不能为0'; | 263 | + $e->message = '数量不能为空'; |
264 | return $this->renderJson($e); | 264 | return $this->renderJson($e); |
265 | } | 265 | } |
266 | - if (1 * $num > 30000) { | ||
267 | - $e->message = '数量不能超过3万'; | 266 | + if ($num *1 <= 0) { |
267 | + $e->message = '数量不能小于等于0'; | ||
268 | + return $this->renderJson($e); | ||
269 | + } | ||
270 | + if (1 * $num > 10000) { | ||
271 | + $e->message = '数量不能超过1万'; | ||
268 | return $this->renderJson($e); | 272 | return $this->renderJson($e); |
269 | } | 273 | } |
270 | 274 |
app-ht/modules/device/views/device/createDevice.php
@@ -263,6 +263,10 @@ $(function() { | @@ -263,6 +263,10 @@ $(function() { | ||
263 | alert('请录入数量'); | 263 | alert('请录入数量'); |
264 | return false; | 264 | return false; |
265 | } | 265 | } |
266 | + if (append_num *1 <=0) { | ||
267 | + alert('请录入大于0的数量'); | ||
268 | + return false; | ||
269 | + } | ||
266 | if (append_num*1 > 3000) { | 270 | if (append_num*1 > 3000) { |
267 | alert('追加数量不要超过3000'); | 271 | alert('追加数量不要超过3000'); |
268 | return false; | 272 | return false; |
console/controllers/TestController.php
@@ -34,13 +34,13 @@ class TestController extends Controller | @@ -34,13 +34,13 @@ class TestController extends Controller | ||
34 | 34 | ||
35 | public function actionDeviceAuth() | 35 | public function actionDeviceAuth() |
36 | { | 36 | { |
37 | - $url = 'http://kingb:8012/app-api/web/authDevice'; | ||
38 | - //$url = 'http://47.107.95.101/app-api/web/authDevice'; | 37 | + //$url = 'http://kingb:8012/app-api/web/authDevice'; |
38 | + $url = 'http://47.107.95.101/app-api/web/authDevice'; | ||
39 | $manufactureNo = '0003'; | 39 | $manufactureNo = '0003'; |
40 | - $device_id = 'HZ5DEVICE00007'; | 40 | + $device_id = '000000010108'; |
41 | $projectNo = '0003'; | 41 | $projectNo = '0003'; |
42 | - $modelNo = '0003'; | ||
43 | - $productionNo = '0003'; | 42 | + $modelNo = '0002'; |
43 | + $productionNo = '0004'; | ||
44 | $timestamp = time(); | 44 | $timestamp = time(); |
45 | $salt = 13456; | 45 | $salt = 13456; |
46 | $sign = md5($manufactureNo. $projectNo. $modelNo . $productionNo . $timestamp .$device_id. $salt); | 46 | $sign = md5($manufactureNo. $projectNo. $modelNo . $productionNo . $timestamp .$device_id. $salt); |
domain/device/Device.php
@@ -119,6 +119,7 @@ class Device | @@ -119,6 +119,7 @@ class Device | ||
119 | $batchModel = CreateBatchRepository::findOne(['batch_no' => $batchNo]); | 119 | $batchModel = CreateBatchRepository::findOne(['batch_no' => $batchNo]); |
120 | if (empty($batchModel)) { | 120 | if (empty($batchModel)) { |
121 | $e->message = '没有该批次'; | 121 | $e->message = '没有该批次'; |
122 | + $e->status = 3; | ||
122 | $item = [ | 123 | $item = [ |
123 | 'manufacture_no' => $manufactureNo, | 124 | 'manufacture_no' => $manufactureNo, |
124 | 'project_no' => $projectNo, | 125 | 'project_no' => $projectNo, |
@@ -136,20 +137,23 @@ class Device | @@ -136,20 +137,23 @@ class Device | ||
136 | if (DeviceStatus::HAS_AUTH == $deviceModel->status) { | 137 | if (DeviceStatus::HAS_AUTH == $deviceModel->status) { |
137 | $e->mac = $deviceModel->mac; | 138 | $e->mac = $deviceModel->mac; |
138 | $e->serial_no = $deviceModel->serial_no; | 139 | $e->serial_no = $deviceModel->serial_no; |
139 | - $e->message = '授权成功'; | 140 | + $e->message = '授权成功, 重复授权'; |
140 | $e->success = true; | 141 | $e->success = true; |
141 | - $e->status = 5; | ||
142 | - } elseif(DeviceStatus::NO_AUTH == $deviceModel->status) { | 142 | + $e->status = 4; |
143 | + } else{ | ||
143 | $deviceModel->status = DeviceStatus::HAS_AUTH; | 144 | $deviceModel->status = DeviceStatus::HAS_AUTH; |
144 | $deviceModel->auth_at = time(); | 145 | $deviceModel->auth_at = time(); |
145 | - $deviceModel->save(); | ||
146 | - $e->mac = $deviceModel->mac; | ||
147 | - $e->serial_no = $deviceModel->serial_no; | ||
148 | - $e->message = '授权成功'; | ||
149 | - $e->success = true; | ||
150 | - $e->status = 5; | ||
151 | - } else { | ||
152 | - $e->message = '授权失败'; | 146 | + if ($deviceModel->save()){ |
147 | + $e->mac = $deviceModel->mac; | ||
148 | + $e->serial_no = $deviceModel->serial_no; | ||
149 | + $e->message = '授权成功, 重复授权'; | ||
150 | + $e->success = true; | ||
151 | + $e->status = 4; | ||
152 | + } else { | ||
153 | + $e->message = '设备已经存在,授权失败'; | ||
154 | + $e->success = false; | ||
155 | + $e->status = 5; | ||
156 | + } | ||
153 | } | 157 | } |
154 | 158 | ||
155 | return $e; | 159 | return $e; |
@@ -169,8 +173,8 @@ class Device | @@ -169,8 +173,8 @@ class Device | ||
169 | ]; | 173 | ]; |
170 | DeviceAuthFail::create($item); | 174 | DeviceAuthFail::create($item); |
171 | } | 175 | } |
172 | - | ||
173 | - $e->message = '授权失败'; | 176 | + $e->status = 6; |
177 | + $e->message = '授权失败,超过厂商设定的批次数量'; | ||
174 | return $e; | 178 | return $e; |
175 | } | 179 | } |
176 | 180 | ||
@@ -184,15 +188,17 @@ class Device | @@ -184,15 +188,17 @@ class Device | ||
184 | $e->serial_no = $genDeviceModel->serial_no; | 188 | $e->serial_no = $genDeviceModel->serial_no; |
185 | $e->mac = $genDeviceModel->mac; | 189 | $e->mac = $genDeviceModel->mac; |
186 | } else { | 190 | } else { |
191 | + $e->status = 7; | ||
187 | $e->message = '授权失败, 下次重试授权!'; | 192 | $e->message = '授权失败, 下次重试授权!'; |
188 | - $e->success = false; | 193 | + |
189 | } | 194 | } |
190 | return $e; | 195 | return $e; |
191 | } | 196 | } |
192 | // 找到未空白未绑定的设备序列号 | 197 | // 找到未空白未绑定的设备序列号 |
193 | $newDeviceModel = DeviceRepository::findOne(['device_id' => null,'batch_id' => $batchId, 'is_delete' => 0, 'status' => DeviceStatus::NO_AUTH]); | 198 | $newDeviceModel = DeviceRepository::findOne(['device_id' => null,'batch_id' => $batchId, 'is_delete' => 0, 'status' => DeviceStatus::NO_AUTH]); |
194 | if (empty($newDeviceModel)) { | 199 | if (empty($newDeviceModel)) { |
195 | - $e->message = '授权失败,系统参数有误'; | 200 | + $e->status = 8; |
201 | + $e->message = '授权失败,系统异常'; | ||
196 | return $e; | 202 | return $e; |
197 | } | 203 | } |
198 | $newDeviceModel->device_id = $deviceId; | 204 | $newDeviceModel->device_id = $deviceId; |
@@ -205,12 +211,10 @@ class Device | @@ -205,12 +211,10 @@ class Device | ||
205 | $e->serial_no = $newDeviceModel->serial_no; | 211 | $e->serial_no = $newDeviceModel->serial_no; |
206 | $e->mac = $newDeviceModel->mac; | 212 | $e->mac = $newDeviceModel->mac; |
207 | } else { | 213 | } else { |
208 | - $e->message = '授权失败'; | ||
209 | - $e->status = 9; //系统异常 | ||
210 | - $e->success = true; | 214 | + $e->message = '授权失败,系统异常'; |
215 | + $e->status = 8; //系统异常 | ||
211 | } | 216 | } |
212 | 217 | ||
213 | - | ||
214 | return $e; | 218 | return $e; |
215 | } | 219 | } |
216 | 220 |