IndexController.php 7.7 KB

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