Index.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. namespace app\api\controller\doctor;
  3. use app\common\controller\Apic;
  4. use app\common\library\Sms;
  5. use think\Exception;
  6. use think\Validate;
  7. use think\Db;
  8. /**
  9. * 首页
  10. */
  11. class Index extends Apic
  12. {
  13. protected $noNeedLogin = [];
  14. protected $noNeedRight = '*';
  15. /*public function test(){
  16. $page = input('page',1);//分页
  17. $a = $this->get_page_week($page);
  18. foreach($a as &$v){
  19. $v = date('Y-m-d H:i:s',$v);
  20. }
  21. dump($a);
  22. }*/
  23. private function get_page_week($page = 1)
  24. {
  25. $time = time() + (($page - 1)*604800);
  26. $arr = [
  27. strtotime('Monday this week',$time),
  28. strtotime('Sunday this week',$time),
  29. ];
  30. return $arr;
  31. }
  32. //获取排班详情
  33. public function paiban_info(){
  34. $today = date('Y-m-d');//今天
  35. $page = input('page',1);//分页
  36. if($page < 1){
  37. $this->error('不能修改本周前的排班');
  38. }
  39. //某周,page=1是本周
  40. $this_week = $this->get_page_week($page);
  41. $this_week[1] = $this_week[1] + 86399;
  42. //医生排班
  43. $paiban = Db::name('doctor_paiban')->where('doctor_id',$this->auth->id)->where('activetime','BETWEEN',$this_week)->order('activetime asc')->column('activetime,active');
  44. //dump($paiban);
  45. //组合数据
  46. $week_text = [1=>'周一',2=>'周二',3=>'周三',4=>'周四',5=>'周五',6=>'周六',7=>'周日'];
  47. $week_data = [];
  48. for($i=1;$i<=7;$i++){
  49. $i_time = $this_week[0] + 86400*($i-1);
  50. $i_data = [
  51. 'time' => $i_time,
  52. 'date' => date('Y-m-d',$i_time),
  53. 'date_text' => date('d日',$i_time),
  54. 'week' => date('w',$i_time),
  55. 'is_today' => 0,
  56. 'year' => date('Y',$i_time),
  57. 'month' => date('n',$i_time),
  58. ];
  59. if($i_data['date'] == $today){
  60. $i_data['is_today'] = 1;//是否今天
  61. }
  62. if($i_data['week'] == 0){
  63. $i_data['week'] = '7'; //周天转换
  64. }
  65. $i_data['week_text'] = $week_text[$i_data['week']];//周一 到 周日
  66. //今天各整点,早8,晚20
  67. $i_child = [];
  68. for($y=8;$y<=20;$y++){
  69. $y_hour = $i_time + $y*3600;
  70. $child = [
  71. 'time' => $y_hour,
  72. 'date' => date('Y-m-d H:i',$y_hour),
  73. 'date_text' => date('H:i',$y_hour),
  74. 'active' => 0,
  75. 'is_edit' => ($y_hour <= time()) ? 0 : 1, //是否能编辑
  76. ];
  77. if(isset($paiban[$y_hour]) && $paiban[$y_hour] == 1){
  78. $child['active'] = 1;
  79. }
  80. $i_child[] = $child;
  81. }
  82. $i_data['child'] = $i_child;
  83. //
  84. $week_data[] = $i_data;
  85. }
  86. //dump($week_data);
  87. $this->success(1,$week_data);
  88. }
  89. //修改排班
  90. public function paiban_edit(){
  91. $active_data = input('active_data','','htmlspecialchars_decode');
  92. if(!$active_data){
  93. $this->error();
  94. }
  95. $active_data = json_decode($active_data,true);
  96. if(!is_array($active_data)){
  97. $this->error();
  98. }
  99. if(empty($active_data)){
  100. $this->success();
  101. }
  102. $old_active = [];//需要删除的
  103. foreach($active_data as $key => $val){
  104. if(!isset($val['activetime']) || !isset($val['active']) || empty($val['activetime'])){continue;}
  105. $val['active'] = $val['active'] == 1 ? 1 : 0;
  106. $old_active[] = $val['activetime'];
  107. //需要新增的
  108. $data = [
  109. 'doctor_id' => $this->auth->id,
  110. 'activetime' => $val['activetime'],
  111. 'active' => $val['active'],
  112. ];
  113. $all_data[] = $data;
  114. }
  115. Db::startTrans();
  116. $rs_del = Db::name('doctor_paiban')->where('doctor_id',$this->auth->id)->where('activetime','IN',$old_active)->delete();
  117. if($rs_del === false){
  118. Db::rollback();
  119. $this->error('设置失败');
  120. }
  121. $rs_add = Db::name('doctor_paiban')->insertAll($all_data);
  122. if($rs_add === false){
  123. Db::rollback();
  124. $this->error('设置失败');
  125. }
  126. Db::commit();
  127. $this->success('设置成功');
  128. }
  129. }