Appointment.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\controller\base\Permissions;
  4. use app\common\model\Appointment as appointmentModel;
  5. use think\Db;
  6. use time\DateHelper;
  7. class Appointment extends Permissions
  8. {
  9. private function getModel()
  10. {
  11. return new appointmentModel();
  12. }
  13. public function publish()
  14. {
  15. $pid = $this->request->param('pid', 0, 'intval');
  16. $post = $this->request->post();
  17. $post['provider_id'] = $pid;
  18. if ($this->request->isPost()) {
  19. //验证
  20. $validate = new \think\Validate([
  21. ['provider_id', 'require|number'],
  22. ]);
  23. if (!$validate->check($post)) {
  24. $this->error('提交失败:' . $validate->getError());
  25. }
  26. }
  27. $model = $this->getModel();
  28. $appointment = $model->where('provider_id', $pid)->find();
  29. if ($appointment) {
  30. //修改
  31. if ($this->request->isPost()) {
  32. $weeks = $post['weeks']??[];
  33. $weeks = array_keys($weeks);
  34. $post['weeks'] = implode(',', $weeks);
  35. $post['morning_time_periods'] = json_encode($post['morning_time_periods']??[]);
  36. $post['afternoon_time_periods'] = json_encode($post['afternoon_time_periods']??[]);
  37. if (false == $appointment->allowField(true)->save($post)) {
  38. $this->error('修改失败');
  39. }
  40. $this->success('修改成功', 'index', ['pid' => $pid]);
  41. } else {
  42. $this->assign('data', $appointment);
  43. $this->assign('morning_time_periods_json', $appointment->morning_time_periods);
  44. $this->assign('afternoon_time_periods_json', $appointment->afternoon_time_periods);
  45. return $this->fetch();
  46. }
  47. } else {
  48. //新增
  49. if ($this->request->isPost()) {
  50. $weeks = $post['weeks']??[];
  51. $weeks = array_keys($weeks);
  52. $post['weeks'] = implode(',', $weeks);
  53. $post['morning_time_periods'] = json_encode($post['morning_time_periods']??[]);
  54. $post['afternoon_time_periods'] = json_encode($post['afternoon_time_periods']??[]);
  55. if (false == $model->allowField(true)->save($post)) {
  56. $this->error('添加失败');
  57. }
  58. $this->success('添加成功', 'index', ['pid' => $pid]);
  59. } else {
  60. //输出系统配置
  61. $webconfig = \app\common\model\Webconfig::get(1);
  62. $this->assign('data', $webconfig);
  63. $this->assign('morning_time_periods_json', json_decode($webconfig->morning_time_periods, true));
  64. $this->assign('afternoon_time_periods_json', json_decode($webconfig->afternoon_time_periods, true));
  65. return $this->fetch();
  66. }
  67. }
  68. }
  69. }