IndexController.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. $socialOpen = ConfigService::make()->getConfigByCode('social_open', 0);
  29. $config = [
  30. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  31. 'app_logo' => get_image_url(ConfigService::make()->getConfigByCode('app_logo')),
  32. 'app_version' => ConfigService::make()->getConfigByCode('app_version'),
  33. 'app_android_url' => ConfigService::make()->getConfigByCode('app_android_url'),
  34. 'alipay_open' => ConfigService::make()->getConfigByCode('alipay_open', 0),
  35. 'agent_apply_desc' => format_content(ConfigService::make()->getConfigByCode('agent_apply_desc', '')),
  36. 'withdraw_desc' => format_content(ConfigService::make()->getConfigByCode('withdraw_desc', '')),
  37. 'recharge_desc' => format_content(ConfigService::make()->getConfigByCode('recharge_desc', '')),
  38. 'wxpay_open' => ConfigService::make()->getConfigByCode('wxpay_open', 0),
  39. 'pay_recharge_open' => ConfigService::make()->getConfigByCode('pay_recharge_open', 0),
  40. 'social_open' => $socialOpen,
  41. 'withdraw_open' => ConfigService::make()->getConfigByCode('withdraw_open', 0),
  42. 'withdraw_min' => ConfigService::make()->getConfigByCode('withdraw_min', 0),
  43. 'withdraw_fee' => ConfigService::make()->getConfigByCode('withdraw_fee', 0),
  44. 'notices' => NoticeService::make()->getRecommandList(),
  45. 'menuList' => [
  46. [
  47. "name" => '首页',
  48. "code" => 'home',
  49. "icon" => 'home',
  50. "status"=> 1,
  51. "page" => '/pages/index/index'
  52. ], [
  53. "name" => '客服',
  54. "code" => 'custom',
  55. "icon" => 'custom',
  56. "status"=> 1,
  57. ], [
  58. "name" => '',
  59. "code" => 'social',
  60. "icon" => 'social',
  61. "status"=> $socialOpen?1:0,
  62. "page" => '/pages/social/index'
  63. ], [
  64. "name" => '购物车',
  65. "code" => 'cart',
  66. "icon" => 'cart',
  67. "badge" => 0,
  68. "status"=> 1,
  69. "page" => '/pages/cart/index'
  70. ], [
  71. "name" => '我的',
  72. "code" => 'mine',
  73. "icon" => 'mine',
  74. "status"=> 1,
  75. "page" => '/pages/mine/index'
  76. ]
  77. ]
  78. ];
  79. RedisService::set($cacheKey, $config, 3600);
  80. }
  81. return showJson(1010, true, $config);
  82. } catch (\Exception $exception) {
  83. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  84. return showJson(1046, false, $error);
  85. }
  86. }
  87. /**
  88. * 首页数据
  89. * @return array
  90. */
  91. public function data()
  92. {
  93. try {
  94. $params = request()->all();
  95. $type = isset($params['type']) && $params['type'] ? $params['type'] : 1;
  96. $position = isset($params['position']) && $params['position'] ? $params['position'] : 1;
  97. $data = [
  98. // 轮播
  99. 'banners' => AdService::make()->getListByPosition($position),
  100. ];
  101. if ($type == 2) {
  102. $data['socials'] = SocialCircleService::make()->getIndexList();
  103. } else {
  104. $data['notices'] = NoticeService::make()->getRecommandList();
  105. }
  106. return showJson(1010, true, $data);
  107. } catch (\Exception $exception) {
  108. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  109. return showJson(1046, false, $error);
  110. }
  111. }
  112. /**
  113. * 主页店铺商品
  114. * @return array
  115. */
  116. public function storeGoods()
  117. {
  118. $params = request()->post();
  119. try {
  120. $params['user_id'] = $this->userId;
  121. $datas = StoreService::make()->getGoodsList($params);
  122. return showJson(StoreService::make()->getError(), true, $datas);
  123. } catch (\Exception $exception) {
  124. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  125. return showJson(1046, false, $error);
  126. }
  127. }
  128. /**
  129. * 验证更新
  130. * @return array
  131. */
  132. public function versionCheck()
  133. {
  134. $version = request()->post('version', '');
  135. $appSources = request()->post('app_sources', 'ios');
  136. $currentVersion = ConfigService::make()->getConfigByCode('app_version');
  137. if (getVersion($version) < getVersion($currentVersion)) {
  138. $data = [
  139. 'has_update' => true,
  140. 'app_version' => $currentVersion,
  141. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  142. 'app_url' => ConfigService::make()->getConfigByCode("app_{$appSources}_url"),
  143. 'is_force' => ConfigService::make()->getConfigByCode("app_force_update"),
  144. 'auto_update' => false, // 是否APP内自动更新
  145. ];
  146. return showJson(1010, true, $data);
  147. } else {
  148. return showJson(1010, false, ['has_update' => false, 'version' => $version]);
  149. }
  150. }
  151. }