123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- <?php
- namespace mobile\controllers;
- use common\models\CategoryCity;
- use common\models\House;
- use common\models\HouseDetail;
- use mobile\base\CommonController;
- use common\models\VideoCategory;
- use common\models\Video;
- use Yii;
- use mobile\base\Help;
- class VideoController extends CommonController
- {
- public $enableCsrfValidation = false;
- public function actionHome()
- {
- return $this->render('home');
- }
- public function actionDetails()
- {
- return $this->render('details');
- }
- /*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#Date:2019-3-28 Author:eit Title:视频页面*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*/
- public function actionVideolist()
- {
- $province = $this->province();
- return $this->render('videolist', ['province' => $province]);
- }
- /**
- * @title ajax获取区域视频
- */
- public function actionGetvideo()
- {
- // $model = new Video();
- $input = Yii::$app->request->get();
- if (isset($input['city']) && !empty($input['city'])) {
- $city = CategoryCity::find()->andWhere(['del' => 1, 'pid' => $input['city']])->select(['id'])->column();
- $city[] = $input['city'];
- // $model->city = $city;
- }
- // $videolist = $model->homeList($input);
- $videolist = House::find();
- $videolist->andWhere(['NOT', ['pfg_house_detail.video_url' => '']]);
- $videolist->andWhere(['pfg_house.del' => 1]);
- $videolist->andWhere(['pfg_house.is_view' => 1]);
- if (!empty($city)) {
- $videolist->andWhere(['pfg_house.city' => $city]);
- }
- $videolist->select(['pfg_house.id', 'pfg_house.name', 'pfg_house.thumb']);
- $videolist->leftJoin('pfg_house_detail', 'pfg_house.id = pfg_house_detail.hid');
- $data = $videolist->orderBy(['pfg_house.sort' => SORT_DESC, 'pfg_house.id' => SORT_DESC])->asArray()->all();
- if (!empty($data)) {
- foreach ($data as &$val) {
- $val['thumb'] = Yii::$app->params['httpImg']['hosts'] . Yii::$app->params['httpImg']['houses'] . $val['thumb'] . '/same';
- }
- return Help::JsonCode(Help::SUCCESS, '成功', $data);
- }
- }
- /**
- * 视频搜索接口@2019.8.20
- */
- public function actionSearch()
- {
- $post = Yii::$app->request->post();
- // $list = (new Video())->getText($post);
- $videolist = House::find();
- $videolist->andWhere(['NOT', ['pfg_house_detail.video_url' => '']]);
- $videolist->andWhere(['pfg_house.del' => 1]);
- $videolist->andWhere(['pfg_house.is_view' => 1]);
- if (!empty($post['text'])) {
- $videolist->andWhere(['like', 'pfg_house.name', $post['text']]);
- }
- $videolist->select(['pfg_house.id', 'pfg_house.name', 'pfg_house.thumb']);
- $videolist->leftJoin('pfg_house_detail', 'pfg_house.id = pfg_house_detail.hid');
- $list = $videolist->orderBy(['pfg_house.sort' => SORT_DESC, 'pfg_house.id' => SORT_DESC])->asArray()->all();
- if (!empty($list)) {
- foreach ($list as &$val) {
- $val['thumb'] = Yii::$app->params['httpImg']['hosts'] . Yii::$app->params['httpImg']['houses'] . $val['thumb'] . '/same';
- }
- return Help::JsonCode(Help::SUCCESS, '成功', $list);
- }
- return Help::JsonCode(Help::ERROR, '暂无数据');
- }
- /**
- * @title ajax统计视频播放次数
- */
- public function actionPlays()
- {
- $model = new Video();
- $input = Yii::$app->request->get();
- if (is_numeric($input['id'])) {
- $row = $model->FindById($input['id']);
- if (!empty($row)) {
- if (isset($input['thumbs_up'])) {
- $row->thumbs_up = ++$row->thumbs_up;
- } else {
- $row->plays = ++$row->plays;
- }
- $row->save(false);
- return true;
- }
- }
- }
- /**
- * @title 视频详情
- */
- public function actionVideodetails()
- {
- $hotplay = $this->HotPlays(Yii::$app->request->get());
- $model = new House();
- $input = Yii::$app->request->get();
- $info = $model::find()
- ->andWhere(['pfg_house.id' => $input['hid'], 'pfg_house.del' => 1, 'pfg_house.is_view' => 1])
- ->leftJoin('pfg_house_detail', 'pfg_house.id = pfg_house_detail.hid')
- ->leftJoin('pfg_category_city', 'pfg_house.city = pfg_category_city.id')
- ->select(['pfg_house.id', 'pfg_house.name', 'pfg_house.thumb', 'pfg_house.characteristic', 'pfg_house_detail.video_url',
- 'pfg_house_detail.features', 'pfg_category_city.city_name'])
- ->asArray()->one();
- // /***2020.6.18 lyy 根据$input['lt'] 判断是否是获取直播视频***/
- // if (isset($input['lt']) && $input['lt'] == 1) {
- // $live = \common\models\Live::find()
- // ->andWhere(['hid' => $input['hid']])
- // ->asArray()->one();
- // $info['video_url'] = $live['video_url'];
- // $info['title'] = $live['title'];
- // $info['thumb'] = $live['img'];
- // } else {
- // $info['thumb'] = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['video'] . $info['thumb'];
- // }
- // if (isset($input['hid']) && !empty($input['hid'])) {
- // $infos = $this->getHouseCity($input['hid']);
- // $info['city'] = $infos['city'];
- // $info['characteristic'] = $infos['characteristic'];
- // }
- if (!empty($info)) {
- $info['characteristic'] = $this->Subject(json_decode($info['characteristic']), 2);
- return $this->render('videodetails', ['hotplay' => $hotplay, 'info' => $info]);
- }
- return false;
- }
- /**
- * @title 楼盘详情的区域
- */
- public function getHouseCity($hid)
- {
- $modelHouse = new \common\models\House();
- $houseinfo = $modelHouse->FindById($hid);
- $houseinfo['characteristic'] = $this->Subject(json_decode($houseinfo['characteristic']), 2);
- $modelCity = new \common\models\CategoryCity();
- $cityData = $modelCity->FindById($houseinfo['city']);
- $Data['city'] = $cityData['city_name'];
- $Data['characteristic'] = $houseinfo['characteristic'];
- return $Data;
- }
- /**
- * 获取热播视频
- */
- private function HotPlays($input)
- {
- // $model = new Video();
- // $model->allow = 1;
- // $input['limit'] = 4;
- // $input['page'] = 1;
- // $videolist = $model->homeList($input);
- // if (!empty($videolist)) {
- // foreach ($videolist as &$val) {
- // $val['thumb'] = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['video'] . $val['thumb'];
- // }
- // return $videolist;
- // }
- // return false;
- $data = House::find()->andWhere(['NOT', ['pfg_house_detail.video_url' => '']])
- ->andWhere(['<>', 'pfg_house.id', $input['hid']])
- ->andWhere(['pfg_house.del' => 1])
- ->andWhere(['pfg_house.is_view' => 1])
- ->select(['pfg_house.id', 'pfg_house.name', 'pfg_house.thumb'])
- ->leftJoin('pfg_house_detail', 'pfg_house.id = pfg_house_detail.hid')
- ->orderBy('RAND()')->limit(4)->asArray()->all();
- if (!empty($data)) {
- return $data;
- }
- return '';
- }
- /**
- * @title 获取省份
- */
- private function province()
- {
- $model = House::find()->andWhere(['NOT', ['pfg_house_detail.video_url' => '']])->andWhere(['del' => 1, 'is_view' => 1])
- ->leftJoin('pfg_house_detail', 'pfg_house.id = pfg_house_detail.hid')->select(['city'])->column();
- $city = CategoryCity::find()->andWhere(['del' => 1, 'id' => $model])->select(['pid'])->column();
- $upcity = CategoryCity::find()->andWhere(['del' => 1, 'id' => $city])->select(['id', 'city_name'])->orderBy(['sort' => SORT_DESC, 'id' => SORT_DESC])->asArray()->all();
- return $upcity;
- }
- //特色主题 超过3个随机返回3个元素
- public function Subject($id, $num = 3)
- {
- $char = new \common\models\Characteristic();
- if (is_array($id) && !empty($id)) {
- $char->id = $id;
- $charMode = array_column($char->getList([], ['id', 'name']), 'name', 'id');
- if ($charMode != null) {
- $count = count($charMode);
- $arr = [];
- if ($count > $num) {
- $rand = array_rand($charMode, $num);
- foreach ($rand as $key => $val) {
- $arr[$key] = $charMode[$val];
- }
- } else {
- $arr = $charMode;
- }
- return $arr;
- }
- }
- }
- }
|