AppointmentApplication.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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["status"]) and "" != $post["status"]) {
  32. $where["status"] = $post["status"];
  33. }
  34. if (!empty($post["remark"])) {
  35. $where["remark"] = ['like', '%' . $post["remark"] . '%'];
  36. }
  37. if (isset($post["create_time"]) and !empty($post["create_time"])) {
  38. $timerang = explode(' - ', $post["create_time"]);
  39. $min_time = strtotime($timerang[0]);
  40. $max_time = $timerang[0] == $timerang[1] ? $min_time + 24 * 3600 - 1 : strtotime($timerang[1]??'');
  41. $where["create_time"] = [['>=', $min_time], ['<=', $max_time]];
  42. }
  43. if (isset($post["finish_time"]) and !empty($post["finish_time"])) {
  44. $timerang = explode(' - ', $post["finish_time"]);
  45. $min_time = strtotime($timerang[0]);
  46. $max_time = $timerang[0] == $timerang[1] ? $min_time + 24 * 3600 - 1 : strtotime($timerang[1]??'');
  47. $where["finish_time"] = [['>=', $min_time], ['<=', $max_time]];
  48. }
  49. $model = $this->getModel();
  50. $count = $model->where($where)->count();
  51. $data = $model->where($where)->page($post['page']??0, $post['limit']??15)->order('id desc')->select();
  52. return array('code' => 0, 'count' => $count, 'data' => $data);
  53. } else {
  54. return $this->fetch();
  55. }
  56. }
  57. public function publish()
  58. {
  59. $id = $this->request->param('id', 0, 'intval');
  60. $model = $this->getModel();
  61. $post = $this->request->post();
  62. if ($this->request->isPost()) {
  63. //验证
  64. $validate = new \think\Validate([
  65. ['status|订单状态', 'number'],
  66. ['remark|备注', 'max:200'],
  67. ]);
  68. if (!$validate->check($post)) {
  69. $this->error('提交失败:' . $validate->getError());
  70. }
  71. }
  72. if ($id > 0) {
  73. //修改
  74. $data = $model->where('id', $id)->find();
  75. if (empty($data)) {
  76. $this->error('id不正确');
  77. }
  78. if ($this->request->isPost()) {
  79. if (false == $model->allowField(true)->save($post, ['id' => $id])) {
  80. $this->error('修改失败');
  81. } else {
  82. $this->success('修改成功');
  83. }
  84. } else {
  85. $this->assign('data', $data);
  86. return $this->fetch();
  87. }
  88. } else {
  89. }
  90. }
  91. public function delete()
  92. {
  93. if ($this->request->isAjax()) {
  94. $id = $this->request->param('id', 0, 'intval');
  95. if (false == $this->getModel()->where('id', $id)->delete()) {
  96. $this->error('删除失败');
  97. } else {
  98. $this->success('删除成功', 'index');
  99. }
  100. }
  101. }
  102. public function deletes()
  103. {
  104. if ($this->request->isAjax()) {
  105. $post = $this->request->param();
  106. $ids = $post['ids'];
  107. if ($this->getModel()->where('id', 'in', $ids)->delete()) {
  108. $this->success('删除成功');
  109. }
  110. }
  111. }
  112. }