PublicController.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\api\v2;
  12. use app\Request;
  13. use app\services\diy\DiyServices;
  14. use app\services\other\CityAreaServices;
  15. use app\services\product\category\StoreProductCategoryServices;
  16. use app\services\product\product\StoreProductServices;
  17. use app\services\wechat\WechatUserServices;
  18. use crmeb\services\CacheService;
  19. use app\services\other\CacheServices;
  20. use crmeb\services\SystemConfigService;
  21. use app\services\system\attachment\SystemAttachmentServices;
  22. class PublicController
  23. {
  24. /**
  25. * 主页获取
  26. * @param Request $request
  27. * @return mixed
  28. */
  29. public function index(Request $request)
  30. {
  31. $uid = $request->hasMacro('uid') ? (int)$request->uid() : 0;
  32. $data = SystemConfigService::more(['fast_number', 'bast_number', 'first_number', 'promotion_number', 'tengxun_map_key', 'site_name']);
  33. $site_name = $data['site_name'] ?? '';
  34. $tengxun_map_key = $data['tengxun_map_key'] ?? '';
  35. $fastNumber = (int)($data['fast_number'] ?? 0);// 快速选择分类个数
  36. $bastNumber = (int)($data['bast_number'] ?? 0);// 精品推荐个数
  37. $firstNumber = (int)($data['first_number'] ?? 0);// 首发新品个数
  38. $promotionNumber = (int)($data['promotion_number'] ?? 0);// 首发新品个数
  39. /** @var StoreProductCategoryServices $categoryService */
  40. $categoryService = app()->make(StoreProductCategoryServices::class);
  41. $info['fastList'] = $fastNumber ? $categoryService->byIndexList($fastNumber, 'id,cate_name,pid,pic') : [];// 快速选择分类个数
  42. /** @var StoreProductServices $storeProductServices */
  43. $storeProductServices = app()->make(StoreProductServices::class);
  44. $info['bastList'] = $bastNumber ? $storeProductServices->getRecommendProduct($uid, ['is_best' => 1], $bastNumber) : [];// 精品推荐个数
  45. $info['firstList'] = $firstNumber ? $storeProductServices->getRecommendProduct($uid, ['is_new' => 1], $firstNumber) : [];// 首发新品个数
  46. $benefit = $promotionNumber ? $storeProductServices->getRecommendProduct($uid, ['is_benefit' => 1], $promotionNumber) : [];// 首页促销单品
  47. $likeInfo = $storeProductServices->getRecommendProduct($uid, ['is_hot' => 1], 3);// 热门榜单 猜你喜欢
  48. if ($uid) {
  49. /** @var WechatUserServices $wechatUserService */
  50. $wechatUserService = app()->make(WechatUserServices::class);
  51. $subscribe = (bool)$wechatUserService->value(['uid' => $uid, 'user_type' => 'wechat'], 'subscribe');
  52. } else {
  53. $subscribe = true;
  54. }
  55. return app('json')->successful(compact('info', 'benefit', 'likeInfo', 'subscribe', 'tengxun_map_key', 'site_name'));
  56. }
  57. /**
  58. * 获取页面数据
  59. * @return mixed
  60. * @throws \think\db\exception\DataNotFoundException
  61. * @throws \think\db\exception\DbException
  62. * @throws \think\db\exception\ModelNotFoundException
  63. */
  64. public function getDiy($name = '')
  65. {
  66. /** @var DiyServices $diyService */
  67. $diyService = app()->make(DiyServices::class);
  68. $data = CacheService::redisHandler('diy')->remember('diy_' . $name, function () use ($name, $diyService) {
  69. $data = $diyService->getDiy($name);
  70. if (isset($data['f_scroll_box']['goodsList']['list'])) {
  71. $data['f_scroll_box']['goodsList']['list'] = get_thumb_water($data['f_scroll_box']['goodsList']['list'], 'small', ['pic']);
  72. }
  73. return $data;
  74. });
  75. return app('json')->successful($data);
  76. }
  77. /**
  78. * 是否强制绑定手机号
  79. * @return mixed
  80. */
  81. public function bindPhoneStatus()
  82. {
  83. $status = (bool)sys_config('store_user_mobile');
  84. return app('json')->success(compact('status'));
  85. }
  86. /**
  87. * 是否关注
  88. * @param Request $request
  89. * @param WechatUserServices $services
  90. * @return mixed
  91. */
  92. public function subscribe(Request $request, WechatUserServices $services)
  93. {
  94. return app('json')->success(['subscribe' => (bool)$services->value(['uid' => $request->uid(), 'user_type' => 'wechat'], 'subscribe')]);
  95. }
  96. /**
  97. * 获取提货点自提开启状态
  98. * @return mixed
  99. */
  100. public function getStoreStatus()
  101. {
  102. $data['store_status'] = 0;
  103. if (sys_config('store_func_status', 1)) {
  104. $data['store_status'] = sys_config('store_self_mention', 0);
  105. }
  106. return app('json')->successful($data);
  107. }
  108. /**
  109. * 获取颜色选择和分类模板选择
  110. * @param DiyServices $services
  111. * @param $name
  112. * @return mixed
  113. * @throws \think\db\exception\DataNotFoundException
  114. * @throws \think\db\exception\DbException
  115. * @throws \think\db\exception\ModelNotFoundException
  116. */
  117. public function colorChange(DiyServices $services, $name)
  118. {
  119. $status = (int)$services->getColorChange((string)$name);
  120. $navigation = (int)sys_config('navigation_open');
  121. return app('json')->success(compact('status', 'navigation'));
  122. }
  123. /**
  124. * 获取商品详情diy
  125. * @param DiyServices $services
  126. * @return mixed
  127. * @throws \think\db\exception\DataNotFoundException
  128. * @throws \think\db\exception\DbException
  129. * @throws \think\db\exception\ModelNotFoundException
  130. */
  131. public function productDetailDiy(DiyServices $services)
  132. {
  133. $product_detail = $services->getProductDetailDiy();
  134. $product_video_status = (bool)sys_config('product_video_status');
  135. return app('json')->success(compact('product_detail', 'product_video_status'));
  136. }
  137. /**
  138. * 获取城市
  139. * @param CityAreaServices $services
  140. * @return mixed
  141. */
  142. public function city(Request $request, CityAreaServices $services)
  143. {
  144. $pid = $request->get('pid', 0);
  145. $type = $request->get('type', 0);
  146. return app('json')->success($services->getCityTreeList((int)$pid, (int)$type));
  147. }
  148. /**
  149. * 解析(获取导入微信地址)
  150. * @param CityAreaServices $services
  151. * @return mixed
  152. */
  153. public function cityList(Request $request, CityAreaServices $services)
  154. {
  155. $address = $request->param('address', '');
  156. if (!$address)
  157. return app('json')->fail('地址不存在');
  158. $city = $services->searchCity(compact('address'));
  159. if (!$city) return app('json')->fail('地址暂未录入,请联系管理员');
  160. $where = [['id', 'in', array_merge([$city['id']], explode('/', trim($city->path, '/')))]];
  161. return app('json')->success($services->getCityList($where, 'id as value,id,name as label,parent_id as pid', ['children']));
  162. }
  163. /**
  164. * 获取客服类型配置
  165. * @return mixed
  166. */
  167. public function getCustomerType()
  168. {
  169. $data = SystemConfigService::more(['routine_contact_type', 'customer_type', 'customer_phone', 'customer_url', 'wechat_work_corpid']);
  170. $data['userInfo'] = [];
  171. return app('json')->success($data);
  172. }
  173. }