Modules_Api_Controllers_BulletinController.proxy.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * 公告管理
  4. */
  5. declare (strict_types=1);
  6. namespace Modules\Api\Controllers;
  7. use App\Constants\AdConstrant;
  8. use App\Model\BulletinModel;
  9. use App\Repositories\Utils\M3u8CacheRepository;
  10. use Carbon\Carbon;
  11. use Modules\Api\Services\AuthService;
  12. use Modules\Api\Services\VideoService;
  13. use Psr\SimpleCache\CacheInterface;
  14. class BulletinController extends BaseController
  15. {
  16. use \Hyperf\Di\Aop\ProxyTrait;
  17. use \Hyperf\Di\Aop\PropertyHandlerTrait;
  18. function __construct()
  19. {
  20. if (method_exists(parent::class, '__construct')) {
  21. parent::__construct(...func_get_args());
  22. }
  23. $this->__handlePropertyHandler(__CLASS__);
  24. }
  25. /**
  26. * 首页数据
  27. * @return mixed
  28. */
  29. public function lists()
  30. {
  31. $userToken = (new AuthService())->getTokenUserInfo();
  32. $device = $userToken['device_type'] == 'A' ? 1 : 2;
  33. $cacheInterface = make(CacheInterface::class);
  34. $videoService = make(VideoService::class);
  35. $deviceAll = [$device, 3];
  36. // 公告
  37. $bulletinModel = $cacheInterface->remember('bulletin:' . $device, 60 * 60, function () use($deviceAll) {
  38. $nowData = Carbon::now()->toDateTimeString();
  39. 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();
  40. });
  41. $newData = [];
  42. $nowTime = time();
  43. $css = <<<HTML
  44. <link rel="stylesheet" type="text/css" href="http://h5.py163.xyz/app/rich_text/css/chuji_rich.css?v={$nowTime}">
  45. HTML;
  46. foreach ($bulletinModel as $bulletin) {
  47. $bulletin['ad_model'] = 2;
  48. $bulletin['text'] = $css . $bulletin['text'];
  49. $newData[] = $bulletin;
  50. }
  51. // 广告
  52. $adImageHomeItems = $videoService->getAdList(AdConstrant::IMAGES_HOME);
  53. if (!empty($adImageHomeItems)) {
  54. foreach ($adImageHomeItems as $adImagesV) {
  55. $link = M3u8CacheRepository::getLinkUrl($adImagesV['link'], ['user_code' => $userToken['user_id']]);
  56. $newData[] = ['ad_model' => 1, 'title' => $adImagesV['title'], 'cover' => M3u8CacheRepository::getImageUrl($adImagesV['cover']), 'link' => $link, 'scheme' => $adImagesV['scheme'], 'resolution' => $adImagesV['resolution']];
  57. }
  58. }
  59. return json_success($newData);
  60. }
  61. }