|
@@ -25,12 +25,46 @@ class OfflineShop extends Api
|
|
return $this->success('success',DataUtil::recursion($list,'id','pid'));
|
|
return $this->success('success',DataUtil::recursion($list,'id','pid'));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // 商铺列表
|
|
public function list()
|
|
public function list()
|
|
{
|
|
{
|
|
$params = $this->request->param();
|
|
$params = $this->request->param();
|
|
- $params['category'] = 0;// 仅查询线下门店
|
|
|
|
|
|
+ $userLng = $this->auth->lng;
|
|
|
|
+ $userLat = $this->auth->lat;
|
|
$model = new OfflineShopModel();
|
|
$model = new OfflineShopModel();
|
|
- $list = $model->getList(params: $params,orderBy: ['weigh' => 'desc']);
|
|
|
|
|
|
+ $select = ['id', 'type_id', 'type_ids', 'name', 'image', 'lng', 'lat', 'address', 'telephone', 'star', 'sales'];
|
|
|
|
+ $orderBy = [];
|
|
|
|
+ if (!empty($userLng) && !empty($userLat)) {
|
|
|
|
+ $select[] = Db::raw("(st_distance(point ({$userLng}, {$userLat}),point(lng,lat))*111195) as distance");
|
|
|
|
+ !empty($params['distance']) && $params['distance'] = $params['distance'] * 1000;
|
|
|
|
+ }
|
|
|
|
+ if (!empty($this->auth->city)) {
|
|
|
|
+ $params['city'] = $this->auth->city;
|
|
|
|
+ }
|
|
|
|
+ if (isset($params['rank_type'])) {
|
|
|
|
+ switch ($params['rank_type']) {
|
|
|
|
+ case 1:
|
|
|
|
+ $orderBy['star'] = 'desc';
|
|
|
|
+ break;
|
|
|
|
+ case 2:
|
|
|
|
+ $orderBy['sales'] = 'desc';
|
|
|
|
+ break;
|
|
|
|
+ case 3:
|
|
|
|
+ if (!empty($userLng) && !empty($userLat)) {
|
|
|
|
+ $orderBy['distance'] = 'asc';
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ if (!empty($userLng) && !empty($userLat)) {
|
|
|
|
+ $orderBy['distance'] = 'asc';
|
|
|
|
+ }
|
|
|
|
+ $orderBy['star'] = 'desc';
|
|
|
|
+ $orderBy['sales'] = 'desc';
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $list = $model->getList(params: $params,orderBy: array_merge($orderBy,['weigh' => 'desc']),select: $select);
|
|
return $this->success('success',$list);
|
|
return $this->success('success',$list);
|
|
}
|
|
}
|
|
}
|
|
}
|