IndexController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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\Common\AdService;
  6. use App\Services\Common\NoticeService;
  7. use App\Services\ConfigService;
  8. use App\Services\RedisService;
  9. /**
  10. * 首页
  11. * Class IndexController
  12. * @package App\Http\Controllers\Api
  13. */
  14. class IndexController extends webApp
  15. {
  16. /**
  17. * 配置信息
  18. * @return array
  19. */
  20. public function config()
  21. {
  22. try {
  23. $appSources = request()->post('app_sources', 'ios');
  24. $cacheKey = "caches:config:app_{$appSources}";
  25. $config = RedisService::get($cacheKey);
  26. if (empty($config)) {
  27. $config = [
  28. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  29. 'app_logo' => get_image_url(ConfigService::make()->getConfigByCode('app_logo')),
  30. 'app_version' => ConfigService::make()->getConfigByCode('app_version'),
  31. 'bonus_desc' => format_content(ConfigService::make()->getConfigByCode('bonus_desc', '')),
  32. 'auth_desc' => format_content(ConfigService::make()->getConfigByCode('auth_desc', '')),
  33. 'withdraw_desc' => format_content(ConfigService::make()->getConfigByCode('withdraw_desc', '')),
  34. 'wxpay_open' => ConfigService::make()->getConfigByCode('wxpay_open', 0),
  35. 'bank_limit_num' => ConfigService::make()->getConfigByCode('bank_limit_num', 5),
  36. 'withdraw_open' => ConfigService::make()->getConfigByCode('withdraw_open', 0),
  37. 'withdraw_min' => ConfigService::make()->getConfigByCode('withdraw_min', 0),
  38. 'withdraw_fee' => ConfigService::make()->getConfigByCode('withdraw_fee', 0),
  39. 'notices' => NoticeService::make()->getRecommandList(),
  40. ];
  41. RedisService::set($cacheKey, $config, 3600);
  42. }
  43. return showJson(1010, true, $config);
  44. } catch (\Exception $exception) {
  45. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  46. return showJson(1046, false, $error);
  47. }
  48. }
  49. /**
  50. * 首页数据
  51. * @return array
  52. */
  53. public function data()
  54. {
  55. $type = request()->post('type',1);
  56. try {
  57. $data = [
  58. // 轮播
  59. 'banners' => AdService::make()->getListByPosition(1),
  60. 'articles' => ArticleService::make()->getListByType(1),
  61. ];
  62. return showJson(1010, true, $data);
  63. } catch (\Exception $exception) {
  64. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  65. return showJson(1046, false, $error);
  66. }
  67. }
  68. /**
  69. * 验证更新
  70. * @return array
  71. */
  72. public function versionCheck()
  73. {
  74. $version = request()->post('version', '');
  75. $appSources = request()->post('app_sources', 'ios');
  76. $currentVersion = ConfigService::make()->getConfigByCode('app_version');
  77. if (getVersion($version) < getVersion($currentVersion)) {
  78. $data = [
  79. 'has_update' => true,
  80. 'app_version' => $currentVersion,
  81. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  82. 'app_url' => ConfigService::make()->getConfigByCode("app_{$appSources}_url"),
  83. 'is_force' => ConfigService::make()->getConfigByCode("app_force_update"),
  84. 'auto_update' => false, // 是否APP内自动更新
  85. ];
  86. return showJson(1010, true, $data);
  87. } else {
  88. return showJson(1010, false, ['has_update' => false, 'version' => $version]);
  89. }
  90. }
  91. }