IndexController.php 3.3 KB

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