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_1_buy_desc' => format_content(ConfigService::make()->getConfigByCode('vip_1_buy_desc', '')),
  36. 'vip_2_buy_desc' => format_content(ConfigService::make()->getConfigByCode('vip_2_buy_desc', '')),
  37. 'vip_3_buy_desc' => format_content(ConfigService::make()->getConfigByCode('vip_3_buy_desc', '')),
  38. 'vip_4_buy_desc' => format_content(ConfigService::make()->getConfigByCode('vip_4_buy_desc', '')),
  39. 'show_index_video' => ConfigService::make()->getConfigByCode('show_index_video', 0),
  40. 'show_read_video' => ConfigService::make()->getConfigByCode('show_read_video', 0),
  41. 'qq_map_key' => ConfigService::make()->getConfigByCode('qq_map_key', ''),
  42. 'show_popup_time' => ConfigService::make()->getConfigByCode('show_popup_time', 0),
  43. 'video_form_auto_close' => ConfigService::make()->getConfigByCode('video_form_auto_close', 0),
  44. 'video_read_switch_time' => ConfigService::make()->getConfigByCode('video_read_switch_time', 3),
  45. 'share_desc' => ConfigService::make()->getConfigByCode('share_desc', ''),
  46. 'share_content' => ConfigService::make()->getConfigByCode('share_content', ''),
  47. 'custom_name' => ConfigService::make()->getConfigByCode('custom_name', ''),
  48. 'custom_desc' => format_content(ConfigService::make()->getConfigByCode('custom_desc', '')),
  49. 'show_custom_header' => format_content(ConfigService::make()->getConfigByCode('show_custom_header', 0)),
  50. 'video_vip_tips' => format_content(ConfigService::make()->getConfigByCode('video_vip_tips', '')),
  51. 'errors' => config('platform.errors'),
  52. ];
  53. RedisService::set($cacheKey, $config, 3600);
  54. }
  55. return showJson(1010, true, $config);
  56. } catch (\Exception $exception) {
  57. RedisService::set("caches:request:error_config", ['trace' => $exception->getTrace()], 7200);
  58. return showJson(1018, false, ['error' => env('APP_DEBUG') ? $exception->getMessage() : '']);
  59. }
  60. }
  61. /**
  62. * 首页数据
  63. * @return array
  64. */
  65. public function data()
  66. {
  67. $type = request()->get('type',1);
  68. if($type==2){
  69. $data = [
  70. // 菜单
  71. 'menuList' => config('platform.menuList'),
  72. ];
  73. }else{
  74. $data = [
  75. // 公告
  76. 'notices' => NoticeService::make()->getRecommandList(),
  77. // 资讯
  78. 'articles' => ArticleService::make()->getIndexList(1),
  79. // 职称评审资料
  80. 'articles1' => ArticleService::make()->getIndexList(5),
  81. // 轮播
  82. 'banners' => AdService::make()->getListByPosition(1),
  83. ];
  84. }
  85. return showJson(1010, true, $data);
  86. }
  87. /**
  88. * 院校列表
  89. * @return array
  90. */
  91. public function institutions()
  92. {
  93. $params = request()->all();
  94. $pageSize = isset($params['pageSize']) && $params['pageSize']? intval($params['pageSize']) : 20;
  95. $data = InstitutionService::make()->getDataList($params, $pageSize);
  96. return showJson(1010, true, $data);
  97. }
  98. /**
  99. * 验证更新
  100. * @return array
  101. */
  102. public function versionCheck()
  103. {
  104. $version = request()->post('version', '');
  105. $appSources = request()->post('app_sources', 'ios');
  106. $currentVersion = ConfigService::make()->getConfigByCode('app_version');
  107. if (getVersion($version) < getVersion($currentVersion)) {
  108. $data = [
  109. 'has_update' => true,
  110. 'app_version' => $currentVersion,
  111. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  112. 'app_url' => ConfigService::make()->getConfigByCode("app_{$appSources}_url"),
  113. 'is_force' => ConfigService::make()->getConfigByCode("app_force_update"),
  114. 'auto_update' => false, // 是否APP内自动更新
  115. ];
  116. return showJson(1010, true, $data);
  117. } else {
  118. return showJson(1010, false, ['has_update' => false, 'version' => $version]);
  119. }
  120. }
  121. }