AppointmentTicket.php 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\controller\base\Permissions;
  4. use think\Db;
  5. class AppointmentTicket extends Permissions
  6. {
  7. private function getModel()
  8. {
  9. return new \app\common\model\AppointmentTicket();
  10. }
  11. public function index()
  12. {
  13. if ($this->request->isAjax()) {
  14. $post = $this->request->param();
  15. $where = [
  16. ];
  17. if (isset($post["appointment_daytime"]) and !empty($post["appointment_daytime"])) {
  18. $timerang = explode(' - ', $post["appointment_daytime"]);
  19. $min_time = strtotime($timerang[0]);
  20. $max_time = $timerang[0] == $timerang[1] ? $min_time + 24 * 3600 - 1 : strtotime($timerang[1]??'');
  21. $where["appointment_daytime"] = [['>=', $min_time], ['<=', $max_time]];
  22. }
  23. if (isset($post["provider_id"]) and "" != $post["provider_id"]) {
  24. $where["provider_id"] = $post["provider_id"];
  25. }
  26. $model = $this->getModel();
  27. $count = $model->where($where)->count();
  28. $data = $model->where($where)->page($post['page']??0, $post['limit']??15)->order('appointment_daytime desc')->select();
  29. foreach ($data as $key => $value) {
  30. $value['specialist_name'] = $value->specialist->name;
  31. $value['address_title'] = $value->address ? $value->address->title : '';
  32. $value['morning_use'] = $value->morning_use;
  33. $value['afternoon_use'] = $value->afternoon_use;
  34. $value['night_use'] = $value->night_use;
  35. $data[$key] = $value;
  36. }
  37. return array('code' => 0, 'count' => $count, 'data' => $data);
  38. } else {
  39. return $this->fetch();
  40. }
  41. }
  42. public function delete()
  43. {
  44. if ($this->request->isAjax()) {
  45. $id = $this->request->param('id', 0, 'intval');
  46. $item = $this->getModel()->where('id', $id)->find();
  47. if (!$item) {
  48. $this->error('删除失败,id不存在');
  49. }
  50. if ($item->morning_use > 0 || $item->afternoon_use > 0 || $item->night_use > 0) {
  51. $this->error("已有预约申请,不可删除");
  52. }
  53. if (false == $item->delete()) {
  54. $this->error('删除失败');
  55. } else {
  56. $this->success('删除成功', 'index');
  57. }
  58. }
  59. }
  60. public function deletes()
  61. {
  62. if ($this->request->isAjax()) {
  63. $post = $this->request->param();
  64. $ids = $post['ids'];
  65. $items = $this->getModel()->where('id', 'in', $ids)->select();
  66. foreach ($items as $item) {
  67. if ($item->morning_use > 0 || $item->afternoon_use > 0 || $item->night_use > 0) {
  68. $this->error("已有预约申请,不可删除");
  69. }
  70. if (false == $item->delete()) {
  71. $this->error('删除失败');
  72. }
  73. }
  74. $this->success('删除成功', 'index');
  75. }
  76. }
  77. public function status()
  78. {
  79. if ($this->request->isPost()) {
  80. $post = $this->request->post();
  81. if (false == $this->getModel()->where('id', $post['id'])->update(['status' => $post['status']])) {
  82. $this->error('设置失败');
  83. } else {
  84. $this->success('设置成功', 'index');
  85. }
  86. }
  87. }
  88. }