调整云仓商品列表查询
This commit is contained in:
parent
852904cbd9
commit
cc8562411c
@ -15,6 +15,7 @@ namespace app\common\dao\system\merchant;
|
||||
|
||||
|
||||
use app\common\dao\BaseDao;
|
||||
use app\common\model\store\product\CloudProduct;
|
||||
use app\common\model\system\merchant\Merchant;
|
||||
use crmeb\services\VicWordService;
|
||||
use think\db\BaseQuery;
|
||||
@ -345,4 +346,33 @@ class MerchantDao extends BaseDao
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 按距离获取有效的商户
|
||||
* @param $lat
|
||||
* @param $lng
|
||||
* @param $sort 是否按距离排序
|
||||
* @param $distance 距离,单位米
|
||||
* @return mixed
|
||||
*/
|
||||
public function getProductByDistance($lat, $lng, $sort = false, $distance = 10000)
|
||||
{
|
||||
$query = CloudProduct::where('type_id', 'IN', ["10", "17"])
|
||||
->whereNotNull('lat')
|
||||
->whereNotNull('long')
|
||||
->field("product_id,st_distance_sphere(point(`long`,`lat`), point({$lng}, {$lat})) as distance");
|
||||
if ($sort) {
|
||||
$query->order('distance')->limit(100);
|
||||
} else {
|
||||
$query->having("distance <= {$distance}")->limit(50);
|
||||
}
|
||||
$product = $query->select()->toArray();
|
||||
if (empty($product) && $distance < 50000 && !$sort) {
|
||||
$product = $this->getProductByDistance($lat, $lng, $sort, 50000);
|
||||
}
|
||||
if (!empty($product)) {
|
||||
return array_column($product, 'product_id');
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -46,27 +46,22 @@ class CloudWarehouse extends BaseController
|
||||
*/
|
||||
public function index($street_code, $page = 1, $category_id = 0, $cate_pid = 0,$cate_id = 0,$location = '')
|
||||
{
|
||||
$query = Db::name('cloud_product')->where('status', 1);
|
||||
if (!empty($location) && $location != ',') {
|
||||
[$lat, $lng] = explode(',', $location);
|
||||
}
|
||||
if (!empty($street_code) && (empty($location) || $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)) {
|
||||
$merIds = (new MerchantDao())->getValidMerchantByDistance($lat, $lng,true,50000);
|
||||
if (!empty($merIds)) {
|
||||
$query->whereIn('mer_id', $merIds);
|
||||
}
|
||||
if (empty($lat) || empty($lng)) {
|
||||
[$lat, $lng] = ['28.889137', '105.443352'];
|
||||
}
|
||||
if (empty($merIds) && !empty($lat)) {
|
||||
$merIds = (new MerchantDao())->getValidMerchantByDistance($lat, $lng, true);
|
||||
$query->whereIn('mer_id', $merIds);
|
||||
$query = Db::name('cloud_product')->where('status', 1);
|
||||
$productIds = (new MerchantDao())->getProductByDistance($lat, $lng,false,50000);
|
||||
if (empty($productIds)) {
|
||||
$productIds = (new MerchantDao())->getProductByDistance($lat, $lng, true);
|
||||
$query->whereIn('product_id', $productIds);
|
||||
}
|
||||
if($cate_pid!=0){
|
||||
$cate_id=Db::name('store_category')->where('pid',$cate_pid)->where('is_show',1)->column('store_category_id');
|
||||
|
Loading…
x
Reference in New Issue
Block a user