IndexController.php 4.2 KB

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