IndexController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. ],
  68. ];
  69. return showJson(1010, true, $data);
  70. }
  71. /**
  72. * 院校列表
  73. * @return array
  74. */
  75. public function institutions()
  76. {
  77. $params = request()->all();
  78. $pageSize = isset($params['pageSize']) && $params['pageSize']? intval($params['pageSize']) : 20;
  79. $data = InstitutionService::make()->getDataList($params, $pageSize);
  80. return showJson(1010, true, $data);
  81. }
  82. /**
  83. * 验证更新
  84. * @return array
  85. */
  86. public function versionCheck()
  87. {
  88. $version = request()->post('version', '');
  89. $appSources = request()->post('app_sources', 'ios');
  90. $currentVersion = ConfigService::make()->getConfigByCode('app_version');
  91. if (getVersion($version) < getVersion($currentVersion)) {
  92. $data = [
  93. 'has_update' => true,
  94. 'app_version' => $currentVersion,
  95. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  96. 'app_url' => ConfigService::make()->getConfigByCode("app_{$appSources}_url"),
  97. 'is_force' => ConfigService::make()->getConfigByCode("app_force_update"),
  98. 'auto_update' => false, // 是否APP内自动更新
  99. ];
  100. return showJson(1010, true, $data);
  101. } else {
  102. return showJson(1010, false, ['has_update' => false, 'version' => $version]);
  103. }
  104. }
  105. }