调整云仓商品列表查询

This commit is contained in:
luofei 2024-01-23 14:05:55 +08:00
parent 7f61f9d6bc
commit dde3899a58
5 changed files with 35 additions and 44 deletions

View File

@ -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];
}
}

View File

@ -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) {

View File

@ -347,7 +347,7 @@ class MerchantDao extends BaseDao
}
/**
* 按距离获取有效的商户
* 按距离获取有效的云仓商品
* @param $lat
* @param $lng
* @param $sort 是否按距离排序

View File

@ -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)) {

View File

@ -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']);