request->param('pid', 0, 'intval'); if ($this->request->isAjax()) { $post = $this->request->param(); $where = [ 'provider_id' => $pid ]; if (isset($post['ids']) and !empty($post['ids'])) { $where['id'] = ['in', $post['ids']]; } if (isset($post["appointment_id"]) and "" != $post["appointment_id"]) { $where["appointment_id"] = $post["appointment_id"]; } if (isset($post["appointment_daytime"]) and !empty($post["appointment_daytime"])) { $timerang = explode(' - ', $post["appointment_daytime"]); $min_time = strtotime($timerang[0]); $max_time = $timerang[0] == $timerang[1] ? $min_time + 24 * 3600 - 1 : strtotime($timerang[1]??''); $where["appointment_daytime"] = [['>=', $min_time], ['<=', $max_time]]; } if (isset($post["provider_id"]) and "" != $post["provider_id"]) { $where["provider_id"] = $post["provider_id"]; } if (isset($post["address_id"]) and "" != $post["address_id"]) { $where["address_id"] = $post["address_id"]; } if (isset($post["morning_use"]) and "" != $post["morning_use"]) { $where["morning_use"] = $post["morning_use"]; } if (isset($post["afternoon_use"]) and "" != $post["afternoon_use"]) { $where["afternoon_use"] = $post["afternoon_use"]; } if (isset($post["night_use"]) and "" != $post["night_use"]) { $where["night_use"] = $post["night_use"]; } $model = $this->getModel(); $count = $model->where($where)->count(); $data = $model->where($where)->page($post['page']??0, $post['limit']??15)->order('appointment_daytime desc')->select(); foreach ($data as $key => $value) { $value['specialist_name'] = $value->specialist->name; $data[$key] = $value; } return array('code' => 0, 'count' => $count, 'data' => $data); } else { return $this->fetch(); } } public function publish() { $id = $this->request->param('id', 0, 'intval'); $model = $this->getModel(); $post = $this->request->post(); if ($this->request->isPost()) { if (isset($post['appointment_daytime']) && !empty($post['appointment_daytime'])) { $post['appointment_daytime'] = strtotime($post['appointment_daytime']); } //验证 $validate = new \think\Validate([ ['appointment_id|放号配置', 'require|number'], ['appointment_daytime|排号日期', 'require|number'], ['provider_id|服务人id', 'require|number'], ['address_id|地址id', 'number'], ['morning_use|上午报名个数', 'number'], ['afternoon_use|中午报名个数', 'number'], ['night_use|晚上报名个数', 'number'], ]); if (!$validate->check($post)) { $this->error('提交失败:' . $validate->getError()); } } if ($id > 0) { //修改 $data = $model->where('id', $id)->find(); if (empty($data)) { $this->error('id不正确'); } if ($this->request->isPost()) { if (false == $model->allowField(true)->save($post, ['id' => $id])) { $this->error('修改失败'); } else { $this->success('修改成功'); } } else { $this->assign('data', $data); return $this->fetch(); } } else { } } public function delete() { if ($this->request->isAjax()) { $id = $this->request->param('id', 0, 'intval'); if (false == $this->getModel()->where('id', $id)->delete()) { $this->error('删除失败'); } else { $this->success('删除成功', 'index'); } } } public function deletes() { if ($this->request->isAjax()) { $post = $this->request->param(); $ids = $post['ids']; if ($this->getModel()->where('id', 'in', $ids)->delete()) { $this->success('删除成功'); } } } }