public function actionUpdate() { $op = Yii::app()->request->getParam('op', ''); $id = Yii::app()->request->getPost('id', ''); $code = Yii::app()->request->getPost("code", ''); $name = Yii::app()->request->getPost("name", ''); if (!$name || !$code) { $this->_output(-1, '参数错误'); } $configModel = new ConfigModel(); $configModel['type'] = Yii::app()->params['configType']['HOSPITAL']; $configModel['c_key'] = $code; $configModel['c_value'] = $name; $hospitalModel = new ConfigModel(); $hospitals = $hospitalModel->getSetByType(Yii::app()->params['configType']['HOSPITAL']); //共享 $shares = array(); $my = new ShareModel(); $my->setIsNewRecord(1); $my['hospital'] = $code; $my['target_hospital'] = $code; $my['permission'] = join(',', array_keys(Yii::app()->params['permission'])); $shares[$code] = $my; foreach ($hospitals as $key => $value) { $permission = Yii::app()->request->getPost('permission_' . $key, ''); if ($permission) { $item = new ShareModel(); $item->setIsNewRecord(1); $item['hospital'] = $code; $item['target_hospital'] = $key; $item['permission'] = join(',', $permission); $shares[$key] = $item; } } //更新 if ($op == 'edit' && $id && ($hospital = $configModel->getModel($configModel['type'], $code))) { $configModel['id'] = $hospital['id']; $configModel->update(); } // 新增 if ($op == 'add') { $configModel->setIsNewRecord(1); $configModel->save(); } $shareModel = new ShareModel(); $shareModel->deleteByHospital($code); $shareModel->saveMany($shares); $this->redirect(Yii::app()->getBaseUrl() . "/admin/hospital/list"); }