VideoController.php 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <?php
  2. namespace mobile\controllers;
  3. use common\models\CategoryCity;
  4. use common\models\House;
  5. use common\models\HouseDetail;
  6. use mobile\base\CommonController;
  7. use common\models\VideoCategory;
  8. use common\models\Video;
  9. use Yii;
  10. use mobile\base\Help;
  11. class VideoController extends CommonController
  12. {
  13. public $enableCsrfValidation = false;
  14. public function actionHome()
  15. {
  16. return $this->render('home');
  17. }
  18. public function actionDetails()
  19. {
  20. return $this->render('details');
  21. }
  22. /*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#Date:2019-3-28 Author:eit Title:视频页面*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*/
  23. public function actionVideolist()
  24. {
  25. $province = $this->province();
  26. return $this->render('videolist', ['province' => $province]);
  27. }
  28. /**
  29. * @title ajax获取区域视频
  30. */
  31. public function actionGetvideo()
  32. {
  33. // $model = new Video();
  34. $input = Yii::$app->request->get();
  35. if (isset($input['city']) && !empty($input['city'])) {
  36. $city = CategoryCity::find()->andWhere(['del' => 1, 'pid' => $input['city']])->select(['id'])->column();
  37. $city[] = $input['city'];
  38. // $model->city = $city;
  39. }
  40. // $videolist = $model->homeList($input);
  41. $videolist = House::find();
  42. $videolist->andWhere(['NOT', ['pfg_house_detail.video_url' => '']]);
  43. $videolist->andWhere(['pfg_house.del' => 1]);
  44. $videolist->andWhere(['pfg_house.is_view' => 1]);
  45. if (!empty($city)) {
  46. $videolist->andWhere(['pfg_house.city' => $city]);
  47. }
  48. $videolist->select(['pfg_house.id', 'pfg_house.name', 'pfg_house.thumb']);
  49. $videolist->leftJoin('pfg_house_detail', 'pfg_house.id = pfg_house_detail.hid');
  50. $data = $videolist->orderBy(['pfg_house.sort' => SORT_DESC, 'pfg_house.id' => SORT_DESC])->asArray()->all();
  51. if (!empty($data)) {
  52. foreach ($data as &$val) {
  53. $val['thumb'] = Yii::$app->params['httpImg']['hosts'] . Yii::$app->params['httpImg']['houses'] . $val['thumb'] . '/same';
  54. }
  55. return Help::JsonCode(Help::SUCCESS, '成功', $data);
  56. }
  57. }
  58. /**
  59. * 视频搜索接口@2019.8.20
  60. */
  61. public function actionSearch()
  62. {
  63. $post = Yii::$app->request->post();
  64. // $list = (new Video())->getText($post);
  65. $videolist = House::find();
  66. $videolist->andWhere(['NOT', ['pfg_house_detail.video_url' => '']]);
  67. $videolist->andWhere(['pfg_house.del' => 1]);
  68. $videolist->andWhere(['pfg_house.is_view' => 1]);
  69. if (!empty($post['text'])) {
  70. $videolist->andWhere(['like', 'pfg_house.name', $post['text']]);
  71. }
  72. $videolist->select(['pfg_house.id', 'pfg_house.name', 'pfg_house.thumb']);
  73. $videolist->leftJoin('pfg_house_detail', 'pfg_house.id = pfg_house_detail.hid');
  74. $list = $videolist->orderBy(['pfg_house.sort' => SORT_DESC, 'pfg_house.id' => SORT_DESC])->asArray()->all();
  75. if (!empty($list)) {
  76. foreach ($list as &$val) {
  77. $val['thumb'] = Yii::$app->params['httpImg']['hosts'] . Yii::$app->params['httpImg']['houses'] . $val['thumb'] . '/same';
  78. }
  79. return Help::JsonCode(Help::SUCCESS, '成功', $list);
  80. }
  81. return Help::JsonCode(Help::ERROR, '暂无数据');
  82. }
  83. /**
  84. * @title ajax统计视频播放次数
  85. */
  86. public function actionPlays()
  87. {
  88. $model = new Video();
  89. $input = Yii::$app->request->get();
  90. if (is_numeric($input['id'])) {
  91. $row = $model->FindById($input['id']);
  92. if (!empty($row)) {
  93. if (isset($input['thumbs_up'])) {
  94. $row->thumbs_up = ++$row->thumbs_up;
  95. } else {
  96. $row->plays = ++$row->plays;
  97. }
  98. $row->save(false);
  99. return true;
  100. }
  101. }
  102. }
  103. /**
  104. * @title 视频详情
  105. */
  106. public function actionVideodetails()
  107. {
  108. $hotplay = $this->HotPlays(Yii::$app->request->get());
  109. $model = new House();
  110. $input = Yii::$app->request->get();
  111. $info = $model::find()
  112. ->andWhere(['pfg_house.id' => $input['hid'], 'pfg_house.del' => 1, 'pfg_house.is_view' => 1])
  113. ->leftJoin('pfg_house_detail', 'pfg_house.id = pfg_house_detail.hid')
  114. ->leftJoin('pfg_category_city', 'pfg_house.city = pfg_category_city.id')
  115. ->select(['pfg_house.id', 'pfg_house.name', 'pfg_house.thumb', 'pfg_house.characteristic', 'pfg_house_detail.video_url',
  116. 'pfg_house_detail.features', 'pfg_category_city.city_name'])
  117. ->asArray()->one();
  118. // /***2020.6.18 lyy 根据$input['lt'] 判断是否是获取直播视频***/
  119. // if (isset($input['lt']) && $input['lt'] == 1) {
  120. // $live = \common\models\Live::find()
  121. // ->andWhere(['hid' => $input['hid']])
  122. // ->asArray()->one();
  123. // $info['video_url'] = $live['video_url'];
  124. // $info['title'] = $live['title'];
  125. // $info['thumb'] = $live['img'];
  126. // } else {
  127. // $info['thumb'] = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['video'] . $info['thumb'];
  128. // }
  129. // if (isset($input['hid']) && !empty($input['hid'])) {
  130. // $infos = $this->getHouseCity($input['hid']);
  131. // $info['city'] = $infos['city'];
  132. // $info['characteristic'] = $infos['characteristic'];
  133. // }
  134. if (!empty($info)) {
  135. $info['characteristic'] = $this->Subject(json_decode($info['characteristic']), 2);
  136. return $this->render('videodetails', ['hotplay' => $hotplay, 'info' => $info]);
  137. }
  138. return false;
  139. }
  140. /**
  141. * @title 楼盘详情的区域
  142. */
  143. public function getHouseCity($hid)
  144. {
  145. $modelHouse = new \common\models\House();
  146. $houseinfo = $modelHouse->FindById($hid);
  147. $houseinfo['characteristic'] = $this->Subject(json_decode($houseinfo['characteristic']), 2);
  148. $modelCity = new \common\models\CategoryCity();
  149. $cityData = $modelCity->FindById($houseinfo['city']);
  150. $Data['city'] = $cityData['city_name'];
  151. $Data['characteristic'] = $houseinfo['characteristic'];
  152. return $Data;
  153. }
  154. /**
  155. * 获取热播视频
  156. */
  157. private function HotPlays($input)
  158. {
  159. // $model = new Video();
  160. // $model->allow = 1;
  161. // $input['limit'] = 4;
  162. // $input['page'] = 1;
  163. // $videolist = $model->homeList($input);
  164. // if (!empty($videolist)) {
  165. // foreach ($videolist as &$val) {
  166. // $val['thumb'] = Yii::$app->params['httpImg']['host'] . Yii::$app->params['httpImg']['video'] . $val['thumb'];
  167. // }
  168. // return $videolist;
  169. // }
  170. // return false;
  171. $data = House::find()->andWhere(['NOT', ['pfg_house_detail.video_url' => '']])
  172. ->andWhere(['<>', 'pfg_house.id', $input['hid']])
  173. ->andWhere(['pfg_house.del' => 1])
  174. ->andWhere(['pfg_house.is_view' => 1])
  175. ->select(['pfg_house.id', 'pfg_house.name', 'pfg_house.thumb'])
  176. ->leftJoin('pfg_house_detail', 'pfg_house.id = pfg_house_detail.hid')
  177. ->orderBy('RAND()')->limit(4)->asArray()->all();
  178. if (!empty($data)) {
  179. return $data;
  180. }
  181. return '';
  182. }
  183. /**
  184. * @title 获取省份
  185. */
  186. private function province()
  187. {
  188. $model = House::find()->andWhere(['NOT', ['pfg_house_detail.video_url' => '']])->andWhere(['del' => 1, 'is_view' => 1])
  189. ->leftJoin('pfg_house_detail', 'pfg_house.id = pfg_house_detail.hid')->select(['city'])->column();
  190. $city = CategoryCity::find()->andWhere(['del' => 1, 'id' => $model])->select(['pid'])->column();
  191. $upcity = CategoryCity::find()->andWhere(['del' => 1, 'id' => $city])->select(['id', 'city_name'])->orderBy(['sort' => SORT_DESC, 'id' => SORT_DESC])->asArray()->all();
  192. return $upcity;
  193. }
  194. //特色主题 超过3个随机返回3个元素
  195. public function Subject($id, $num = 3)
  196. {
  197. $char = new \common\models\Characteristic();
  198. if (is_array($id) && !empty($id)) {
  199. $char->id = $id;
  200. $charMode = array_column($char->getList([], ['id', 'name']), 'name', 'id');
  201. if ($charMode != null) {
  202. $count = count($charMode);
  203. $arr = [];
  204. if ($count > $num) {
  205. $rand = array_rand($charMode, $num);
  206. foreach ($rand as $key => $val) {
  207. $arr[$key] = $charMode[$val];
  208. }
  209. } else {
  210. $arr = $charMode;
  211. }
  212. return $arr;
  213. }
  214. }
  215. }
  216. }