Index.php 6.6 KB

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