Ejemplo n.º 1
0
 /**
  * type
  * @param  string
  * @return array
  */
 public function getMvBasicType()
 {
     return self::hasOne(MvBasicType::className(), ['basic_id' => 'id']);
 }
Ejemplo n.º 2
0
 /**
  * 详情页
  */
 public function actionDetail($id)
 {
     $this->menu_tag = 'list';
     if (!is_numeric($id)) {
         return $this->render('404.php');
     }
     $redis = Yii::$app->params['redis'][$this->ctr . '_' . $this->act];
     $redis_key = sprintf($redis['key'], $id);
     $redis_exp = $redis['t'];
     // cache
     $movieInfo = Yii::$app->cache->get($redis_key);
     $movieInfo = json_decode($movieInfo, true);
     if (empty($movieInfo)) {
         $movieInfo = [];
         $movieInfo = models\MvBasic::getMovieInfo($id);
         if (is_array($movieInfo)) {
             $movieInfo['aka'] = str_replace(',', ' / ', $movieInfo['aka']);
             $movieInfo['directors'] = str_replace(',', ' / ', $movieInfo['directors']);
             $movieInfo['casts'] = str_replace(',', ' / ', $movieInfo['casts']);
             $movieInfo['countries'] = str_replace(',', ' / ', $movieInfo['countries']);
             $basic_id = $movieInfo['id'];
             $cateIdDate = models\MvBasicType::find()->select('cate_id')->where(['basic_id' => $basic_id])->asArray()->all();
             $cateIdArr = [];
             foreach ($cateIdDate as $v) {
                 $cateIdArr[] = $v['cate_id'];
             }
             $cateData = models\MvBasicCondition::find()->select('name')->where(['id' => $cateIdArr])->asArray()->all();
             $cate = [];
             foreach ($cateData as $v) {
                 $cate[] = $v['name'];
             }
             $movieInfo['cate'] = $cate;
             // source
             $sourceData = models\MvSource::find()->where(['basic_id' => $basic_id, 'status' => models\MvSource::STATUS_SHOW])->andWhere('type!=0')->orderBy('sort desc, update_time DESC')->asArray()->all();
             // source sort
             $sourceSort = [];
             foreach ($sourceData as $k => $v) {
                 if (in_array($v['type'], [1, 2, 5, 6])) {
                     $sourceSort['1'][] = $v;
                 } elseif (in_array($v['type'], [3, 4])) {
                     $sourceSort['2'][] = $v;
                 } elseif ($v['type'] >= 20) {
                     $sourceSort['3'][] = $v;
                 } elseif ($v['type'] == 13) {
                     $sourceSort['4'][] = $v;
                 } elseif ($v['type'] >= 10 && $v['type'] < 13) {
                     $sourceSort['5'][] = $v;
                 }
             }
             ksort($sourceSort);
             $source = [];
             foreach ($sourceSort as $v) {
                 $source = array_merge($source, $v);
             }
             $movieInfo['source'] = $source;
             // set cache
             if ($movieInfo) {
                 Yii::$app->cache->set($redis_key, json_encode($movieInfo), $redis_exp);
             }
         } else {
             return $this->render('404.php');
         }
     }
     // meta title
     if ($movieInfo['title']) {
         Yii::$app->view->title = $movieInfo['title'];
     }
     return $this->render('movie_detail', ['movie' => $movieInfo]);
 }