IndexController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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\GoodsService;
  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. 'withdraw_1_desc' => format_content(ConfigService::make()->getConfigByCode('withdraw_1_desc', '')),
  33. 'withdraw_2_desc' => format_content(ConfigService::make()->getConfigByCode('withdraw_2_desc', '')),
  34. 'transfer_desc' => format_content(ConfigService::make()->getConfigByCode('transfer_desc', '')),
  35. 'goods_disclaimer' => format_content(ConfigService::make()->getConfigByCode('goods_disclaimer', '')),
  36. 'wxpay_open' => ConfigService::make()->getConfigByCode('wxpay_open', 0),
  37. 'show_bd_score' => ConfigService::make()->getConfigByCode('show_bd_score', 0),
  38. 'withdraw_1_open' => ConfigService::make()->getConfigByCode('withdraw_1_open', 0),
  39. 'withdraw_1_min' => ConfigService::make()->getConfigByCode('withdraw_1_min', 0),
  40. 'withdraw_1_fee' => ConfigService::make()->getConfigByCode('withdraw_1_fee', 0),
  41. 'withdraw_2_open' => ConfigService::make()->getConfigByCode('withdraw_2_open', 0),
  42. 'withdraw_2_fee' => ConfigService::make()->getConfigByCode('withdraw_2_fee', 0),
  43. 'withdraw_2_rate' => ConfigService::make()->getConfigByCode('withdraw_2_rate', 0),
  44. 'transfer_3_open' => ConfigService::make()->getConfigByCode('transfer_3_open', 0),
  45. 'notices' => NoticeService::make()->getRecommandList(),
  46. ];
  47. RedisService::set($cacheKey, $config, 3600);
  48. }
  49. return showJson(1010, true, $config);
  50. } catch (\Exception $exception) {
  51. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  52. return showJson(1046, false, $error);
  53. }
  54. }
  55. /**
  56. * 首页数据
  57. * @return array
  58. */
  59. public function data()
  60. {
  61. $areaId = $this->areaId;
  62. $buyType = $this->buyType;
  63. if($areaId<=0){
  64. $cacheInfo = RedisService::get("caches:index:area_".get_client_ip());
  65. $areaId = isset($cacheInfo['area_id'])?$cacheInfo['area_id'] : 1;
  66. $buyType = isset($cacheInfo['buy_type'])?$cacheInfo['buy_type'] : 1;
  67. }
  68. try {
  69. $data = [
  70. // 轮播
  71. 'banners' => AdService::make()->getListByPosition(1),
  72. 'goods' => $this->userId?GoodsService::make()->getListByType(2, $buyType, $this->userId):[],
  73. 'areaId'=> $areaId,
  74. 'buyType'=> $buyType,
  75. ];
  76. return showJson(1010, true, $data);
  77. } catch (\Exception $exception) {
  78. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  79. return showJson(1046, false, $error);
  80. }
  81. }
  82. /**
  83. * 验证更新
  84. * @return array
  85. */
  86. public function versionCheck()
  87. {
  88. $version = request()->post('version', '');
  89. $appSources = request()->post('app_sources', 'ios');
  90. $currentVersion = ConfigService::make()->getConfigByCode('app_version');
  91. if (getVersion($version) < getVersion($currentVersion)) {
  92. $data = [
  93. 'has_update' => true,
  94. 'app_version' => $currentVersion,
  95. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  96. 'app_url' => ConfigService::make()->getConfigByCode("app_{$appSources}_url"),
  97. 'is_force' => ConfigService::make()->getConfigByCode("app_force_update"),
  98. 'auto_update' => false, // 是否APP内自动更新
  99. ];
  100. return showJson(1010, true, $data);
  101. } else {
  102. return showJson(1010, false, ['has_update' => false, 'version' => $version]);
  103. }
  104. }
  105. }