From dde3899a5833e5129917a56c494bb264bef50364 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Tue, 23 Jan 2024 14:05:55 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BA=91=E4=BB=93?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=97=E8=A1=A8=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/dao/store/CityAreaDao.php | 26 +++++++++++++++++++ app/common/dao/store/StoreActivityDao.php | 15 +---------- .../dao/system/merchant/MerchantDao.php | 2 +- .../api/store/product/CloudWarehouse.php | 14 ++-------- app/controller/api/store/product/StoreSpu.php | 22 ++++------------ 5 files changed, 35 insertions(+), 44 deletions(-) diff --git a/app/common/dao/store/CityAreaDao.php b/app/common/dao/store/CityAreaDao.php index a9d8067c..0e439da0 100644 --- a/app/common/dao/store/CityAreaDao.php +++ b/app/common/dao/store/CityAreaDao.php @@ -95,4 +95,30 @@ class CityAreaDao extends BaseDao $lst[] = $city; return $lst; } + + /** + * 获取经纬度 + * @param $location + * @param $streetCode + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public function getLngAndLat($location, $streetCode) + { + if (!empty($location) && $location != ',') { + [$lat, $lng] = explode(',', $location); + } elseif (!empty($streetCode)) { + $location = GeoStreet::where('street_code', $streetCode)->field('lng,lat')->find(); + if (!empty($location)) { + [$lat, $lng] = [$location['lat'], $location['lng']]; + } + } + if (empty($lat) || empty($lng)) { + [$lat, $lng] = ['28.889137', '105.443352']; + } + return [$lat, $lng]; + } + } diff --git a/app/common/dao/store/StoreActivityDao.php b/app/common/dao/store/StoreActivityDao.php index 21bacf82..ad683647 100644 --- a/app/common/dao/store/StoreActivityDao.php +++ b/app/common/dao/store/StoreActivityDao.php @@ -15,13 +15,10 @@ namespace app\common\dao\store; use app\common\dao\BaseDao; use app\common\dao\store\product\CloudProductDao; -use app\common\model\BaseModel; -use app\common\model\store\GeoStreet; use app\common\model\store\product\CloudProduct; use app\common\model\store\StoreActivity; use app\common\model\store\StoreActivityOrderProduct; use app\common\repositories\store\product\SpuRepository; -use app\common\repositories\system\RelevanceRepository; use think\exception\ValidateException; use think\facade\Db; @@ -55,17 +52,7 @@ class StoreActivityDao extends BaseDao */ public function product($location, $streetCode, $activityId) { - if (!empty($location) && $location != ',') { - [$lat, $lng] = explode(',', $location); - } elseif (!empty($streetCode)) { - $location = GeoStreet::where('street_code', $streetCode)->field('lng,lat')->find(); - if (!empty($location)) { - [$lat, $lng] = [$location['lat'], $location['lng']]; - } - } - if (empty($lat) || empty($lng)) { - [$lat, $lng] = ['28.889137', '105.443352']; - } + [$lat, $lng] = (new CityAreaDao())->getLngAndLat($location, $streetCode); $cloud_product_arr = (new CloudProductDao())->getByDistance($lat, $lng, ['activity_id' => $activityId], 4); $cloud_product = []; foreach ($cloud_product_arr as $key => $value) { diff --git a/app/common/dao/system/merchant/MerchantDao.php b/app/common/dao/system/merchant/MerchantDao.php index c28fc8a8..998c57a6 100644 --- a/app/common/dao/system/merchant/MerchantDao.php +++ b/app/common/dao/system/merchant/MerchantDao.php @@ -347,7 +347,7 @@ class MerchantDao extends BaseDao } /** - * 按距离获取有效的商户 + * 按距离获取有效的云仓商品 * @param $lat * @param $lng * @param $sort 是否按距离排序 diff --git a/app/controller/api/store/product/CloudWarehouse.php b/app/controller/api/store/product/CloudWarehouse.php index 68e6786f..d6fcf60b 100644 --- a/app/controller/api/store/product/CloudWarehouse.php +++ b/app/controller/api/store/product/CloudWarehouse.php @@ -2,8 +2,8 @@ namespace app\controller\api\store\product; +use app\common\dao\store\CityAreaDao; use app\common\dao\system\merchant\MerchantDao; -use app\common\model\store\GeoStreet; use app\common\model\system\merchant\Merchant; use app\common\repositories\store\product\SpuRepository; use think\facade\Db; @@ -47,17 +47,7 @@ class CloudWarehouse extends BaseController public function index($street_code, $page = 1, $category_id = 0, $cate_pid = 0,$cate_id = 0,$location = '') { $keyword = $this->request->get('keyword'); - if (!empty($location) && $location != ',') { - [$lat, $lng] = explode(',', $location); - } elseif (!empty($street_code)) { - $location = GeoStreet::where('street_code', $street_code)->field('lng,lat')->find(); - if (!empty($location)) { - [$lat, $lng] = [$location['lat'], $location['lng']]; - } - } - if (empty($lat) || empty($lng)) { - [$lat, $lng] = ['28.889137', '105.443352']; - } + [$lat, $lng] = (new CityAreaDao())->getLngAndLat($location, $street_code); $query = Db::name('cloud_product')->where('status', 1); $productIds = (new MerchantDao())->getProductByDistance($lat, $lng,false,50000); if (empty($productIds)) { diff --git a/app/controller/api/store/product/StoreSpu.php b/app/controller/api/store/product/StoreSpu.php index 31cd4c4f..22f1814c 100644 --- a/app/controller/api/store/product/StoreSpu.php +++ b/app/controller/api/store/product/StoreSpu.php @@ -10,10 +10,9 @@ // +---------------------------------------------------------------------- namespace app\controller\api\store\product; +use app\common\dao\store\CityAreaDao; use app\common\dao\system\merchant\MerchantDao; -use app\common\model\store\GeoStreet; use app\common\model\system\merchant\Merchant; -use app\common\repositories\store\product\ProductRepository; use app\common\repositories\store\StoreCategoryRepository; use app\common\repositories\system\merchant\MerchantRepository; use app\common\repositories\user\UserHistoryRepository; @@ -68,23 +67,12 @@ class StoreSpu extends BaseController 'location' ]); if ($where['type_id']||$where['type_code']) { + [$lat, $lng] = (new CityAreaDao())->getLngAndLat($where['location'], $where['street_id']); $arr = ['status' => 1, 'mer_state' => 1, 'is_del' => 0]; $query = Merchant::where($arr); - if ($where['location']) { - [$lat, $lng] = explode(',', $where['location']); - $merIds = (new MerchantDao())->getValidMerchantByDistance($lat, $lng); - if (!empty($merIds)) { - $query->whereIn('mer_id', $merIds); - } - } - if ($where['street_id'] && empty($where['location'])) { - $location = GeoStreet::where('street_code', $where['street_id'])->field('lng,lat')->find(); - if (!empty($location)) { - $merIds = (new MerchantDao())->getValidMerchantByDistance($location['lat'], $location['lng']); - if (!empty($merIds)) { - $query->whereIn('mer_id', $merIds); - } - } + $merIds = (new MerchantDao())->getValidMerchantByDistance($lat, $lng); + if (!empty($merIds)) { + $query->whereIn('mer_id', $merIds); } if ($where['village_id']) { $query->where('village_id', $where['village_id']); From 593875f7519e5c853c9f421cfaf685c31f0b9bb3 Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Tue, 23 Jan 2024 15:55:26 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=BA=91=E4=BB=93?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=88=97=E8=A1=A8=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/api/store/product/CloudWarehouse.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/controller/api/store/product/CloudWarehouse.php b/app/controller/api/store/product/CloudWarehouse.php index d6fcf60b..eb1cb8d4 100644 --- a/app/controller/api/store/product/CloudWarehouse.php +++ b/app/controller/api/store/product/CloudWarehouse.php @@ -47,6 +47,7 @@ class CloudWarehouse extends BaseController public function index($street_code, $page = 1, $category_id = 0, $cate_pid = 0,$cate_id = 0,$location = '') { $keyword = $this->request->get('keyword'); + $order = $this->request->get('order'); [$lat, $lng] = (new CityAreaDao())->getLngAndLat($location, $street_code); $query = Db::name('cloud_product')->where('status', 1); $productIds = (new MerchantDao())->getProductByDistance($lat, $lng,false,50000); @@ -63,6 +64,15 @@ class CloudWarehouse extends BaseController if (!empty($keyword)) { $query->where('store_name', 'like', '%'. $keyword . '%'); } + if (!empty($order)) { + if ($order == 'sales') { + $query->order($order, 'desc'); + } elseif ($order == 'price_desc') { + $query->order('price', 'desc'); + } else { + $query->order('price', 'asc'); + } + } $cloud_product_arr = $query->where(function($query){ $query->where('mer_labels', '') ->whereOr('mer_labels',',5,'); @@ -77,7 +87,8 @@ class CloudWarehouse extends BaseController 'status' => 1, 'is_del' => 0, 'mer_status' => 1, - 'product_id' => $cloud_product + 'product_id' => $cloud_product, + 'order' => $order ]; if (!$cloud_product) { return app('json')->success(['count' => 0, 'list' => []]);