IndexController.php 4.1 KB

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