AppointmentApplication.php 4.7 KB

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