IndexController.php 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. namespace App\Http\Controllers\Api\v1;
  3. use App\Http\Controllers\Api\webApp;
  4. use App\Services\Common\AdService;
  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. 'app_android_url' => ConfigService::make()->getConfigByCode('app_android_url'),
  31. 'alipay_open' => ConfigService::make()->getConfigByCode('alipay_open', 0),
  32. 'agent_apply_desc' => ConfigService::make()->getConfigByCode('agent_apply_desc', ''),
  33. 'wxpay_open' => ConfigService::make()->getConfigByCode('wxpay_open', 0),
  34. 'withdraw_open' => ConfigService::make()->getConfigByCode('withdraw_open', 0),
  35. 'withdraw_min' => ConfigService::make()->getConfigByCode('withdraw_min', 0),
  36. 'withdraw_fee' => ConfigService::make()->getConfigByCode('withdraw_fee', 0),
  37. 'notices' => NoticeService::make()->getRecommandList(),
  38. ];
  39. RedisService::set($cacheKey, $config, 3600);
  40. }
  41. return showJson(1010, true, $config);
  42. } catch (\Exception $exception) {
  43. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  44. return showJson(1046, false, $error);
  45. }
  46. }
  47. /**
  48. * 首页数据
  49. * @return array
  50. */
  51. public function data()
  52. {
  53. try {
  54. $data = [
  55. // 公告
  56. 'notices' => NoticeService::make()->getRecommandList(),
  57. // 轮播
  58. 'banners' => AdService::make()->getListByPosition(1),
  59. ];
  60. return showJson(1010, true, $data);
  61. } catch (\Exception $exception) {
  62. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  63. return showJson(1046, false, $error);
  64. }
  65. }
  66. /**
  67. * 验证更新
  68. * @return array
  69. */
  70. public function versionCheck()
  71. {
  72. $version = request()->post('version', '');
  73. $appSources = request()->post('app_sources', 'ios');
  74. $currentVersion = ConfigService::make()->getConfigByCode('app_version');
  75. if (getVersion($version) < getVersion($currentVersion)) {
  76. $data = [
  77. 'has_update' => true,
  78. 'app_version' => $currentVersion,
  79. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  80. 'app_url' => ConfigService::make()->getConfigByCode("app_{$appSources}_url"),
  81. 'is_force' => ConfigService::make()->getConfigByCode("app_force_update"),
  82. 'auto_update' => false, // 是否APP内自动更新
  83. ];
  84. return showJson(1010, true, $data);
  85. } else {
  86. return showJson(1010, false, ['has_update' => false, 'version' => $version]);
  87. }
  88. }
  89. }