/** * 编辑科室 * @param array $param 包含科室信息的数组 */ public function edit($param) { $model = Department::findOne($param['id']); unset($param['id']); $flag = 0; //所属一级科室是否修改 if (array_key_exists('pid', $param)) { if ($model->attributes['pid'] != $param['pid']) { $count = $this->getLevel1ChildNum($model->attributes['pid']); $forepid = $model->attributes['pid']; $flag = 1; } } $model->attributes = $param; if ($model->save()) { if ($flag) { //所属科室更改,将新的所属科室child->1 $this->updateAll(['child' => '1'], 'id = :id', [':id' => $param['pid']]); $this->editDepartmentDisease($model->attributes['class_level2'], $model->attributes['class_level1']); if ($count['count'] == 1) { //若为原属一级科室的唯一子科室,将原属科室的child->0 $this->updateAll(['child' => '0'], 'id = :id', [':id' => $forepid]); } } return true; } else { return false; } }
/** * Finds the Department model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Department the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Department::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }