PublicController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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\api\controller\v2;
  12. use app\Request;
  13. use app\services\diy\DiyServices;
  14. use app\services\product\product\StoreCategoryServices;
  15. use app\services\product\product\StoreProductServices;
  16. use app\services\wechat\WechatUserServices;
  17. class PublicController
  18. {
  19. /**
  20. * 主页获取
  21. * @param Request $request
  22. * @return mixed
  23. */
  24. public function index(Request $request)
  25. {
  26. $fastNumber = (int)sys_config('fast_number', 0);//TODO 快速选择分类个数
  27. $bastNumber = (int)sys_config('bast_number', 0);//TODO 精品推荐个数
  28. $firstNumber = (int)sys_config('first_number', 0);//TODO 首发新品个数
  29. $promotionNumber = (int)sys_config('promotion_number', 0);//TODO 首发新品个数
  30. /** @var StoreCategoryServices $categoryService */
  31. $categoryService = app()->make(StoreCategoryServices::class);
  32. $info['fastList'] = $fastNumber ? $categoryService->byIndexList($fastNumber, 'id,cate_name,pid,pic') : [];//TODO 快速选择分类个数
  33. /** @var StoreProductServices $storeProductServices */
  34. $storeProductServices = app()->make(StoreProductServices::class);
  35. $info['bastList'] = $bastNumber ? $storeProductServices->getRecommendProduct($request->uid(), 'is_best', $bastNumber) : [];//TODO 精品推荐个数
  36. $info['firstList'] = $firstNumber ? $storeProductServices->getRecommendProduct($request->uid(), 'is_new', $firstNumber) : [];//TODO 首发新品个数
  37. $benefit = $promotionNumber ? $storeProductServices->getRecommendProduct($request->uid(), 'is_benefit', $promotionNumber) : [];//TODO 首页促销单品
  38. $likeInfo = $storeProductServices->getRecommendProduct($request->uid(), 'is_hot', 3);//TODO 热门榜单 猜你喜欢
  39. if ($request->uid()) {
  40. /** @var WechatUserServices $wechatUserService */
  41. $wechatUserService = app()->make(WechatUserServices::class);
  42. $subscribe = $wechatUserService->value(['uid' => $request->uid(),'user_type' => 'wechat'], 'subscribe') ? true : false;
  43. } else {
  44. $subscribe = true;
  45. }
  46. $tengxun_map_key = sys_config('tengxun_map_key');
  47. $site_name = sys_config('site_name');
  48. return app('json')->successful(compact('info', 'benefit', 'likeInfo', 'subscribe', 'tengxun_map_key', 'site_name'));
  49. }
  50. /**
  51. * 获取页面数据
  52. * @return mixed
  53. * @throws \think\db\exception\DataNotFoundException
  54. * @throws \think\db\exception\DbException
  55. * @throws \think\db\exception\ModelNotFoundException
  56. */
  57. public function getDiy($name = '')
  58. {
  59. /** @var DiyServices $diyService */
  60. $diyService = app()->make(DiyServices::class);
  61. $data = $diyService->getDiy($name);
  62. return app('json')->successful($data);
  63. }
  64. /**
  65. * 是否强制绑定手机号
  66. * @return mixed
  67. */
  68. public function bindPhoneStatus()
  69. {
  70. $status = sys_config('store_user_mobile') ? true : false;
  71. return app('json')->success(compact('status'));
  72. }
  73. /**
  74. * 是否关注
  75. * @param Request $request
  76. * @param WechatServices $services
  77. * @return mixed
  78. */
  79. public function subscribe(Request $request, WechatUserServices $services)
  80. {
  81. return app('json')->success(['subscribe' => $services->value(['uid' => $request->uid(), 'user_type' => 'wechat'], 'subscribe') ? true : false]);
  82. }
  83. /**
  84. * 获取提货点自提开启状态
  85. * @return mixed
  86. */
  87. public function getStoreStatus()
  88. {
  89. $data['store_status'] = sys_config('store_self_mention', 0);
  90. return app('json')->successful($data);
  91. }
  92. }