AppointmentApplication.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\controller\base\Permissions;
  4. use think\Db;
  5. class AppointmentApplication extends Permissions
  6. {
  7. private function getModel()
  8. {
  9. return new \app\common\model\AppointmentApplication();
  10. }
  11. public function index()
  12. {
  13. if ($this->request->isAjax()) {
  14. $post = $this->request->param();
  15. $where = [];
  16. if (isset($post['ids']) and !empty($post['ids'])) {
  17. $where['id'] = ['in', $post['ids']];
  18. }
  19. if (!empty($post["name"])) {
  20. $where["name"] = ['like', '%' . $post["name"] . '%'];
  21. }
  22. if (isset($post["user_id"]) and ""!=$post["user_id"]) {
  23. $where["user_id"] = $post["user_id"];
  24. }
  25. if (!empty($post["phone"])) {
  26. $where["phone"] = ['like', '%' . $post["phone"] . '%'];
  27. }
  28. if (isset($post["age"]) and ""!=$post["age"]) {
  29. $where["age"] = $post["age"];
  30. }
  31. if (isset($post["childs_num"]) and ""!=$post["childs_num"]) {
  32. $where["childs_num"] = $post["childs_num"];
  33. }
  34. if (!empty($post["desc"])) {
  35. $where["desc"] = ['like', '%' . $post["desc"] . '%'];
  36. }
  37. if (isset($post["appointment_id"]) and ""!=$post["appointment_id"]) {
  38. $where["appointment_id"] = $post["appointment_id"];
  39. }
  40. if (isset($post["time_period"]) and !empty($post["time_period"])) {
  41. $timerang = explode(' - ', $post["time_period"]);
  42. $min_time = strtotime($timerang[0]);
  43. $max_time = $timerang[0] == $timerang[1] ? $min_time + 24 * 3600 - 1 : strtotime($timerang[1]??'');
  44. $where["time_period"] = [['>=', $min_time], ['<=', $max_time]];
  45. }
  46. if (isset($post["appointment_num"]) and ""!=$post["appointment_num"]) {
  47. $where["appointment_num"] = $post["appointment_num"];
  48. }
  49. if (isset($post["status"]) and ""!=$post["status"]) {
  50. $where["status"] = $post["status"];
  51. }
  52. if (!empty($post["remark"])) {
  53. $where["remark"] = ['like', '%' . $post["remark"] . '%'];
  54. }
  55. if (isset($post["create_time"]) and !empty($post["create_time"])) {
  56. $timerang = explode(' - ', $post["create_time"]);
  57. $min_time = strtotime($timerang[0]);
  58. $max_time = $timerang[0] == $timerang[1] ? $min_time + 24 * 3600 - 1 : strtotime($timerang[1]??'');
  59. $where["create_time"] = [['>=', $min_time], ['<=', $max_time]];
  60. }
  61. if (isset($post["finish_time"]) and !empty($post["finish_time"])) {
  62. $timerang = explode(' - ', $post["finish_time"]);
  63. $min_time = strtotime($timerang[0]);
  64. $max_time = $timerang[0] == $timerang[1] ? $min_time + 24 * 3600 - 1 : strtotime($timerang[1]??'');
  65. $where["finish_time"] = [['>=', $min_time], ['<=', $max_time]];
  66. }
  67. $model = $this->getModel();
  68. $count = $model->where($where)->count();
  69. $data = $model->where($where)->page($post['page']??0, $post['limit']??15)->order('id desc')->select();
  70. return array('code' => 0, 'count' => $count, 'data' => $data);
  71. } else {
  72. return $this->fetch();
  73. }
  74. }
  75. public function publish()
  76. {
  77. $id = $this->request->param('id', 0, 'intval');
  78. $model = $this->getModel();
  79. $post = $this->request->post();
  80. if ($this->request->isPost()) {
  81. if (isset($post['time_period']) && !empty($post['time_period'])) {
  82. $post['time_period'] = strtotime($post['time_period']);
  83. }
  84. if (isset($post['finish_time']) && !empty($post['finish_time'])) {
  85. $post['finish_time'] = strtotime($post['finish_time']);
  86. }
  87. //验证
  88. $validate = new \think\Validate([
  89. ['name|姓名', 'require|max:50'],
  90. ['user_id', 'require|number'],
  91. ['phone|电话', 'require|max:50'],
  92. ['age|年龄', 'number'],
  93. ['childs_num|子女数量', 'number'],
  94. ['desc|问题描述', 'require|max:200'],
  95. ['appointment_id|预约放号ID', 'require|number'],
  96. ['time_period|1上午2下午3晚上', 'require|number'],
  97. ['appointment_num|预约号码', 'require|number'],
  98. ['status|订单状态', 'number'],
  99. ['remark|备注', 'max:200'],
  100. ['finish_time|完成时间', 'number'],
  101. ]);
  102. if (!$validate->check($post)) {
  103. $this->error('提交失败:' . $validate->getError());
  104. }
  105. }
  106. if ($id > 0) {
  107. //修改
  108. $data = $model->where('id', $id)->find();
  109. if (empty($data)) {
  110. $this->error('id不正确');
  111. }
  112. if ($this->request->isPost()) {
  113. if (false == $model->allowField(true)->save($post, ['id' => $id])) {
  114. $this->error('修改失败');
  115. } else {
  116. $this->success('修改成功');
  117. }
  118. } else {
  119. $this->assign('data', $data);
  120. return $this->fetch();
  121. }
  122. } else {
  123. //新增
  124. if ($this->request->isPost()) {
  125. if (false == $model->allowField(true)->save($post)) {
  126. $this->error('添加失败');
  127. } else {
  128. $this->success('添加成功', 'index');
  129. }
  130. } else {
  131. return $this->fetch();
  132. }
  133. }
  134. }
  135. public function delete()
  136. {
  137. if ($this->request->isAjax()) {
  138. $id = $this->request->param('id', 0, 'intval');
  139. if (false == $this->getModel()->where('id', $id)->delete()) {
  140. $this->error('删除失败');
  141. } else {
  142. $this->success('删除成功', 'index');
  143. }
  144. }
  145. }
  146. public function deletes()
  147. {
  148. if ($this->request->isAjax()) {
  149. $post = $this->request->param();
  150. $ids = $post['ids'];
  151. if ($this->getModel()->where('id', 'in', $ids)->delete()) {
  152. $this->success('删除成功');
  153. }
  154. }
  155. }
  156. }