Commit 4e3f2365fac2d86fd91d0a049934fce7dccf2763
1 parent
200040c1
Exists in
master
common
1. F 调整IP地址换城市的key domain 1. F 授权设备到空序列号的匹配方法改为随机产生,不能按顺序获取一个空绑定的设备记录
Showing
4 changed files
with
209 additions
and
37 deletions
Show diff stats
common/helpers/Utils.php
@@ -8,7 +8,7 @@ use Faker\Provider\Uuid; | @@ -8,7 +8,7 @@ use Faker\Provider\Uuid; | ||
8 | class Utils | 8 | class Utils |
9 | { | 9 | { |
10 | private static $vKey = 'thisisakey0olk2i8suwjshwks'; | 10 | private static $vKey = 'thisisakey0olk2i8suwjshwks'; |
11 | - private static $GDKey = '51125f9275f98d30e78f0d4a11251983'; // 高德IP地址获取归属地 KEY 日配额100000次 | 11 | + private static $GDKey = 'a09624f98c82f573140813d7fa25b805'; // 高德IP地址获取归属地 KEY 日配额100000次 |
12 | 12 | ||
13 | public static function getVKey() | 13 | public static function getVKey() |
14 | { | 14 | { |
console/controllers/TestController.php
@@ -7,6 +7,7 @@ namespace console\controllers; | @@ -7,6 +7,7 @@ namespace console\controllers; | ||
7 | * Time: 11:32 AM | 7 | * Time: 11:32 AM |
8 | */ | 8 | */ |
9 | 9 | ||
10 | +use domain\device\DeviceRepository; | ||
10 | use Yii; | 11 | use Yii; |
11 | use common\exts\Aes; | 12 | use common\exts\Aes; |
12 | use common\exts\RSACrypt; | 13 | use common\exts\RSACrypt; |
@@ -25,6 +26,24 @@ class TestController extends Controller | @@ -25,6 +26,24 @@ class TestController extends Controller | ||
25 | { | 26 | { |
26 | $no = hexdec('000A') + 1; | 27 | $no = hexdec('000A') + 1; |
27 | echo sprintf('%04X', $no); | 28 | echo sprintf('%04X', $no); |
29 | + echo "=================\r\n"; | ||
30 | + $v = "0:998654321:A0"; | ||
31 | + //echo preg_match('/^[0-9a-fA-F:]{12,18}$/', $v); | ||
32 | + | ||
33 | + //echo Utils::macGenerate(); | ||
34 | + | ||
35 | + //echo "\r\n"; | ||
36 | + //echo Utils::coverToMacAddress("aaaddddd"); | ||
37 | + $regex = '/^([0-9a-fA-F]{2})(([:|-]{0,1}[0-9a-fA-F]{2}){5})$/'; | ||
38 | + if (preg_match($regex, $v)) { | ||
39 | + $v = str_replace('-', '',$v); | ||
40 | + $v = str_replace(':','', $v); | ||
41 | + echo Utils::coverToMacAddress($v); | ||
42 | + } | ||
43 | + | ||
44 | + | ||
45 | + | ||
46 | + echo "\r\n"; | ||
28 | } | 47 | } |
29 | 48 | ||
30 | public function actionCheckSign() | 49 | public function actionCheckSign() |
@@ -63,15 +82,37 @@ class TestController extends Controller | @@ -63,15 +82,37 @@ class TestController extends Controller | ||
63 | public function actionDeviceSt() | 82 | public function actionDeviceSt() |
64 | { | 83 | { |
65 | $url = 'http://kingb:8012/app-api/web/reportDeviceVersion'; | 84 | $url = 'http://kingb:8012/app-api/web/reportDeviceVersion'; |
85 | + //$url = 'http://47.107.95.101/app-api/web/reportDeviceVersion'; | ||
66 | $params = [ | 86 | $params = [ |
67 | - 'barcode' => '0001000100010001', | ||
68 | - 'device_id' => 'DEVICE003', | ||
69 | - 'software_version' => 'V1.0.1', | ||
70 | - 'hardware_version' => 'V1.0.2', | ||
71 | - 'timestamp' => 1500000000 | 87 | + 'barcode' => '0002000100010001', |
88 | + 'device_id' => 'DEVICE000000002', | ||
89 | + 'software_version' => 'V1.0.20191001', | ||
90 | + 'hardware_version' => '', | ||
91 | + 'timestamp' => time() | ||
72 | ]; | 92 | ]; |
93 | + $params = json_encode($params); | ||
94 | + | ||
95 | + $data = array( | ||
96 | + '119.120'.'.'.rand(1,255).'.'.rand(1,255), | ||
97 | + '124.174'.'.'.rand(1,255).'.'.rand(1,255), | ||
98 | + '116.249'.'.'.rand(1,255).'.'.rand(1,255), | ||
99 | + '118.125'.'.'.rand(1,255).'.'.rand(1,255), | ||
100 | + '42.175'.'.'.rand(1,255).'.'.rand(1,255), | ||
101 | + '124.162'.'.'.rand(1,255).'.'.rand(1,255), | ||
102 | + '211.167'.'.'.rand(1,255).'.'.rand(1,255), | ||
103 | + '58.206'.'.'.rand(1,255).'.'.rand(1,255), | ||
104 | + '117.24'.'.'.rand(1,255).'.'.rand(1,255), | ||
105 | + '203.93'.'.'.rand(1,255).'.'.rand(1,255), | ||
106 | + ); | ||
107 | + | ||
108 | + $ip = $data[array_rand($data)]; | ||
109 | + $header = [ | ||
110 | + 'CLIENT-IP:'.$ip, | ||
111 | + 'X-FORWARDED-FOR:'.$ip, | ||
112 | + ]; | ||
113 | + $params = '{"barcode":"0002000100010001","device_id":"DGDEVBICEID00BB8", "software_version":"V1.0.1", "hardware_version":"", "timestamp":'.time().'}'; | ||
114 | + $postResult = Http::POST($url, $params,true, $header); | ||
73 | 115 | ||
74 | - $postResult = Http::POST($url, json_encode($params)); | ||
75 | echo $postResult; | 116 | echo $postResult; |
76 | } | 117 | } |
77 | 118 | ||
@@ -80,13 +121,13 @@ class TestController extends Controller | @@ -80,13 +121,13 @@ class TestController extends Controller | ||
80 | //actionCheckAppVersion | 121 | //actionCheckAppVersion |
81 | $url = 'http://47.107.95.101/app-api/web/checkAppVersion'; | 122 | $url = 'http://47.107.95.101/app-api/web/checkAppVersion'; |
82 | $params = [ | 123 | $params = [ |
83 | - 'barcode' => '0001000100010001', | ||
84 | - 'device_id' => 'DEVICE000001', | ||
85 | - 'current_version' => 'V1.0.1', | ||
86 | - 'package_name' => 'V1.0.2安装包', | 124 | + 'barcode' => '0004000100010001', |
125 | + 'device_id' => 'V1.00.20190708', | ||
126 | + 'current_version' => '1', | ||
127 | + 'package_name' => 'com.kingboard.settings', | ||
87 | ]; | 128 | ]; |
88 | - //$params = json_decode($params); | ||
89 | - $params = '{"barcode":"0001000100010001","device_id":"DGDEVBICEID00001","package_name":"com.kingboard.settings","current_version":"1"}'; | 129 | + $params = json_encode($params); |
130 | + //$params = '{"barcode":"0004000100010001","device_id":"DGDEVBICEID00001","package_name":"com.kingboard.settings","current_version":"V1.00.20190708"}'; | ||
90 | 131 | ||
91 | $postResult = Http::POST($url, $params); | 132 | $postResult = Http::POST($url, $params); |
92 | echo $postResult; | 133 | echo $postResult; |
@@ -100,11 +141,11 @@ class TestController extends Controller | @@ -100,11 +141,11 @@ class TestController extends Controller | ||
100 | $params = [ | 141 | $params = [ |
101 | 'barcode' => '0001000100010001', | 142 | 'barcode' => '0001000100010001', |
102 | 'device_id' => 'DGDEVBICEID00001', | 143 | 'device_id' => 'DGDEVBICEID00001', |
103 | - 'software_version' => 'V1.0.1', | ||
104 | - 'hardware_version' => 'V1.0.1', | 144 | + 'software_version' => 'V1.00.1A.20191002', |
145 | + 'hardware_version' => '', | ||
105 | ]; | 146 | ]; |
106 | $params = json_encode($params); | 147 | $params = json_encode($params); |
107 | - $params = '{"barcode":"0001000100010001","device_id":"DEVICEID00001","software_version":"V1.00.1A.20191002","hardware_version":""}'; | 148 | + //$params = '{"barcode":"0001000100010001","device_id":"DEVICEID00001","software_version":"V1.00.1A.20191002","hardware_version":""}'; |
108 | $postResult = Http::POST($url, $params); | 149 | $postResult = Http::POST($url, $params); |
109 | echo $postResult; | 150 | echo $postResult; |
110 | } | 151 | } |
@@ -115,16 +156,19 @@ class TestController extends Controller | @@ -115,16 +156,19 @@ class TestController extends Controller | ||
115 | { | 156 | { |
116 | //actionCheckAppVersion | 157 | //actionCheckAppVersion |
117 | $url = 'http://47.107.95.101/app-api/web/reportOtaUpgradeEvent'; | 158 | $url = 'http://47.107.95.101/app-api/web/reportOtaUpgradeEvent'; |
118 | - //$url = 'http://kingb:8012/app-api/web/reportOtaUpgradeEvent'; | 159 | + $url = 'http://kingb:8012/app-api/web/reportOtaUpgradeEvent'; |
119 | 160 | ||
120 | $params = [ | 161 | $params = [ |
121 | - 'barcode' => '0001000100010001', | ||
122 | - 'device_id' => 'DGDEVBICEID00001', | ||
123 | - 'software_version' => 'V1.0.1', | ||
124 | - 'hardware_version' => 'V1.0.1', | 162 | + "barcode" => '0001000100010001', |
163 | + "device_id" => 'DGDEVBICEID00002', | ||
164 | + "current_version" => 'V1.00.1A.20191022', | ||
165 | + "target_version" => 'V1.00.1A.20191022', | ||
166 | + "status" => 3, | ||
167 | + "error_code" => '', | ||
168 | + "timestamp" => time() | ||
125 | ]; | 169 | ]; |
126 | $params = json_encode($params); | 170 | $params = json_encode($params); |
127 | - $params = '{"barcode":"0001000100010001","device_id":"DEVICEID00001","current_version":"V1.00.1A.20191022", "target_version":"V1.00.1A.20191022","status":5,"timestamp":"1572759793"}'; | 171 | + //$params = '{"barcode":"0001000100010001","device_id":"DGDEVBICEID00002", "current_version":"V1.00.1A.20191022", "target_version":"V1.00.1A.20191023","status":5,"error_code":"", "timestamp":"1572759793"}'; |
128 | $postResult = Http::POST($url, $params); | 172 | $postResult = Http::POST($url, $params); |
129 | echo $postResult; | 173 | echo $postResult; |
130 | } | 174 | } |
@@ -136,14 +180,14 @@ class TestController extends Controller | @@ -136,14 +180,14 @@ class TestController extends Controller | ||
136 | $url = 'http://kingb:8012/app-api/web/reportAppUpgradeEvent'; | 180 | $url = 'http://kingb:8012/app-api/web/reportAppUpgradeEvent'; |
137 | 181 | ||
138 | $params = [ | 182 | $params = [ |
139 | - 'barcode' => '0001000100010001', | ||
140 | - 'device_id' => 'DGDEVBICEID00001', | 183 | + 'barcode' => '0001000100010002', |
184 | + 'device_id' => 'DGDEVBICEID00002', | ||
141 | 'current_version' => 'V1.0.1', | 185 | 'current_version' => 'V1.0.1', |
142 | 'target_version' => 'V1.0.1', | 186 | 'target_version' => 'V1.0.1', |
143 | 'package_name' => 'com.app.king.dd', | 187 | 'package_name' => 'com.app.king.dd', |
144 | - "status" => 0, | 188 | + "status" => 5, |
145 | "error_code" => '', | 189 | "error_code" => '', |
146 | - "timestamp" => 1572767677 | 190 | + "timestamp" => time() |
147 | 191 | ||
148 | ]; | 192 | ]; |
149 | $params = json_encode($params); | 193 | $params = json_encode($params); |
@@ -176,20 +220,19 @@ class TestController extends Controller | @@ -176,20 +220,19 @@ class TestController extends Controller | ||
176 | } | 220 | } |
177 | 221 | ||
178 | /** | 222 | /** |
179 | - * | 223 | + * 授权设备,加密过 |
180 | */ | 224 | */ |
181 | public function actionAuthDevice() | 225 | public function actionAuthDevice() |
182 | { | 226 | { |
183 | $url = 'http://kingb:8012/app-api/web/authDevice'; | 227 | $url = 'http://kingb:8012/app-api/web/authDevice'; |
184 | $url = 'http://47.107.95.101/app-api/web/authDevice'; | 228 | $url = 'http://47.107.95.101/app-api/web/authDevice'; |
185 | - $manufactureNo = '0001'; | ||
186 | - $device_id = 'DEVICE00000B'; | 229 | + $manufactureNo = '000E'; |
230 | + $device_id = 'HDEVICEG0000001'; | ||
187 | $projectNo = '0001'; | 231 | $projectNo = '0001'; |
188 | - $modelNo = '0001'; | ||
189 | - $productionNo = '0001'; | 232 | + $modelNo = '000B'; |
233 | + $productionNo = '0010'; | ||
190 | $timestamp = time(); | 234 | $timestamp = time(); |
191 | 235 | ||
192 | - | ||
193 | $randKey = Utils::rand(16); | 236 | $randKey = Utils::rand(16); |
194 | $salt = "13456"; | 237 | $salt = "13456"; |
195 | $sign = md5($manufactureNo. $projectNo. $modelNo . $productionNo . $timestamp .$device_id. $salt); | 238 | $sign = md5($manufactureNo. $projectNo. $modelNo . $productionNo . $timestamp .$device_id. $salt); |
@@ -213,6 +256,7 @@ class TestController extends Controller | @@ -213,6 +256,7 @@ class TestController extends Controller | ||
213 | 'content' => $aes->encrypt($deviceParams) | 256 | 'content' => $aes->encrypt($deviceParams) |
214 | ]; | 257 | ]; |
215 | $params = json_encode($params); | 258 | $params = json_encode($params); |
259 | + | ||
216 | $postResult = Http::POST($url, $params); | 260 | $postResult = Http::POST($url, $params); |
217 | 261 | ||
218 | $postResult = json_decode($postResult, true); | 262 | $postResult = json_decode($postResult, true); |
@@ -222,12 +266,40 @@ class TestController extends Controller | @@ -222,12 +266,40 @@ class TestController extends Controller | ||
222 | } | 266 | } |
223 | 267 | ||
224 | 268 | ||
269 | + public function actionAuthDeviceN() | ||
270 | + { | ||
271 | + $url = 'http://kingb:8012/app-api/web/authDeviceN'; | ||
272 | + //$url = 'http://47.107.95.101/app-api/web/authDeviceN'; | ||
273 | + $manufactureNo = '0001'; | ||
274 | + $device_id = 'BDEVICEG0000006'; | ||
275 | + $projectNo = '0001'; | ||
276 | + $modelNo = '0001'; | ||
277 | + $productionNo = '0002'; | ||
278 | + $timestamp = time(); | ||
279 | + | ||
280 | + $salt = "13456"; | ||
281 | + $sign = md5($manufactureNo. $projectNo. $modelNo . $productionNo . $timestamp .$device_id. $salt); | ||
282 | + $deviceParams = [ | ||
283 | + 'manufacture' => $manufactureNo, | ||
284 | + 'device_id' => $device_id, | ||
285 | + 'project' => $projectNo, | ||
286 | + 'model' => $modelNo, | ||
287 | + 'production' => $productionNo, | ||
288 | + 'timestamp' => $timestamp, | ||
289 | + 'sign' => $sign, | ||
290 | + ]; | ||
291 | + $deviceParams = json_encode($deviceParams); | ||
292 | + $postResult = Http::POST($url, $deviceParams); | ||
293 | + | ||
294 | + echo $postResult; | ||
295 | + } | ||
296 | + | ||
225 | public function actionA() | 297 | public function actionA() |
226 | { | 298 | { |
227 | $str = "87654321"; | 299 | $str = "87654321"; |
228 | $rsaKeys = Yii::$app->params['AUTH_DEVICE_RSA_PKCS_1']; | 300 | $rsaKeys = Yii::$app->params['AUTH_DEVICE_RSA_PKCS_1']; |
229 | $rsa = new RSACrypt($rsaKeys['PRIVATE'], $rsaKeys['PUBLIC']); | 301 | $rsa = new RSACrypt($rsaKeys['PRIVATE'], $rsaKeys['PUBLIC']); |
230 | - $deStr = "SRAeq\/pjyDA+0TtCTo06cbskERUUXvmGh3FdocS9AFmMsYDN\/TACQeU9pZhB5zKYHsJSTo\/JawuN\nG0ZBFd1B6TvJ\/1PkX30cvL9i03Ujo1JVe1njhMrig3mvNd7RDAylNzaFAAHU\/Wb\/94kf7gRGNyTj\ngj78Oe0bLdwasz4vBFE=\n"; | 302 | + $deStr = "Eu2nx0APQBcicPXuw1r+4vKJCPJ5ln5uzepYXSJ1mfSaymjgdGdXT9s5SxNHXe4cK8ZRO9wK7RxO\/MjSJwOoTDvy7xez+rC96yBDJV3vZ5bv85OtKc8k6R60mfc\/Fasw+dTI1FBKs9BNY2fs6w+67HJqeUD1JenuZSyX4ryWM44="; |
231 | 303 | ||
232 | //echo $deStr."\r\n"; | 304 | //echo $deStr."\r\n"; |
233 | $randKey = $rsa->decrypt($deStr); | 305 | $randKey = $rsa->decrypt($deStr); |
@@ -235,9 +307,95 @@ echo $randKey."\r\n"; | @@ -235,9 +307,95 @@ echo $randKey."\r\n"; | ||
235 | $randKey = substr(md5($randKey.'12356'), 8, 16)."\r\n"; | 307 | $randKey = substr(md5($randKey.'12356'), 8, 16)."\r\n"; |
236 | echo $randKey."\r\n"; | 308 | echo $randKey."\r\n"; |
237 | $aes = new Aes($randKey); | 309 | $aes = new Aes($randKey); |
238 | - echo $aes->decrypt("nZ8U4BlG0vxckrPM0lquvGDZ9Yuv32+MbYKZG8cqfMGJcltEEquc9v88bzpzm2dpkX5nR4ugLxfw\nc65yqYouozxyX+UdXPNHqaOYIQK\/MVWi+GkYsEafezJhozyGrLWAo7hHIdYcV\/fnm7xyEAaN\/91Q\nWdrhYmGvMf1IusGPBDaRnZtJ+mR1MhElZP73mQppFlusI8EJVFcEx\/z\/SkE9ywhPqAsK721xV+Fe\ncd7sNKs=\n"); | 310 | + echo $aes->decrypt("1nnp92dtMfxUSvmZHQPeWp4smz0DzVzp4ZDJHdR1R1Dt8KvPYZ2WC6TEc+ACbwOxCtop6gBIn1DNNNL5cVw3nU8kl4yRXIsMojciK064rekOCVmRln3Z2NHn6SThmcLcwthxwHt0rlXVdeWecvhpXve1QPk0eD1qEfGsP2B3D4X9iUlZ6JZndM3og7XpukrawtPWazIVaBqlfa4ugfD86mAHlD+RYl+ZW2QpDGVGPXk="); |
311 | + | ||
312 | + } | ||
313 | + | ||
314 | + /** | ||
315 | + * 批量产生授权数据 | ||
316 | + */ | ||
317 | + public function actionPGTest() | ||
318 | + { | ||
319 | + $url = 'http://47.107.95.101/app-api/web/authDevice'; | ||
320 | + $manufactureNo = '000E'; | ||
321 | + | ||
322 | + $projectNo = '0001'; | ||
323 | + $modelNo = '000B'; | ||
324 | + $productionNo = '0010'; | ||
239 | 325 | ||
326 | + $salt = "13456"; | ||
327 | + $rsaKeys = Yii::$app->params['AUTH_DEVICE_RSA_PKCS_1']; | ||
328 | + $rsa = new RSACrypt($rsaKeys['PRIVATE'], $rsaKeys['PUBLIC']); | ||
329 | + for($i = 1; $i < 5000; $i++) { | ||
330 | + $device_id = 'HDEVICEG000000'.sprintf('%04X',$i); | ||
331 | + $timestamp = time(); | ||
332 | + $randKey = Utils::rand(16); | ||
333 | + | ||
334 | + $sign = md5($manufactureNo. $projectNo. $modelNo . $productionNo . $timestamp .$device_id. $salt); | ||
335 | + $deviceParams = [ | ||
336 | + 'manufacture' => $manufactureNo, | ||
337 | + 'device_id' => $device_id, | ||
338 | + 'project' => $projectNo, | ||
339 | + 'model' => $modelNo, | ||
340 | + 'production' => $productionNo, | ||
341 | + 'timestamp' => $timestamp, | ||
342 | + 'sign' => $sign, | ||
343 | + ]; | ||
344 | + $deviceParams = json_encode($deviceParams); | ||
345 | + $randomKey = $rsa->encrypt($randKey); | ||
346 | + $aes = new Aes(substr(md5($randKey.'12356'), 8, 16)); | ||
347 | + $params = [ | ||
348 | + 'randomKey' => $randomKey, | ||
349 | + 'content' => $aes->encrypt($deviceParams) | ||
350 | + ]; | ||
351 | + $params = json_encode($params); | ||
352 | + //echo $url." POST ".$params."\r\n"; | ||
353 | + $postResult = Http::POST($url, $params); | ||
354 | + | ||
355 | + $postResult = json_decode($postResult, true); | ||
356 | + $decodeJson = $aes->decrypt($postResult['content']); | ||
357 | + echo $decodeJson."\r\n"; | ||
358 | + } | ||
240 | } | 359 | } |
241 | 360 | ||
361 | + /** | ||
362 | + * 批量产生不加密的设备授权数据 | ||
363 | + */ | ||
364 | + public function actionPgnTest() | ||
365 | + { | ||
366 | + $url = 'http://47.107.95.101/app-api/web/authDeviceN'; | ||
367 | + $manufactureNo = '000E'; | ||
368 | + $projectNo = '0001'; | ||
369 | + $modelNo = '000B'; | ||
370 | + $productionNo = '0010'; | ||
371 | + for($i = 1; $i < 3; $i++) { | ||
372 | + $device_id = 'ADEVICEG000000'.sprintf('%04X',$i); | ||
373 | + $timestamp = time(); | ||
374 | + $salt = "13456"; | ||
375 | + $sign = md5($manufactureNo. $projectNo. $modelNo . $productionNo . $timestamp .$device_id. $salt); | ||
376 | + $deviceParams = [ | ||
377 | + 'manufacture' => $manufactureNo, | ||
378 | + 'device_id' => $device_id, | ||
379 | + 'project' => $projectNo, | ||
380 | + 'model' => $modelNo, | ||
381 | + 'production' => $productionNo, | ||
382 | + 'timestamp' => $timestamp, | ||
383 | + 'sign' => $sign, | ||
384 | + ]; | ||
385 | + $deviceParams = json_encode($deviceParams); | ||
386 | + echo $url." POST ". $deviceParams."\r\n"; | ||
387 | + } | ||
388 | + | ||
389 | + } | ||
390 | + public function actionB() | ||
391 | + { | ||
392 | + | ||
393 | + $deviceModel = DeviceRepository::findBatchRandOne(2); | ||
394 | + if ($deviceModel) { | ||
395 | + echo $deviceModel->id; | ||
396 | + $deviceModel->device_id = '000000000012'; | ||
397 | + $deviceModel->save(); | ||
398 | + } | ||
399 | + } | ||
242 | } | 400 | } |
243 | 401 |
domain/device/Device.php
@@ -217,8 +217,8 @@ class Device | @@ -217,8 +217,8 @@ class Device | ||
217 | $e->mac = ''; | 217 | $e->mac = ''; |
218 | $e->status = 0; | 218 | $e->status = 0; |
219 | $tt = time(); | 219 | $tt = time(); |
220 | - // 找到未空白未绑定的设备序列号 | ||
221 | - $newDeviceModel = DeviceRepository::findOne(['device_id' => null,'batch_id' => $batchId, 'is_delete' => 0, 'status' => DeviceStatus::NO_AUTH]); | 220 | + // 找到未空白未绑定的设备序列号, 必须随机找出对应的序列号,否则多个并发的时候一直都出错 |
221 | + $newDeviceModel = DeviceRepository::findBatchRandOne($batchId); | ||
222 | 222 | ||
223 | if (empty($newDeviceModel)) { | 223 | if (empty($newDeviceModel)) { |
224 | $e->status = 8; | 224 | $e->status = 8; |
domain/device/DeviceRepository.php
@@ -9,7 +9,7 @@ use domain\device\models\DeviceStats; | @@ -9,7 +9,7 @@ use domain\device\models\DeviceStats; | ||
9 | 9 | ||
10 | class DeviceRepository | 10 | class DeviceRepository |
11 | { | 11 | { |
12 | - const DEBUG = true; | 12 | + const DEBUG = false; |
13 | private static function myLog($str) | 13 | private static function myLog($str) |
14 | { | 14 | { |
15 | if (false == self::DEBUG) { | 15 | if (false == self::DEBUG) { |
@@ -153,4 +153,18 @@ class DeviceRepository | @@ -153,4 +153,18 @@ class DeviceRepository | ||
153 | 153 | ||
154 | return false; | 154 | return false; |
155 | } | 155 | } |
156 | + | ||
157 | + /** | ||
158 | + * @param $batchId | ||
159 | + * @return array|null|\yii\db\ActiveRecord | ||
160 | + */ | ||
161 | + static function findBatchRandOne($batchId) | ||
162 | + { | ||
163 | + $deviceFind = DeviceModel::find(); | ||
164 | + $deviceFind->where(['device_id' => null,'batch_id' => $batchId, 'is_delete' => 0, 'status' => DeviceStatus::NO_AUTH]); | ||
165 | + $deviceFind->orderBy("rand()"); | ||
166 | + $nullDevice = $deviceFind->one(); | ||
167 | + | ||
168 | + return $nullDevice; | ||
169 | + } | ||
156 | } | 170 | } |
157 | \ No newline at end of file | 171 | \ No newline at end of file |