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.

129 lines
3.7 KiB
PHTML

5 years ago
<?php
namespace Base\Service;
use Base\Model\PromoteModel;
use Base\Model\ApplyModel;
use Base\Facade\Request;
5 years ago
class ApplyService {
const ENCRYPT_METHOD = 'AES-256-ECB';
const ENCRYPT_KEY = 'WmtX1@#Landing&Download2048';
const ENCRYPT_TYPE_DOWNLOAD = 1;
const ENCRYPT_TYPE_LANDING_PAGE = 2;
public static $enableStatusList = [
'-1' => '打包失败',
'0' => '打包失败',
'1' => '打包成功 ',
'2' => '准备打包 ',
'3' => '打包中',
];
5 years ago
public function __construct()
{
}
public function checkApplyStatus($apply)
{
if ($apply['status'] == 0) {
return [
'status' => false,
'message' => '游戏未审核',
];
}
if ($apply['offline_status'] == 1) {
return [
'status' => false,
'message' => '游戏已下架',
];
}
if ($apply['enable_status'] != 1) {
return [
'status' => false,
'message' => self::$enableStatusList[$apply['enable_status']] ?? '未知错误',
];
}
return [
'status' => true,
'message' => '游戏打包成功',
];
5 years ago
}
public function cancelGame($gameId, $promoteId) {
$ids = [$promoteId];
$list = M('promote', 'tab_')->field('id')->where('parent_id=' . $promoteId . ' or grand_id=' . $promoteId)->select();
$ids = array_merge($ids, array_column($list, 'id'));
5 years ago
$save['offline_status'] = 1;
M('apply', 'tab_')->where(['game_id' => $gameId, 'promote_id' => ['in', $ids]])->save($save);
5 years ago
}
public function getDownloadUrl($apply)
{
$host = Request::getHost();
$code = $this->encodeApplyCode($apply, self::ENCRYPT_TYPE_DOWNLOAD);
return $host . '/index.php?s=/Home/Download/index/code/' . $code;
}
public function getLandingPageUrl($apply)
{
$host = Request::getHost();
$code = $this->encodeApplyCode($apply, self::ENCRYPT_TYPE_LANDING_PAGE);
return $host . '/index.php?s=/Home/Home/landingPage/code/' . $code;
}
public function encodeApplyCode($apply, $type)
{
$expiresIn = 0;
$data = [
'promote_id' => $apply['promote_id'],
'game_id' => $apply['game_id'],
'expires_in' => $expiresIn,
'created_at' => date('Y-m-d H:i:s'),
'type' => $type
];
$jsonStr = json_encode($data);
return base64_encode(openssl_encrypt($jsonStr, self::ENCRYPT_METHOD, self::ENCRYPT_KEY));
}
public function decodeApplyCode($code)
{
$decryptStr = openssl_decrypt(base64_decode($code), self::ENCRYPT_METHOD, self::ENCRYPT_KEY);
return json_decode($decryptStr, true);
}
public function checkApplyCode($data, $type)
{
if (
!isset($data['promote_id']) ||
!isset($data['game_id']) ||
!isset($data['expires_in']) ||
!isset($data['created_at']) ||
!isset($data['type'])
) {
return [
'status' => false,
'message' => '参数异常',
];
}
if ($data['type'] != $type) {
return [
'status' => false,
'message' => '参数异常',
];
}
if ($data['expires_in'] > 0 && time() > (strtotime($data['created_at']) + $data['expires_in'])) {
return [
'status' => false,
'message' => '链接已过期',
];
}
return [
'status' => true,
'message' => '验证成功',
];
}
5 years ago
}