IndexController.php 8.0 KB

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