AppointmentApplication.php 5.0 KB

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