IndexController.php 3.4 KB

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