IndexController.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. 'articles1' => ArticleService::make()->getIndexList(5),
  75. // 轮播
  76. 'banners' => AdService::make()->getListByPosition(1),
  77. // 政策解读
  78. // 'readList'=> VideosReadsService::make()->getIndexList(),
  79. // 线上课程
  80. // 'courses' => [
  81. // CourseService::make()->getListByType(1),
  82. // CourseService::make()->getListByType(2),
  83. // CourseService::make()->getListByType(3),
  84. // ],
  85. ];
  86. return showJson(1010, true, $data);
  87. }
  88. /**
  89. * 院校列表
  90. * @return array
  91. */
  92. public function institutions()
  93. {
  94. $params = request()->all();
  95. $pageSize = isset($params['pageSize']) && $params['pageSize']? intval($params['pageSize']) : 20;
  96. $data = InstitutionService::make()->getDataList($params, $pageSize);
  97. return showJson(1010, true, $data);
  98. }
  99. /**
  100. * 验证更新
  101. * @return array
  102. */
  103. public function versionCheck()
  104. {
  105. $version = request()->post('version', '');
  106. $appSources = request()->post('app_sources', 'ios');
  107. $currentVersion = ConfigService::make()->getConfigByCode('app_version');
  108. if (getVersion($version) < getVersion($currentVersion)) {
  109. $data = [
  110. 'has_update' => true,
  111. 'app_version' => $currentVersion,
  112. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  113. 'app_url' => ConfigService::make()->getConfigByCode("app_{$appSources}_url"),
  114. 'is_force' => ConfigService::make()->getConfigByCode("app_force_update"),
  115. 'auto_update' => false, // 是否APP内自动更新
  116. ];
  117. return showJson(1010, true, $data);
  118. } else {
  119. return showJson(1010, false, ['has_update' => false, 'version' => $version]);
  120. }
  121. }
  122. }