AppointmentApplication.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. foreach ($data as $key => $value) {
  53. $value['sex_text'] = $value->sex_text;
  54. $value['status_text'] = $value->status_text;
  55. $data[$key] = $value;
  56. }
  57. return array('code' => 0, 'count' => $count, 'data' => $data);
  58. } else {
  59. return $this->fetch();
  60. }
  61. }
  62. public function publish()
  63. {
  64. $id = $this->request->param('id', 0, 'intval');
  65. $model = $this->getModel();
  66. $post = $this->request->post();
  67. if ($this->request->isPost()) {
  68. //验证
  69. $validate = new \think\Validate([
  70. ['status|订单状态', 'number'],
  71. ['remark|备注', 'max:200'],
  72. ]);
  73. if (!$validate->check($post)) {
  74. $this->error('提交失败:' . $validate->getError());
  75. }
  76. }
  77. if ($id > 0) {
  78. //修改
  79. $data = $model->where('id', $id)->find();
  80. if (empty($data)) {
  81. $this->error('id不正确');
  82. }
  83. if ($this->request->isPost()) {
  84. if (false == $model->allowField(true)->save($post, ['id' => $id])) {
  85. $this->error('修改失败');
  86. } else {
  87. $this->success('修改成功');
  88. }
  89. } else {
  90. $this->assign('data', $data);
  91. return $this->fetch();
  92. }
  93. } else {
  94. }
  95. }
  96. public function status()
  97. {
  98. if ($this->request->isPost()) {
  99. $post = $this->request->post();
  100. if (false == Db::name('appointment_application')->where('id', $post['id'])->update(['status' => $post['status'],'finish_time'=>time()])) {
  101. $this->error('设置失败');
  102. } else {
  103. $this->success('设置成功', 'index');
  104. }
  105. }
  106. }
  107. }