From cfa0b4451eecc199cb4ac7e6e00eff363a8147e3 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 7 Nov 2023 17:28:58 +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/merchant/Merchant.php | 5 +++ .../api/store/product/CloudWarehouse.php | 44 +++++++++++++++---- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/app/controller/api/store/merchant/Merchant.php b/app/controller/api/store/merchant/Merchant.php index 2aada127..78b59eaf 100644 --- a/app/controller/api/store/merchant/Merchant.php +++ b/app/controller/api/store/merchant/Merchant.php @@ -242,6 +242,11 @@ class Merchant extends BaseController if ($data['mer_state'] && !$merchant['sub_mchid'] && systemConfig('open_wx_combine')) return app('json')->fail('开启店铺前请先完成微信子商户入驻'); } + if($data['long']!=''&& $data['lat']!=''){ + $long=$data['long']; + $lat=$data['lat']; + Db::query("UPDATE eb_merchant SET coordinates = ST_GeomFromText('POINT($long $lat)') WHERE mer_id = $id"); + } Db::name('merchant')->where('mer_id',$id)->update($data); Queue::push(ChangeMerchantStatusJob::class, $id); diff --git a/app/controller/api/store/product/CloudWarehouse.php b/app/controller/api/store/product/CloudWarehouse.php index dc63ac0f..7a90d7c1 100644 --- a/app/controller/api/store/product/CloudWarehouse.php +++ b/app/controller/api/store/product/CloudWarehouse.php @@ -95,15 +95,12 @@ class CloudWarehouse extends BaseController * 云仓商品列表 * @return mixed */ - public function index($street_code, $page_num = 1, $category_id = 0) + public function index($street_code, $page_num = 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('category_id', $category_id)->where('status', 1)->page($page_num)->column('product_id'); - if (!$cloud_product) { - return app('json')->success(['count' => 0, 'list' => []]); - } + // 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_num)->column('product_id'); $where = [ 'is_show' => 1, 'is_used' => 1, @@ -111,6 +108,37 @@ class CloudWarehouse extends BaseController 'is_del' => 0, 'mer_status' => 1, ]; + if (!$cloud_product) { + $list=[]; + if($location){ + [$lon,$lat]=explode(',',$location); + if($page_num==1){ + $limit=0; + }else{ + $limit=$page_num*10; + } + $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) + ->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]; + }) + ->select(); + foreach ($product_list as $k1 => $v1){ + $arr=$v1; + $v['distance']=round($v['distance'],2).'km'; + $arr['merchant']=$v; + $list[]=$arr; + } + + } + + } + return app('json')->success(['count' => 0, 'list' => $list]); + } $count = Db::name('cloud_product')->where('street_code', $street_code)->where('status', 1)->count(); $select = Db::name('store_product')->whereIn('product_id', $cloud_product)->where($where) ->withAttr('merchant', function ($value, $data) {