调整商品列表查询

This commit is contained in:
luofei 2024-01-22 15:18:30 +08:00
parent 13403e44e7
commit 07a4dba152
2 changed files with 16 additions and 7 deletions

View File

@ -319,20 +319,25 @@ class MerchantDao extends BaseDao
* 按距离获取有效的商户
* @param $lat
* @param $lng
* @param $sort 是否按距离排序
* @param $distance 距离,单位米
* @return mixed
*/
public function getValidMerchantByDistance($lat, $lng, $distance = 2000)
public function getValidMerchantByDistance($lat, $lng, $sort = false, $distance = 2000)
{
$merchant = Merchant::where('type_id', 'IN', ["10", "17"])
$query = Merchant::where('type_id', 'IN', ["10", "17"])
->where(['is_del' => 0, 'mer_state' => 1])
->whereNotNull('lat')
->whereNotNull('long')
->field("mer_id,st_distance_sphere(point(`long`,`lat`), point({$lng}, {$lat})) as distance")
->having("distance <= {$distance}")
->limit(50)->select()->toArray();
if (empty($merchant) && $distance < 5000) {
$merchant = $this->getValidMerchantByDistance($lat, $lng, 5000);
->field("mer_id,st_distance_sphere(point(`long`,`lat`), point({$lng}, {$lat})) as distance");
if ($sort) {
$query->order('distance')->limit(20);
} else {
$query->having("distance <= {$distance}")->limit(50);
}
$merchant = $query->select()->toArray();
if (empty($merchant) && $distance < 5000 && !$sort) {
$merchant = $this->getValidMerchantByDistance($lat, $lng, $sort, 5000);
}
if (!empty($merchant)) {
return array_column($merchant, 'mer_id');

View File

@ -56,6 +56,10 @@ class CloudWarehouse extends BaseController
}
}
}
if (empty($merIds)) {
$merIds = (new MerchantDao())->getValidMerchantByDistance($location['lat'], $location['lng'], true);
$query->whereIn('mer_id', $merIds);
}
if($cate_pid!=0){
$cate_id=Db::name('store_category')->where('pid',$cate_pid)->where('is_show',1)->column('store_category_id');
}