You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

117 lines
4.2 KiB
PHTML

5 years ago
<?php
namespace Home\Controller;
use Think\Controller;
use Think\Think;
5 years ago
use Base\Service\PromoteService;
use Base\Facade\Request;
use Base\Service\ApplyService;
5 years ago
/**
5 years ago
* @author elf<360197197@qq.com>
5 years ago
*/
5 years ago
5 years ago
class PackageController extends Controller
{
protected function _initialize()
{
C(api('Config/lists'));
}
5 years ago
public function downloadError($message)
5 years ago
{
5 years ago
$this->assign('message', $message);
$this->display('error');
5 years ago
}
5 years ago
public function download()
5 years ago
{
5 years ago
$code = I('code', '');
$gameId = I('game_id', 0);
$promoteId = I('promote_id', 0);
5 years ago
if ($code == '' && ($gameId == 0 || $promoteId == 0)) {
5 years ago
$this->redirect("package/downloadError", ['message' => '访问错误']);
5 years ago
}
5 years ago
$identifier = $code != '' ? $code : 'game_id/' . $gameId . '/promote_id/' . $promoteId;
$isBlack = M('device_bans', 'tab_')->where(['type' => 4, 'tag' => ['like', '%' . $identifier . '%']])->limit(1)->getField('id');
if ($isBlack) {
5 years ago
$this->redirect("package/downloadError", ['message' => '该链接已被禁']);
5 years ago
}
$applyService = new ApplyService();
5 years ago
if ($code != '') {
$data = $applyService->decodeApplyCode($code);
$result = $applyService->checkApplyCode($data, ApplyService::ENCRYPT_TYPE_DOWNLOAD);
if (!$result['status']) {
$this->error($result['message']);
5 years ago
}
5 years ago
$gameId = $data['game_id'];
$promoteId = $data['promote_id'];
}
$map = [];
$map['status'] = 1;
$map['enable_status'] = 1;
$map['game_id'] = $gameId;
$map['promote_id'] = $promoteId;
$columns = ['game_id', 'promote_id', 'promote_account', 'pack_url', 'plist_url', 'status', 'enable_status'];
$apply = M('apply','tab_')->field($columns)->where($map)->find();
if (!$apply) {
$this->redirect("package/downloadError", ['message' => '该链接已经停止使用']);
}
$promote = M('promote', 'tab_')->field(['id', 'parent_id', 'chain', 'level'])->where(['id' => $promoteId])->find();
5 years ago
$game = M('game','tab_')->field(['id', 'game_name', 'sdk_version', 'apply_auth'])->where(['id' => $apply['game_id']])->find();
if (!$applyService->checkSociatyPerm($promote, $game)) {
5 years ago
$this->redirect("package/downloadError", ['message' => '该链接已经失效']);
}
5 years ago
if (Request::isMobile()) {
if (!Request::isAndroid() && $game['sdk_version'] == 1) {
5 years ago
$this->redirect("package/downloadError", ['message' => '请使用安卓浏览器下载']);
5 years ago
}
if (!Request::isIOS() && $game['sdk_version'] == 2) {
5 years ago
$this->redirect("package/downloadError", ['message' => '请使用ios浏览器下载']);
5 years ago
}
}
5 years ago
$packageUrl = $game['sdk_version'] == 1 ? $apply['pack_url'] : $apply['plist_url'];
5 years ago
5 years ago
M('game','tab_')->where(['id' => $game['id']])->setInc('dow_num');
if (Request::isAndroid()) {
$this->gotoPkgUrl($packageUrl);
} else if (Request::isIOS()) {
$plistUrl = substr($packageUrl, 1, strlen($packageUrl));
header("HTTP/1.1 303 See Other");
5 years ago
header("Location: "."itms-services://?action=download-manifest&url=" . C('DOMAIN_DOWNLOAD') . '/' . ltrim($plistUrl, '/'));
5 years ago
} else {
5 years ago
$this->gotoPkgUrl($packageUrl);
5 years ago
}
}
5 years ago
private function gotoPkgUrl($packageUrl)
5 years ago
{
if (preg_match("/http/", $packageUrl)) {
5 years ago
$url = str_replace('-internal', '', $packageUrl);
echo "<script>window.location.href='$url';</script>";
} elseif (preg_match("/clouddn/", $packageUrl)) {
$url = "http://".$packageUrl;
redirect($url);
} elseif (preg_match("/myqcloud/", $packageUrl)) {
redirect($packageUrl);
} elseif(preg_match("/bcebos/", $packageUrl)) {
redirect($packageUrl);
} else {
if (!file_exists($packageUrl)) {
$this->error('文件不存在哦,亲!');
}else{
redirect(Request::getHost() . ltrim($packageUrl, '.'));
}
5 years ago
}
}
}