AppointmentTicket.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. $pid = $this->request->param('pid', 0, 'intval');
  14. if ($this->request->isAjax()) {
  15. $post = $this->request->param();
  16. $where = [
  17. 'provider_id' => $pid
  18. ];
  19. if (isset($post['ids']) and !empty($post['ids'])) {
  20. $where['id'] = ['in', $post['ids']];
  21. }
  22. if (isset($post["appointment_id"]) and "" != $post["appointment_id"]) {
  23. $where["appointment_id"] = $post["appointment_id"];
  24. }
  25. if (isset($post["appointment_daytime"]) and !empty($post["appointment_daytime"])) {
  26. $timerang = explode(' - ', $post["appointment_daytime"]);
  27. $min_time = strtotime($timerang[0]);
  28. $max_time = $timerang[0] == $timerang[1] ? $min_time + 24 * 3600 - 1 : strtotime($timerang[1]??'');
  29. $where["appointment_daytime"] = [['>=', $min_time], ['<=', $max_time]];
  30. }
  31. if (isset($post["provider_id"]) and "" != $post["provider_id"]) {
  32. $where["provider_id"] = $post["provider_id"];
  33. }
  34. if (isset($post["address_id"]) and "" != $post["address_id"]) {
  35. $where["address_id"] = $post["address_id"];
  36. }
  37. if (isset($post["morning_use"]) and "" != $post["morning_use"]) {
  38. $where["morning_use"] = $post["morning_use"];
  39. }
  40. if (isset($post["afternoon_use"]) and "" != $post["afternoon_use"]) {
  41. $where["afternoon_use"] = $post["afternoon_use"];
  42. }
  43. if (isset($post["night_use"]) and "" != $post["night_use"]) {
  44. $where["night_use"] = $post["night_use"];
  45. }
  46. $model = $this->getModel();
  47. $count = $model->where($where)->count();
  48. $data = $model->where($where)->page($post['page']??0, $post['limit']??15)->order('appointment_daytime desc')->select();
  49. foreach ($data as $key => $value) {
  50. $value['specialist_name'] = $value->specialist->name;
  51. $data[$key] = $value;
  52. }
  53. return array('code' => 0, 'count' => $count, 'data' => $data);
  54. } else {
  55. return $this->fetch();
  56. }
  57. }
  58. public function publish()
  59. {
  60. $id = $this->request->param('id', 0, 'intval');
  61. $model = $this->getModel();
  62. $post = $this->request->post();
  63. if ($this->request->isPost()) {
  64. if (isset($post['appointment_daytime']) && !empty($post['appointment_daytime'])) {
  65. $post['appointment_daytime'] = strtotime($post['appointment_daytime']);
  66. }
  67. //验证
  68. $validate = new \think\Validate([
  69. ['appointment_id|放号配置', 'require|number'],
  70. ['appointment_daytime|排号日期', 'require|number'],
  71. ['provider_id|服务人id', 'require|number'],
  72. ['address_id|地址id', 'number'],
  73. ['morning_use|上午报名个数', 'number'],
  74. ['afternoon_use|中午报名个数', 'number'],
  75. ['night_use|晚上报名个数', 'number'],
  76. ]);
  77. if (!$validate->check($post)) {
  78. $this->error('提交失败:' . $validate->getError());
  79. }
  80. }
  81. if ($id > 0) {
  82. //修改
  83. $data = $model->where('id', $id)->find();
  84. if (empty($data)) {
  85. $this->error('id不正确');
  86. }
  87. if ($this->request->isPost()) {
  88. if (false == $model->allowField(true)->save($post, ['id' => $id])) {
  89. $this->error('修改失败');
  90. } else {
  91. $this->success('修改成功');
  92. }
  93. } else {
  94. $this->assign('data', $data);
  95. return $this->fetch();
  96. }
  97. } else {
  98. }
  99. }
  100. public function delete()
  101. {
  102. if ($this->request->isAjax()) {
  103. $id = $this->request->param('id', 0, 'intval');
  104. if (false == $this->getModel()->where('id', $id)->delete()) {
  105. $this->error('删除失败');
  106. } else {
  107. $this->success('删除成功', 'index');
  108. }
  109. }
  110. }
  111. public function deletes()
  112. {
  113. if ($this->request->isAjax()) {
  114. $post = $this->request->param();
  115. $ids = $post['ids'];
  116. if ($this->getModel()->where('id', 'in', $ids)->delete()) {
  117. $this->success('删除成功');
  118. }
  119. }
  120. }
  121. }