From 2c72112defee548acc9319e42e818772fa9dfc3d Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Wed, 8 Nov 2023 14:48:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/store/product/CloudWarehouse.php | 38 +++++++++++-------- app/controller/api/store/product/StoreSpu.php | 15 +++++++- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/app/controller/api/store/product/CloudWarehouse.php b/app/controller/api/store/product/CloudWarehouse.php index 508e23e3..c38f9344 100644 --- a/app/controller/api/store/product/CloudWarehouse.php +++ b/app/controller/api/store/product/CloudWarehouse.php @@ -92,14 +92,11 @@ class CloudWarehouse extends BaseController // } /** - * 云仓商品列表 + * type_id 13云仓商品列表 * @return mixed */ public function index($street_code, $page = 1, $category_id = 0,$location='') { - // if ($category_id == 0) { - // return app('json')->fail('分类id不能为0'); - // } $cloud_product = Db::name('cloud_product')->where('street_code', $street_code)->where('status', 1)->page($page)->column('product_id'); $where = [ 'is_show' => 1, @@ -118,23 +115,32 @@ class CloudWarehouse extends BaseController }else{ $limit=$page*10; } - $count=Db::name('merchant')->where('coordinates','<>','')->count(); - $select=Db::query("select mer_id,mer_name ,ST_Distance(coordinates, POINT($lon,$lat)) AS distance from eb_merchant where coordinates !='' ORDER BY distance LIMIT $limit, 10;"); - foreach ($select as $k => $v) { - $where['mer_id']=$v['mer_id']; - $product_list = Db::name('store_product')->where($where) - ->limit(3) + $where=[ + 'type_id'=>13, + 'is_de'=>0, + 'mer_state'=>1 + ]; + $mer_id=Db::name('merchant')->where($where)->column('mer_id'); + // $select=Db::query("select mer_id,mer_name ,ST_Distance(coordinates, POINT($lon,$lat)) AS distance from eb_merchant where coordinates !='' and type_id= 13 and is_del=0 and mer_state=1 ORDER BY distance LIMIT 100;"); + // halt($select); + if ($mer_id) { + $where['mer_id']=$mer_id; + $select = Db::name('store_product')->where($where) ->withAttr('sku', function ($value, $data) { $find = Db::name('store_product_attr_value')->where('mer_id', $data['mer_id'])->where('product_id', $data['product_id'])->find(); return ['' => $find]; }) + ->withAttr('merchant', function ($value, $data) { + $find= Db::name('merchant')->where('mer_id', $data['mer_id'])->field('mer_id,mer_name')->find(); + return $find; + }) ->select(); - foreach ($product_list as $k1 => $v1){ - $arr=$v1; - $v['distance']=round($v['distance'],2).'km'; - $arr['merchant']=$v; - $list[]=$arr; - } + // foreach ($product_list as $k1 => $v1){ + // $arr=$v1; + // $v['distance']=round($v['distance'],2).'km'; + // $arr['merchant']=$v; + // $list[]=$arr; + // } } diff --git a/app/controller/api/store/product/StoreSpu.php b/app/controller/api/store/product/StoreSpu.php index e05b2658..7f76d0f5 100644 --- a/app/controller/api/store/product/StoreSpu.php +++ b/app/controller/api/store/product/StoreSpu.php @@ -170,6 +170,7 @@ class StoreSpu extends BaseController { [$page, $limit] = $this->getPage(); $where = $this->request->params(['common','mer_id']); + $params = $this->request->params(['location']); $typeIdArray = Db::name('MerchantType')->whereNotIn('type_code', Merchant::TypeCode['TypeCloudWarehouse'] . ',' .Merchant::TypeCode['TypeSupplyChain'])->column('mer_type_id'); $where['is_gift_bag'] = 0; //1:星级 @@ -196,8 +197,18 @@ class StoreSpu extends BaseController } $where['product_type'] = 0; $where['is_stock'] = 1; - $where['mer_ids'] = Merchant::getInstance()->whereIn('type_id', implode(',', $typeIdArray ??[])) - ->where(['status' => 1, 'mer_state' => 1, 'is_del' => 0])->column('mer_id'); + if($params['location']!=''){ + [$lon,$lat]=explode(',',$params['location']); + $select=Db::query("select mer_id,ST_Distance(coordinates, POINT($lon,$lat)) AS distance from eb_merchant where coordinates !='' and type_id IN ('10', '17') and is_del=0 and mer_state=1 ORDER BY distance LIMIT 100;"); + $arr=[]; + foreach($select as $k=>$v){ + $arr[]=$v['mer_id']; + } + if($arr){ + $where['mer_ids'] =$arr; + + } + } $data = $this->repository->getApiSearch($where, $page, $limit, $this->userInfo); return app('json')->success($data); }