Index.php
23.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
<?php
namespace app\api\controller;
use app\api\model\Appointment;
use app\api\model\AppointmentAppraise;
use app\api\model\AppointmentLog;
use app\api\model\Dept;
use app\api\model\Doctor;
use app\api\model\DoctorLevel;
use app\api\model\UserCollectDoctor;
use app\common\controller\Api;
use app\common\controller\Wechat;
use think\Db;
/**
* 首页接口
*/
class Index extends Api
{
protected $noNeedLogin = ['index','deptInfo','dateList','doctorList','filterList','doctorInfo'];
protected $noNeedRight = ['*'];
/**
* @ApiWeigh (99)
* @ApiTitle (首页)
* @ApiSummary (首页)
* @ApiMethod (POST)
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1625281539",
"data": {
"dept_list": [{ //专科
"id": 1,
"image": "http://www.consultation.top/assets/img/qrcode.png",
"name": "官方新闻"
}],
"doctor_list": [{ //医生数据
"id": 1, //医生ID
"avatar": "http://www.consultation.top/assets/img/qrcode.png", //头像
"nickname": "小何", //昵称
"level_id": 2,
"dept_ids": "1,15,6,13",
"star": "0.00", //评分
"good_field": "爬树", //擅长
"level": 2, //等级
"dept_list": [{ //专科列表
"id": 1, //ID
"name": "骨科与神经外科" //名称
}]
}]
"appointment_log": [{ //会诊记录
"id": 3, //ID
"avatar": "http://www.consultation.top/uploads/20201225/37520d1204a0c55474021b43dac2a69e.png", //头像
"nickname": "何**", //昵称
"date": "07月07日", //日期
"doctor": { //医生
"id": 1, //ID
"nickname": "张清北" //姓名
}
}]
}
})
*/
public function index()
{
$dept_list = Dept::where('pid',0)->field('id,image,name')->select();
$doctor_list = (new Doctor)->getList(['a.status'=>'1'],['a.star'=>'desc','a.createtime'=>'desc']);
$doctor_list = $doctor_list->items();
$appointment_log = AppointmentLog::with(['doctor'])
->order('createtime desc')
->paginate(10)
->each(function($v){
$v->visible(['id','avatar','nickname','date','doctor']);
});
$appointment_log = $appointment_log->items();
$this->success('成功',compact('dept_list','doctor_list','appointment_log'));
}
/**
* @ApiWeigh (97)
* @ApiTitle (专科服务)
* @ApiSummary (专科服务)
* @ApiMethod (POST)
* @ApiParams (name=dept_id, type=integer, required=true, description="专科ID")
* @ApiParams (name=doctor_id, type=integer, required=true, description="医生ID")
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1625558684",
"data": {
"title": "会诊下单", //标题
"text_prie": "100.00", //文字沟通费用
"audio_price": "110.00", //语音沟通费用
"doctor": { //医生信息
"id": 1, //医生ID
"nickname": "小何", //姓名
"good_field": "爬树", //擅长
"description": "爬树小王子", //简介
"level": 2 //等级
}
}
})
*/
public function deptInfo()
{
$dept_id = $this->request->post('dept_id');
$doctor_id = $this->request->post('doctor_id');
if(empty($doctor_id)){
empty($dept_id) && $this->error('请选择专科');
$dept = Dept::where('id',$dept_id)->field('id,name,text_price,audio_price')->find();
empty($dept) && $this->error('专科不存在');
$data = [
'title' => $dept['name'],
'text_prie' => $dept['text_price'],
'audio_price' => $dept['audio_price'],
'doctor' => (Object)[],
];
}else{
$doctor = Doctor::get($doctor_id);
empty($doctor) && $this->error('医生信息不存在');
$data = [
'title' => '会诊下单',
'text_prie' => $doctor['text_price'],
'audio_price' => $doctor['audio_price'],
'doctor' => $doctor->visible(['id','nickname','good_field','description'])->append(['level']),
];
}
$this->success('成功',$data);
}
/**
* @ApiWeigh (97)
* @ApiTitle (专科服务-预约)
* @ApiSummary (专科服务-预约)
* @ApiMethod (POST)
* @ApiParams (name=type, type=integer, required=true, description="服务类型:1=文字沟通,2=音频沟通")
* @ApiParams (name=date, type=string, required=true, description="日期", sample="2021-07-08")
* @ApiParams (name=time, type=string, required=true, description="时间", sample="11:00")
* @ApiParams (name=description, type=string, required=true, description="病状描述")
* @ApiParams (name=dept_id, type=integer, required=true, description="专科ID")
* @ApiParams (name=doctor_id, type=integer, required=true, description="专科ID")
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1624349789",
"data": null
})
*/
public function appointment(){
$post = $this->request->post();
empty($post['type']) && $this->error('请选择服务类型');
empty($post['date']) && $this->error('请选择预约日期');
empty($post['time']) && $this->error('请选择预约时间');
empty($post['description']) && $this->error('请填写病状描述');
!in_array($post['type'],[1,2]) && $this->error('服务类型不合法');
for($i = 0; $i < 7; $i++){
$day = time()+$i*86400;
$date_arr[] = date('Y-m-d',$day);
}
!in_array($post['date'],$date_arr) && $this->error('预约时间不合法');
// $tomorrow_time = strtotime('+1 days',strtotime($post['date']));
if(empty($post['doctor_id'])){
empty($post['dept_id']) && $this->error('请选择专科');
$dept = Dept::get($post['dept_id']);
empty($dept) && $this->error('专科不存在');
// 是否已预约
$has = Appointment::where('user_id',$this->auth->id)
->where("find_in_set({$post['dept_id']},dept_ids)")
->where('date',$post['date'])
// ->where('date_time','<',$tomorrow_time)
->where('status','in','1,2')
->find();
!empty($has) && $this->error('您已预约,请勿重复操作');
// 是否可以预约,随机分配医生
$doctor = Doctor::alias('a')
->join('doctor_nowork b','b.doctor_id = a.id and b.date = '.$post['date'],'left')
->join('appointment c','c.doctor_id = a.id and c.date = '.$post['date'].' and c.status in (1,2)','left')
// ->join('appointment c','c.doctor_id = a.id and c.date_time < '.$tomorrow_time.' and c.status in (1,2)','left')
->where('b.id',null)
->where('c.id',null)
->where("find_in_set({$post['dept_id']},a.dept_ids)")
->field('a.id')
->orderRaw('rand()')
->limit(1)
->select();
count($doctor) < 1 && $this->error('已被预约满了,请再等等或选择其他日期预约');
$dept_ids = $post['dept_id'];
$pay_fee = $post['type'] == 1 ? $dept['text_price'] : $dept['audio_price'];
$doctor_id = $doctor[0]['id'];
$is_distribute = '0';
}else{
$doctor = Doctor::get($post['doctor_id']);
empty($doctor) && $this->error('医生信息不存在');
empty($doctor['dept_ids']) && $this->error('请通知管理员,给医生添加服务类目');
// 是否已预约
$has = Appointment::where('user_id',$this->auth->id)
->where('doctor_id',$post['doctor_id'])
->where('date',$post['date'])
// ->where('date_time','<',$tomorrow_time)
->where('status','in','1,2')
->find();
!empty($has) && $this->error('您已预约,请勿重复操作');
// 是否可以预约,随机分配医生
$ok = Doctor::alias('a')
->join('doctor_nowork b','b.doctor_id = a.id and b.date = '.$post['date'],'left')
->join('appointment c','c.doctor_id = a.id and c.date = '.$post['date'].' and c.status in (1,2)','left')
// ->join('appointment c','c.doctor_id = a.id and c.date_time < '.$tomorrow_time.' and c.status in (1,2)','left')
->where('b.id',null)
->where('c.id',null)
->where('a.id',$post['doctor_id'])
->field('a.id')
->find();
empty($ok) && $this->error('已被预约满了,请再等等或选择其他日期预约');
$dept_ids = Dept::where('id','in',$doctor['dept_ids'])->where('pid',0)->column('id');
$dept_ids = implode(',',$dept_ids);
$pay_fee = $post['type'] == 1 ? $doctor['text_price'] : $doctor['audio_price'];
$doctor_id = $post['doctor_id'];
$is_distribute = '1';
}
// 创建订单
$appointment = Appointment::create([
'user_id' => $this->auth->id,
'order_sn' => get_order_sn(),
'doctor_id' => $doctor_id,
'pay_fee' => $pay_fee,
'dept_ids' => $dept_ids,
'is_distribute' => $is_distribute,
'date_time' => strtotime($post['date']. ' ' .$post['time']),
'type' => $post['type'],
'description' => $post['description'],
'date' => $post['date']
]);
// 发起微信支付
$Wechat = new Wechat;
$openid = Db::name('third')->where('user_id',$this->auth->id)->value('openid');
$notify_url = $this->request->root(true) . '/api/notify/notifyAppointment';
if(!$payment = $Wechat->wxPay($appointment['order_sn'], $openid, $pay_fee, $notify_url)){
$this->error($Wechat->getError());
}
// $payment = [];
// (new Notify())->notifyAppointmentZero([
// 'out_trade_no' => $appointment['order_sn'],
// 'transaction_id' => ''
// ]);
$this->success('成功',[
'payment' => $payment,
'appointment_id' => $appointment['id']
]);
}
/**
* @ApiWeigh (95)
* @ApiTitle (专科服务-会诊时间-日期)
* @ApiSummary (专科服务-会诊时间-日期)
* @ApiMethod (POST)
* @ApiParams (name=dept_id, type=integer, required=true, description="专科ID")
* @ApiParams (name=doctor_id, type=integer, required=true, description="医生ID")
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1625560009",
"data": [{
"date": "2021-07-06", //日期
"name": "今天", //文字展示
"status": 2 //预约状态:1=确认预约,2=已选择,3=已预约
}]
})
*/
public function dateList(){
$dept_id = $this->request->post('dept_id');
$doctor_id = $this->request->post('doctor_id');
if(empty($doctor_id)){
empty($dept_id) && $this->error('请选择专科');
$dept = Dept::get($dept_id);
empty($dept) && $this->error('专科不存在');
$arr = [];
for($i = 0; $i < 7; $i++){
$day = time()+$i*86400;
$date = date('Y-m-d',$day);
// $tomorrow_time = strtotime('+1 days',strtotime($date));
// 预约状态:1=确认预约,2=已选择,3=已预约
$appointment = Appointment::where('user_id',$this->auth->id)
->where("find_in_set({$dept_id},dept_ids)")
->where('date',$date)
// ->where('date_time','<',$tomorrow_time)
->where('status','in','1,2')
->find();
$doctor = Doctor::alias('a')
->join('doctor_nowork b','b.doctor_id = a.id and b.date = '.$date,'left')
->join('appointment c','c.doctor_id = a.id and c.date = '.$date.' and c.status in (1,2)','left')
// ->join('appointment c','c.doctor_id = a.id and c.date_time < '.$tomorrow_time.' and c.status in (1,2)','left')
->where('b.id',null)
->where('c.id',null)
->where('a.dept_ids','1')
->where("find_in_set({$dept_id},a.dept_ids)")
->field('a.id')
->find();
$arr[] = [
'date' => $date,
'name' => $i == 0 ? '今天' : date('m月d日',$day),
'status' => !empty($appointment) ? 2 : (!empty($doctor) ? 1 : 3),
];
}
}else{
$doctor = Doctor::get($doctor_id);
empty($doctor) && $this->error('医生信息不存在');
$arr = [];
for($i = 0; $i < 7; $i++){
$day = time()+$i*86400;
$date = date('Y-m-d',$day);
// $tomorrow_time = strtotime('+1 days',strtotime($date));
// 预约状态:1=确认预约,2=已选择,3=已预约
$appointment = Appointment::where('user_id',$this->auth->id)
->where('doctor_id',$doctor_id)
->where('date',$date)
// ->where('date_time','<',$tomorrow_time)
->where('status','in','1,2')
->find();
$doctor = Doctor::alias('a')
->join('doctor_nowork b','b.doctor_id = a.id and b.date = '.$date,'left')
->join('appointment c','c.doctor_id = a.id and c.date = '.$date.' and c.status in (1,2)','left')
// ->join('appointment c','c.doctor_id = a.id and c.date_time < '.$tomorrow_time.' and c.status in (1,2)','left')
->where('b.id',null)
->where('c.id',null)
->where('a.id',$doctor_id)
->field('a.id')
->find();
$arr[] = [
'date' => $date,
'name' => $i == 0 ? '今天' : date('m月d日',$day),
'status' => !empty($appointment) ? 2 : (!empty($doctor) ? 1 : 3),
];
}
}
$this->success('成功',$arr);
}
/**
* @ApiWeigh (91)
* @ApiTitle (医生帮)
* @ApiSummary (医生帮)
* @ApiMethod (POST)
* @ApiParams (name=page, type=integer, required=false, description="分页")
* @ApiParams (name=keyword, type=string, required=false, description="关键字")
* @ApiParams (name=order, type=string, required=false, description="排序:1=评分最高,2=月接单量,3=总接单量")
* @ApiParams (name=level_ids, type=inter, required=false, description="医生等级ID集合")
* @ApiParams (name=dept_ids, type=inter, required=false, description="专科ID集合")
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1625560239",
"data": {
"total": 1, //数据总数
"per_page": 10,
"current_page": 1,
"last_page": 1,
"data": [{ //医生列表
"id": 1, //ID
"avatar": "http://www.consultation.top/assets/img/qrcode.png", //头像
"nickname": "小何", //姓名
"level_id": 2,
"dept_ids": "1,15,6,13",
"star": "0.00", //评分
"good_field": "爬树", //擅长
"level": 2, //等级
"dept_list": [{ //专科
"id": 1, //ID
"name": "骨科与神经外科" //名称
}]
}]
}
})
*/
public function doctorList(){
$keyword = $this->request->post('keyword');
$order = $this->request->post('order');
$level_ids = $this->request->post('level_ids');
$dept_ids = $this->request->post('dept_ids');
switch ($order){
case 1:
$order = ['a.star' => 'desc'];
break;
case 2:
$order = ['a.month_receive_num' => 'desc'];
break;
case 3:
$order = ['a.total_receive_num' => 'desc'];
break;
default:
$order = ['a.createtime' => 'desc'];
}
$where = 'a.status = "1"';
if(!empty($keyword)){
$where .= ' and a.nickname like "%'.$keyword.'%"';
}
if(!empty($level_ids)){
$where .= ' and a.level_id in ('.$level_ids.')';
}
if(!empty($dept_ids)){
$where1 = [];
foreach (explode(',',$dept_ids) as $v){
$where1[] = 'find_in_set('.$v.','.$dept_ids.')';
}
$where .= ' and ('.implode(' or ',$where1).')';
}
$this->success('成功',(new Doctor)->getList($where,$order));
}
/**
* @ApiWeigh (89)
* @ApiTitle (医生帮-筛选项)
* @ApiSummary (医生帮-筛选项)
* @ApiMethod (POST)
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1625560401",
"data": {
"level_list": [{ //等级列表
"id": 1, //ID
"name": "1级" //名称
}],
"dept_list": [{ //专科列表
"id": 1, //ID
"name": "骨科与神经外科" //名称
}]
}
})
*/
public function filterList(){
$level_list = DoctorLevel::field('id,name')->select();
$dept_list = Dept::where('pid',0)->field('id,name')->select();
$this->success('成功',compact('level_list','dept_list'));
}
/**
* @ApiWeigh (87)
* @ApiTitle (医生详情)
* @ApiSummary (医生详情)
* @ApiMethod (POST)
* @ApiHeaders (name="token", type="string", required=true, description="token")
* @ApiParams (name=doctor_id, type=integer, required=true, description="医生ID")
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1625560939",
"data": {
"doctor": { //医生信息
"id": 1, //ID
"nickname": "小何", //姓名
"avatar": "http://www.consultation.top/assets/img/qrcode.png", //头像
"images": [ //图片
"http://www.consultation.top/assets/img/qrcode.png",
"http://www.consultation.top/assets/img/qrcode.png"
],
"good_field": "爬树", //擅长
"description": "爬树小王子", //简介
"star": "0.00", //评分
"total_receive_num": 0, //接单量
"text_price": "100.00", //文字沟通费用
"audio_price": "110.00", //语音沟通费用
"level": 2, //等级
"is_collect": 0 //是否已收藏:0=否,1=是
},
"dept_list": [{ //专科列表
"id": 15, //ID
"name": "骨科与神经外科二级1" //名称
}]
}
})
*/
public function doctorInfo(){
$user_id = $this->auth->id > 0 ? $this->auth->id : 0;
$doctor_id = $this->request->post('doctor_id');
empty($doctor_id) && $this->error('缺少必须参数');
$doctor = Doctor::get($doctor_id);
empty($doctor) && $this->error('医生信息不存在');
$doctor['total_receive_num'] = $doctor['total_receive_num'] > 10000 ? round($doctor['total_receive_num']/10000,1).'万' : $doctor['total_receive_num'];
$doctor['is_collect'] = UserCollectDoctor::where('user_id',$user_id)->where('doctor_id',$doctor_id)->count();
$dept_list = Dept::where('id','in',$doctor['dept_ids'])->where('pid','>',0)->field("id,name")->select();
$doctor->visible(['id','avatar','nickname','star','total_receive_num','description','good_field','images','text_price','audio_price'])->append(['level','is_collect']);
$this->success('成功',compact('doctor','dept_list'));
}
/**
* @ApiWeigh (85)
* @ApiTitle (医生详情-收藏)
* @ApiSummary (医生详情-收藏)
* @ApiMethod (POST)
* @ApiHeaders (name="token", type="string", required=true, description="token")
* @ApiParams (name=doctor_id, type=integer, required=true, description="医生ID")
* @ApiReturn ({
"code": 1,
"msg": "收藏成功/取消收藏成功",
"time": "1616765142",
"data": null
})
*/
public function doctorCollect()
{
$doctor_id = $this->request->post('doctor_id');
empty($doctor_id) && $this->error('缺少必需参数');
$doctor = Doctor::get($doctor_id);
empty($doctor) && $this->error('医生信息不存在');
$where = [
'user_id' => $this->auth->id,
'doctor_id' => $doctor_id
];
$has = UserCollectDoctor::where($where)->find();
if(!$has){
UserCollectDoctor::create($where);
$msg = '收藏成功';
}else{
$has->delete();
$msg = '取消收藏成功';
}
$this->success($msg);
}
/**
* @ApiWeigh (83)
* @ApiTitle (医生详情-评价列表)
* @ApiSummary (医生详情-评价列表)
* @ApiMethod (POST)
* @ApiParams (name="doctor_id", type="integer", required=true, description="医生ID")
* @ApiParams (name="page", type="integer", required=false, description="分页")
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1625564431",
"data": {
"total": 1, //数据总数
"per_page": 10,
"current_page": 1,
"last_page": 1,
"data": [{ //列表
"id": 1, //ID
"star": 3, //评分
"content": "这就是街舞", //评论内容
"images": [ //图片
"http://www.consultation.top/uploads/20210623/32a69f0cb6c609b1d55f56f17583c473.png"
],
"video": "", //视频地址
"video_cover": "", //视频封面
"reply": "", //回复内容
"createtime": "2021-07/06-17:37", //评论时间
"user": { //用户信息
"id": 1, //ID
"nickname": "何先生", //姓名
"avatar": "http://www.consultation.top/uploads/20201225/37520d1204a0c55474021b43dac2a69e.png" //头像
},
"star_level_text": "中" //评分文字
}]
}
})
*/
public function appraiseList(){
$doctor_id = $this->request->post('doctor_id');
empty($doctor_id) && $this->error('缺少必须参数');
$doctor = Doctor::get($doctor_id);
empty($doctor) && $this->error('医生信息不存在');
$data = AppointmentAppraise::with(['user'])
->where('doctor_id',$doctor_id)
->where('delete_status','neq','2')
->order('createtime desc')
->paginate(10)
->each(function($v) {
$v->visible(['id','star','content','video','video_cover','images','reply','createtime','user']);
// 用户信息
$v->getRelation('user')->visible(['id','nickname','avatar']);
});
$this->success('成功', $data);
}
}