diff --git a/app/api/lists/store/SystemStoreLists.php b/app/api/lists/store/SystemStoreLists.php index 52bef3231..301b80b05 100644 --- a/app/api/lists/store/SystemStoreLists.php +++ b/app/api/lists/store/SystemStoreLists.php @@ -5,6 +5,8 @@ namespace app\api\lists\store; use app\admin\lists\BaseAdminDataLists; use app\common\enum\YesNoEnum; +use app\common\model\order\Cart; +use app\common\model\store_branch_product\StoreBranchProduct; use app\common\model\system_store\SystemStore; use app\common\lists\ListsSearchInterface; use app\MyBusinessException; @@ -48,6 +50,7 @@ class SystemStoreLists extends BaseAdminDataLists implements ListsSearchInterfac { $latitude = $this->request->get('latitude',''); $longitude = $this->request->get('longitude',''); + $cart_id = $this->request->get('cart_id',''); if(empty($longitude) || empty($latitude)){ throw new Exception('缺失经纬度'); } @@ -61,10 +64,34 @@ class SystemStoreLists extends BaseAdminDataLists implements ListsSearchInterfac ->order(['id' => 'desc']) ->select() ->toArray(); + if($cart_id){ + $cart_id = explode(',',$cart_id); + $cart_select = Cart::whereIn('id', $cart_id) + ->field('id,product_id,cart_num,store_id')->select()->toArray(); + foreach ($cart_select as $v) { + foreach ($data as &$values){ + $store = StoreBranchProduct::where([ + 'store_id'=>$values['id'], + 'product_id'=>$v['product_id'], + ])->field('id,store_name,stock')->withTrashed()->find(); + if(empty($store)){ + $store['stock'] =0; + } + $values['reservation'] = 0; + if($store['stock'] < $v['cart_num']){ + $values['reservation'] = 1; + } + $values['distance'] = haversineDistance($values['latitude'],$values['longitude'],$latitude,$longitude); + } - foreach ($data as &$value){ - $value['distance'] = haversineDistance($value['latitude'],$value['longitude'],$latitude,$longitude); + } + }else{ + foreach ($data as &$value){ + $value['distance'] = haversineDistance($value['latitude'],$value['longitude'],$latitude,$longitude); + + } } + usort($data, function ($a, $b) { return $a['distance'] <=> $b['distance']; });