AppointmentApplication.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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["sex"]) and "" != $post["sex"]) {
  23. $where["sex"] = $post["sex"];
  24. }
  25. if (!empty($post["phone"])) {
  26. $where["phone"] = ['like', '%' . $post["phone"] . '%'];
  27. }
  28. if (!empty($post["id_card"])) {
  29. $where["id_card"] = ['like', '%' . $post["id_card"] . '%'];
  30. }
  31. if (isset($post["appointment_id"]) and "" != $post["appointment_id"]) {
  32. $where["appointment_id"] = $post["appointment_id"];
  33. }
  34. if (isset($post["appointment_ticket"]) and "" != $post["appointment_ticket"]) {
  35. $where["appointment_ticket"] = $post["appointment_ticket"];
  36. }
  37. if (isset($post["status"]) and "" != $post["status"]) {
  38. $where["status"] = $post["status"];
  39. }
  40. if (isset($post["create_time"]) and !empty($post["create_time"])) {
  41. $timerang = explode(' - ', $post["create_time"]);
  42. $min_time = strtotime($timerang[0]);
  43. $max_time = $timerang[0] == $timerang[1] ? $min_time + 24 * 3600 - 1 : strtotime($timerang[1]??'');
  44. $where["create_time"] = [['>=', $min_time], ['<=', $max_time]];
  45. }
  46. if (isset($post["finish_time"]) and !empty($post["finish_time"])) {
  47. $timerang = explode(' - ', $post["finish_time"]);
  48. $min_time = strtotime($timerang[0]);
  49. $max_time = $timerang[0] == $timerang[1] ? $min_time + 24 * 3600 - 1 : strtotime($timerang[1]??'');
  50. $where["finish_time"] = [['>=', $min_time], ['<=', $max_time]];
  51. }
  52. $model = $this->getModel();
  53. $count = $model->where($where)->count();
  54. $data = $model->where($where)->page($post['page']??0, $post['limit']??15)->order('id desc')->select();
  55. return array('code' => 0, 'count' => $count, 'data' => $data);
  56. } else {
  57. return $this->fetch();
  58. }
  59. }
  60. public function publish()
  61. {
  62. $id = $this->request->param('id', 0, 'intval');
  63. $model = $this->getModel();
  64. $post = $this->request->post();
  65. if ($this->request->isPost()) {
  66. //验证
  67. $validate = new \think\Validate([
  68. ['name|姓名', 'require|max:50'],
  69. ['age|年龄', 'number'],
  70. ['birthday|出生年月', 'max:50'],
  71. ['sex|性别', 'number'],
  72. ['id_card|身份证', 'require|max:50'],
  73. ['childs_num|子女数量', 'number'],
  74. ['problem_desc|问题描述', 'require|max:200'],
  75. ['requirement_desc|需求描述', 'require|max:200'],
  76. ['remark|备注', 'max:200'],
  77. ]);
  78. if (!$validate->check($post)) {
  79. $this->error('提交失败:' . $validate->getError());
  80. }
  81. }
  82. if ($id > 0) {
  83. //修改
  84. $data = $model->where('id', $id)->find();
  85. if (empty($data)) {
  86. $this->error('id不正确');
  87. }
  88. if ($this->request->isPost()) {
  89. if (false == $model->allowField(true)->save($post, ['id' => $id])) {
  90. $this->error('修改失败');
  91. } else {
  92. $this->success('修改成功');
  93. }
  94. } else {
  95. $this->assign('data', $data);
  96. return $this->fetch();
  97. }
  98. } else {
  99. }
  100. }
  101. public function delete()
  102. {
  103. if ($this->request->isAjax()) {
  104. $id = $this->request->param('id', 0, 'intval');
  105. if (false == $this->getModel()->where('id', $id)->delete()) {
  106. $this->error('删除失败');
  107. } else {
  108. $this->success('删除成功', 'index');
  109. }
  110. }
  111. }
  112. public function deletes()
  113. {
  114. if ($this->request->isAjax()) {
  115. $post = $this->request->param();
  116. $ids = $post['ids'];
  117. if ($this->getModel()->where('id', 'in', $ids)->delete()) {
  118. $this->success('删除成功');
  119. }
  120. }
  121. }
  122. }