IndexController.php 3.2 KB

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