1.获取距离

This commit is contained in:
xucong 2024-08-12 22:34:27 +08:00
parent 4bddbf2c80
commit f36c9d49ad
2 changed files with 5 additions and 12 deletions

@ -49,13 +49,6 @@ class LocalStore extends Api
$result = $model->getLocalUserOrderList($data);
return JsonServer::success('查询成功',$result);
}
// 查询距离
public function getLocalDistance(){
$model = new LocalStoreLogic;
$data = $this->request->param();
$result = $model->getLocalDistance($data);
return JsonServer::success('查询成功',$result);
}
public function addLocalStore()
{
$user_id = $this->user_id;
@ -222,11 +215,15 @@ class LocalStore extends Api
public function getLocalShopById()
{
$id = $this->request->post('id');
$latitude = $this->request->post('latitude');
$longitude = $this->request->post('longitude');
$result = Db::name('local_store')
->where(['lstore_id' => $id, 'user_id' => $this->user_id, 'store_state' => 1])
->order('create_time', 'desc')
->field('lstore_id, store_state, header_image, store_nickname, pay_image,shopName,shopLogo')
->field('latitude,longitude,lstore_id, store_state, header_image, store_nickname, pay_image,shopName,shopLogo')
->find();
$model = new LocalStoreLogic;
$result['distance']=round($model->distance($result['latitude'],$result['longitude'],$latitude,$longitude)/1000,2)."公里";
if ($result) {
$result['header_image'] = FileConfig::get('aliyunoss.domain') . 'local_life_shop/' . $result['header_image'] ;
return JsonServer::success('成功获取', $result);

@ -104,10 +104,6 @@ class LocalStoreLogic extends Logic
];
return $data;
}
public function getLocalDistance($data){
$result = Db::name("local_store")->where("lstore_id",$data['id'])->find();
return round($this->distance($data['latitude'], $data['longitude'], $result['latitude'], $result['longitude'])/1000,2)."公里";
}
function distance($lat1, $lon1, $lat2, $lon2) {
$earthRadius = 6371000; // 地球平均半径,单位为米