IndexController.php 8.2 KB

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