StoreController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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\v1\store;
  12. use app\services\order\StoreCartServices;
  13. use app\services\store\SystemStoreServices;
  14. use app\services\store\SystemStoreStaffServices;
  15. use app\Request;
  16. /**
  17. * Class StoreController
  18. * @package app\controller\api\v1\store
  19. */
  20. class StoreController
  21. {
  22. protected $services;
  23. public function __construct(SystemStoreServices $services)
  24. {
  25. $this->services = $services;
  26. }
  27. /**
  28. * 附近门店
  29. * @param Request $request
  30. * @param SystemStoreServices $services
  31. * @param StoreCartServices $cartServices
  32. * @return mixed
  33. * @throws \think\db\exception\DataNotFoundException
  34. * @throws \think\db\exception\DbException
  35. * @throws \think\db\exception\ModelNotFoundException
  36. */
  37. public function nearbyStore(Request $request, SystemStoreServices $services, StoreCartServices $cartServices)
  38. {
  39. [$latitude, $longitude, $store_id] = $request->getMore([
  40. ['latitude', ''],
  41. ['longitude', ''],
  42. ['store_id', 0]//选择具体门店
  43. ], true);
  44. $where = [];
  45. if ((int)$store_id) {
  46. $where['id'] = $store_id;
  47. }
  48. $storeStatus = sys_config('store_func_status', 1);
  49. $storeInfo = [];
  50. //开启门店
  51. if ($storeStatus) {
  52. $storeInfo = $services->getNearbyStore($where, $latitude, $longitude, $request->ip(), 1);
  53. }
  54. $data['info'] = $storeInfo;
  55. $data['tengxun_map_key'] = sys_config('tengxun_map_key');
  56. $data['store_splicing_switch'] = $storeStatus && sys_config('store_splicing_switch');
  57. $uid = (int)$request->uid();
  58. $data['cart_num'] = 0;
  59. if ($uid && $data['info']) {
  60. $cartArr = $cartServices->getUserCartCount($uid, 0, (int)($data['info']['id'] ?? 0));
  61. $data['cart_num'] = $cartArr['count'] ?? 0;
  62. }
  63. return app('json')->successful($data);
  64. }
  65. /**
  66. * 获取门店列表
  67. * @param Request $request
  68. * @return mixed
  69. * @throws \think\db\exception\DataNotFoundException
  70. * @throws \think\db\exception\DbException
  71. * @throws \think\db\exception\ModelNotFoundException
  72. */
  73. public function getStoreList(Request $request)
  74. {
  75. [$store_type, $keywords, $latitude, $longitude, $province, $city, $area, $street] = $request->getMore([
  76. ['store_type', 1],
  77. ['keyword', ''],
  78. ['latitude', ''],
  79. ['longitude', ''],
  80. ['province', 0],
  81. ['city', 0],
  82. ['area', 0],
  83. ['street', 0]
  84. ], true);
  85. $where = ['uid' => (int)$request->uid(), 'store_type' => $store_type, 'keywords' => $keywords, 'province' => $province, 'city' => $city, 'area' => $area, 'street' => $street];
  86. $storeList = [];
  87. //开启门店
  88. if (sys_config('store_func_status', 1)) {
  89. $storeList = $this->services->getNearbyStore($where, $latitude, $longitude);
  90. }
  91. return app('json')->success($storeList);
  92. }
  93. /**
  94. * 获取门店客服列表
  95. * @param SystemStoreStaffServices $staffServices
  96. * @param $store_id
  97. * @return mixed
  98. * @throws \think\db\exception\DataNotFoundException
  99. * @throws \think\db\exception\DbException
  100. * @throws \think\db\exception\ModelNotFoundException
  101. */
  102. public function getCustomerList(SystemStoreStaffServices $staffServices, $store_id)
  103. {
  104. $customer = [];
  105. if ($store_id) {
  106. $customer = $staffServices->getCustomerList((int)$store_id, 'id,store_id,staff_name,avatar,customer_phone,customer_url');
  107. }
  108. return app('json')->success($customer);
  109. }
  110. /**
  111. * 获取客服详情
  112. * @param SystemStoreStaffServices $staffServices
  113. * @param $id
  114. * @return mixed
  115. * @throws \think\db\exception\DataNotFoundException
  116. * @throws \think\db\exception\DbException
  117. * @throws \think\db\exception\ModelNotFoundException
  118. */
  119. public function getCustomerInfo(SystemStoreStaffServices $staffServices, $id)
  120. {
  121. $info = [];
  122. if (!$id) {
  123. return app('json')->fail('缺少参数');
  124. }
  125. $info = $staffServices->getStaffInfo((int)$id, 'id,store_id,staff_name,avatar,customer_phone,customer_url');
  126. if (!$info) {
  127. return app('json')->fail('客服不存在');
  128. }
  129. $info = $info->toArray();
  130. $storeInfo = $this->services->getStoreInfo((int)$info['store_id']);
  131. $info['store_name'] = $storeInfo['name'] ?? '';
  132. $info['address'] = $storeInfo['address'] ?? '';
  133. $info['detailed_address'] = $storeInfo['detailed_address'] ?? '';
  134. $info['latitude'] = $storeInfo['latitude'] ?? '';
  135. $info['longitude'] = $storeInfo['longitude'] ?? '';
  136. $info['day_time'] = $storeInfo['day_time'] ?? '';
  137. $info['day_start'] = $storeInfo['day_start'] ?? '';
  138. $info['day_end'] = $storeInfo['day_end'] ?? '';
  139. return app('json')->success($info);
  140. }
  141. }