2023-06-16 12:02:02 +08:00
< ? php
/*
* Copyright © 2016 - 2023 筱锋xiao_lfeng . All Rights Reserved .
* 开发开源遵循 MIT 许可,若需商用请联系开发者
* https :// www . x - lf . com /
*/
namespace App\Http\Controllers\Console ;
use App\Http\Controllers\Controller ;
use App\Http\Controllers\Index ;
use Illuminate\Contracts\Foundation\Application ;
use Illuminate\Contracts\View\Factory ;
use Illuminate\Contracts\View\View ;
use Illuminate\Http\RedirectResponse ;
use Illuminate\Http\Request ;
use Illuminate\Support\Facades\DB ;
use Illuminate\Support\Facades\Response ;
class Link extends Controller
{
protected array $data ;
public function __construct ()
{
$data = new Index ();
$this -> data = $data -> data ;
}
2023-06-16 13:12:32 +08:00
public function ViewEdit ( Request $request , $userId ) : Application | Factory | View | RedirectResponse
{
// 查找友链
$resultBlog = DB :: table ( 'blog_link' )
-> find ( $userId );
$this -> data [ 'blog' ] = [
$resultBlog ,
];
2023-06-16 17:19:01 +08:00
$this -> data [ 'blogSort' ] = DB :: table ( 'blog_sort' )
-> orderBy ( 'sort' )
-> get ()
-> toArray ();
$this -> data [ 'blogColor' ] = DB :: table ( 'blog_color' )
-> orderBy ( 'id' )
-> get ()
-> toArray ();
2023-06-16 13:12:32 +08:00
// 没有查询到执行删除
if ( $this -> data [ 'blog' ][ 0 ] == null ) return Response :: redirectTo ( route ( 'console.friends-link.list' ));
return view ( 'console.friends-link.edit' , $this -> data );
}
2023-06-16 12:02:02 +08:00
protected function ViewList ( Request $request ) : Factory | View | Application | RedirectResponse
{
2023-06-16 12:42:33 +08:00
$this -> data [ 'request' ] = $request ;
2023-06-16 12:02:02 +08:00
$dataMarge = [
'blogFriendsTotal' => DB :: table ( 'blog_link' )
-> whereNotIn ( 'blog_link.blogLocation' , [ 0 ])
-> count (),
'blogFriendsCheck' => DB :: table ( 'blog_link' )
-> where ( 'blog_link.blogLocation' , 0 )
-> count (),
'blogFriendsBest' => DB :: table ( 'blog_link' )
-> where ( 'blog_link.blogLocation' , 2 )
-> count (),
];
if ( empty ( $request -> search )) {
// 获取数据库信息
if ( empty ( $request -> page )) $request -> page = 0 ;
$this -> data [ 'blog' ] = DB :: table ( 'blog_link' )
2023-06-16 13:12:32 +08:00
-> whereNotIn ( 'blogLocation' , [ 0 ])
2023-06-16 12:02:02 +08:00
-> orderBy ( 'id' )
2023-06-16 13:12:32 +08:00
-> offset ( $request -> page * 10 )
2023-06-16 12:02:02 +08:00
-> limit ( 10 )
-> get ()
-> toArray ();
$this -> data [ 'blogCount' ] = DB :: table ( 'blog_link' )
2023-06-16 13:12:32 +08:00
-> whereNotIn ( 'blogLocation' , [ 0 ])
2023-06-16 12:02:02 +08:00
-> orderBy ( 'id' )
-> count ();
$this -> data [ 'webClass' ] = [
'active' => 'px-3 py-2 text-blue-600 border border-gray-300 bg-blue-50 hover:bg-blue-100 hover:text-blue-700 dark:border-gray-700 dark:bg-gray-700 dark:text-white' ,
'unactive' => 'px-3 py-2 leading-tight text-gray-500 bg-white border border-gray-300 hover:bg-gray-100 hover:text-gray-700 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400 dark:hover:bg-gray-700 dark:hover:text-white' ,
];
2023-06-16 13:12:32 +08:00
$this -> data [ 'blogCount' ] = ceil ( $this -> data [ 'blogCount' ] / 10 );
if ( $this -> data [ 'request' ] -> page > $this -> data [ 'blogCount' ] - 1 ) return Response :: redirectTo ( route ( 'console.friends-link.list' ));
2023-06-16 12:02:02 +08:00
} else {
$this -> data [ 'blog' ] = DB :: select ( " SELECT * FROM xf_index.blog_link WHERE blogName LIKE '% $request->search %' OR blogUrl LIKE '% $request->search %' ORDER BY id " );
}
$this -> data = array_merge ( $this -> data , $dataMarge );
return view ( 'console.friends-link.list' , $this -> data );
}
2023-06-16 13:12:32 +08:00
protected function ViewCheck ( Request $request ) : Factory | View | Application
{
2023-06-24 22:51:03 +08:00
// 检查是否存在含有未在本站分配位置
$this -> data [ 'blog' ] = DB :: table ( 'blog_link' )
-> whereIn ( 'blog_link.blogLocation' ,[ 0 ])
-> get ()
-> toArray ();
2023-06-16 13:12:32 +08:00
return view ( 'console.friends-link.check' , $this -> data );
}
2023-06-16 12:02:02 +08:00
2023-06-16 13:12:32 +08:00
protected function ViewAdd ( Request $request ) : Factory | View | Application
{
return view ( 'console.friends-link.add' , $this -> data );
}
2023-06-16 17:19:01 +08:00
protected function ViewSort () : Factory | View | Application
{
return view ( 'console.friends-link.sort' , $this -> data );
}
protected function ViewColor () : Factory | View | Application
{
2023-06-24 22:51:03 +08:00
return view ( 'console.friends-link.color' , $this -> data );
}
protected function apiConsoleAdd () {
// 检查数据
2023-06-16 17:19:01 +08:00
}
2023-06-16 12:02:02 +08:00
}