Index.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 首页接口
  7. */
  8. class Index extends Api
  9. {
  10. protected $noNeedLogin = ['*'];
  11. protected $noNeedRight = ['*'];
  12. /**
  13. * 首页
  14. *
  15. */
  16. public function index()
  17. {
  18. $this->success('请求成功');
  19. }
  20. //科室列表
  21. public function keshi_list(){
  22. $list = Db::name('keshi')->where('is_show',1)->order('weigh','desc')->select();
  23. $this->success(1,$list);
  24. }
  25. //职称列表
  26. public function level_list(){
  27. $list = Db::name('doctor_level')->select();
  28. $this->success(1,$list);
  29. }
  30. //医生列表
  31. //首页推荐,搜索
  32. public function doctor_list(){
  33. $where = [
  34. 'd.status' => 1,
  35. 'd.doctor_status' => 1,
  36. ];
  37. //科室id
  38. $keshi_id = input('keshi_id',0);
  39. if($keshi_id){
  40. $where['d.keshi_id'] = $keshi_id;
  41. }
  42. //职称id
  43. $level_id = input('level_id',0);
  44. if($level_id){
  45. $where['d.level_id'] = $level_id;
  46. }
  47. //关注
  48. $folllow = input('follow',0);
  49. if($folllow){
  50. $my_follow_ids = controller('Userfollow')->my_follow_uids();
  51. $where['d.id'] = ['IN',$my_follow_ids];
  52. }
  53. //搜索
  54. $keyword = input('keyword','');
  55. if(!empty($keyword)){
  56. $where['d.nickname|d.goodat|keshi.name'] = ['LIKE','%'.$keyword.'%'];
  57. if($this->auth->isLogin()){
  58. Db::name('user_search')->insertGetId(['user_id'=>$this->auth->id,'keyword'=>$keyword]);
  59. }
  60. }
  61. //dump($where);
  62. $field = [
  63. 'd.id','d.nickname','d.avatar','d.keshi_id','d.level_id','d.hospital','d.goodat','d.ordernum',
  64. 'keshi.name as keshi_name',
  65. 'level.name as level_name','level.name_en as level_name_en',
  66. 'info.typing_switch','info.video_switch','info.typing_price','info.video_price','info.video_model'
  67. ];
  68. $list = Db::name('doctor')->alias('d')
  69. ->field($field)
  70. ->join('doctor_level level','d.level_id = level.id','LEFT')
  71. ->join('keshi','d.keshi_id = keshi.id','LEFT')
  72. ->join('doctor_info info','d.id = info.doctor_id','LEFT')
  73. ->where($where)->order('d.ordernum desc')->autopage()->select();
  74. $list = list_domain_image($list,['avatar']);
  75. $this->success(1,$list);
  76. }
  77. //医生详情
  78. public function doctor_info(){
  79. $id = input('id',0);
  80. $field = [
  81. 'd.id','d.nickname','d.avatar','d.keshi_id','d.level_id','d.hospital','d.goodat','d.ordernum','d.info','d.job_status',
  82. 'keshi.name as keshi_name',
  83. 'level.name as level_name',
  84. 'info.typing_switch','info.video_switch','info.typing_price','info.video_price','info.video_model',
  85. ];
  86. $info = Db::name('doctor')->alias('d')
  87. ->field($field)
  88. ->join('doctor_level level','d.level_id = level.id','LEFT')
  89. ->join('keshi','d.keshi_id = keshi.id','LEFT')
  90. ->join('doctor_info info','d.id = info.doctor_id','LEFT')
  91. ->where('d.id',$id)->find();
  92. $info = info_domain_image($info,['avatar']);
  93. //是否关注
  94. $info['is_follw'] = $this->is_follow($this->auth->id,$id);
  95. //图文说明
  96. $info['wenzhen_typing_serverrule'] = config('site.wenzhen_typing_serverrule');
  97. //视频说明
  98. $info['wenzhen_video_serverrule'] = config('site.wenzhen_video_serverrule');
  99. //没上班,文字接诊 停掉
  100. if($info['typing_switch'] == 1 && $info['job_status'] == 0){
  101. $info['typing_switch'] = 2;
  102. }
  103. //没上班,即时视频 停掉
  104. if($info['video_switch'] == 1 && $info['video_model'] == 2 && $info['job_status'] == 0){
  105. $info['video_switch'] = 2;
  106. }
  107. //视频问诊,排班模式,如果没排班 停掉
  108. if($info['video_switch'] == 1 && $info['video_model'] == 1){
  109. $paiban_list = $this->doctor_paiban($id,true);
  110. if(empty($paiban_list)){
  111. $info['video_switch'] = 2;//表示没有排班了,或已经约满
  112. }
  113. }
  114. $this->success(1,$info);
  115. }
  116. //医生排班
  117. public function doctor_paiban($this_doctor_id = 0,$return = false){
  118. $doctor_id = input('doctor_id',$this_doctor_id);
  119. if(!$doctor_id){
  120. $this->error();
  121. }
  122. //测试临时屏蔽
  123. // $list = Db::name('doctor_paiban')->where('doctor_id',$doctor_id)->where('active',1)->where('activetime','gt',time()+7200)->order('activetime asc')->select();
  124. $list = Db::name('doctor_paiban')->where('doctor_id',$doctor_id)->where('active',1)->where('activetime','gt',time())->order('activetime asc')->select();
  125. $newlist = [];
  126. if(!empty($list)){
  127. //预约到此刻后面的订单
  128. $need_unset = [];
  129. $map = [
  130. 'doctor_id' => $doctor_id,
  131. 'ordertype' => 2,
  132. 'status' => ['IN','10,20,25,30'],//有效订单
  133. 'book_time'=> ['gt',time()],
  134. 'video_model' => 1, //预约模式
  135. ];
  136. $order_booked = Db::name('wenzhen_order')->where($map)->group('book_time')->column('book_time,count(id) as count_number');
  137. if(!empty($order_booked)){
  138. foreach($order_booked as $bk => $bv){
  139. if($bv >= 4){
  140. $need_unset[] = $bk;
  141. }
  142. }
  143. }
  144. //重组时间数据
  145. foreach($list as $key => $val){
  146. //排除接满4单的
  147. if(in_array($val['activetime'],$need_unset)){
  148. continue;
  149. }
  150. $date = date('Y-m-d',$val['activetime']);
  151. if(!isset($newlist[$date])){
  152. $newlist[$date] = [];
  153. }
  154. $newlist[$date][] = date('H:i',$val['activetime']);
  155. }
  156. }
  157. if($return == true){
  158. return $newlist;
  159. }
  160. $this->success(1,$newlist);
  161. }
  162. }