Exemplo n.º 1
0
 /**
  * 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;
 }
Exemplo n.º 2
0
 /**
  * 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.');
     }
 }