IndexController.php 6.8 KB

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