IndexController.php 4.6 KB

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