forked from XiaoLFeng/XF_Index
AddFeature: 赞助列表功能显示
添加赞助列表内容显示,前端构建及赞助方式API获取 修改: - api.php - Sponsor.php - sponsor.blade.php Signed-off-by: XiaoLFeng <gm@x-lf.cn>
This commit is contained in:
parent
566773e05b
commit
cfc71e1951
|
@ -9,9 +9,17 @@
|
|||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Controllers\Index;
|
||||
use ErrorException;
|
||||
use GuzzleHttp\Client;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
|
||||
class Sponsor extends Controller
|
||||
{
|
||||
|
@ -23,8 +31,135 @@ public function __construct()
|
|||
$this->data = $data->data;
|
||||
}
|
||||
|
||||
protected function viewSponsor(): Factory|View|Application
|
||||
protected function viewSponsor(): Application|Factory|View
|
||||
{
|
||||
// 获取赞助信息
|
||||
$this->getAfadianData();
|
||||
$this->data['sponsorCountNumber'] = count($this->data['sponsor']);
|
||||
$resultSponsorType = DB::table('sponsor_type')
|
||||
->get()
|
||||
->toArray();
|
||||
foreach ($resultSponsorType as $value) {
|
||||
$this->data['sponsorType'][$value->id] = [
|
||||
'id' => $value->id,
|
||||
'name' => $value->name,
|
||||
'url' => $value->url,
|
||||
'include' => $value->include,
|
||||
'link' => $value->link,
|
||||
];
|
||||
}
|
||||
$this->data['sponsorInfo'] = (new Index())->MarkdownToStringReplace(DB::table('info')->find(20)->data);
|
||||
$this->data['sponsorCountYear'] = 0;
|
||||
$this->data['sponsorCount'] = 0;
|
||||
foreach ($this->data['sponsorType'] as $value) {
|
||||
$this->data['sponsorURL'] = $value['url'];
|
||||
break;
|
||||
};
|
||||
foreach ($this->data['sponsor'] as $value) {
|
||||
$this->data['sponsorCount'] += $value['money'];
|
||||
if ($value['time'] >= date('Y') . '-01-01 00:00:00') {
|
||||
$this->data['sponsorCountYear'] += $value['money'];
|
||||
}
|
||||
}
|
||||
return view('function.sponsor', $this->data);
|
||||
}
|
||||
|
||||
public function apiSponsorType(Request $request): JsonResponse
|
||||
{
|
||||
$checkData = Validator::make($request->all(), [
|
||||
'id' => 'required|int',
|
||||
]);
|
||||
if (!$checkData->fails()) {
|
||||
$resultSponsorType = DB::table('sponsor_type')
|
||||
->where([['id', '=', $request->id]])
|
||||
->get()
|
||||
->toArray();
|
||||
$returnData = [
|
||||
'output' => 'Success',
|
||||
'code' => 200,
|
||||
'data' => $resultSponsorType[0],
|
||||
];
|
||||
} else {
|
||||
$returnData = [
|
||||
'output' => 'CheckFail',
|
||||
'code' => 403,
|
||||
'data' => [
|
||||
'message' => '输入参数有误',
|
||||
],
|
||||
];
|
||||
}
|
||||
return Response::json($returnData, $returnData['code']);
|
||||
}
|
||||
|
||||
private function getAfadianData(): void
|
||||
{
|
||||
$verify = ['verify' => true];
|
||||
if ($_SERVER['SERVER_PORT'] != 443) $verify = ['verify' => false];
|
||||
|
||||
// 从数据库获取数据
|
||||
$result = DB::table('info')
|
||||
->get()
|
||||
->toArray();
|
||||
$sponsor = DB::table('sponsor')
|
||||
->orderBy('time', 'desc')
|
||||
->limit(50)
|
||||
->get()
|
||||
->toArray();
|
||||
try {
|
||||
for ($i = 0; $sponsor[$i] != null; $i++) {
|
||||
$this->data['sponsor'][$i] = [
|
||||
'id' => $sponsor[$i]->id,
|
||||
'name' => $sponsor[$i]->name,
|
||||
'url' => $sponsor[$i]->url,
|
||||
'type' => $sponsor[$i]->type,
|
||||
'money' => $sponsor[$i]->money,
|
||||
'time' => $sponsor[$i]->time,
|
||||
];
|
||||
}
|
||||
} catch (ErrorException $e) {
|
||||
}
|
||||
$userID = $result[20]->data;
|
||||
$token = $result[21]->data;
|
||||
$time = time();
|
||||
$params = [
|
||||
'page' => 1,
|
||||
'per_page' => 50,
|
||||
];
|
||||
$sign = md5($token . 'params' . json_encode($params) . 'ts' . $time . 'user_id' . $userID);
|
||||
|
||||
$data = [
|
||||
'query' => [
|
||||
'user_id' => $userID,
|
||||
'params' => json_encode($params),
|
||||
'ts' => $time,
|
||||
'sign' => $sign,
|
||||
],
|
||||
];
|
||||
|
||||
$client = new Client($verify);
|
||||
try {
|
||||
$response = $client->get('https://afdian.net/api/open/query-sponsor', $data);
|
||||
$getData = json_decode($response->getBody()->getContents());
|
||||
} catch (GuzzleException $e) {
|
||||
return;
|
||||
}
|
||||
// 处理数据
|
||||
$j = 0;
|
||||
foreach ($getData->data->list as $value) {
|
||||
// 整合数据
|
||||
$data_elem[$j] = [
|
||||
'id' => $value->last_pay_time,
|
||||
'name' => $value->user->name,
|
||||
'url' => null,
|
||||
'type' => 5,
|
||||
'money' => (double)$value->all_sum_amount,
|
||||
'time' => date('Y-m-d H:i:s', $value->last_pay_time),
|
||||
];
|
||||
$j++;
|
||||
}
|
||||
$this->data['sponsor'] = array_merge($this->data['sponsor'], $data_elem);
|
||||
usort($this->data['sponsor'], function ($a, $b) {
|
||||
return strtotime($b['time']) - strtotime($a['time']);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
@include('modules.head')
|
||||
{!! $webHeader !!}
|
||||
</head>
|
||||
<body style="overflow: hidden;height: 100vh">
|
||||
<body style="height: 100vh">
|
||||
<div class="bg-white">
|
||||
@include('modules.navbar')
|
||||
<div class="relative isolate px-6 lg:px-8">
|
||||
|
@ -21,11 +21,62 @@ class="relative left-[calc(50%-11rem)] aspect-[1155/678] w-[36.125rem] -translat
|
|||
style="clip-path: polygon(74.1% 44.1%, 100% 61.6%, 97.5% 26.9%, 85.5% 0.1%, 80.7% 2%, 72.5% 32.5%, 60.2% 62.4%, 52.4% 68.1%, 47.5% 58.3%, 45.2% 34.5%, 27.5% 76.7%, 0.1% 64.9%, 17.9% 100%, 27.6% 76.8%, 76.1% 97.7%, 74.1% 44.1%)"></div>
|
||||
</div>
|
||||
<div class="mx-auto my-10 max-w-6xl py-8 sm:py-16 lg:py-16 grid grid-cols-12 gap-4">
|
||||
<div class="w-full p-4 bg-white border border-gray-200 rounded-lg shadow-lg sm:p-8 dark:bg-gray-800 dark:border-gray-700 col-span-12 lg:col-span-4">
|
||||
qwe
|
||||
<div class="col-span-12 lg:col-span-4">
|
||||
@csrf
|
||||
<div class="p-4 bg-white border border-gray-200 rounded-lg shadow-lg sm:p-8 dark:bg-gray-800 dark:border-gray-700 grid grid-cols-1">
|
||||
<img class="h-auto w-auto mx-auto rounded-lg mb-6" src="{{ $webIcon }}" alt="image description">
|
||||
<div class="text-xl font-bold text-center mb-1">{{ $sqlAuthor }}</div>
|
||||
<div class="text-center mb-3">{{ $webDescription }}</div>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2">
|
||||
<button data-modal-target="Modal" data-modal-toggle="Modal" type="button" class="text-white bg-gradient-to-r from-cyan-500 to-blue-500 hover:bg-gradient-to-bl focus:ring-4
|
||||
focus:outline-none focus:ring-cyan-300 dark:focus:ring-cyan-800 font-medium rounded-lg text-sm px-5 py-2.5 text-center mr-2 mb-2">
|
||||
详情
|
||||
</button>
|
||||
<button data-modal-target="ModalPay" data-modal-toggle="ModalPay" type="button" class="text-white bg-gradient-to-br from-green-400
|
||||
to-blue-600 hover:bg-gradient-to-bl focus:ring-4 focus:outline-none focus:ring-green-200 dark:focus:ring-green-800 font-medium
|
||||
rounded-lg text-sm px-5 py-2.5 text-center mr-2 mb-2">
|
||||
赞助
|
||||
</button>
|
||||
</div>
|
||||
<hr class="w-48 h-1 mx-auto my-1 bg-gray-100 border-0 rounded md:my-10 dark:bg-gray-700">
|
||||
<div class="p-2 bg-green-50 rounded-lg shadow-sm sm:p-4 dark:bg-gray-800 dark:border-gray-700 text-center mb-3">
|
||||
今年({{ date('Y') }})收款 <b>{{ $sponsorCountYear }}</b> 元
|
||||
</div>
|
||||
<div class="p-2 bg-pink-50 rounded-lg shadow-sm sm:p-4 dark:bg-gray-800 dark:border-gray-700 text-center mb-3">
|
||||
总计金额 <b>{{ $sponsorCount }}</b> 元
|
||||
</div>
|
||||
<div class="p-2 bg-blue-50 rounded-lg shadow-sm sm:p-4 dark:bg-gray-800 dark:border-gray-700 text-center">
|
||||
目前站长收到了 <b>{{ $sponsorCountNumber }}</b> 份赞助
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="w-full p-4 bg-white border border-gray-200 rounded-lg shadow-lg sm:p-8 dark:bg-gray-800 dark:border-gray-700 col-span-12 lg:col-span-8">
|
||||
qwe
|
||||
<div class="col-span-12 lg:col-span-8">
|
||||
<div class="flex p-4 bg-white border border-gray-200 rounded-lg shadow-lg sm:p-8 dark:bg-gray-800 dark:border-gray-700">
|
||||
@if($sponsor[0] != null)
|
||||
<ol class="w-full relative border-l border-gray-200 dark:border-gray-700">
|
||||
@foreach($sponsor as $value)
|
||||
<li class="mb-10 ml-6">
|
||||
<span class="absolute flex items-center justify-center w-6 h-6 bg-blue-100 rounded-full -left-3 ring-8 ring-white
|
||||
dark:ring-gray-900 dark:bg-blue-900">
|
||||
<i class="bi bi-calendar-check"></i>
|
||||
</span>
|
||||
<h3 class="flex items-center mb-1 text-lg font-semibold text-gray-900 dark:text-white">
|
||||
@if(!empty($value['url']))
|
||||
<a target="_blank" href="https://{{ $value['url'] }}">{{ $value['name'] }}</a>
|
||||
@else
|
||||
{{ $value['name'] }}
|
||||
@endif
|
||||
</h3>
|
||||
<time class="mb-2 text-sm font-normal leading-none text-gray-400 dark:text-gray-500 grid grid-cols-3">
|
||||
<div>{{ $value['time'] }}</div>
|
||||
<div class="text-center">{{ $sponsorType[$value['type']]['name'] }}</div>
|
||||
<div class="text-end"><b>{{ $value['money'] }}</b> CNY</div>
|
||||
</time>
|
||||
</li>
|
||||
@endforeach
|
||||
</ol>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
|
@ -35,39 +86,103 @@ class="absolute inset-x-0 top-[calc(100%-13rem)] -z-10 transform-gpu overflow-hi
|
|||
class="relative left-[calc(50%+3rem)] aspect-[1155/678] w-[36.125rem] -translate-x-1/2 bg-gradient-to-tr from-[#ff80b5] to-[#9089fc] opacity-30 sm:left-[calc(50%+36rem)] sm:w-[72.1875rem]"
|
||||
style="clip-path: polygon(74.1% 44.1%, 100% 61.6%, 97.5% 26.9%, 85.5% 0.1%, 80.7% 2%, 72.5% 32.5%, 60.2% 62.4%, 52.4% 68.1%, 47.5% 58.3%, 45.2% 34.5%, 27.5% 76.7%, 0.1% 64.9%, 17.9% 100%, 27.6% 76.8%, 76.1% 97.7%, 74.1% 44.1%)"></div>
|
||||
</div>
|
||||
@include('modules.footer')
|
||||
</div>
|
||||
</div>
|
||||
<footer class="fixed bottom-0 left-0 z-20 w-full p-4 md:flex md:items-end md:justify-between md:p-6">
|
||||
@if(empty($sqlIcp) && empty($sqlGongan))
|
||||
<div class="flex text-sm text-gray-500 dark:text-gray-400"></div>
|
||||
<div class="flex text-sm text-gray-500 dark:text-gray-400">
|
||||
<span class="flex justify-start"><i class="bi bi-c-circle"></i> @if(empty(!$sqlCopyRightYear))
|
||||
{{ $sqlCopyRightYear }}-{{ date('Y') }}
|
||||
@else
|
||||
{{ date('Y') }}
|
||||
@endif {{ $sqlAuthor }}. All Rights Reserved.</span>
|
||||
<!-- Modal -->
|
||||
<div id="Modal" tabindex="-1" aria-hidden="true" class="fixed top-0 left-0 right-0 z-50 hidden w-full p-4 overflow-x-hidden overflow-y-auto md:inset-0
|
||||
h-[calc(100%-1rem)] max-h-full">
|
||||
<div class="relative w-full max-w-2xl max-h-full">
|
||||
<!-- Modal content -->
|
||||
<div class="relative bg-white rounded-lg shadow dark:bg-gray-700">
|
||||
<!-- Modal header -->
|
||||
<div class="flex items-start justify-between p-4 border-b rounded-t dark:border-gray-600">
|
||||
<h3 class="text-xl font-semibold text-gray-900 dark:text-white">
|
||||
赞助说明
|
||||
</h3>
|
||||
<button type="button" class="text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm w-8 h-8 ml-auto
|
||||
inline-flex justify-center items-center dark:hover:bg-gray-600 dark:hover:text-white" data-modal-hide="Modal">
|
||||
<svg class="w-3 h-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14">
|
||||
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6"/>
|
||||
</svg>
|
||||
<span class="sr-only">Close modal</span>
|
||||
</button>
|
||||
</div>
|
||||
<!-- Modal body -->
|
||||
<div class="p-6 space-y-6">
|
||||
{!! $sponsorInfo !!}
|
||||
</div>
|
||||
<!-- Modal footer -->
|
||||
<div class="flex items-center p-6 space-x-2 border-t border-gray-200 rounded-b dark:border-gray-600">
|
||||
<button data-modal-hide="Modal" type="button" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none
|
||||
focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700
|
||||
dark:focus:ring-blue-800">
|
||||
我知道了
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@else
|
||||
<div class="flex text-sm text-gray-500 dark:text-gray-400">
|
||||
<span class="flex justify-start"><i class="bi bi-c-circle pe-2"></i> @if(empty(!$sqlCopyRightYear))
|
||||
{{ $sqlCopyRightYear }}-{{ date('Y') }}
|
||||
@else
|
||||
{{ date('Y') }}
|
||||
@endif {{ $sqlAuthor }}. All Rights Reserved.</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="ModalPay" tabindex="-1" aria-hidden="true" class="fixed top-0 left-0 right-0 z-50 hidden w-full p-4 overflow-x-hidden overflow-y-auto md:inset-0
|
||||
h-[calc(100%-1rem)] max-h-full">
|
||||
<div class="relative w-full max-w-2xl max-h-full">
|
||||
<!-- Modal content -->
|
||||
<div class="relative bg-white rounded-lg shadow dark:bg-gray-700">
|
||||
<!-- Modal header -->
|
||||
<div class="flex items-start justify-between p-4 border-b rounded-t dark:border-gray-600">
|
||||
<h3 class="text-xl font-semibold text-gray-900 dark:text-white">
|
||||
赞助方法
|
||||
</h3>
|
||||
<button type="button" class="text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm w-8 h-8 ml-auto
|
||||
inline-flex justify-center items-center dark:hover:bg-gray-600 dark:hover:text-white" data-modal-hide="ModalPay">
|
||||
<svg class="w-3 h-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14">
|
||||
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6"/>
|
||||
</svg>
|
||||
<span class="sr-only">Close modal</span>
|
||||
</button>
|
||||
</div>
|
||||
<!-- Modal body -->
|
||||
<div class="p-6 space-y-6 grid grid-cols-1">
|
||||
<img class="max-w-[256px] h-auto mx-auto" id="Image" src="{{ $sponsorURL }}" alt="">
|
||||
<div class="grid grid-cols-5 gap-4">
|
||||
@foreach($sponsorType as $value)
|
||||
<button @if(!$value['link']) onclick="clickType({{ $value['id'] }})" @endif type="button" class="text-white bg-gradient-to-r
|
||||
from-cyan-400 via-cyan-500 to-cyan-600 hover:bg-gradient-to-br focus:ring-4 focus:outline-none focus:ring-cyan-300
|
||||
dark:focus:ring-cyan-800 font-medium rounded-lg text-sm px-5 py-2.5 text-center mr-2 mb-2">
|
||||
<a @if($value['link'])href="{{ $value['url'] }}" target="_blank" @endif class="w-full">
|
||||
{{ $value['name'] }}
|
||||
</a>
|
||||
</button>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
<!-- Modal footer -->
|
||||
<div class="flex items-center p-6 space-x-2 bor border-t border-gray-200 rounded-b dark:border-gray-600">
|
||||
<button data-modal-hide="ModalPay" type="button" class="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:outline-none
|
||||
focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 text-center dark:bg-blue-600 dark:hover:bg-blue-700
|
||||
dark:focus:ring-blue-800">
|
||||
关闭页面
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="grid grid-cols-1 text-sm text-gray-500 dark:text-gray-400">
|
||||
@if(!empty($sqlIcp))
|
||||
<a href="https://beian.miit.gov.cn/"><span class="flex justify-end @if(!empty($sqlGongan))mb-1 @endif"><i class="bi bi-balloon pe-2"></i> {{ $sqlIcp }}</span></a>
|
||||
@endif
|
||||
@if(!empty($sqlGongan))
|
||||
<a href="https://www.beian.gov.cn/portal/registerSystemInfo?recordcode={{ $GonganCode }}"><span
|
||||
class="flex justify-end @if(!empty($sqlIcp))mt-1 @endif"><i class="bi bi-balloon-heart pe-2"></i> {{ $sqlGongan }}</span></a>
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
</footer>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
<script src="{{ asset('js/app.js') }}"></script>
|
||||
<script src="{{ asset('js/jquery.js') }}"></script>
|
||||
<script async src="{{ asset('js/jquery.js') }}"></script>
|
||||
<script type="text/javascript">
|
||||
function clickType(sponsorType) {
|
||||
$.ajax({
|
||||
async: true,
|
||||
method: "GET",
|
||||
url: '{{ route('api.sponsor.get-type','id=') }}' + sponsorType,
|
||||
dataType: "json",
|
||||
success: function (returnData) {
|
||||
$('#Image').attr('src', returnData.data.url);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
{!! $webFooter !!}
|
||||
</html>
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
use App\Http\Controllers\Authme;
|
||||
use App\Http\Controllers\Console\Link as ConsoleLink;
|
||||
use App\Http\Controllers\Function\Link;
|
||||
use App\Http\Controllers\Function\Sponsor;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
@ -25,9 +26,9 @@
|
|||
|
||||
// 登陆类
|
||||
Route::prefix('auth')->group(function () {
|
||||
Route::post('login',[Authme::class,'Login'])->name('api.auth.login');
|
||||
Route::post('register',[Authme::class,'Register'])->name('api.auth.register');
|
||||
Route::match(['get','post'],'logout',function () {
|
||||
Route::post('login', [Authme::class, 'Login'])->name('api.auth.login');
|
||||
Route::post('register', [Authme::class, 'Register'])->name('api.auth.register');
|
||||
Route::match(['get', 'post'], 'logout', function () {
|
||||
Auth::logout();
|
||||
return Response::redirectTo('');
|
||||
})->name('logout');
|
||||
|
@ -46,7 +47,11 @@
|
|||
Route::post('add', [Link::class, 'apiCustomAdd'])->name('api.link.custom.add');
|
||||
Route::post('edit/{friendId}', [Link::class, 'apiCustomEdit'])->name('api.link.custom.edit');
|
||||
Route::get('search', [Link::class, 'apiCustomSearch'])->name('api.link.custom.search');
|
||||
Route::post('blogCheck',[Link::class,'apiCustomBlogCheck'])->name('api.link.custom.blogCheck');
|
||||
Route::post('blogVerify',[Link::class,'apiCustomBlogVerify'])->name('api.link.custom.blogVerify');
|
||||
Route::post('blogCheck', [Link::class, 'apiCustomBlogCheck'])->name('api.link.custom.blogCheck');
|
||||
Route::post('blogVerify', [Link::class, 'apiCustomBlogVerify'])->name('api.link.custom.blogVerify');
|
||||
});
|
||||
});
|
||||
|
||||
Route::prefix('sponsor')->group(function () {
|
||||
Route::get('get-type', [Sponsor::class, 'apiSponsorType'])->name('api.sponsor.get-type');
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user