IndexController.php 6.9 KB

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