master
ELF 4 years ago
parent 9973e72bf3
commit 560fc4e4ba

@ -51,7 +51,18 @@ class SourceEvent extends Controller
$data['bao_name'] = $packageName;
$game = M('game', 'tab_')->where(['id' => $data['game_id']])->find();
$gameSourceService = new GameSourceService();
$result = $gameSourceService->sourcePack($data, $game);
$gameSourceData = array_merge(
$data,
[
'plist_url' => '',
'org_plist_url' => '',
'file_url' => '',
'original_url' => '',
]
);
$result = $gameSourceService->sourcePack($gameSourceData, $game);
if (!$result['status']) {
$this->error('添加失败' , U('GameSource/lists', ['type' => $data['type']]));
}
@ -114,8 +125,19 @@ class SourceEvent extends Controller
$data['bao_name'] = $packageName;
$game = M('game', 'tab_')->where(['id' => $data['game_id']])->find();
$gameSourceService = new GameSourceService();
$result = $gameSourceService->sourcePack($data, $game);
$gameSourceData = array_merge(
$data,
[
'plist_url' => $game_source['plist_url'],
'org_plist_url' => $game_source['org_plist_url'],
'file_url' => $game_source['file_url'],
'original_url' => $game_source['original_url'],
]
);
$result = $gameSourceService->sourcePack($gameSourceData, $game);
if (!$result['status']) {
if ($from == "dev") {
$this->error('修改失败', U('Developers/source'));
@ -135,7 +157,7 @@ class SourceEvent extends Controller
$app_data = $appmodel->where($app_map)->select();
if ($app_data) {
M()->startTrans();
$app_res = $appmodel->where($app_map)->save(['enable_status'=>2, 'pack_url'=>'', 'plist_url'=>'']);
$app_res = $appmodel->where($app_map)->save(['enable_status' => 2]);
M('apply_launch', 'tab_') -> where(['launch_game_id'=>$game_source['game_id']])->setField('launch_packge', 0);
if ($app_res === false) {
M()->rollback();

@ -1,6 +1,7 @@
<?php
namespace Base\Service;
use ZipArchive;
use Base\Model\PromoteModel;
use Base\Model\ApplyModel;
use Base\Tool\Base62;
@ -87,8 +88,8 @@ class GameSourceService {
'source_version' => $gameSource['source_version'],
];
$zip = new \ZipArchive();
if (!$zip->open($localPath, \ZipArchive::CREATE)) {
$zip = new ZipArchive();
if (!$zip->open($localPath, ZipArchive::CREATE)) {
return false;
}
@ -108,7 +109,7 @@ class GameSourceService {
/**
* 打入渠道信息文件
* @param string $zip 包文件
* @param ZipArchive $zip 包文件
* @param string $distFile 打入文件名
* @param array $packData 打入信息
* @return boolean 是否成功
@ -121,7 +122,7 @@ class GameSourceService {
/**
* 打入渠道信息目录用于IOS主要为了解决IOS13问题
* @param string $zip 包文件
* @param ZipArchive $zip 包文件
* @param string $distFolder 打入文件夹
* @return boolean 是否成功
*/
@ -159,6 +160,11 @@ class GameSourceService {
];
}
$this->removeOlderFile($gameSource['plist_url']);
$this->removeOlderFile($gameSource['org_plist_url']);
$this->removeOlderFile($gameSource['file_url']);
$this->removeOlderFile($gameSource['original_url']);
$distFilePath = 'SourcePack/' . $gameSource['file_name'];
$result = $this->uploadPackage($localPath, $distFilePath);
$fileUrl = '';
@ -168,7 +174,7 @@ class GameSourceService {
} else {
return [
'status' => false,
'message' => '打包失败,上传OSS失败!' . $result['message'],
'message' => '打包失败,上传文件失败!' . $result['message'],
];
}
@ -219,6 +225,31 @@ class GameSourceService {
];
}
private function isRemoteFile(string $file)
{
if (strpos($file, 'http://') === 0 || strpos($file, 'https://')) {
return true;
}
return false;
}
private function removeOlderFile(string $file)
{
if (!$file) {
return;
}
if ($this->isRemoteFile($file)) {
$urlInfo = parse_url($file);
$objectName = trim('/', $urlInfo['path']);
$this->deletePackage($objectName);
} else {
$olderPackage = ROOTTT . substr($file, 2);
if (file_exists($olderPackage)) {
unlink($olderPackage);
}
}
}
/**
* 渠道打包
*/
@ -242,8 +273,13 @@ class GameSourceService {
M('apply_launch', 'tab_')->where(['apply_id' => $apply['id'], 'launch_packge'=>['in', [0, 2, 3]]])->save($launchData);
}
$this->removeOlderFile($apply['pack_url']);
$this->removeOlderFile($apply['plist_url']);
$savePath = '';
$fileName = 'game_package' . $apply['game_id'] . '-' . $apply['promote_id'];
$fileName = substr(md5(microtime(true) . 'game_package' . $apply['game_id'] . '-' . $apply['promote_id']), 8 , 16);
if ($apply['sdk_version'] == 1) {
$fileName .= '.apk';
$savePath = 'Uploads/GamePack/' . $fileName;
@ -278,7 +314,7 @@ class GameSourceService {
} else {
return [
'status' => false,
'message' => '打包失败,上传OSS失败!' . $result['message'],
'message' => '打包失败,上传文件失败!' . $result['message'],
];
}
@ -349,6 +385,37 @@ class GameSourceService {
];
}
}
public function deletePackage($objectName)
{
$client = new Client([
'base_uri' => C('PACKAGE_CHUNK_URL'),
'timeout' => 30.0,
]);
try {
$response = $client->post('/delete', [
'verify' => false,
'form_params' => [
'file' => $objectName,
]
]);
$result = (string)$response->getBody();
$result = json_decode($result, true);
if (!$result) {
return [
'status' => false,
'message' => '请求异常',
];
}
} catch (\Exception $e) {
return [
'status' => false,
'message' => '请求异常: ' . $e->getMessage(),
];
}
return $result;
}
public function uploadPackageChunk($localFilePath, $distFilePath, $isDeleteLocal = false)
{
$client = new Client([
@ -449,17 +516,15 @@ class GameSourceService {
}
}
$fileName = '';
$fileName = substr(md5($type . '_' . $gameId . '_' . $promoteId . '_' . $platformId . '_' . $position . '_' . microtime()), 8, 16);
if ($type == 'pack') {
if ($promoteId == 0) {
$fileName = 'Uploads/SourcePlist/'. $gameId . '.Plist';
} elseif ($platformId > 0) {
$fileName = 'Uploads/GamePlist/'. $gameId . '-' . $promoteId . '-' . $platformId . '-' .$position . '.Plist';
$fileName = 'Uploads/SourcePlist/'. $fileName . '.Plist';
} else {
$fileName = 'Uploads/GamePlist/'. $gameId . '-' . $promoteId . '.Plist';
$fileName = 'Uploads/GamePlist/'. $fileName . '.Plist';
}
} elseif ($type == 'org') {
$fileName = 'Uploads/OrgSourcePlist/'. $gameId . '.Plist';
$fileName = 'Uploads/OrgSourcePlist/'. $fileName . '.Plist';
}
$xml->save('./' . $fileName);
return [

Loading…
Cancel
Save