1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- /**
- * Created by PhpStorm.
- * User: zilongs
- * Date: 20-10-29
- * Time: 下午3:43
- */
- namespace App\Http\Controllers\Api\V1;
- use App\Models\Area;
- use App\Models\Organization;
- use App\Models\Schedule;
- use DB;
- class OrganizationController extends AuthController
- {
- public function organizationList()
- {
- $req = request()->post();
- $this->validate(request(), [
- '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);
- }
- public function organizationCityList()
- {
- $city_ids = Organization::pluck('city_id')->toArray();
- $data = Area::select(['id', 'name'])->whereIn('id', $city_ids)->get();
- return out($data);
- }
- }
|