123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- /**
- * Created by PhpStorm.
- * User: zilongs
- * Date: 20-9-29
- * Time: 上午11:09
- */
- namespace App\Http\Controllers\Api\V1;
- use App\Models\Docter;
- use App\Models\Organization;
- use App\Models\Schedule;
- use App\Models\SchedulePeriod;
- use App\Models\TimePeriod;
- use DB;
- class DocterController extends AuthController
- {
- public function docterList()
- {
- $req = request()->post();
- $this->validate(request(), [
- 'list_type' => 'in:0,1,2,3',
- 'city_id' => 'integer',
- 'name' => 'max:255',
- 'latitude' => 'numeric',
- 'longitude' => 'numeric',
- 'sort_type' => 'in:0,1,2,3',
- 'schedule_date' => 'required_if:list_type,3|date',
- 'time_period_id' => 'required_if:list_type,3|integer',
- ]);
- $user = $this->user;
- $distance_field = get_user_distance_field($user);
- $builder = Docter::with('office', 'qualification')->select(['id', 'type', 'name', 'phone', 'sex', 'birthday', 'avatar', 'status', 'label', 'sign', 'intro', 'office_id', 'qualification_id', 'score', 'service_persons', 'eva_num', 'service_days', 'phone_minutes', 'chat_price', 'phone_price', 'appoint_price', 'is_chat', 'is_phone', 'is_appoint', 'latitude', 'longitude', DB::raw($distance_field)])->where('status', 1);
- $list_type = !empty($req['list_type']) ? $req['list_type'] : 0;
- if ($list_type == 1) {
- $builder->where('is_phone', 1);
- }
- if ($list_type == 2) {
- $builder->where('is_chat', 1);
- }
- if ($list_type == 3) {
- $builder->where('is_appoint', 1);
- }
- if (!empty($req['name'])) {
- $name = $req['name'];
- $organizations = Organization::with('docter')->select(['id'])->where('name', 'like', '%'.$name.'%')->get()->toArray();
- $docterIds = [];
- foreach ($organizations as $k => $v) {
- $tmpDocterIds = array_column($v['docter'], 'id');
- $docterIds = array_merge($docterIds, $tmpDocterIds);
- }
- $docterIds = array_values(array_unique($docterIds));
- $builder->where(function ($query) use($name, $docterIds) {
- $query->where('name', 'like', '%'.$name.'%')->orWhereIn('id', $docterIds);
- });
- }
- if ($list_type == 3) {
- $docterIds2 = SchedulePeriod::where('time_period_id', $req['time_period_id'])->where('schedule_date', $req['schedule_date'])->pluck('docter_id')->toArray();
- $builder->whereIn('id', $docterIds2);
- }
- if (!empty($req['sort_type'])) {
- if ($req['sort_type'] == 1) {
- $builder->orderBy('distance', 'asc');
- }
- elseif ($req['sort_type'] == 2) {
- $builder->orderBy('eva_num', 'desc');
- }
- elseif ($req['sort_type'] == 3) {
- $builder->orderBy('service_persons', 'desc');
- }
- }
- $data = $builder->paginate();
- return out($data);
- }
- public function docterDetail()
- {
- $req = request()->post();
- $this->validate(request(), [
- 'docter_id' => 'required|integer',
- 'list_type' => 'in:0,1,2,3',
- 'schedule_date' => 'required_if:list_type,3|date',
- 'time_period_id' => 'required_if:list_type,3|integer',
- 'latitude' => 'numeric',
- 'longitude' => 'numeric',
- ]);
- $user = $this->user;
- $distance_field = get_user_distance_field($user);
- $data = Docter::with('office', 'qualification', 'evaluate.user')->select(['id', 'type', 'name', 'phone', 'sex', 'birthday', 'avatar', 'status', 'label', 'sign', 'intro', 'office_id', 'qualification_id', 'score', 'service_persons', 'eva_num', 'service_days', 'phone_minutes', 'chat_price', 'phone_price', 'appoint_price', 'is_chat', 'is_phone', 'is_appoint', 'latitude', 'longitude', DB::raw($distance_field)])->where('id', $req['docter_id'])->where('status', 1)->first()->toArray();
- $data['organization'] = null;
- if (!empty($req['list_type']) && $req['list_type'] == 3) {
- $schedulePeriod = SchedulePeriod::with('organization')->select(['organization_id'])->where('docter_id', $req['docter_id'])->where('time_period_id', $req['time_period_id'])->where('schedule_date', $req['schedule_date'])->first()->toArray();
- $data['organization'] = $schedulePeriod['organization'];
- }
- return ($data);
- }
- public function schedulePeriodList()
- {
- $req = request()->post();
- $this->validate(request(), [
- 'docter_id' => 'required|integer',
- 'per_page' => 'integer',
- 'latitude' => 'numeric',
- 'longitude' => 'numeric',
- ]);
- $user = $this->user;
- $data = Schedule::with(['schedulePeriod.timePeriod', 'schedulePeriod.organization'])->where('docter_id', $req['docter_id'])->where('schedule_day', '>=', date('Ymd'))->paginate($req['per_page']??15)->toArray();
- if (!empty($data)) {
- foreach ($data['data'] as $k => &$v) {
- foreach ($v['schedule_period'] as $k1 => &$v1) {
- if (!empty($v1['organization'])) {
- $v1['organization']['distance'] = get_user_distance($user, $v1['organization']['latitude'], $v1['organization']['longitude']);
- }
- }
- }
- }
- return out($data);
- }
- public function timePeriodList()
- {
- $data = [];
- $data['list'] = TimePeriod::select(['id', 'start_time_period', 'end_time_period'])->get();
- for ($i = 0; $i < 7; $i++) {
- if ($i > 0) {
- $data['dates'][] = date('m-d', strtotime("+$i days"));
- }
- else {
- $data['dates'][] = date('m-d');
- }
- }
- return out($data);
- }
- }
|