IndexController.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Services\Api\AccountService;
  5. use App\Services\Api\MemberService;
  6. use App\Services\Api\OrderService;
  7. use App\Services\Common\NoticeService;
  8. use App\Services\ConfigService;
  9. use App\Services\MpService;
  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. 'kfUrl' => ConfigService::make()->getConfigByCode('wechat_kf_url', ''),
  35. 'notices' => NoticeService::make()->getRecommandList(),
  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. 'courses' => [],
  55. 'articles' => [],
  56. ];
  57. return showJson(1010, true, $data);
  58. }
  59. /**
  60. * 验证更新
  61. * @return array
  62. */
  63. public function versionCheck()
  64. {
  65. $version = request()->post('version', '');
  66. $appSources = request()->post('app_sources', 'ios');
  67. $currentVersion = ConfigService::make()->getConfigByCode('app_version');
  68. if (getVersion($version) < getVersion($currentVersion)) {
  69. $data = [
  70. 'has_update' => true,
  71. 'app_version' => $currentVersion,
  72. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  73. 'app_url' => ConfigService::make()->getConfigByCode("app_{$appSources}_url"),
  74. 'is_force' => ConfigService::make()->getConfigByCode("app_force_update"),
  75. 'auto_update' => false, // 是否APP内自动更新
  76. ];
  77. return showJson(1010, true, $data);
  78. } else {
  79. return showJson(1010, false, ['has_update' => false, 'version' => $version]);
  80. }
  81. }
  82. }