/** * Deletes an existing SourceRatio model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { $model = $this->findModel($id); if ($model->status != $model::STATUS_MATCHED) { throw new ServerErrorHttpException('资源没有匹配,不能删除'); } #$model->delete(); $model->status = $model::STATUS_NO_MATCHED; $model->save(); #update sourceTemp $sourceTempModel = models\SourceTemp::findOne($model->source_id); if ($sourceTempModel) { $sourceTempModel->basic_id = 0; $tempRet = $sourceTempModel->save(); } #delete source $sourceModel = models\Source::findOne(['source_temp_id' => $model->source_id]); if ($sourceModel) { $sourceModel->delete($sourceModel->id); } #update basic $basicModel = models\Basic::findOne($model->basic_id); if ($basicModel) { $basicModel->source_num = $basicModel->source_num - 1; $ret = $basicModel->save(); } return $this->redirect(['index']); }
/** * Finds the Source model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Source the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Source::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }