예제 #1
0
 /**
  * Lists all Recommend models.
  * @return mixed
  */
 public function actionIndex()
 {
     $params = Yii::$app->request->get();
     $query = Recommend::find();
     #$query->where(['status' => Basic::STATUS_NORMAL]);
     if (isset($params['title'])) {
         $query->andWhere(['like', 'title', $params['title']]);
     }
     if (isset($params['type'])) {
         $query->andWhere(['in', 'type', explode(',', $params['type'])]);
     }
     $countQuery = clone $query;
     $pages = new Pagination(['totalCount' => $countQuery->count()]);
     $data = $query->offset($pages->offset)->limit($pages->limit)->orderBy('sort desc')->asArray()->all();
     if ($data) {
         foreach ($data as $key => $value) {
             if ($value['type'] == Recommend::TYPE_HOT) {
                 $basicData = Basic::findOne($value['rec_content']);
                 $data[$key]['title'] = $basicData->title;
             }
         }
     }
     #echo "<pre>";print_r($data);exit;
     return $this->render('index', ['data' => $data, 'pages' => $pages, 'params' => $params]);
 }
예제 #2
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;
 }
예제 #3
0
 /**
  * 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');
     }
 }
예제 #4
0
 /**
  * Finds the Basic model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Basic the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Basic::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }