IndexController.php 6.5 KB

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