diff --git a/app-api/controllers/UpgradeController.php b/app-api/controllers/UpgradeController.php index 7123e79..b37c8d4 100644 --- a/app-api/controllers/UpgradeController.php +++ b/app-api/controllers/UpgradeController.php @@ -390,11 +390,13 @@ class UpgradeController extends BaseController $deviceId = isset($getPostData['device_id'])? $getPostData['device_id']: ''; $currentVersion = isset($getPostData['current_version'])? $getPostData['current_version']: ''; $targetVersion = isset($getPostData['target_version'])? $getPostData['target_version']: ''; + $packageName = isset($getPostData['package_name'])? $getPostData['package_name']: ''; + $status = isset($getPostData['status'])? $getPostData['status']: ''; $errorCode = isset($getPostData['error_code'])? $getPostData['error_code']: ''; $timestamp = isset($getPostData['timestamp'])? $getPostData['timestamp']: ''; - if (empty($barcode) || empty($currentVersion) || empty($targetVersion) || empty($timestamp)) { + if (empty($barcode) || empty($currentVersion) || empty($targetVersion) || empty($timestamp) || empty($packageName)) { $e->status = 2; $e->message = '部分数据为空'; return $e; @@ -412,7 +414,7 @@ class UpgradeController extends BaseController $e->message = 'barcode格式有误'; return $e; } - $upgradeLogModel = UpgradeLogRepository::findOne(['device_id' => $deviceId, 'current_version' => $currentVersion, 'target_version' => $targetVersion, 'status' => $status, 'type' => UpgradeStatus::TYPE_APP]); + $upgradeLogModel = UpgradeLogRepository::findOne(['device_id' => $deviceId, 'package_name' => $packageName ,'current_version' => $currentVersion, 'target_version' => $targetVersion, 'status' => $status, 'type' => UpgradeStatus::TYPE_APP]); if ($upgradeLogModel) { $upgradeLogModel->timestamp = $timestamp; $upgradeLogModel->save(); @@ -442,6 +444,7 @@ class UpgradeController extends BaseController "project_id" => $projectId, "model_id" => $modelId, "current_version" => $currentVersion, + "package_name" => $packageName, "target_version" => $targetVersion, "status" => $status, "error_code" => $errorCode, diff --git a/app-ht/modules/datas/controllers/UpgradeLogController.php b/app-ht/modules/datas/controllers/UpgradeLogController.php index ede76de..375f56f 100644 --- a/app-ht/modules/datas/controllers/UpgradeLogController.php +++ b/app-ht/modules/datas/controllers/UpgradeLogController.php @@ -43,6 +43,7 @@ class UpgradeLogController extends BaseController $barcode = $request->get('barcode'); $error_code = $request->get('error_code'); $device_device_id = $request->get('device_device_id'); + $package_name = $request->get('package_name'); $dataType = !empty($request->get('type')) ? $request->get('type') : UpgradeStatus::TYPE_APP; $gets = [ @@ -56,6 +57,7 @@ class UpgradeLogController extends BaseController 'barcode' => $barcode, 'error_code' => $error_code, 'device_device_id' => $device_device_id, + 'package_name' => $package_name, 'type' => $dataType, ]; @@ -71,6 +73,9 @@ class UpgradeLogController extends BaseController if ($status) { $where[] = ['=', 'ul.status', $status]; } + if ($package_name) { + $where[] = ['like', 'ul.package_name', $package_name]; + } if ($current_version) { $where[] = ['like', 'ul.current_version', $current_version]; } diff --git a/app-ht/modules/datas/views/upgrade-log/export.php b/app-ht/modules/datas/views/upgrade-log/export.php index 67252a1..5bc3d5a 100644 --- a/app-ht/modules/datas/views/upgrade-log/export.php +++ b/app-ht/modules/datas/views/upgrade-log/export.php @@ -23,24 +23,26 @@ $cnt = 0;
- +
- + + - - - + + + $item) : ?> + diff --git a/app-ht/modules/datas/views/upgrade-log/index.php b/app-ht/modules/datas/views/upgrade-log/index.php index 7debd2d..f397c0a 100644 --- a/app-ht/modules/datas/views/upgrade-log/index.php +++ b/app-ht/modules/datas/views/upgrade-log/index.php @@ -77,8 +77,8 @@ $this->params['breadcrumbs'][] = $this->title; - - + + @@ -104,14 +104,15 @@ $this->params['breadcrumbs'][] = $this->title; - + + - - - + + + @@ -120,6 +121,7 @@ $this->params['breadcrumbs'][] = $this->title; + diff --git a/app-ht/modules/device/controllers/DeviceController.php b/app-ht/modules/device/controllers/DeviceController.php index b0de48c..ecf051d 100644 --- a/app-ht/modules/device/controllers/DeviceController.php +++ b/app-ht/modules/device/controllers/DeviceController.php @@ -673,6 +673,8 @@ class DeviceController extends BaseController return $this->renderJson($e); } $batchNo = Device::getBatchNo($deviceFailModel->manufacture_no, $deviceFailModel->project_no, $deviceFailModel->model_no, $deviceFailModel->production_no); + $deviceId = $deviceFailModel->device_id; + $tt = time(); $batchInfo = CreateBatchRepository::findOne(['batch_no' => $batchNo]); if (empty($batchInfo)) { $e->message = '该厂商未生产过该批次的设备无法处理'; @@ -680,68 +682,68 @@ class DeviceController extends BaseController } $batchId = $batchInfo->id; $deviceModel = DeviceRepository::findOne(['device_id' => $deviceFailModel->device_id , 'is_delete' => 0]); + if ($deviceModel) { - $e->message = '该设备已经授权过'; + if (DeviceStatus::HAS_AUTH == $deviceModel->status) { + $e->mac = $deviceModel->mac; + $e->message = '已经存在该授权设备'; + $e->success = false; + } elseif(DeviceStatus::NO_AUTH == $deviceModel->status) { + $deviceModel->status = DeviceStatus::HAS_AUTH; + $deviceModel->auth_at = time(); + $deviceModel->save(); + $e->message = '已经存在该授权设备'; + $e->success = false; + } else { + $e->message = '处理失败'; + } + return $this->renderJson($e); } - $count = DeviceRepository::rowsCount(['batch_id' => $batchId, 'status' => DeviceStatus::HAS_AUTH, 'is_delete' => 0]); - if (($count *1) >= ($batchInfo->num * 1)) { + $needGen = DeviceRepository::checkNeedAutoGen($batchId, $batchInfo->num); + if ($needGen) { $trans = Yii::$app->getDb()->beginTransaction(); try { - - Device::createWithMacSerialNo($batchId, $batchNo, $deviceFailModel->device_id, $deviceFailModel->apply_at, 1, DeviceStatus::HAS_AUTH); - // 设备改为删除了 + $genDeviceModel = Device::createWithMacSerialNo($batchId, $batchNo, $deviceId, $tt, 0, DeviceStatus::HAS_AUTH); $deviceFailModel->is_delete = 1; $deviceFailModel->save(); $trans->commit(); + $e->message = '处理成功'; $e->success = true; - return $this->renderJson($e); - } catch (Exception $exception) { + } catch(Exception $exception) { $trans->rollBack(); - $e->message = '处理失败,请再尝试一次'; - return $this->renderJson($e); - } - - } else { - $newDeviceModel = DeviceRepository::findOne(['device_id'=> null, 'batch_id' => $batchId, 'is_delete' => 0, 'status' => DeviceStatus::NO_AUTH]); - if (!$newDeviceModel) { - $trans = Yii::$app->getDb()->beginTransaction(); - try { - Device::createWithMacSerialNo($batchId, $batchNo, $deviceFailModel->device_id, $deviceFailModel->apply_at, 1, DeviceStatus::HAS_AUTH); - $deviceFailModel->is_delete = 1; - $deviceFailModel->save(); - $trans->commit(); - $e->success = true; - $e->message = '处理成功'; - } catch (Exception $exception) { - $trans->rollBack(); - $e->message = '处理失败, 生成的设备序列号用完,请再点击处理一次'; - } - return $this->renderJson($e); + $e->message = '处理失败, 请再次重处理!'; + $e->success = false; } - $trans = Yii::$app->getDb()->beginTransaction(); - try { - $newDeviceModel->device_id = $deviceFailModel->device_id; - $newDeviceModel->status = DeviceStatus::HAS_AUTH; - $newDeviceModel->apply_at = $deviceFailModel->apply_at; - $newDeviceModel->auth_at = time(); - $newDeviceModel->status = DeviceStatus::HAS_AUTH; - $newDeviceModel->save(); - - $deviceFailModel->is_delete = 1; - $deviceFailModel->save(); - $trans->commit(); - $e->success = true; - $e->message = '处理成功'; - return $this->renderJson($e); - } catch (Exception $exception) { - $trans->rollBack(); - $e->message = '处理失败,系统错误'; - return $this->renderJson($e); - } + return $this->renderJson($e); + } + // 找到未空白未绑定的设备序列号 + $newDeviceModel = DeviceRepository::findOne(['device_id' => null,'batch_id' => $batchId, 'is_delete' => 0, 'status' => DeviceStatus::NO_AUTH]); + if (empty($newDeviceModel)) { + $e->message = '处理失败,系统参数有误'; + return $this->renderJson($e); + } + $trans = Yii::$app->getDb()->beginTransaction(); + try { + $newDeviceModel->device_id = $deviceId; + $newDeviceModel->status = DeviceStatus::HAS_AUTH; + $newDeviceModel->apply_at = $tt ; + $newDeviceModel->auth_at = $tt; + $newDeviceModel->save(); + $deviceFailModel->is_delete = 1; + $deviceFailModel->save(); + $trans->commit(); + $e->message = '处理成功'; + $e->success = true; + } catch (Exception $exception) { + $trans->rollBack(); + $e->message = '处理失败'; + $e->success = false; } + + return $this->renderJson($e); } /** @@ -761,6 +763,7 @@ class DeviceController extends BaseController $e->message = '未找到记录'; return $this->renderJson($e); } + $tt = time(); $exitCount = 0; $successCount = 0; $failCount = 0; @@ -768,7 +771,7 @@ class DeviceController extends BaseController $deviceExitCount = 0; foreach ($deviceFailModels as $k => $deviceFailModel) { $batchNo = Device::getBatchNo($deviceFailModel->manufacture_no, $deviceFailModel->project_no, $deviceFailModel->model_no, $deviceFailModel->production_no); - + $deviceId = $deviceFailModel->device_id ; $batchInfo = CreateBatchRepository::findOne(['batch_no' => $batchNo]); if (empty($batchInfo)) { //该厂商未生产过该批次的设备无法生成 @@ -776,103 +779,59 @@ class DeviceController extends BaseController continue; } $batchId = $batchInfo->id; - $deviceModel = DeviceRepository::findOne(['device_id' => $deviceFailModel->device_id , 'is_delete' => 0]); + $deviceModel = DeviceRepository::findOne(['device_id' => $deviceId, 'is_delete' => 0]); if ($deviceModel) { //该设备已经授权过 - $deviceExitCount++; + if (DeviceStatus::HAS_AUTH == $deviceModel->status) { + $deviceExitCount++; + } elseif(DeviceStatus::NO_AUTH == $deviceModel->status) { + $deviceModel->status = DeviceStatus::HAS_AUTH; + $deviceModel->auth_at = time(); + $deviceModel->save(); + $deviceExitCount++; + + } else { + $deviceExitCount++; + } + continue; } - $count = DeviceRepository::rowsCount(['batch_id' => $batchId, 'status' => DeviceStatus::HAS_AUTH, 'is_delete' => 0]); - - if (($count *1) >= ($batchInfo->num * 1)) { - $exitDeviceModel = DeviceModel::find(); - $exitDeviceModel->where(['batch_id' => $batchId]); - $exitDeviceModel->orderBy('serial_no desc'); - $exitDevice = $exitDeviceModel->one(); - $serialNo = ''; - if ($exitDevice) { - $numNo = mb_substr($exitDevice->serial_no, -4); - $no1 = hexdec($numNo); - $no =($no1 * 1) + 1; - $newNo = sprintf('%04X', $no); - $serialNo = $batchNo.$newNo; + $needGen = DeviceRepository::checkNeedAutoGen($batchId, $batchInfo->num); + if ($needGen) { + $trans = Yii::$app->getDb()->beginTransaction(); + try { + $genDeviceModel = Device::createWithMacSerialNo($batchId, $batchNo, $deviceId, $tt, 0, DeviceStatus::HAS_AUTH); + $deviceFailModel->is_delete = 1; + $deviceFailModel->save(); + $trans->commit(); + $successCount++; + } catch(Exception $exception) { + $trans->rollBack(); + $failCount++; } - $macAddress = Utils::macGenerate(); - $deviceFind = DeviceModel::find(); - $deviceFind->where( - [ - 'or', - ['=', 'serial_no', $serialNo], - ['=', 'mac', $macAddress] - ] - ); - $checkDevice = $deviceFind->one(); - if ($checkDevice) { - //'MAC地址或序列号已经存在,请再处理一次'; - $exitCount++; + } else { + + $newDeviceModel = DeviceRepository::findOne(['device_id' => null, 'batch_id' => $batchId, 'is_delete' => 0, 'status' => DeviceStatus::NO_AUTH]); + if (empty($newDeviceModel)) { + $failCount++; continue; } - $trans = Yii::$app->getDb()->beginTransaction(); try { - $item = [ - 'serial_no' => $serialNo, - 'mac' => $macAddress, - 'device_id' => $deviceFailModel->device_id, - 'batch_id' => $batchId, - 'status' => DeviceStatus::HAS_AUTH, - 'has_re_auth' => 1, - 'apply_at' => $deviceFailModel->apply_at, - 'auth_at' => time(), - ]; - Device::create($item); - // 设备改为删除了 + $newDeviceModel->device_id = $deviceId; + $newDeviceModel->status = DeviceStatus::HAS_AUTH; + $newDeviceModel->apply_at = $tt ; + $newDeviceModel->auth_at = $tt; + $newDeviceModel->save(); $deviceFailModel->is_delete = 1; $deviceFailModel->save(); $trans->commit(); $successCount++; - } catch (Exception $exception) { $trans->rollBack(); $failCount++; } - } else { - - $newDeviceModel = DeviceRepository::findOne(['device_id'=> null, 'batch_id' => $batchId, 'is_delete' => 0, 'status' => DeviceStatus::NO_AUTH]); - if (!$newDeviceModel) { - - $trans = Yii::$app->getDb()->beginTransaction(); - try { - Device::createWithMacSerialNo($batchId, $batchNo, $deviceFailModel->device_id, $deviceFailModel->apply_at, 1, DeviceStatus::HAS_AUTH); - $deviceFailModel->is_delete = 1; - $deviceFailModel->save(); - $trans->commit(); - $successCount++; - } catch (Exception $exception) { - $trans->rollBack(); - $failCount++; - } - - } else { - $trans = Yii::$app->getDb()->beginTransaction(); - try { - $newDeviceModel->device_id = $deviceFailModel->device_id; - $newDeviceModel->status = DeviceStatus::HAS_AUTH; - $newDeviceModel->apply_at = $deviceFailModel->apply_at; - $newDeviceModel->auth_at = time(); - $newDeviceModel->status = DeviceStatus::HAS_AUTH; - $newDeviceModel->save(); - - $deviceFailModel->is_delete = 1; - $deviceFailModel->save(); - $trans->commit(); - $successCount++; - } catch (Exception $exception) { - $trans->rollBack(); - $failCount++; - } - } } } @@ -929,10 +888,16 @@ class DeviceController extends BaseController $e->message = '未找到厂商对应的批次无法恢复'; return $this->renderJson($e); } - $count = DeviceRepository::rowsCount(['batch_id' => $batchModel->id, 'status' => DeviceStatus::HAS_AUTH, 'is_delete' => 0]); + $where = [ + 'and', + ['=', 'batch_id' , $batchModel->id], + ['=', 'is_delete', 0], + ['is not', 'device_id', Null] + ]; + $count = DeviceRepository::rowsCount($where); if (($count *1) >= ($batchModel->num * 1)) { - $e->message = '该厂商的批次已经满了无法恢复该设备'; + $e->message = '该厂商的批次已满,无法恢复该设备'; return $this->renderJson($e); } // 检测当前设备ID是否存在表里面 @@ -956,6 +921,9 @@ class DeviceController extends BaseController return $this->renderJson($e); } + /** + * @return string + */ public function actionBatchRestoreDevice() { $req = Yii::$app->request; @@ -978,9 +946,16 @@ class DeviceController extends BaseController if (empty($batchModel)) { continue; } - $count = DeviceRepository::rowsCount(['batch_id' => $batchModel->id, 'status' => DeviceStatus::HAS_AUTH, 'is_delete' => 0]); + $where = [ + 'and', + ['=', 'batch_id' , $delDevice->batch_id], + ['=', 'is_delete', 0], + ['is not', 'device_id', Null] + ]; + $count = DeviceRepository::rowsCount($where); if (($count *1) >= ($batchModel->num * 1)) { $fullCount++; + continue; } // 检测当前设备ID是否存在表里面 $exitDevice = DeviceRepository::findOne(['device_id' => $delDevice->device_id, 'is_delete' => 0]); diff --git a/console/controllers/TestController.php b/console/controllers/TestController.php index 2dcc3c2..d96bea8 100644 --- a/console/controllers/TestController.php +++ b/console/controllers/TestController.php @@ -157,17 +157,22 @@ class TestController extends Controller public function actionReportAppEvent() { //actionCheckAppVersion - $url = 'http://47.107.95.101/app-api/web/reportAppUpgradeEvent'; - //$url = 'http://kingb:8012/app-api/web/reportAppUpgradeEvent'; + //$url = 'http://47.107.95.101/app-api/web/reportAppUpgradeEvent'; + $url = 'http://kingb:8012/app-api/web/reportAppUpgradeEvent'; $params = [ 'barcode' => '0001000100010001', 'device_id' => 'DGDEVBICEID00001', - 'software_version' => 'V1.0.1', - 'hardware_version' => 'V1.0.1', + 'current_version' => 'V1.0.1', + 'target_version' => 'V1.0.1', + 'package_name' => 'com.app.king.dd', + "status" => 0, + "error_code" => '', + "timestamp" => 1572767677 + ]; $params = json_encode($params); - $params = '{"barcode":"0001000100010001","device_id":"DGDEVBICEID00001","current_version":"1","target_version":"2","status":"5","error_code":"0","timestamp":"1572767677"}'; + //$params = '{"barcode":"0001000100010001","device_id":"DGDEVBICEID00001","current_version":"1","target_version":"2","status":"5","error_code":"0","timestamp":"1572767677"}'; $postResult = Http::POST($url, $params); echo $postResult; } diff --git a/domain/upgrade/UpgradeLog.php b/domain/upgrade/UpgradeLog.php index a25d307..d31551c 100644 --- a/domain/upgrade/UpgradeLog.php +++ b/domain/upgrade/UpgradeLog.php @@ -36,6 +36,9 @@ class UpgradeLog if (isset($item["model_id"])) { $upgradeLogModel->model_id = $item["model_id"]; // 设备型号ID } + if (isset($item["package_name"])) { + $upgradeLogModel->package_name = $item["package_name"]; // 包名 + } if (isset($item["current_version"])) { $upgradeLogModel->current_version = $item["current_version"]; // 当前版本 } -- libgit2 0.21.0
设备ID当前版本包名当前版本 目标版本 厂商 机器型号 Barcode升级状态升级错误码时间升级状态升级错误码时间
包名
设备ID当前版本包名当前版本 目标版本 厂商 机器型号 Barcode升级状态升级错误码时间升级状态升级错误码时间