Commit f656f33b044f285fea57eab9892750d3b292e1ac

Authored by xu
1 parent 37a28dcc
Exists in master

1. F 上报app 升级记录里面添加一个 package_name 的字段

2. F 后台恢复删除的设备,从失败那里授权的设备逻辑要重新调整
app-api/controllers/UpgradeController.php
@@ -390,11 +390,13 @@ class UpgradeController extends BaseController @@ -390,11 +390,13 @@ class UpgradeController extends BaseController
390 $deviceId = isset($getPostData['device_id'])? $getPostData['device_id']: ''; 390 $deviceId = isset($getPostData['device_id'])? $getPostData['device_id']: '';
391 $currentVersion = isset($getPostData['current_version'])? $getPostData['current_version']: ''; 391 $currentVersion = isset($getPostData['current_version'])? $getPostData['current_version']: '';
392 $targetVersion = isset($getPostData['target_version'])? $getPostData['target_version']: ''; 392 $targetVersion = isset($getPostData['target_version'])? $getPostData['target_version']: '';
  393 + $packageName = isset($getPostData['package_name'])? $getPostData['package_name']: '';
  394 +
393 $status = isset($getPostData['status'])? $getPostData['status']: ''; 395 $status = isset($getPostData['status'])? $getPostData['status']: '';
394 $errorCode = isset($getPostData['error_code'])? $getPostData['error_code']: ''; 396 $errorCode = isset($getPostData['error_code'])? $getPostData['error_code']: '';
395 $timestamp = isset($getPostData['timestamp'])? $getPostData['timestamp']: ''; 397 $timestamp = isset($getPostData['timestamp'])? $getPostData['timestamp']: '';
396 398
397 - if (empty($barcode) || empty($currentVersion) || empty($targetVersion) || empty($timestamp)) { 399 + if (empty($barcode) || empty($currentVersion) || empty($targetVersion) || empty($timestamp) || empty($packageName)) {
398 $e->status = 2; 400 $e->status = 2;
399 $e->message = '部分数据为空'; 401 $e->message = '部分数据为空';
400 return $e; 402 return $e;
@@ -412,7 +414,7 @@ class UpgradeController extends BaseController @@ -412,7 +414,7 @@ class UpgradeController extends BaseController
412 $e->message = 'barcode格式有误'; 414 $e->message = 'barcode格式有误';
413 return $e; 415 return $e;
414 } 416 }
415 - $upgradeLogModel = UpgradeLogRepository::findOne(['device_id' => $deviceId, 'current_version' => $currentVersion, 'target_version' => $targetVersion, 'status' => $status, 'type' => UpgradeStatus::TYPE_APP]); 417 + $upgradeLogModel = UpgradeLogRepository::findOne(['device_id' => $deviceId, 'package_name' => $packageName ,'current_version' => $currentVersion, 'target_version' => $targetVersion, 'status' => $status, 'type' => UpgradeStatus::TYPE_APP]);
416 if ($upgradeLogModel) { 418 if ($upgradeLogModel) {
417 $upgradeLogModel->timestamp = $timestamp; 419 $upgradeLogModel->timestamp = $timestamp;
418 $upgradeLogModel->save(); 420 $upgradeLogModel->save();
@@ -442,6 +444,7 @@ class UpgradeController extends BaseController @@ -442,6 +444,7 @@ class UpgradeController extends BaseController
442 "project_id" => $projectId, 444 "project_id" => $projectId,
443 "model_id" => $modelId, 445 "model_id" => $modelId,
444 "current_version" => $currentVersion, 446 "current_version" => $currentVersion,
  447 + "package_name" => $packageName,
445 "target_version" => $targetVersion, 448 "target_version" => $targetVersion,
446 "status" => $status, 449 "status" => $status,
447 "error_code" => $errorCode, 450 "error_code" => $errorCode,
app-ht/modules/datas/controllers/UpgradeLogController.php
@@ -43,6 +43,7 @@ class UpgradeLogController extends BaseController @@ -43,6 +43,7 @@ class UpgradeLogController extends BaseController
43 $barcode = $request->get('barcode'); 43 $barcode = $request->get('barcode');
44 $error_code = $request->get('error_code'); 44 $error_code = $request->get('error_code');
45 $device_device_id = $request->get('device_device_id'); 45 $device_device_id = $request->get('device_device_id');
  46 + $package_name = $request->get('package_name');
46 $dataType = !empty($request->get('type')) ? $request->get('type') : UpgradeStatus::TYPE_APP; 47 $dataType = !empty($request->get('type')) ? $request->get('type') : UpgradeStatus::TYPE_APP;
47 48
48 $gets = [ 49 $gets = [
@@ -56,6 +57,7 @@ class UpgradeLogController extends BaseController @@ -56,6 +57,7 @@ class UpgradeLogController extends BaseController
56 'barcode' => $barcode, 57 'barcode' => $barcode,
57 'error_code' => $error_code, 58 'error_code' => $error_code,
58 'device_device_id' => $device_device_id, 59 'device_device_id' => $device_device_id,
  60 + 'package_name' => $package_name,
59 'type' => $dataType, 61 'type' => $dataType,
60 ]; 62 ];
61 63
@@ -71,6 +73,9 @@ class UpgradeLogController extends BaseController @@ -71,6 +73,9 @@ class UpgradeLogController extends BaseController
71 if ($status) { 73 if ($status) {
72 $where[] = ['=', 'ul.status', $status]; 74 $where[] = ['=', 'ul.status', $status];
73 } 75 }
  76 + if ($package_name) {
  77 + $where[] = ['like', 'ul.package_name', $package_name];
  78 + }
74 if ($current_version) { 79 if ($current_version) {
75 $where[] = ['like', 'ul.current_version', $current_version]; 80 $where[] = ['like', 'ul.current_version', $current_version];
76 } 81 }
app-ht/modules/datas/views/upgrade-log/export.php
@@ -23,24 +23,26 @@ $cnt = 0; @@ -23,24 +23,26 @@ $cnt = 0;
23 </head> 23 </head>
24 <body> 24 <body>
25 <div id="Classeur1_16681" align='center' x:publishsource="Excel"> 25 <div id="Classeur1_16681" align='center' x:publishsource="Excel">
26 - <table border='1' cellpadding='0' cellspacing='0' width='100%' style="border-collapse: collapse"> 26 + <table x:str border='1' cellpadding='0' cellspacing='0' width='100%' style="border-collapse: collapse">
27 <thead> 27 <thead>
28 <tr> 28 <tr>
29 <th width="10%">设备ID</th> 29 <th width="10%">设备ID</th>
30 - <th width="10%">当前版本</th> 30 + <th width="8%">包名</th>
  31 + <th width="8%">当前版本</th>
31 <th width="10%">目标版本</th> 32 <th width="10%">目标版本</th>
32 <th width="10%">厂商</th> 33 <th width="10%">厂商</th>
33 <th width="10%">机器型号</th> 34 <th width="10%">机器型号</th>
34 <th width="10%">Barcode</th> 35 <th width="10%">Barcode</th>
35 - <th width="10%">升级状态</th>  
36 - <th width="15%">升级错误码</th>  
37 - <th width="15%">时间</th> 36 + <th width="7%">升级状态</th>
  37 + <th width="10%">升级错误码</th>
  38 + <th width="10%">时间</th>
38 </tr> 39 </tr>
39 </thead> 40 </thead>
40 <tbody> 41 <tbody>
41 <?php foreach ($listdata as $key => $item) : ?> 42 <?php foreach ($listdata as $key => $item) : ?>
42 <tr> 43 <tr>
43 <td style="padding:12px;"><?= (isset($item["device_id"]) ? $item["device_id"] : "") ?></td> 44 <td style="padding:12px;"><?= (isset($item["device_id"]) ? $item["device_id"] : "") ?></td>
  45 + <td style="padding:12px;"><?= (isset($item["package_name"]) ? $item["package_name"] : "-") ?></td>
44 <td style="padding:12px;"><?= (isset($item["current_version"]) ? $item["current_version"] : "") ?></td> 46 <td style="padding:12px;"><?= (isset($item["current_version"]) ? $item["current_version"] : "") ?></td>
45 <td style="padding:12px;"><?= (isset($item["target_version"]) ? $item["target_version"] : "") ?></td> 47 <td style="padding:12px;"><?= (isset($item["target_version"]) ? $item["target_version"] : "") ?></td>
46 <td style="padding:12px;"><?= (isset($item["manufacture_name"]) ? $item["manufacture_name"] : "") ?></td> 48 <td style="padding:12px;"><?= (isset($item["manufacture_name"]) ? $item["manufacture_name"] : "") ?></td>
app-ht/modules/datas/views/upgrade-log/index.php
@@ -77,8 +77,8 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title; @@ -77,8 +77,8 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
77 <td class="text-left"> 77 <td class="text-left">
78 <input type="text" class="form-control" name="device_device_id" style="width: 150px;" placeholder="输入设备ID" value="<?php if (!empty($gets['device_device_id'])){ echo $gets['device_device_id']; } ?>"> 78 <input type="text" class="form-control" name="device_device_id" style="width: 150px;" placeholder="输入设备ID" value="<?php if (!empty($gets['device_device_id'])){ echo $gets['device_device_id']; } ?>">
79 </td> 79 </td>
80 - <td class="text-right"></td>  
81 - <td class="text-left"></td> 80 + <td class="text-right">包名</td>
  81 + <td class="text-left"> <input type="text" class="form-control" name="package_name" style="width: 150px;" placeholder="包名" value="<?php if (!empty($gets['package_name'])){ echo $gets['package_name']; } ?>"></td>
82 <td class="text-right"></td> 82 <td class="text-right"></td>
83 <td class="text-left"></td> 83 <td class="text-left"></td>
84 <td class="text-right"></td> 84 <td class="text-right"></td>
@@ -104,14 +104,15 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title; @@ -104,14 +104,15 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
104 <thead> 104 <thead>
105 <tr> 105 <tr>
106 <th width="10%">设备ID</th> 106 <th width="10%">设备ID</th>
107 - <th width="10%">当前版本</th> 107 + <th width="8%">包名</th>
  108 + <th width="8%">当前版本</th>
108 <th width="10%">目标版本</th> 109 <th width="10%">目标版本</th>
109 <th width="10%">厂商</th> 110 <th width="10%">厂商</th>
110 <th width="10%">机器型号</th> 111 <th width="10%">机器型号</th>
111 <th width="10%">Barcode</th> 112 <th width="10%">Barcode</th>
112 - <th width="10%">升级状态</th>  
113 - <th width="15%">升级错误码</th>  
114 - <th width="15%">时间</th> 113 + <th width="7%">升级状态</th>
  114 + <th width="10%">升级错误码</th>
  115 + <th width="10%">时间</th>
115 </tr> 116 </tr>
116 </thead> 117 </thead>
117 118
@@ -120,6 +121,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title; @@ -120,6 +121,7 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
120 <?php foreach ($listdata as $item) : ?> 121 <?php foreach ($listdata as $item) : ?>
121 <tr> 122 <tr>
122 <td style="padding:12px;"><?= (isset($item["device_id"]) ? $item["device_id"] : "") ?></td> 123 <td style="padding:12px;"><?= (isset($item["device_id"]) ? $item["device_id"] : "") ?></td>
  124 + <td style="padding:12px;"><?= (isset($item["package_name"]) ? $item["package_name"] : "-") ?></td>
123 <td style="padding:12px;"><?= (isset($item["current_version"]) ? $item["current_version"] : "") ?></td> 125 <td style="padding:12px;"><?= (isset($item["current_version"]) ? $item["current_version"] : "") ?></td>
124 <td style="padding:12px;"><?= (isset($item["target_version"]) ? $item["target_version"] : "") ?></td> 126 <td style="padding:12px;"><?= (isset($item["target_version"]) ? $item["target_version"] : "") ?></td>
125 <td style="padding:12px;"><?= (isset($item["manufacture_name"]) ? $item["manufacture_name"] : "") ?></td> 127 <td style="padding:12px;"><?= (isset($item["manufacture_name"]) ? $item["manufacture_name"] : "") ?></td>
app-ht/modules/device/controllers/DeviceController.php
@@ -673,6 +673,8 @@ class DeviceController extends BaseController @@ -673,6 +673,8 @@ class DeviceController extends BaseController
673 return $this->renderJson($e); 673 return $this->renderJson($e);
674 } 674 }
675 $batchNo = Device::getBatchNo($deviceFailModel->manufacture_no, $deviceFailModel->project_no, $deviceFailModel->model_no, $deviceFailModel->production_no); 675 $batchNo = Device::getBatchNo($deviceFailModel->manufacture_no, $deviceFailModel->project_no, $deviceFailModel->model_no, $deviceFailModel->production_no);
  676 + $deviceId = $deviceFailModel->device_id;
  677 + $tt = time();
676 $batchInfo = CreateBatchRepository::findOne(['batch_no' => $batchNo]); 678 $batchInfo = CreateBatchRepository::findOne(['batch_no' => $batchNo]);
677 if (empty($batchInfo)) { 679 if (empty($batchInfo)) {
678 $e->message = '该厂商未生产过该批次的设备无法处理'; 680 $e->message = '该厂商未生产过该批次的设备无法处理';
@@ -680,68 +682,68 @@ class DeviceController extends BaseController @@ -680,68 +682,68 @@ class DeviceController extends BaseController
680 } 682 }
681 $batchId = $batchInfo->id; 683 $batchId = $batchInfo->id;
682 $deviceModel = DeviceRepository::findOne(['device_id' => $deviceFailModel->device_id , 'is_delete' => 0]); 684 $deviceModel = DeviceRepository::findOne(['device_id' => $deviceFailModel->device_id , 'is_delete' => 0]);
  685 +
683 if ($deviceModel) { 686 if ($deviceModel) {
684 - $e->message = '该设备已经授权过'; 687 + if (DeviceStatus::HAS_AUTH == $deviceModel->status) {
  688 + $e->mac = $deviceModel->mac;
  689 + $e->message = '已经存在该授权设备';
  690 + $e->success = false;
  691 + } elseif(DeviceStatus::NO_AUTH == $deviceModel->status) {
  692 + $deviceModel->status = DeviceStatus::HAS_AUTH;
  693 + $deviceModel->auth_at = time();
  694 + $deviceModel->save();
  695 + $e->message = '已经存在该授权设备';
  696 + $e->success = false;
  697 + } else {
  698 + $e->message = '处理失败';
  699 + }
  700 +
685 return $this->renderJson($e); 701 return $this->renderJson($e);
686 } 702 }
687 - $count = DeviceRepository::rowsCount(['batch_id' => $batchId, 'status' => DeviceStatus::HAS_AUTH, 'is_delete' => 0]);  
688 703
689 - if (($count *1) >= ($batchInfo->num * 1)) { 704 + $needGen = DeviceRepository::checkNeedAutoGen($batchId, $batchInfo->num);
  705 + if ($needGen) {
690 $trans = Yii::$app->getDb()->beginTransaction(); 706 $trans = Yii::$app->getDb()->beginTransaction();
691 try { 707 try {
692 -  
693 - Device::createWithMacSerialNo($batchId, $batchNo, $deviceFailModel->device_id, $deviceFailModel->apply_at, 1, DeviceStatus::HAS_AUTH);  
694 - // 设备改为删除了 708 + $genDeviceModel = Device::createWithMacSerialNo($batchId, $batchNo, $deviceId, $tt, 0, DeviceStatus::HAS_AUTH);
695 $deviceFailModel->is_delete = 1; 709 $deviceFailModel->is_delete = 1;
696 $deviceFailModel->save(); 710 $deviceFailModel->save();
697 $trans->commit(); 711 $trans->commit();
  712 + $e->message = '处理成功';
698 $e->success = true; 713 $e->success = true;
699 - return $this->renderJson($e);  
700 - } catch (Exception $exception) { 714 + } catch(Exception $exception) {
701 $trans->rollBack(); 715 $trans->rollBack();
702 - $e->message = '处理失败,请再尝试一次';  
703 - return $this->renderJson($e);  
704 - }  
705 -  
706 - } else {  
707 - $newDeviceModel = DeviceRepository::findOne(['device_id'=> null, 'batch_id' => $batchId, 'is_delete' => 0, 'status' => DeviceStatus::NO_AUTH]);  
708 - if (!$newDeviceModel) {  
709 - $trans = Yii::$app->getDb()->beginTransaction();  
710 - try {  
711 - Device::createWithMacSerialNo($batchId, $batchNo, $deviceFailModel->device_id, $deviceFailModel->apply_at, 1, DeviceStatus::HAS_AUTH);  
712 - $deviceFailModel->is_delete = 1;  
713 - $deviceFailModel->save();  
714 - $trans->commit();  
715 - $e->success = true;  
716 - $e->message = '处理成功';  
717 - } catch (Exception $exception) {  
718 - $trans->rollBack();  
719 - $e->message = '处理失败, 生成的设备序列号用完,请再点击处理一次';  
720 - }  
721 - return $this->renderJson($e); 716 + $e->message = '处理失败, 请再次重处理!';
  717 + $e->success = false;
722 } 718 }
723 719
724 - $trans = Yii::$app->getDb()->beginTransaction();  
725 - try {  
726 - $newDeviceModel->device_id = $deviceFailModel->device_id;  
727 - $newDeviceModel->status = DeviceStatus::HAS_AUTH;  
728 - $newDeviceModel->apply_at = $deviceFailModel->apply_at;  
729 - $newDeviceModel->auth_at = time();  
730 - $newDeviceModel->status = DeviceStatus::HAS_AUTH;  
731 - $newDeviceModel->save();  
732 -  
733 - $deviceFailModel->is_delete = 1;  
734 - $deviceFailModel->save();  
735 - $trans->commit();  
736 - $e->success = true;  
737 - $e->message = '处理成功';  
738 - return $this->renderJson($e);  
739 - } catch (Exception $exception) {  
740 - $trans->rollBack();  
741 - $e->message = '处理失败,系统错误';  
742 - return $this->renderJson($e);  
743 - } 720 + return $this->renderJson($e);
  721 + }
  722 + // 找到未空白未绑定的设备序列号
  723 + $newDeviceModel = DeviceRepository::findOne(['device_id' => null,'batch_id' => $batchId, 'is_delete' => 0, 'status' => DeviceStatus::NO_AUTH]);
  724 + if (empty($newDeviceModel)) {
  725 + $e->message = '处理失败,系统参数有误';
  726 + return $this->renderJson($e);
  727 + }
  728 + $trans = Yii::$app->getDb()->beginTransaction();
  729 + try {
  730 + $newDeviceModel->device_id = $deviceId;
  731 + $newDeviceModel->status = DeviceStatus::HAS_AUTH;
  732 + $newDeviceModel->apply_at = $tt ;
  733 + $newDeviceModel->auth_at = $tt;
  734 + $newDeviceModel->save();
  735 + $deviceFailModel->is_delete = 1;
  736 + $deviceFailModel->save();
  737 + $trans->commit();
  738 + $e->message = '处理成功';
  739 + $e->success = true;
  740 + } catch (Exception $exception) {
  741 + $trans->rollBack();
  742 + $e->message = '处理失败';
  743 + $e->success = false;
744 } 744 }
  745 +
  746 + return $this->renderJson($e);
745 } 747 }
746 748
747 /** 749 /**
@@ -761,6 +763,7 @@ class DeviceController extends BaseController @@ -761,6 +763,7 @@ class DeviceController extends BaseController
761 $e->message = '未找到记录'; 763 $e->message = '未找到记录';
762 return $this->renderJson($e); 764 return $this->renderJson($e);
763 } 765 }
  766 + $tt = time();
764 $exitCount = 0; 767 $exitCount = 0;
765 $successCount = 0; 768 $successCount = 0;
766 $failCount = 0; 769 $failCount = 0;
@@ -768,7 +771,7 @@ class DeviceController extends BaseController @@ -768,7 +771,7 @@ class DeviceController extends BaseController
768 $deviceExitCount = 0; 771 $deviceExitCount = 0;
769 foreach ($deviceFailModels as $k => $deviceFailModel) { 772 foreach ($deviceFailModels as $k => $deviceFailModel) {
770 $batchNo = Device::getBatchNo($deviceFailModel->manufacture_no, $deviceFailModel->project_no, $deviceFailModel->model_no, $deviceFailModel->production_no); 773 $batchNo = Device::getBatchNo($deviceFailModel->manufacture_no, $deviceFailModel->project_no, $deviceFailModel->model_no, $deviceFailModel->production_no);
771 - 774 + $deviceId = $deviceFailModel->device_id ;
772 $batchInfo = CreateBatchRepository::findOne(['batch_no' => $batchNo]); 775 $batchInfo = CreateBatchRepository::findOne(['batch_no' => $batchNo]);
773 if (empty($batchInfo)) { 776 if (empty($batchInfo)) {
774 //该厂商未生产过该批次的设备无法生成 777 //该厂商未生产过该批次的设备无法生成
@@ -776,103 +779,59 @@ class DeviceController extends BaseController @@ -776,103 +779,59 @@ class DeviceController extends BaseController
776 continue; 779 continue;
777 } 780 }
778 $batchId = $batchInfo->id; 781 $batchId = $batchInfo->id;
779 - $deviceModel = DeviceRepository::findOne(['device_id' => $deviceFailModel->device_id , 'is_delete' => 0]); 782 + $deviceModel = DeviceRepository::findOne(['device_id' => $deviceId, 'is_delete' => 0]);
780 if ($deviceModel) { 783 if ($deviceModel) {
781 //该设备已经授权过 784 //该设备已经授权过
782 - $deviceExitCount++; 785 + if (DeviceStatus::HAS_AUTH == $deviceModel->status) {
  786 + $deviceExitCount++;
  787 + } elseif(DeviceStatus::NO_AUTH == $deviceModel->status) {
  788 + $deviceModel->status = DeviceStatus::HAS_AUTH;
  789 + $deviceModel->auth_at = time();
  790 + $deviceModel->save();
  791 + $deviceExitCount++;
  792 +
  793 + } else {
  794 + $deviceExitCount++;
  795 + }
  796 +
783 continue; 797 continue;
784 } 798 }
785 - $count = DeviceRepository::rowsCount(['batch_id' => $batchId, 'status' => DeviceStatus::HAS_AUTH, 'is_delete' => 0]);  
786 -  
787 - if (($count *1) >= ($batchInfo->num * 1)) {  
788 - $exitDeviceModel = DeviceModel::find();  
789 - $exitDeviceModel->where(['batch_id' => $batchId]);  
790 - $exitDeviceModel->orderBy('serial_no desc');  
791 - $exitDevice = $exitDeviceModel->one();  
792 - $serialNo = '';  
793 - if ($exitDevice) {  
794 - $numNo = mb_substr($exitDevice->serial_no, -4);  
795 - $no1 = hexdec($numNo);  
796 - $no =($no1 * 1) + 1;  
797 - $newNo = sprintf('%04X', $no);  
798 - $serialNo = $batchNo.$newNo; 799 + $needGen = DeviceRepository::checkNeedAutoGen($batchId, $batchInfo->num);
  800 + if ($needGen) {
  801 + $trans = Yii::$app->getDb()->beginTransaction();
  802 + try {
  803 + $genDeviceModel = Device::createWithMacSerialNo($batchId, $batchNo, $deviceId, $tt, 0, DeviceStatus::HAS_AUTH);
  804 + $deviceFailModel->is_delete = 1;
  805 + $deviceFailModel->save();
  806 + $trans->commit();
  807 + $successCount++;
  808 + } catch(Exception $exception) {
  809 + $trans->rollBack();
  810 + $failCount++;
799 } 811 }
800 812
801 - $macAddress = Utils::macGenerate();  
802 - $deviceFind = DeviceModel::find();  
803 - $deviceFind->where(  
804 - [  
805 - 'or',  
806 - ['=', 'serial_no', $serialNo],  
807 - ['=', 'mac', $macAddress]  
808 - ]  
809 - );  
810 - $checkDevice = $deviceFind->one();  
811 - if ($checkDevice) {  
812 - //'MAC地址或序列号已经存在,请再处理一次';  
813 - $exitCount++; 813 + } else {
  814 +
  815 + $newDeviceModel = DeviceRepository::findOne(['device_id' => null, 'batch_id' => $batchId, 'is_delete' => 0, 'status' => DeviceStatus::NO_AUTH]);
  816 + if (empty($newDeviceModel)) {
  817 + $failCount++;
814 continue; 818 continue;
815 } 819 }
816 -  
817 $trans = Yii::$app->getDb()->beginTransaction(); 820 $trans = Yii::$app->getDb()->beginTransaction();
818 try { 821 try {
819 - $item = [  
820 - 'serial_no' => $serialNo,  
821 - 'mac' => $macAddress,  
822 - 'device_id' => $deviceFailModel->device_id,  
823 - 'batch_id' => $batchId,  
824 - 'status' => DeviceStatus::HAS_AUTH,  
825 - 'has_re_auth' => 1,  
826 - 'apply_at' => $deviceFailModel->apply_at,  
827 - 'auth_at' => time(),  
828 - ];  
829 - Device::create($item);  
830 - // 设备改为删除了 822 + $newDeviceModel->device_id = $deviceId;
  823 + $newDeviceModel->status = DeviceStatus::HAS_AUTH;
  824 + $newDeviceModel->apply_at = $tt ;
  825 + $newDeviceModel->auth_at = $tt;
  826 + $newDeviceModel->save();
831 $deviceFailModel->is_delete = 1; 827 $deviceFailModel->is_delete = 1;
832 $deviceFailModel->save(); 828 $deviceFailModel->save();
833 $trans->commit(); 829 $trans->commit();
834 $successCount++; 830 $successCount++;
835 -  
836 } catch (Exception $exception) { 831 } catch (Exception $exception) {
837 $trans->rollBack(); 832 $trans->rollBack();
838 $failCount++; 833 $failCount++;
839 } 834 }
840 - } else {  
841 -  
842 - $newDeviceModel = DeviceRepository::findOne(['device_id'=> null, 'batch_id' => $batchId, 'is_delete' => 0, 'status' => DeviceStatus::NO_AUTH]);  
843 - if (!$newDeviceModel) {  
844 -  
845 - $trans = Yii::$app->getDb()->beginTransaction();  
846 - try {  
847 - Device::createWithMacSerialNo($batchId, $batchNo, $deviceFailModel->device_id, $deviceFailModel->apply_at, 1, DeviceStatus::HAS_AUTH);  
848 - $deviceFailModel->is_delete = 1;  
849 - $deviceFailModel->save();  
850 - $trans->commit();  
851 - $successCount++;  
852 - } catch (Exception $exception) {  
853 - $trans->rollBack();  
854 - $failCount++;  
855 - }  
856 -  
857 - } else {  
858 - $trans = Yii::$app->getDb()->beginTransaction();  
859 - try {  
860 - $newDeviceModel->device_id = $deviceFailModel->device_id;  
861 - $newDeviceModel->status = DeviceStatus::HAS_AUTH;  
862 - $newDeviceModel->apply_at = $deviceFailModel->apply_at;  
863 - $newDeviceModel->auth_at = time();  
864 - $newDeviceModel->status = DeviceStatus::HAS_AUTH;  
865 - $newDeviceModel->save();  
866 -  
867 - $deviceFailModel->is_delete = 1;  
868 - $deviceFailModel->save();  
869 - $trans->commit();  
870 - $successCount++;  
871 - } catch (Exception $exception) {  
872 - $trans->rollBack();  
873 - $failCount++;  
874 - }  
875 - }  
876 835
877 } 836 }
878 } 837 }
@@ -929,10 +888,16 @@ class DeviceController extends BaseController @@ -929,10 +888,16 @@ class DeviceController extends BaseController
929 $e->message = '未找到厂商对应的批次无法恢复'; 888 $e->message = '未找到厂商对应的批次无法恢复';
930 return $this->renderJson($e); 889 return $this->renderJson($e);
931 } 890 }
932 - $count = DeviceRepository::rowsCount(['batch_id' => $batchModel->id, 'status' => DeviceStatus::HAS_AUTH, 'is_delete' => 0]); 891 + $where = [
  892 + 'and',
  893 + ['=', 'batch_id' , $batchModel->id],
  894 + ['=', 'is_delete', 0],
  895 + ['is not', 'device_id', Null]
  896 + ];
  897 + $count = DeviceRepository::rowsCount($where);
933 898
934 if (($count *1) >= ($batchModel->num * 1)) { 899 if (($count *1) >= ($batchModel->num * 1)) {
935 - $e->message = '该厂商的批次已经满了无法恢复该设备'; 900 + $e->message = '该厂商的批次已满,无法恢复该设备';
936 return $this->renderJson($e); 901 return $this->renderJson($e);
937 } 902 }
938 // 检测当前设备ID是否存在表里面 903 // 检测当前设备ID是否存在表里面
@@ -956,6 +921,9 @@ class DeviceController extends BaseController @@ -956,6 +921,9 @@ class DeviceController extends BaseController
956 return $this->renderJson($e); 921 return $this->renderJson($e);
957 } 922 }
958 923
  924 + /**
  925 + * @return string
  926 + */
959 public function actionBatchRestoreDevice() 927 public function actionBatchRestoreDevice()
960 { 928 {
961 $req = Yii::$app->request; 929 $req = Yii::$app->request;
@@ -978,9 +946,16 @@ class DeviceController extends BaseController @@ -978,9 +946,16 @@ class DeviceController extends BaseController
978 if (empty($batchModel)) { 946 if (empty($batchModel)) {
979 continue; 947 continue;
980 } 948 }
981 - $count = DeviceRepository::rowsCount(['batch_id' => $batchModel->id, 'status' => DeviceStatus::HAS_AUTH, 'is_delete' => 0]); 949 + $where = [
  950 + 'and',
  951 + ['=', 'batch_id' , $delDevice->batch_id],
  952 + ['=', 'is_delete', 0],
  953 + ['is not', 'device_id', Null]
  954 + ];
  955 + $count = DeviceRepository::rowsCount($where);
982 if (($count *1) >= ($batchModel->num * 1)) { 956 if (($count *1) >= ($batchModel->num * 1)) {
983 $fullCount++; 957 $fullCount++;
  958 + continue;
984 } 959 }
985 // 检测当前设备ID是否存在表里面 960 // 检测当前设备ID是否存在表里面
986 $exitDevice = DeviceRepository::findOne(['device_id' => $delDevice->device_id, 'is_delete' => 0]); 961 $exitDevice = DeviceRepository::findOne(['device_id' => $delDevice->device_id, 'is_delete' => 0]);
console/controllers/TestController.php
@@ -157,17 +157,22 @@ class TestController extends Controller @@ -157,17 +157,22 @@ class TestController extends Controller
157 public function actionReportAppEvent() 157 public function actionReportAppEvent()
158 { 158 {
159 //actionCheckAppVersion 159 //actionCheckAppVersion
160 - $url = 'http://47.107.95.101/app-api/web/reportAppUpgradeEvent';  
161 - //$url = 'http://kingb:8012/app-api/web/reportAppUpgradeEvent'; 160 + //$url = 'http://47.107.95.101/app-api/web/reportAppUpgradeEvent';
  161 + $url = 'http://kingb:8012/app-api/web/reportAppUpgradeEvent';
162 162
163 $params = [ 163 $params = [
164 'barcode' => '0001000100010001', 164 'barcode' => '0001000100010001',
165 'device_id' => 'DGDEVBICEID00001', 165 'device_id' => 'DGDEVBICEID00001',
166 - 'software_version' => 'V1.0.1',  
167 - 'hardware_version' => 'V1.0.1', 166 + 'current_version' => 'V1.0.1',
  167 + 'target_version' => 'V1.0.1',
  168 + 'package_name' => 'com.app.king.dd',
  169 + "status" => 0,
  170 + "error_code" => '',
  171 + "timestamp" => 1572767677
  172 +
168 ]; 173 ];
169 $params = json_encode($params); 174 $params = json_encode($params);
170 - $params = '{"barcode":"0001000100010001","device_id":"DGDEVBICEID00001","current_version":"1","target_version":"2","status":"5","error_code":"0","timestamp":"1572767677"}'; 175 + //$params = '{"barcode":"0001000100010001","device_id":"DGDEVBICEID00001","current_version":"1","target_version":"2","status":"5","error_code":"0","timestamp":"1572767677"}';
171 $postResult = Http::POST($url, $params); 176 $postResult = Http::POST($url, $params);
172 echo $postResult; 177 echo $postResult;
173 } 178 }
domain/upgrade/UpgradeLog.php
@@ -36,6 +36,9 @@ class UpgradeLog @@ -36,6 +36,9 @@ class UpgradeLog
36 if (isset($item["model_id"])) { 36 if (isset($item["model_id"])) {
37 $upgradeLogModel->model_id = $item["model_id"]; // 设备型号ID 37 $upgradeLogModel->model_id = $item["model_id"]; // 设备型号ID
38 } 38 }
  39 + if (isset($item["package_name"])) {
  40 + $upgradeLogModel->package_name = $item["package_name"]; // 包名
  41 + }
39 if (isset($item["current_version"])) { 42 if (isset($item["current_version"])) {
40 $upgradeLogModel->current_version = $item["current_version"]; // 当前版本 43 $upgradeLogModel->current_version = $item["current_version"]; // 当前版本
41 } 44 }