| xqd
@@ -10,6 +10,7 @@ namespace App\Http\Controllers\Api\V1;
|
|
|
|
|
|
use App\Models\Area;
|
|
|
use App\Models\Organization;
|
|
|
+use App\Models\Schedule;
|
|
|
use DB;
|
|
|
|
|
|
class OrganizationController extends AuthController
|
| xqd
@@ -21,15 +22,27 @@ class OrganizationController extends AuthController
|
|
|
'latitude' => 'numeric',
|
|
|
'longitude' => 'numeric',
|
|
|
'city_id' => 'integer',
|
|
|
+ 'schedule_type' => 'integer',
|
|
|
+ 'city_name' => 'max:50',
|
|
|
]);
|
|
|
$user = $this->user;
|
|
|
|
|
|
+ $schedule_type = !empty($req['schedule_type']) ? $req['schedule_type'] : 0;
|
|
|
$distance_field = get_user_distance_field($user);
|
|
|
|
|
|
$builder = Organization::with('docter')->select(['id', 'type', 'name', 'province_id', 'city_id', 'area_id', 'address', 'latitude', 'longitude','nurse_notice','vaccine_notice', DB::raw($distance_field)]);
|
|
|
+ if (in_array($schedule_type, [2,3])) {
|
|
|
+ $organization_ids = Schedule::where('schedule_type', $schedule_type)->where('schedule_day', '>=', date('Ymd'))->pluck('organization_id')->toArray();
|
|
|
+ $builder->whereIn('id', $organization_ids);
|
|
|
+ }
|
|
|
if (!empty($req['city_id'])) {
|
|
|
$builder->where('city_id', $req['city_id']);
|
|
|
}
|
|
|
+ if (!empty($req['city_name'])) {
|
|
|
+ $city_id = Area::where('name', 'like', '%'.$req['city_name'].'%')->where('level', 2)->value('id');
|
|
|
+ $city_id = !empty($city_id) ? $city_id : '';
|
|
|
+ $builder->where('city_id', $city_id);
|
|
|
+ }
|
|
|
$data = $builder->orderBy('distance', 'asc')->paginate();
|
|
|
|
|
|
return out($data);
|