IndexController.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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\Api\StoreService;
  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. 'app_android_url' => ConfigService::make()->getConfigByCode('app_android_url'),
  33. 'alipay_open' => ConfigService::make()->getConfigByCode('alipay_open', 0),
  34. 'agent_apply_desc' => format_content(ConfigService::make()->getConfigByCode('agent_apply_desc', '')),
  35. 'withdraw_desc' => format_content(ConfigService::make()->getConfigByCode('withdraw_desc', '')),
  36. 'recharge_desc' => format_content(ConfigService::make()->getConfigByCode('recharge_desc', '')),
  37. 'wxpay_open' => ConfigService::make()->getConfigByCode('wxpay_open', 0),
  38. 'pay_recharge_open' => ConfigService::make()->getConfigByCode('pay_recharge_open', 0),
  39. 'social_open' => ConfigService::make()->getConfigByCode('social_open', 0),
  40. 'withdraw_open' => ConfigService::make()->getConfigByCode('withdraw_open', 0),
  41. 'withdraw_min' => ConfigService::make()->getConfigByCode('withdraw_min', 0),
  42. 'withdraw_fee' => ConfigService::make()->getConfigByCode('withdraw_fee', 0),
  43. 'notices' => NoticeService::make()->getRecommandList(),
  44. ];
  45. RedisService::set($cacheKey, $config, 3600);
  46. }
  47. return showJson(1010, true, $config);
  48. } catch (\Exception $exception) {
  49. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  50. return showJson(1046, false, $error);
  51. }
  52. }
  53. /**
  54. * 首页数据
  55. * @return array
  56. */
  57. public function data()
  58. {
  59. try {
  60. $params = request()->all();
  61. $type = isset($params['type']) && $params['type']?$params['type'] : 1;
  62. $position = isset($params['position']) && $params['position']?$params['position'] : 1;
  63. $data = [
  64. // 轮播
  65. 'banners' => AdService::make()->getListByPosition($position),
  66. ];
  67. if($type==2){
  68. $data['socials'] = SocialCircleService::make()->getIndexList();
  69. }else{
  70. $data['notices'] = NoticeService::make()->getRecommandList();
  71. }
  72. return showJson(1010, true, $data);
  73. } catch (\Exception $exception) {
  74. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  75. return showJson(1046, false, $error);
  76. }
  77. }
  78. /**
  79. * 主页店铺商品
  80. * @return array
  81. */
  82. public function storeGoods()
  83. {
  84. $params =request()->post();
  85. try {
  86. $params['user_id'] = $this->userId;
  87. $datas = StoreService::make()->getGoodsList($params);
  88. return showJson(StoreService::make()->getError(), true, $datas);
  89. }catch (\Exception $exception) {
  90. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  91. return showJson(1046, false, $error);
  92. }
  93. }
  94. /**
  95. * 验证更新
  96. * @return array
  97. */
  98. public function versionCheck()
  99. {
  100. $version = request()->post('version', '');
  101. $appSources = request()->post('app_sources', 'ios');
  102. $currentVersion = ConfigService::make()->getConfigByCode('app_version');
  103. if (getVersion($version) < getVersion($currentVersion)) {
  104. $data = [
  105. 'has_update' => true,
  106. 'app_version' => $currentVersion,
  107. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  108. 'app_url' => ConfigService::make()->getConfigByCode("app_{$appSources}_url"),
  109. 'is_force' => ConfigService::make()->getConfigByCode("app_force_update"),
  110. 'auto_update' => false, // 是否APP内自动更新
  111. ];
  112. return showJson(1010, true, $data);
  113. } else {
  114. return showJson(1010, false, ['has_update' => false, 'version' => $version]);
  115. }
  116. }
  117. }