| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- /**
- * 公告管理
- */
- declare(strict_types=1);
- namespace Modules\Api\Controllers;
- use App\Constants\AdConstrant;
- use App\Model\BulletinModel;
- use App\Repositories\Utils\M3u8CacheRepository;
- use Carbon\Carbon;
- use Modules\Api\Services\AuthService;
- use Modules\Api\Services\VideoService;
- use Psr\SimpleCache\CacheInterface;
- class BulletinController extends BaseController
- {
- /**
- * 首页数据
- * @return mixed
- */
- public function lists()
- {
- $userToken = (new AuthService)->getTokenUserInfo();
- $device = $userToken['device_type'] == 'A' ? 1 : 2;
- $cacheInterface = make(CacheInterface::class);
- $videoService = make(VideoService::class);
- $deviceAll = [$device,3];
- // 公告
- $bulletinModel = $cacheInterface->remember(
- 'bulletin:' . $device,
- 60 * 60,
- function () use ($deviceAll) {
- $nowData = Carbon::now()->toDateTimeString();
- return BulletinModel::query()
- ->whereNull('deleted_at')
- ->whereIn('device', $deviceAll)
- ->where([
- ['status', '=', 1],
- ['start_time', '<', $nowData],
- ['end_time', '>', $nowData],
- ])
- ->orderByDesc('sort')
- ->get(['title', 'sort', 'start_time', 'end_time', 'text'])
- ->toArray();
- }
- );
- $newData = [];
- $nowTime = time();
- $css = <<<HTML
- <link rel="stylesheet" type="text/css" href="http://h5.py163.xyz/app/rich_text/css/chuji_rich.css?v={$nowTime}">
- HTML;
- foreach ($bulletinModel as $bulletin){
- $bulletin['ad_model'] = 2;
- $bulletin['text'] = $css.$bulletin['text'];
- $newData[] = $bulletin;
- }
- // 广告
- $adImageHomeItems = $videoService->getAdList(AdConstrant::IMAGES_HOME);
- if (!empty($adImageHomeItems)) {
- foreach ($adImageHomeItems as $adImagesV) {
- $link = M3u8CacheRepository::getLinkUrl($adImagesV['link'], ['user_code' => $userToken['user_id']]);
- $newData[] = [
- 'ad_model'=>1,
- 'title' => $adImagesV['title'],
- 'cover' => M3u8CacheRepository::getImageUrl($adImagesV['cover']),
- 'link' => $link,
- 'scheme' => $adImagesV['scheme'],
- 'resolution' => $adImagesV['resolution'],
- ];
- }
- }
- return json_success($newData);
- }
- }
|