| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?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
- {
- use \Hyperf\Di\Aop\ProxyTrait;
- use \Hyperf\Di\Aop\PropertyHandlerTrait;
- function __construct()
- {
- if (method_exists(parent::class, '__construct')) {
- parent::__construct(...func_get_args());
- }
- $this->__handlePropertyHandler(__CLASS__);
- }
- /**
- * 首页数据
- * @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);
- }
- }
|