IndexController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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' => format_content(ConfigService::make()->getConfigByCode('agent_apply_desc', '')),
  33. 'withdraw_desc' => format_content(ConfigService::make()->getConfigByCode('withdraw_desc', '')),
  34. 'recharge_desc' => format_content(ConfigService::make()->getConfigByCode('recharge_desc', '')),
  35. 'wxpay_open' => ConfigService::make()->getConfigByCode('wxpay_open', 0),
  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. try {
  56. $type = request()->post('type',1);
  57. $position = request()->post('position',1);
  58. $data = [
  59. // 公告
  60. 'notices' => NoticeService::make()->getRecommandList(),
  61. // 轮播
  62. 'banners' => AdService::make()->getListByPosition($position),
  63. ];
  64. if($type==2){
  65. $data['socials'] = SocialS
  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 versionCheck()
  78. {
  79. $version = request()->post('version', '');
  80. $appSources = request()->post('app_sources', 'ios');
  81. $currentVersion = ConfigService::make()->getConfigByCode('app_version');
  82. if (getVersion($version) < getVersion($currentVersion)) {
  83. $data = [
  84. 'has_update' => true,
  85. 'app_version' => $currentVersion,
  86. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  87. 'app_url' => ConfigService::make()->getConfigByCode("app_{$appSources}_url"),
  88. 'is_force' => ConfigService::make()->getConfigByCode("app_force_update"),
  89. 'auto_update' => false, // 是否APP内自动更新
  90. ];
  91. return showJson(1010, true, $data);
  92. } else {
  93. return showJson(1010, false, ['has_update' => false, 'version' => $version]);
  94. }
  95. }
  96. }