request->isAjax()) { $post = $this->request->param(); $where = []; if (isset($post['ids']) and !empty($post['ids'])) { $where['id'] = ['in', $post['ids']]; } if (!empty($post["name"])) { $where["name"] = ['like', '%' . $post["name"] . '%']; } if (!empty($post["title"])) { $where["title"] = ['like', '%' . $post["title"] . '%']; } if (!empty($post["head_pic"])) { $where["head_pic"] = ['like', '%' . $post["head_pic"] . '%']; } if (isset($post["sex"]) and "" != $post["sex"]) { $where["sex"] = $post["sex"]; } if (!empty($post["desc"])) { $where["desc"] = ['like', '%' . $post["desc"] . '%']; } if (!empty($post["consultation_direction"])) { $where["consultation_direction"] = ['like', '%' . $post["consultation_direction"] . '%']; } if (isset($post["address_id"]) and "" != $post["address_id"]) { $where["address_id"] = $post["address_id"]; } if (isset($post["module"]) and "" != $post["module"]) { $where["module"] = $post["module"]; } $model = $this->getModel(); $count = $model->where($where)->count(); $data = $model->where($where)->page($post['page']??0, $post['limit']??15)->order('id desc')->select(); $boxsIdAndName = (new \app\common\model\ConfigOption())->where(['pid' => 2])->column('name', 'id'); foreach ($data as $key => $value) { $value['head_pic_url'] = geturl($value['head_pic']); $value['sex_text'] = $value->sex_text; $value['address_name'] = $value->address ? $value->address->title : ''; $value['module_name'] = $boxsIdAndName[$value->module]??''; $data[$key] = $value; } return array('code' => 0, 'count' => $count, 'data' => $data); } else { $this->assign('addresslist', \app\common\model\Address::all()); $boxs = (new \app\common\model\ConfigOption())->where(['pid' => 2, 'status' => \app\common\model\ConfigOption::STATUS_OPEN])->order('sort desc')->select(); $this->assign('modules', $boxs); return $this->fetch(); } } public function publish() { $id = $this->request->param('id', 0, 'intval'); $model = $this->getModel(); $post = $this->request->post(); if ($this->request->isPost()) { //验证 $validate = new \think\Validate([ ['name|名字', 'require|max:50'], ['title|职称', 'require|max:50'], ['head_pic|头像', 'max:255'], ['sex|性别', 'number'], ['desc|简介', 'max:500'], ['consultation_direction|咨询方向', 'max:500'], ['address_id|地址', 'require|number'], ['phone|联系电话', 'max:50'], ]); if (!$validate->check($post)) { $this->error('提交失败:' . $validate->getError()); } } else { $this->assign('addresslist', \app\common\model\Address::all()); $boxs = (new \app\common\model\ConfigOption())->where(['pid' => 2, 'status' => \app\common\model\ConfigOption::STATUS_OPEN])->order('sort desc')->select(); $this->assign('modules', $boxs); } 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 { //新增 if ($this->request->isPost()) { if (false == $model->allowField(true)->save($post)) { $this->error('添加失败'); } else { //新增放号设置记录 $webconfig = \app\common\model\Webconfig::get(1); $data['provider_id'] = $model->id; $data['weeks'] = $webconfig->weeks; $data['morning_time_periods'] = $webconfig->morning_time_periods; $data['afternoon_time_periods'] = $webconfig->afternoon_time_periods; (new \app\common\model\Appointment())->allowField(true)->save($data); $this->success('添加成功', 'index'); } } else { return $this->fetch(); } } } 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->deleteAfter($id); $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->deleteAfter($ids); $this->success('删除成功'); } } } /** * 删除后操作 * @param $id * @author jiang */ private function deleteAfter($id) { $where = []; if (!is_array($id)) { $where['provider_id'] = $id; } else { $where['provider_id'] = ['in', $id]; } //删除该专家所有号源和记录 (new \app\common\model\Appointment())->where($where)->delete(); (new \app\common\model\AppointmentTicket())->where($where)->delete(); (new \app\common\model\AppointmentApplication())->where($where)->delete(); } }