/** * type * @param string * @return array */ public function getSourceTemp() { return $this->hasOne(SourceTemp::className(), ['id' => 'source_id']); }
/** * Deletes an existing Source model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { #$this->findModel($id)->delete(); $model = $this->findModel($id); $model->status = $model::STATUS_DELETED; #$ret = $model->delete(); $ret = $model->save(); if ($ret) { #update basic $basicModel = Basic::findOne($model->basic_id); if (!$basicModel) { throw new NotFoundHttpException('The requested page does not exist.'); } $basicModel->source_num = $basicModel->source_num - 1; $basicRet = $basicModel->save(); #update sourceTemp $sourceTempModel = SourceTemp::findOne($model->source_temp_id); if ($sourceTempModel) { $sourceTempModel->basic_id = 0; $tempRet = $sourceTempModel->save(); #update source ratio $sourceRatioModel = SourceRatio::findOne(['source_id' => $model->source_temp_id]); if ($sourceRatioModel) { $sourceRatioModel->status = SourceRatio::STATUS_NO_MATCHED; $sourceRatioModel->save(); } } return $this->redirect(['source/index', 'basic_id' => $model->basic_id]); } else { throw new ServerErrorHttpException('Delete Error'); } }
/** * Updates an existing SourceRatio model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionMatch($id) { $ratioModel = $this->findModel($id); #update sourceTemp $sourceTempModel = models\SourceTemp::findOne($ratioModel->source_id); if (!$sourceTempModel) { throw new NotFoundHttpException('The requested page does not exist.'); } $sourceTempModel->basic_id = $ratioModel->basic_id; $tempRet = $sourceTempModel->save(); if (!$tempRet) { throw new ServerErrorHttpException('update source temp fail'); } #add source $sourceModel = new models\Source(); $sourceModel->source_temp_id = $ratioModel->source_id; $sourceModel->basic_id = $sourceTempModel->basic_id; $sourceModel->type = $sourceTempModel->type; $sourceModel->name = $sourceTempModel->name; $sourceModel->download_url = $sourceTempModel->download_url; $sourceModel->play_url = $sourceTempModel->play_url; $sourceModel->ext = $sourceTempModel->ext; $sourceModel->update_time = time(); $sourceModel->create_time = time(); $sourceModel->save(); #update sourceRatio $ratioModel->status = $ratioModel::STATUS_MATCHED; $ret = $ratioModel->save(); #update basic $basicModel = models\Basic::findOne($ratioModel->basic_id); if (!$basicModel) { throw new NotFoundHttpException('The requested page does not exist.'); } $basicModel->source_num = $basicModel->source_num + 1; $basicModel->update_time = time(); $ret = $basicModel->save(); if ($ret) { $data['code'] = 0; } else { $data['code'] = 1; $data['message'] = "更新失败"; } echo json_encode($data); exit; }
/** * Finds the SourceTemp model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return SourceTemp the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = SourceTemp::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }