| xqd
@@ -8,17 +8,123 @@
|
|
|
|
|
|
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 Illuminate\Support\Facades\DB;
|
|
|
+
|
|
|
class DocterController extends AuthController
|
|
|
{
|
|
|
- public function docterConsultList()
|
|
|
+ public function docterList()
|
|
|
{
|
|
|
$req = request()->post();
|
|
|
$this->validate(request(), [
|
|
|
- 'type' => 'required|in:1,2',
|
|
|
- 'docter_name' => 'max:50',
|
|
|
- 'organization_name' => 'max:255',
|
|
|
+ 'list_type' => 'in:1,2,3',
|
|
|
+ 'city_id' => 'integer',
|
|
|
+ 'name' => 'max:255',
|
|
|
+ 'latitude' => 'numeric',
|
|
|
+ 'longitude' => 'numeric',
|
|
|
+ 'sort_type' => 'in:1,2,3',
|
|
|
+ 'schedule_date' => 'required_if:list_type,3|date',
|
|
|
+ 'time_period_id' => 'required_if:list_type,3|integer',
|
|
|
]);
|
|
|
+ $user = $this->user;
|
|
|
+
|
|
|
+ $latitude = !empty($req['latitude']) ? $req['latitude'] : $user['latitude'];
|
|
|
+ $longitude = !empty($req['longitude']) ? $req['longitude'] : $user['longitude'];
|
|
|
+ $distance_field = get_distance_field($latitude, $longitude);
|
|
|
+
|
|
|
+ $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);
|
|
|
+ if ($req['list_type'] == 1) {
|
|
|
+ $builder->where('is_phone', 1);
|
|
|
+ }
|
|
|
+ if ($req['list_type'] == 2) {
|
|
|
+ $builder->where('is_chat', 1);
|
|
|
+ }
|
|
|
+ if ($req['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 ($req['list_type'] == 3) {
|
|
|
+ $docterIds2 = SchedulePeriod::where('time_period_id', $req['time_period_id'])->where('schedule_date', $req['schedule_date'])->pluck('docter_id');
|
|
|
+ $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: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;
|
|
|
+
|
|
|
+ $latitude = !empty($req['latitude']) ? $req['latitude'] : $user['latitude'];
|
|
|
+ $longitude = !empty($req['longitude']) ? $req['longitude'] : $user['longitude'];
|
|
|
+ $distance_field = get_distance_field($latitude, $longitude);
|
|
|
|
|
|
+ $data = 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('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',
|
|
|
+ ]);
|
|
|
+
|
|
|
+ $data = Schedule::with('schedulePeriod.timePeriod')->where('docter_id', $req['docter_id'])->where('schedule_day', '>=', date('Ymd'))->paginate($req['per_page']??15);
|
|
|
+
|
|
|
+ return out($data);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function timePeriodList()
|
|
|
+ {
|
|
|
+ $data = TimePeriod::select(['id', 'start_time_period', 'end_time_period'])->get();
|
|
|
+ return out($data);
|
|
|
}
|
|
|
}
|