AppointmentApplication.php 4.4 KB

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