PublicController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 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\user\UserServices;
  17. use app\services\wechat\WechatUserServices;
  18. class PublicController
  19. {
  20. /**
  21. * 主页获取
  22. * @param Request $request
  23. * @return mixed
  24. */
  25. public function index(Request $request)
  26. {
  27. $fastNumber = (int)sys_config('fast_number', 0);//TODO 快速选择分类个数
  28. /** @var StoreCategoryServices $categoryService */
  29. $categoryService = app()->make(StoreCategoryServices::class);
  30. $info['fastList'] = $fastNumber ? $categoryService->byIndexList($fastNumber, 'id,cate_name,pid,pic') : [];//TODO 快速选择分类个数
  31. /** @var StoreProductServices $storeProductServices */
  32. $storeProductServices = app()->make(StoreProductServices::class);
  33. //获取推荐商品
  34. [$baseList, $firstList, $benefit, $likeInfo, $vipList] = $storeProductServices->getRecommendProductArr((int)$request->uid(), ['is_best', 'is_new', 'is_benefit', 'is_hot']);
  35. $info['bastList'] = $baseList;//TODO 精品推荐个数
  36. $info['firstList'] = $firstList;//TODO 首发新品个数
  37. if ($request->uid()) {
  38. /** @var UserServices $userService */
  39. $userService = app()->make(UserServices::class);
  40. //看是否会员过期
  41. $userService->offMemberLevel($request->uid());
  42. /** @var WechatUserServices $wechatUserService */
  43. $wechatUserService = app()->make(WechatUserServices::class);
  44. $subscribe = (bool)$wechatUserService->value(['uid' => $request->uid(), 'user_type' => 'wechat'], 'subscribe');
  45. } else {
  46. $subscribe = true;
  47. }
  48. $tengxun_map_key = sys_config('tengxun_map_key');
  49. $site_name = sys_config('site_name');
  50. return app('json')->success(compact('info', 'benefit', 'likeInfo', 'subscribe', 'tengxun_map_key', 'site_name'));
  51. }
  52. /**
  53. * 获取页面数据
  54. * @param Request $request
  55. * @param string $name
  56. * @return mixed
  57. * @throws \think\db\exception\DataNotFoundException
  58. * @throws \think\db\exception\DbException
  59. * @throws \think\db\exception\ModelNotFoundException
  60. */
  61. public function getDiy(Request $request, $name = '')
  62. {
  63. list($id) = $request->getMore([
  64. ['id', 0]
  65. ], true);
  66. /** @var DiyServices $diyService */
  67. $diyService = app()->make(DiyServices::class);
  68. $data = $diyService->getDiy($id);
  69. return app('json')->success($data);
  70. }
  71. /**
  72. * @param int $id
  73. * @return mixed
  74. * @author 等风来
  75. * @email 136327134@qq.com
  76. * @date 2023/2/8
  77. */
  78. public function getVersion($id = 0)
  79. {
  80. /** @var DiyServices $diyService */
  81. $diyService = app()->make(DiyServices::class);
  82. $data = $diyService->getDiyVersion((int)$id);
  83. return app('json')->success(['version' => $data['version'] ?: '', 'is_diy' => $data['is_diy']]);
  84. }
  85. /**
  86. * 是否强制绑定手机号
  87. * @return mixed
  88. */
  89. public function bindPhoneStatus()
  90. {
  91. $status = (bool)sys_config('store_user_mobile');
  92. return app('json')->success(compact('status'));
  93. }
  94. /**
  95. * 是否关注
  96. * @param Request $request
  97. * @param WechatServices $services
  98. * @return mixed
  99. */
  100. public function subscribe(Request $request, WechatUserServices $services)
  101. {
  102. return app('json')->success(['subscribe' => (bool)$services->value(['uid' => $request->uid(), 'user_type' => 'wechat'], 'subscribe')]);
  103. }
  104. /**
  105. * 获取提货点自提开启状态
  106. * @return mixed
  107. */
  108. public function getStoreStatus()
  109. {
  110. $data['store_status'] = sys_config('store_self_mention', 0);
  111. return app('json')->success($data);
  112. }
  113. /**
  114. * 获取颜色选择和分类模板选择
  115. * @param DiyServices $services
  116. * @param $name
  117. * @return mixed
  118. * @throws \think\db\exception\DataNotFoundException
  119. * @throws \think\db\exception\DbException
  120. * @throws \think\db\exception\ModelNotFoundException
  121. */
  122. public function colorChange(DiyServices $services, $name)
  123. {
  124. $status = (int)$services->getColorChange((string)$name);
  125. $is_diy = $services->value(['status' => 1, 'is_del' => 0], 'is_diy');
  126. return app('json')->success(compact('status', 'is_diy'));
  127. }
  128. }