From f878847d28773935a656b8b81d770474b31a231f Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Mon, 1 Jul 2024 11:50:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E5=BA=97=E9=93=BA?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=A2=9E=E5=8A=A0=E6=98=AF=E5=90=A6=E5=8F=AF?= =?UTF-8?q?=E5=BD=93=E6=97=A5=E8=8E=B7=E5=8F=96=E7=9A=84=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/lists/store/SystemStoreLists.php | 31 ++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) 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']; });