同步更改
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* 游戏下载控制器
|
||||
* 资源下载控制器
|
||||
*/
|
||||
namespace app\index\controller;
|
||||
use app\index\controller\BaseController;
|
||||
@@ -27,6 +27,8 @@ use think\facade\Request;
|
||||
use app\index\model\Resources\Resources;
|
||||
use app\index\model\Resources\ResourcesCategory;
|
||||
use app\index\model\Attachments;
|
||||
use app\index\model\Users;
|
||||
use app\index\model\Articles\Articles;
|
||||
|
||||
class ResourcesController extends BaseController
|
||||
{
|
||||
@@ -66,7 +68,7 @@ class ResourcesController extends BaseController
|
||||
return View::fetch();
|
||||
}
|
||||
|
||||
// 游戏列表页
|
||||
// 资源列表页
|
||||
public function list()
|
||||
{
|
||||
$cid = input('cid/d', 0);
|
||||
@@ -99,60 +101,84 @@ class ResourcesController extends BaseController
|
||||
return View::fetch('list');
|
||||
}
|
||||
|
||||
// 游戏详情页
|
||||
// 资源详情页
|
||||
public function detail()
|
||||
{
|
||||
$id = Request::param('id/d', 0);
|
||||
$game = Resources::where('id', $id)->find();
|
||||
$resources = Resources::where('id', $id)->find();
|
||||
|
||||
if (!$game) {
|
||||
return json(['code' => 0, 'msg' => '游戏不存在或已被删除']);
|
||||
if (!$resources) {
|
||||
return json(['code' => 0, 'msg' => '资源不存在或已被删除']);
|
||||
}
|
||||
|
||||
// 如果size没有,从附件表中获取
|
||||
if (empty($game['size']) && !empty($game['fileurl'])) {
|
||||
$attachment = Attachments::where('src', $game['fileurl'])
|
||||
if (empty($resources['size']) && !empty($resources['fileurl'])) {
|
||||
$attachment = Attachments::where('src', $resources['fileurl'])
|
||||
->find();
|
||||
|
||||
if ($attachment && !empty($attachment['size'])) {
|
||||
$size = $attachment['size'];
|
||||
// 转换文件大小为合适的单位
|
||||
if ($size >= 1073741824) { // 1GB = 1024MB = 1024*1024KB = 1024*1024*1024B
|
||||
$game['size'] = round($size / 1073741824, 2) . 'GB';
|
||||
$resources['size'] = round($size / 1073741824, 2) . 'GB';
|
||||
} elseif ($size >= 1048576) { // 1MB = 1024KB = 1024*1024B
|
||||
$game['size'] = round($size / 1048576, 2) . 'MB';
|
||||
$resources['size'] = round($size / 1048576, 2) . 'MB';
|
||||
} else {
|
||||
$game['size'] = round($size / 1024, 2) . 'KB';
|
||||
$resources['size'] = round($size / 1024, 2) . 'KB';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取分类名称
|
||||
$cateName = ResourcesCategory::where('id', $game['cate'])
|
||||
$cateName = ResourcesCategory::where('id', $resources['cate'])
|
||||
->value('name');
|
||||
|
||||
// 获取上一个和下一个游戏
|
||||
$prevGame = Resources::where('id', '<', $id)
|
||||
// 获取作者信息
|
||||
$authorInfo = Users::where('name', $resources['uploader'])->find();
|
||||
// var_dump($authorInfo);
|
||||
if ($authorInfo) {
|
||||
// 统计作者的文章数
|
||||
$resourcesCount = Articles::where('author', $resources['uploader'])->count();
|
||||
// 统计作者的资源数
|
||||
$resourceCount = Resources::where('uploader', $resources['uploader'])->count();
|
||||
|
||||
$authorData = [
|
||||
'avatar' => $authorInfo['avatar'] ?: '/static/images/avatar.png',
|
||||
'name' => $authorInfo['name'],
|
||||
'resource_count' => $resourceCount,
|
||||
'article_count' => $resourcesCount
|
||||
];
|
||||
} else {
|
||||
$authorData = [
|
||||
'avatar' => '/static/images/avatar.png',
|
||||
'name' => $resources['author'],
|
||||
'resource_count' => 0,
|
||||
'article_count' => 0
|
||||
];
|
||||
}
|
||||
|
||||
// 获取上一个和下一个资源
|
||||
$prevResources = Resources::where('id', '<', $id)
|
||||
->where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->where('cate', $game['cate'])
|
||||
->where('cate', $resources['cate'])
|
||||
->field(['id', 'title'])
|
||||
->order('id DESC')
|
||||
->find();
|
||||
|
||||
$nextGame = Resources::where('id', '>', $id)
|
||||
$nextResources = Resources::where('id', '>', $id)
|
||||
->where('delete_time', null)
|
||||
->where('status', 1)
|
||||
->where('cate', $game['cate'])
|
||||
->where('cate', $resources['cate'])
|
||||
->field(['id', 'title'])
|
||||
->order('id ASC')
|
||||
->find();
|
||||
|
||||
// 获取相关游戏(同分类的其他游戏)
|
||||
$relatedGames = Db::table('yz_resources')
|
||||
// 获取相关资源(同分类的其他资源)
|
||||
$relatedResourcess = Db::table('yz_resources')
|
||||
->alias('g')
|
||||
->join('yz_resources_category c', 'g.cate = c.id')
|
||||
->where('g.cate', $game['cate'])
|
||||
->where('g.cate', $resources['cate'])
|
||||
->where('g.id', '<>', $id)
|
||||
->where('g.delete_time', null)
|
||||
->where('g.status', 1)
|
||||
@@ -162,7 +188,7 @@ class ResourcesController extends BaseController
|
||||
'IF(g.icon IS NULL OR g.icon = "", c.icon, g.icon) as icon'
|
||||
])
|
||||
->order('g.id DESC')
|
||||
->limit(3)
|
||||
->limit(5)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
@@ -172,28 +198,29 @@ class ResourcesController extends BaseController
|
||||
'code' => 1,
|
||||
'msg' => '获取成功',
|
||||
'data' => [
|
||||
'game' => $game,
|
||||
'resources' => $resources,
|
||||
'cateName' => $cateName,
|
||||
'prevGame' => $prevGame,
|
||||
'nextGame' => $nextGame,
|
||||
'relatedGames' => $relatedGames
|
||||
'prevResources' => $prevResources,
|
||||
'nextResources' => $nextResources,
|
||||
'relatedResourcess' => $relatedResourcess
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
// 非 AJAX 请求返回视图
|
||||
View::assign([
|
||||
'game' => $game,
|
||||
'resources' => $resources,
|
||||
'cateName' => $cateName,
|
||||
'prevGame' => $prevGame,
|
||||
'nextGame' => $nextGame,
|
||||
'relatedGames' => $relatedGames
|
||||
'authorInfo' => $authorData,
|
||||
'prevResources' => $prevResources,
|
||||
'nextResources' => $nextResources,
|
||||
'relatedResourcess' => $relatedResourcess
|
||||
]);
|
||||
|
||||
return View::fetch('detail');
|
||||
}
|
||||
|
||||
// 游戏下载
|
||||
// 资源下载
|
||||
public function downloadurl()
|
||||
{
|
||||
if (!Request::isAjax()) {
|
||||
@@ -202,13 +229,13 @@ class ResourcesController extends BaseController
|
||||
|
||||
$id = Request::param('id/d', 0);
|
||||
|
||||
// 获取游戏信息
|
||||
$game = Resources::where('id', $id)
|
||||
// 获取资源信息
|
||||
$resources = Resources::where('id', $id)
|
||||
->where('delete_time', null)
|
||||
->find();
|
||||
|
||||
if (!$game) {
|
||||
return json(['code' => 0, 'msg' => '游戏不存在']);
|
||||
if (!$resources) {
|
||||
return json(['code' => 0, 'msg' => '资源不存在']);
|
||||
}
|
||||
|
||||
// 更新下载次数
|
||||
@@ -222,7 +249,7 @@ class ResourcesController extends BaseController
|
||||
'code' => 1,
|
||||
'msg' => '下载成功',
|
||||
'data' => [
|
||||
'url' => $game['url']
|
||||
'url' => $resources['url']
|
||||
]
|
||||
]);
|
||||
} else {
|
||||
@@ -248,7 +275,7 @@ class ResourcesController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新游戏访问次数
|
||||
* 更新资源访问次数
|
||||
*/
|
||||
public function updateViews()
|
||||
{
|
||||
@@ -263,9 +290,9 @@ class ResourcesController extends BaseController
|
||||
|
||||
try {
|
||||
// 更新访问次数
|
||||
$game = Resources::where('id', $id)->find();
|
||||
if (!$game) {
|
||||
return json(['code' => 0, 'msg' => '游戏不存在']);
|
||||
$resources = Resources::where('id', $id)->find();
|
||||
if (!$resources) {
|
||||
return json(['code' => 0, 'msg' => '资源不存在']);
|
||||
}
|
||||
|
||||
// 更新访问次数
|
||||
|
||||
Reference in New Issue
Block a user