IndexController.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Services\Api\ArticleService;
  5. use App\Services\Api\CourseService;
  6. use App\Services\Common\AdService;
  7. use App\Services\Common\InstitutionService;
  8. use App\Services\Common\NoticeService;
  9. use App\Services\Common\VideosReadsService;
  10. use App\Services\ConfigService;
  11. use App\Services\RedisService;
  12. /**
  13. * 首页
  14. * Class IndexController
  15. * @package App\Http\Controllers\Api
  16. */
  17. class IndexController extends webApp
  18. {
  19. /**
  20. * 配置信息
  21. * @return array
  22. */
  23. public function config()
  24. {
  25. try {
  26. $appSources = request()->post('app_sources', 'ios');
  27. $cacheKey = "caches:config:app_{$appSources}";
  28. $config = RedisService::get($cacheKey);
  29. if (empty($config)) {
  30. $config = [
  31. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  32. 'app_logo' => get_image_url(ConfigService::make()->getConfigByCode('app_logo')),
  33. 'app_version' => ConfigService::make()->getConfigByCode('app_version'),
  34. 'wxpay_open' => ConfigService::make()->getConfigByCode('wxpay_open', 1),
  35. 'vip_buy_desc' => format_content(ConfigService::make()->getConfigByCode('vip_buy_desc', '')),
  36. 'zsb_vip_buy_desc' => format_content(ConfigService::make()->getConfigByCode('zsb_vip_buy_desc', '')),
  37. 'show_zsb_entry' => ConfigService::make()->getConfigByCode('show_zsb_entry', 0),
  38. 'show_index_video' => ConfigService::make()->getConfigByCode('show_index_video', 0),
  39. 'show_read_video' => ConfigService::make()->getConfigByCode('show_read_video', 0),
  40. 'qq_map_key' => ConfigService::make()->getConfigByCode('qq_map_key', ''),
  41. 'show_popup_time' => ConfigService::make()->getConfigByCode('show_popup_time', 0),
  42. 'video_form_auto_close' => ConfigService::make()->getConfigByCode('video_form_auto_close', 0),
  43. 'video_read_switch_time' => ConfigService::make()->getConfigByCode('video_read_switch_time', 3),
  44. 'share_desc' => ConfigService::make()->getConfigByCode('share_desc', ''),
  45. 'share_content' => ConfigService::make()->getConfigByCode('share_content', ''),
  46. 'custom_name' => ConfigService::make()->getConfigByCode('custom_name', ''),
  47. 'custom_desc' => format_content(ConfigService::make()->getConfigByCode('custom_desc', '')),
  48. 'show_custom_header' => format_content(ConfigService::make()->getConfigByCode('show_custom_header', 0)),
  49. 'video_vip_tips' => format_content(ConfigService::make()->getConfigByCode('video_vip_tips', '')),
  50. 'errors' => config('platform.errors'),
  51. ];
  52. RedisService::set($cacheKey, $config, 3600);
  53. }
  54. return showJson(1010, true, $config);
  55. } catch (\Exception $exception) {
  56. RedisService::set("caches:request:error_config", ['trace' => $exception->getTrace()], 7200);
  57. return showJson(1018, false, ['error' => env('APP_DEBUG') ? $exception->getMessage() : '']);
  58. }
  59. }
  60. /**
  61. * 首页数据
  62. * @return array
  63. */
  64. public function data()
  65. {
  66. $data = [
  67. // 菜单
  68. 'menuList' => config('platform.menuList'),
  69. // 公告
  70. 'notices' => NoticeService::make()->getRecommandList(),
  71. // 资讯
  72. 'articles' => ArticleService::make()->getIndexList(1),
  73. // 轮播
  74. 'banners' => AdService::make()->getListByPosition(1),
  75. // 政策解读
  76. 'readList'=> VideosReadsService::make()->getIndexList(),
  77. // 线上课程
  78. 'courses' => [
  79. CourseService::make()->getListByType(1),
  80. CourseService::make()->getListByType(2),
  81. CourseService::make()->getListByType(3),
  82. ],
  83. ];
  84. return showJson(1010, true, $data);
  85. }
  86. /**
  87. * 院校列表
  88. * @return array
  89. */
  90. public function institutions()
  91. {
  92. $params = request()->all();
  93. $pageSize = isset($params['pageSize']) && $params['pageSize']? intval($params['pageSize']) : 20;
  94. $data = InstitutionService::make()->getDataList($params, $pageSize);
  95. return showJson(1010, true, $data);
  96. }
  97. /**
  98. * 验证更新
  99. * @return array
  100. */
  101. public function versionCheck()
  102. {
  103. $version = request()->post('version', '');
  104. $appSources = request()->post('app_sources', 'ios');
  105. $currentVersion = ConfigService::make()->getConfigByCode('app_version');
  106. if (getVersion($version) < getVersion($currentVersion)) {
  107. $data = [
  108. 'has_update' => true,
  109. 'app_version' => $currentVersion,
  110. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  111. 'app_url' => ConfigService::make()->getConfigByCode("app_{$appSources}_url"),
  112. 'is_force' => ConfigService::make()->getConfigByCode("app_force_update"),
  113. 'auto_update' => false, // 是否APP内自动更新
  114. ];
  115. return showJson(1010, true, $data);
  116. } else {
  117. return showJson(1010, false, ['has_update' => false, 'version' => $version]);
  118. }
  119. }
  120. }