|
|
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Api\Museum;
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
use Illuminate\Http\Request;
|
|
|
+use Illuminate\Support\Facades\DB;
|
|
|
use App\Servers\Wenlv\MuseumServer;
|
|
|
use App\Models\Api\Museum\Spot as SpotModel;
|
|
|
use App\Models\Api\Museum\SpotTmp as SpotTmpModel;
|
|
|
@@ -31,7 +32,7 @@ class Spot extends Controller
|
|
|
continue;
|
|
|
}
|
|
|
$list_data = $MuseumServer->getMuseumList($page);
|
|
|
- $list = isset($list_data['rows']['records']) ? $list_data['rows']['records']:'';
|
|
|
+ $list = isset($list_data['rows']['records']) ? $list_data['rows']['records'] : '';
|
|
|
if (!$list) continue;
|
|
|
$SpotTmpModel->insert(['page' => $page, 'data' => json_encode($list)]);
|
|
|
}
|
|
|
@@ -72,4 +73,34 @@ class Spot extends Controller
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取附近博物馆列表数据
|
|
|
+ * @author 唐远望
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2026-04-02
|
|
|
+ */
|
|
|
+ public function nearby_list(Request $request, SpotModel $SpotModel)
|
|
|
+ {
|
|
|
+ $longitude = $request->input('longitude', '');
|
|
|
+ $latitude = $request->input('latitude', '');
|
|
|
+ $page = $request->input('page', 1);
|
|
|
+ $limit = $request->input('limit', 10);
|
|
|
+ $query = $SpotModel->query()->where('status', 0);
|
|
|
+ $field = ['id', 'name', 'museum_type_id', 'museum_level', 'is_open', 'intro', 'longitude', 'latitude', 'province_name', 'city_name', 'district_name'];
|
|
|
+ $latlot_feild = ["DB::raw('(6371 * ACOS(COS(RADIANS(' . $latitude . ')) * COS(RADIANS(latitude)) * COS(RADIANS(longitude) - RADIANS(' . $longitude . ')) + SIN(RADIANS(' . $latitude . ')) * SIN(RADIANS(latitude)))) AS distance')"];
|
|
|
+ if (is_numeric($longitude) && $longitude > 0 && is_numeric($latitude) && $latitude > 0) {
|
|
|
+ $field = array_merge($field, $latlot_feild);
|
|
|
+ $query->select($field)->orderBy('distance', 'asc');
|
|
|
+ } else {
|
|
|
+ $query->select($field);
|
|
|
+ }
|
|
|
+ $data = $query->paginate($limit, ['*'], 'page', $page);
|
|
|
+ if (!empty($data['data'])) {
|
|
|
+ foreach ($$data['data'] as $key => $value) {
|
|
|
+ $data['data'][$key]['distance'] = isset($value['distance']) ? $value['distance'] : '0';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $data]);
|
|
|
+ }
|
|
|
}
|