コード例 #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
ファイル: BasicSearch.php プロジェクト: s-nice/snece
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Basic::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'pid' => $this->pid, 'orderid' => $this->orderid, 'create_uid' => $this->create_uid, 'create_at' => $this->create_at, 'update_at' => $this->update_at]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
コード例 #3
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;
 }
コード例 #4
0
ファイル: SourceController.php プロジェクト: nicevoice/ddll
 /**
  * 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');
     }
 }
コード例 #5
0
 public function actionDouBanCreate()
 {
     $params = Yii::$app->request->post();
     if ($params && $params['Basic']) {
         foreach ($params['Basic'] as $key => $value) {
             $params['Basic']['update_time'] = time();
             $params['Basic']['create_time'] = time();
         }
     }
     $model = new Basic();
     if ($model->load($params) && $model->save()) {
         return $this->redirect(['basic/view', 'id' => $model->id]);
     } else {
         throw new ServerErrorHttpException('Create Error');
     }
 }
コード例 #6
0
ファイル: BasicController.php プロジェクト: nicevoice/ddll
 /**
  * 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.');
     }
 }