From 8b4dacbc089964518f9cb086f796abb6751aed49 Mon Sep 17 00:00:00 2001 From: wangxiaowei Date: Mon, 21 Oct 2024 16:36:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BA=97=E9=93=BA=E8=A1=97?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/logic/LocalStoreLogic.php | 25 +++++++++++++------ app/common/model/LocalStore.php | 8 +++++- .../model/localstore/LocalStoreGoodsPic.php | 6 +++++ 3 files changed, 31 insertions(+), 8 deletions(-) diff --git a/app/api/logic/LocalStoreLogic.php b/app/api/logic/LocalStoreLogic.php index f8a00962..00e17ae7 100644 --- a/app/api/logic/LocalStoreLogic.php +++ b/app/api/logic/LocalStoreLogic.php @@ -164,8 +164,13 @@ class LocalStoreLogic extends Logic } $pic = LocalStoreGoodsPic::where('lsg_id', $value['id'])->field('url')->find(); - $lists[$key]['url'] = UrlServer::getFileUrl($pic['url']); - $lists[$key]['distance'] = number_format($value['distance'], 2, '.', '') . "km"; + $lists[$key]['url'] = $pic['url']; + + if ($value['distance'] <= 0) { + $lists[$key]['distance'] = '<500m'; + } else { + $lists[$key]['distance'] = number_format($value['distance'], 2, '.', '') . "km"; + } // $lists[$key]['distance'] = round($this->distance($data['latitude'], $data['longitude'], $value['latitude'], $value['longitude']) / 1000, 2) . "km"; $lists[$key]['store_nickname'] = $value["shopName"]; } @@ -229,7 +234,7 @@ class LocalStoreLogic extends Logic ->join('local_store_goods lsg', 'lsg.lstore_id = ls.lstore_id') ->where(['ls.is_delete' => 0, 'ls.store_state' => 1]) ->whereNotNull('ls.shopLogo') - ->field('ls.lstore_id as ls_id, ls.shopName, ls.longitude, ls.latitude, ' . $distance_sql . ', lsg.lstore_id') + ->field('ls.lstore_id as ls_id, ls.shopLogo, ls.shopName, ls.longitude, ls.latitude, ' . $distance_sql . ', lsg.lstore_id') ->order($order) ->page($data['page_no'], $data['page_size']) ->group('ls.lstore_id') @@ -242,10 +247,16 @@ class LocalStoreLogic extends Logic $lists[$key]['price'] = round($value['price'] * LocalStoreGoodsLogic::$sale, 2); } -// $pic = LocalStoreGoodsPic::where('lsg_id', $value['id'])->field('url')->find(); -// $lists[$key]['url'] = UrlServer::getFileUrl($pic['url']); - $lists[$key]['distance'] = number_format($value['distance'], 2, '.', '') . "km"; -// $lists[$key]['distance'] = round($this->distance($data['latitude'], $data['longitude'], $value['latitude'], $value['longitude']) / 1000, 2) . "km"; + // 获取商品下的商品图片 + foreach ($value['street_goods'] as &$v) { + $v['url'] = UrlServer::getFileUrl($v['url']); + } + + if ($value['distance'] <= 0) { + $lists[$key]['distance'] = '<500m'; + } else { + $lists[$key]['distance'] = number_format($value['distance'], 2, '.', '') . "km"; + } $lists[$key]['store_nickname'] = $value["shopName"]; } diff --git a/app/common/model/LocalStore.php b/app/common/model/LocalStore.php index cfe9a460..f419ff05 100755 --- a/app/common/model/LocalStore.php +++ b/app/common/model/LocalStore.php @@ -15,8 +15,14 @@ class LocalStore extends Model return $this->belongsTo(User::class, 'user_id', 'id')->field('id, nickname'); } + // 店铺街 public function streetGoods() { - return $this->hasMany(LocalStoreGoods::class, 'lstore_id', 'lstore_id')->field('id, lstore_id, title, price')->order('id desc')->limit(10); + return $this->hasMany(LocalStoreGoods::class, 'lstore_id', 'lstore_id') + ->alias('lsg') + ->join('local_store_goods_pic p', 'lsg.id = p.lsg_id') + ->field('lsg.id, lsg.lstore_id, lsg.title, lsg.price, p.url') + ->order('lsg.id desc') + ->limit(10); } } \ No newline at end of file diff --git a/app/common/model/localstore/LocalStoreGoodsPic.php b/app/common/model/localstore/LocalStoreGoodsPic.php index 2fd4e636..5704b27d 100644 --- a/app/common/model/localstore/LocalStoreGoodsPic.php +++ b/app/common/model/localstore/LocalStoreGoodsPic.php @@ -3,8 +3,14 @@ namespace app\common\model\localstore; use app\common\basics\Models; +use app\common\server\UrlServer; class LocalStoreGoodsPic extends Models { protected $table = 'ls_local_store_goods_pic'; + + public function getUrlAttr($value) + { + return $value ? UrlServer::getFileUrl($value) : ''; + } } \ No newline at end of file