IndexController.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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\SupervisorsService;
  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. 'index_logo' => get_image_url(ConfigService::make()->getConfigByCode('index_logo')),
  32. 'app_name_logo' => get_image_url(ConfigService::make()->getConfigByCode('app_name_logo')),
  33. 'app_version' => ConfigService::make()->getConfigByCode('app_version'),
  34. 'bonus_desc' => format_content(ConfigService::make()->getConfigByCode('bonus_desc', '')),
  35. 'auth_desc' => format_content(ConfigService::make()->getConfigByCode('auth_desc', '')),
  36. 'bank_desc' => format_content(ConfigService::make()->getConfigByCode('bank_desc', '')),
  37. 'withdraw_desc' => format_content(ConfigService::make()->getConfigByCode('withdraw_desc', '')),
  38. 'goods_disclaimer' => format_content(ConfigService::make()->getConfigByCode('goods_disclaimer', '')),
  39. 'wxpay_open' => ConfigService::make()->getConfigByCode('wxpay_open', 0),
  40. 'bank_limit_num' => ConfigService::make()->getConfigByCode('bank_limit_num', 5),
  41. 'withdraw_open' => ConfigService::make()->getConfigByCode('withdraw_open', 0),
  42. 'withdraw_min' => ConfigService::make()->getConfigByCode('withdraw_min', 0),
  43. 'withdraw_fee' => ConfigService::make()->getConfigByCode('withdraw_fee', 0),
  44. 'notices' => NoticeService::make()->getRecommandList(),
  45. ];
  46. RedisService::set($cacheKey, $config, 3600);
  47. }
  48. return showJson(1010, true, $config);
  49. } catch (\Exception $exception) {
  50. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  51. return showJson(1046, false, $error);
  52. }
  53. }
  54. /**
  55. * 首页数据
  56. * @return array
  57. */
  58. public function data()
  59. {
  60. $type = request()->post('type',1);
  61. try {
  62. $data = [
  63. // 轮播
  64. 'banners' => AdService::make()->getListByPosition(1),
  65. 'articles' => ArticleService::make()->getListByType(1),
  66. ];
  67. return showJson(1010, true, $data);
  68. } catch (\Exception $exception) {
  69. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  70. return showJson(1046, false, $error);
  71. }
  72. }
  73. /**
  74. * 行业数据
  75. * @return array
  76. */
  77. public function industry()
  78. {
  79. try {
  80. $data = [
  81. // 轮播
  82. 'banners' => AdService::make()->getListByPosition(2), // 轮播
  83. 'supervisors' => SupervisorsService::make()->getRecommendList(), // 推荐导师
  84. 'articles' => ArticleService::make()->getListByType(2), // 行业政策资讯
  85. ];
  86. return showJson(1010, true, $data);
  87. } catch (\Exception $exception) {
  88. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  89. return showJson(1046, false, $error);
  90. }
  91. }
  92. /**
  93. * 验证更新
  94. * @return array
  95. */
  96. public function versionCheck()
  97. {
  98. $version = request()->post('version', '');
  99. $appSources = request()->post('app_sources', 'ios');
  100. $currentVersion = ConfigService::make()->getConfigByCode('app_version');
  101. if (getVersion($version) < getVersion($currentVersion)) {
  102. $data = [
  103. 'has_update' => true,
  104. 'app_version' => $currentVersion,
  105. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  106. 'app_url' => ConfigService::make()->getConfigByCode("app_{$appSources}_url"),
  107. 'is_force' => ConfigService::make()->getConfigByCode("app_force_update"),
  108. 'auto_update' => false, // 是否APP内自动更新
  109. ];
  110. return showJson(1010, true, $data);
  111. } else {
  112. return showJson(1010, false, ['has_update' => false, 'version' => $version]);
  113. }
  114. }
  115. }