BulletinController.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. /**
  17. * 首页数据
  18. * @return mixed
  19. */
  20. public function lists()
  21. {
  22. $userToken = (new AuthService)->getTokenUserInfo();
  23. $device = $userToken['device_type'] == 'A' ? 1 : 2;
  24. $cacheInterface = make(CacheInterface::class);
  25. $videoService = make(VideoService::class);
  26. $deviceAll = [$device,3];
  27. // 公告
  28. $bulletinModel = $cacheInterface->remember(
  29. 'bulletin:' . $device,
  30. 60 * 60,
  31. function () use ($deviceAll) {
  32. $nowData = Carbon::now()->toDateTimeString();
  33. return BulletinModel::query()
  34. ->whereNull('deleted_at')
  35. ->whereIn('device', $deviceAll)
  36. ->where([
  37. ['status', '=', 1],
  38. ['start_time', '<', $nowData],
  39. ['end_time', '>', $nowData],
  40. ])
  41. ->orderByDesc('sort')
  42. ->get(['title', 'sort', 'start_time', 'end_time', 'text'])
  43. ->toArray();
  44. }
  45. );
  46. $newData = [];
  47. $nowTime = time();
  48. $css = <<<HTML
  49. <link rel="stylesheet" type="text/css" href="http://h5.py163.xyz/app/rich_text/css/chuji_rich.css?v={$nowTime}">
  50. HTML;
  51. foreach ($bulletinModel as $bulletin){
  52. $bulletin['ad_model'] = 2;
  53. $bulletin['text'] = $css.$bulletin['text'];
  54. $newData[] = $bulletin;
  55. }
  56. // 广告
  57. $adImageHomeItems = $videoService->getAdList(AdConstrant::IMAGES_HOME);
  58. if (!empty($adImageHomeItems)) {
  59. foreach ($adImageHomeItems as $adImagesV) {
  60. $link = M3u8CacheRepository::getLinkUrl($adImagesV['link'], ['user_code' => $userToken['user_id']]);
  61. $newData[] = [
  62. 'ad_model'=>1,
  63. 'title' => $adImagesV['title'],
  64. 'cover' => M3u8CacheRepository::getImageUrl($adImagesV['cover']),
  65. 'link' => $link,
  66. 'scheme' => $adImagesV['scheme'],
  67. 'resolution' => $adImagesV['resolution'],
  68. ];
  69. }
  70. }
  71. return json_success($newData);
  72. }
  73. }