|
|
|
|
@ -9,6 +9,7 @@ use App\Helpers\ResponseCode;
|
|
|
|
|
use App\Models\AppointmentConfig;
|
|
|
|
|
use App\Models\AppointmentType;
|
|
|
|
|
use App\Models\Banner;
|
|
|
|
|
use App\Models\Company;
|
|
|
|
|
use App\Models\Config;
|
|
|
|
|
use App\Repositories\YuanheRepository;
|
|
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
|
@ -137,4 +138,73 @@ class OtherController extends CommonController
|
|
|
|
|
return $this->success($result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @OA\Get(
|
|
|
|
|
* path="/api/mobile/other/company-list",
|
|
|
|
|
* tags={"小程序-其他"},
|
|
|
|
|
* summary="公司列表",
|
|
|
|
|
* @OA\Parameter(name="company_longitude", in="query", @OA\Schema(type="string"), required=false, description="经度"),
|
|
|
|
|
* @OA\Parameter(name="company_latitude", in="query", @OA\Schema(type="string"), required=false, description="纬度"),
|
|
|
|
|
* @OA\Parameter(name="page_size", in="query", @OA\Schema(type="string"), required=false, description="每页显示的条数"),
|
|
|
|
|
* @OA\Parameter(name="page", in="query", @OA\Schema(type="string"), required=false, description="页码"),
|
|
|
|
|
* @OA\Parameter(name="sort_name", in="query", @OA\Schema(type="string"), required=false, description="排序字段名字"),
|
|
|
|
|
* @OA\Parameter(name="sort_type", in="query", @OA\Schema(type="string"), required=false, description="排序类型"),
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
* response=200,
|
|
|
|
|
* description="操作成功"
|
|
|
|
|
* )
|
|
|
|
|
* )
|
|
|
|
|
*/
|
|
|
|
|
public function companyList()
|
|
|
|
|
{
|
|
|
|
|
$all = \request()->all();
|
|
|
|
|
$messages = [
|
|
|
|
|
'company_longitude.required' => '经度必填',
|
|
|
|
|
'company_latitude.required' => '纬度必填',
|
|
|
|
|
];
|
|
|
|
|
$validator = Validator::make($all, [
|
|
|
|
|
'company_longitude' => 'required',
|
|
|
|
|
'company_latitude' => 'required',
|
|
|
|
|
], $messages);
|
|
|
|
|
if ($validator->fails()) {
|
|
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$longitude = $all['company_longitude'];
|
|
|
|
|
$latitude = $all['company_latitude'];
|
|
|
|
|
$pageSize = $all['page_size'] ?? 10;
|
|
|
|
|
$page = $all['page'] ?? 1;
|
|
|
|
|
$sortName = $all['sort_name'] ?? 'distance';
|
|
|
|
|
$sortType = $all['sort_type'] ?? 'asc';
|
|
|
|
|
|
|
|
|
|
// 使用 Haversine 公式计算距离
|
|
|
|
|
$distanceFormula = "
|
|
|
|
|
(6371 * acos(
|
|
|
|
|
cos(radians(?)) *
|
|
|
|
|
cos(radians(CAST(company_latitude AS DECIMAL(10,8)))) *
|
|
|
|
|
cos(radians(CAST(company_longitude AS DECIMAL(10,8))) - radians(?)) +
|
|
|
|
|
sin(radians(?)) *
|
|
|
|
|
sin(radians(CAST(company_latitude AS DECIMAL(10,8))))
|
|
|
|
|
)) AS distance
|
|
|
|
|
";
|
|
|
|
|
|
|
|
|
|
$query = Company::select('*')
|
|
|
|
|
->selectRaw($distanceFormula, [$latitude, $longitude, $latitude])
|
|
|
|
|
->whereNotNull('company_longitude')
|
|
|
|
|
->whereNotNull('company_latitude')
|
|
|
|
|
->where('company_longitude', '!=', '')
|
|
|
|
|
->where('company_latitude', '!=', '');
|
|
|
|
|
|
|
|
|
|
// 根据排序字段进行排序
|
|
|
|
|
if ($sortName === 'distance') {
|
|
|
|
|
$query->orderBy('distance', $sortType);
|
|
|
|
|
} else {
|
|
|
|
|
$query->orderBy($sortName, $sortType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$result = $query->paginate($pageSize, ['*'], 'page', $page);
|
|
|
|
|
|
|
|
|
|
return $this->success($result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|