Commit 9394a543ff0156eb46cb57f187cf33565a7c658e

Authored by 曹明
1 parent 78ba6991
Exists in master

1.OTA 上传ECS和OSS分开上传

app-api/controllers/UpgradeController.php
... ... @@ -178,7 +178,7 @@ class UpgradeController extends BaseController
178 178 $e->update_flag = $upgradeRecord->focuse;
179 179 $e->version = $upgradeRecord->version;
180 180 // 根据配置文件切换读取更新文件的路径
181   - if (isset(Yii::$app->params['UPGRADE_FILE_FROM']) && 'FROM_ECS' == Yii::$app->params['UPGRADE_FILE_FROM']) {
  181 + if (isset(Yii::$app->params['UPGRADE_FILE_FROM']) && 'FROM_OSS' == Yii::$app->params['UPGRADE_FILE_FROM']) {
182 182 $ossConfig = Yii::$app->params['ossOptions'];
183 183 $domainURL = $ossConfig['url'];
184 184 $filePath = $domainURL.'/'.$upgradeRecord->path;
... ... @@ -368,7 +368,7 @@ class UpgradeController extends BaseController
368 368 $e->version_message = '';
369 369 } else {
370 370  
371   - if (isset(Yii::$app->params['UPGRADE_FILE_FROM']) && 'FROM_ECS' == Yii::$app->params['UPGRADE_FILE_FROM']) {
  371 + if (isset(Yii::$app->params['UPGRADE_FILE_FROM']) && 'FROM_OSS' == Yii::$app->params['UPGRADE_FILE_FROM']) {
372 372 $ossConfig = Yii::$app->params['ossOptions'];
373 373 $domainURL = $ossConfig['url'];
374 374 $filePath = $domainURL.'/'.$upgradeRecord->path;
... ...
app-ht/modules/upgrade/controllers/UpgradeController.php
... ... @@ -554,8 +554,9 @@ class UpgradeController extends BaseController
554 554  
555 555 // 上传OSS
556 556  
557   - $fileService = new FileService();
558   - $fileService->add($uploadPath, $savePath);
  557 + /* 分两步上传
  558 + $fileService = new FileService();
  559 + $fileService->add($uploadPath, $savePath);*/
559 560  
560 561 // 删除服务器传成功的文件
561 562 //@unlink($uploadPath);
... ... @@ -572,6 +573,46 @@ class UpgradeController extends BaseController
572 573 }
573 574  
574 575 /**
  576 + * 同步文件到OSS
  577 + * @return array
  578 + */
  579 + public function actionPushOss()
  580 + {
  581 + $e = new stdClass();
  582 + try {
  583 + $request = Yii::$app->request;
  584 + $upgradeId = $request->post('upgrade_id');
  585 + $e->success = false;
  586 + $e->message = "";
  587 + if (empty($upgradeId)) {
  588 + $e->message = "缺少版本编号";
  589 + return $this->renderJson($e);
  590 + }
  591 + $upgradeModel = UpgradeRepository::findOne($upgradeId);
  592 + if (empty($upgradeModel)) {
  593 + $e->message = "该版本不存在";
  594 + return $this->renderJson($e);
  595 + }
  596 + $uploadPath = dirname(dirname(dirname(__DIR__))) . "/" . $upgradeModel->upload_path;
  597 + if (!file_exists($uploadPath)) {
  598 + $e->message = "该版本ECS文件不存在";
  599 + return $this->renderJson($e);
  600 + }
  601 + $savePath = $upgradeModel->path;
  602 + $fileService = new FileService();
  603 + $fileService->add($uploadPath, $savePath);
  604 + $upgradeModel->oss_upload_status = UpgradeStatus::OSS_UPLOAD_SUCCESS;
  605 + $upgradeModel->save();
  606 + $e->success = true;
  607 + $e->message = "同步OSS成功";
  608 + return $this->renderJson($e);
  609 + } catch (\Exception $ex) {
  610 + $e->message = "同步OSS异常:" . $ex->getMessage();
  611 + return $this->renderJson($e);
  612 + }
  613 + }
  614 +
  615 + /**
575 616 * 发布APP版本
576 617 * @return string
577 618 */
... ...
app-ht/modules/upgrade/views/upgrade/index.php
... ... @@ -115,18 +115,31 @@ $this->params['breadcrumbs'][] = $this->title;
115 115 <button class="btn btn-danger btn-sm btn_del" aid="<?=$item['id'] ?>">删除</button>
116 116 <?php if (isset($item["status"]) && UpgradeStatus::STATUS_WAIT == $item["status"]) { ?>
117 117 &nbsp;|&nbsp;
118   - <a class="btn btn-info btn-sm btn_auth_success" href="<?=Url::toRoute(["/upgrade/upgrade/edit", "uid" => $item['id']])?>" aid="<?=$item['id'] ?>">编辑</a>&nbsp;|&nbsp;
  118 + <a class="btn btn-info btn-sm btn_auth_success" href="<?=Url::toRoute(["/upgrade/upgrade/edit", "uid" => $item['id']])?>" aid="<?=$item['id'] ?>">编辑</a>
119 119 <?php if (isset($item["type"]) && UpgradeStatus::TYPE_OTA == $item["type"]) { ?>
120   - <a class="btn btn-info btn-sm btn_auth_success" href="<?=Url::toRoute(["/upgrade/upgrade/push-ota", "uid" => $item['id']])?>" aid="<?=$item['id'] ?>">发布</a>
  120 + <?php if (isset(Yii::$app->params['UPGRADE_FILE_FROM']) &&
  121 + 'FROM_OSS' == Yii::$app->params['UPGRADE_FILE_FROM']) {
  122 + if ( UpgradeStatus::OSS_UPLOAD_SUCCESS == $item["oss_upload_status"]) { ?>
  123 + &nbsp;|&nbsp; <a class="btn btn-info btn-sm btn_auth_success" href="<?=Url::toRoute(["/upgrade/upgrade/push-ota", "uid" => $item['id']])?>" aid="<?=$item['id'] ?>">发布</a>
  124 + <?php } } else { ?>
  125 + &nbsp;|&nbsp; <a class="btn btn-info btn-sm btn_auth_success" href="<?=Url::toRoute(["/upgrade/upgrade/push-ota", "uid" => $item['id']])?>" aid="<?=$item['id'] ?>">发布</a>
  126 + <?php } ?>
121 127 <?php } else { ?>
122   - <a class="btn btn-info btn-sm btn_auth_success" href="<?=Url::toRoute(["/upgrade/upgrade/push-app", "uid" => $item['id']])?>" aid="<?=$item['id'] ?>">发布</a>
  128 + <?php if (isset(Yii::$app->params['UPGRADE_FILE_FROM']) &&
  129 + 'FROM_OSS' == Yii::$app->params['UPGRADE_FILE_FROM']) {
  130 + if ( UpgradeStatus::OSS_UPLOAD_SUCCESS == $item["oss_upload_status"]) { ?>
  131 + &nbsp;|&nbsp; <a class="btn btn-info btn-sm btn_auth_success" href="<?=Url::toRoute(["/upgrade/upgrade/push-app", "uid" => $item['id']])?>" aid="<?=$item['id'] ?>">发布</a>
  132 + <?php } } else { ?>
  133 + &nbsp;|&nbsp; <a class="btn btn-info btn-sm btn_auth_success" href="<?=Url::toRoute(["/upgrade/upgrade/push-app", "uid" => $item['id']])?>" aid="<?=$item['id'] ?>">发布</a>
  134 + <?php } ?>
123 135 <?php } ?>
124 136 <?php } ?>
125   - <?php
126   - if (UpgradeStatus::STATUS_ON == $item["status"]) {
127   - ?>
128   - <a class="btn btn-info btn-sm btn_auth_cancel" aid="<?=$item['id'] ?>">取消发布</a>
  137 + <?php if (UpgradeStatus::STATUS_ON == $item["status"]) { ?>
  138 + &nbsp;|&nbsp; <a class="btn btn-info btn-sm btn_auth_cancel" aid="<?=$item['id'] ?>">取消发布</a>
129 139 <?php }?>
  140 + <?php if (isset($item["oss_upload_status"]) && UpgradeStatus::OSS_UPLOAD_WAIT == $item["oss_upload_status"]) { ?>
  141 + &nbsp;|&nbsp;<a class="btn btn-info btn-sm btn_upload_oss" aid="<?=$item['id'] ?>">同步OSS</a>
  142 + <?php }?>
130 143 </td>
131 144 </tr>
132 145 <?php endforeach; ?>
... ... @@ -207,5 +220,40 @@ $this-&gt;params[&#39;breadcrumbs&#39;][] = $this-&gt;title;
207 220 });
208 221 }
209 222 });
  223 +
  224 + $(".btn_upload_oss").bind("click",function () {
  225 + if (confirm("确定要同步该版本文件到OSS吗?")){
  226 + var data_id = $.trim($(this).attr("aid"));
  227 + if (data_id == null || data_id == ""){
  228 + alert("丢失参数,暂时无法取消,请刷新后再试");
  229 + return false;
  230 + }
  231 + var thiz = $(this);
  232 + thiz.text("同步中…");
  233 + var loding = $.loading();
  234 + loding.show();
  235 + $.ajax({
  236 + type: "post",
  237 + url: "<?=Url::toRoute('upgrade/push-oss')?>",
  238 + dataType:"json",
  239 + data: $.csrf({upgrade_id:data_id}),
  240 + success:function(res){
  241 + loding.hide();
  242 + loding = null;
  243 + if(!res.success) {
  244 + alert(res.message);
  245 + } else {
  246 + var versionType = $('#versionType').val();
  247 + window.location.href = 'index?type='+versionType;
  248 + }
  249 + },
  250 + error:function(msg){
  251 + loding.hide();
  252 + loding = null;
  253 + //提示确认失败
  254 + }
  255 + });
  256 + }
  257 + });
210 258 });
211 259 </script>
212 260 \ No newline at end of file
... ...
common/config/params.php
... ... @@ -11,7 +11,7 @@ return [
11 11 'url' => 'https://kingboard-prod.oss-cn-shenzhen.aliyuncs.com',
12 12 'styleUrl' => 'https://kingboard-prod.oss-cn-shenzhen.aliyuncs.com'
13 13 ],
14   - 'UPGRADE_FILE_FROM' => 'FROM_ECS',
  14 + 'UPGRADE_FILE_FROM' => 'FROM_OSS',
15 15 'AUTH_DEVICE_RSA_PKCS_1' => [
16 16 'PRIVATE' => require(__DIR__ . '/rsa/privateKey.php'),
17 17 'PUBLIC' => require(__DIR__ . '/rsa/publicKey.php')
... ...
domain/upgrade/UpgradeStatus.php
... ... @@ -34,6 +34,12 @@ class UpgradeStatus
34 34 const PACKAGE_TYPE_PART = 2; // 增量升级
35 35  
36 36 /**
  37 + * 同步OSS状态
  38 + */
  39 + const OSS_UPLOAD_WAIT = 1; // 等待同步OSS
  40 + const OSS_UPLOAD_SUCCESS = 2; // 同步OSS成功
  41 +
  42 + /**
37 43 * @return array
38 44 */
39 45 public static function statusLabels()
... ...