IndexController.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. ];
  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. * @param int $socialOpen
  58. * @return array[]
  59. */
  60. public function getMenus($socialOpen=-1)
  61. {
  62. $socialOpen = $socialOpen>=0?$socialOpen:ConfigService::make()->getConfigByCode('social_open', 0);
  63. return [
  64. [
  65. "name" => '首页',
  66. "code" => 'home',
  67. "icon" => 'home',
  68. "status"=> 1,
  69. "page" => '/pages/index/index'
  70. ], [
  71. "name" => '客服',
  72. "code" => 'custom',
  73. "icon" => 'custom',
  74. "status"=> 1,
  75. ], [
  76. "name" => '',
  77. "code" => 'social',
  78. "icon" => 'social',
  79. "status"=> $socialOpen?1:0,
  80. "page" => '/pages/social/index'
  81. ], [
  82. "name" => '购物车',
  83. "code" => 'cart',
  84. "icon" => 'cart',
  85. "badge" => OrderService::make()->getCountByStatus($this->userId,1),
  86. "status"=> 1,
  87. "page" => '/pages/cart/index'
  88. ], [
  89. "name" => '我的',
  90. "code" => 'mine',
  91. "icon" => 'mine',
  92. "status"=> 1,
  93. "page" => '/pages/mine/index'
  94. ]
  95. ];
  96. }
  97. /**
  98. * 首页数据
  99. * @return array
  100. */
  101. public function data()
  102. {
  103. try {
  104. $params = request()->all();
  105. $type = isset($params['type']) && $params['type'] ? $params['type'] : 1;
  106. $position = isset($params['position']) && $params['position'] ? $params['position'] : 1;
  107. $data = [
  108. // 轮播
  109. 'banners' => AdService::make()->getListByPosition($position),
  110. ];
  111. if ($type == 2) {
  112. $data['socials'] = SocialCircleService::make()->getIndexList();
  113. } else {
  114. $data['notices'] = NoticeService::make()->getRecommandList();
  115. $data['social_open'] = ConfigService::make()->getConfigByCode('social_open', 0);
  116. $data['pay_recharge_open'] = ConfigService::make()->getConfigByCode('pay_recharge_open', 0);
  117. }
  118. return showJson(1010, true, $data);
  119. } catch (\Exception $exception) {
  120. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  121. return showJson(1046, false, $error);
  122. }
  123. }
  124. /**
  125. * 主页店铺商品
  126. * @return array
  127. */
  128. public function storeGoods()
  129. {
  130. $params = request()->post();
  131. try {
  132. $params['user_id'] = $this->userId;
  133. $datas = StoreService::make()->getGoodsList($params);
  134. return showJson(StoreService::make()->getError(), true, $datas);
  135. } catch (\Exception $exception) {
  136. $error = ['data' => $exception->getTrace(), 'err' => $exception->getMessage()];
  137. return showJson(1046, false, $error);
  138. }
  139. }
  140. /**
  141. * 验证更新
  142. * @return array
  143. */
  144. public function versionCheck()
  145. {
  146. $version = request()->post('version', '');
  147. $appSources = request()->post('app_sources', 'ios');
  148. $currentVersion = ConfigService::make()->getConfigByCode('app_version');
  149. if (getVersion($version) < getVersion($currentVersion)) {
  150. $data = [
  151. 'has_update' => true,
  152. 'app_version' => $currentVersion,
  153. 'app_name' => ConfigService::make()->getConfigByCode('app_name'),
  154. 'app_url' => ConfigService::make()->getConfigByCode("app_{$appSources}_url"),
  155. 'is_force' => ConfigService::make()->getConfigByCode("app_force_update"),
  156. 'auto_update' => false, // 是否APP内自动更新
  157. ];
  158. return showJson(1010, true, $data);
  159. } else {
  160. return showJson(1010, false, ['has_update' => false, 'version' => $version]);
  161. }
  162. }
  163. }