Video.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/3/4
  6. * Time: 上午9:50
  7. */
  8. namespace common\models;
  9. class Video extends Common
  10. {
  11. public function rules()
  12. {
  13. return [
  14. ['hid', 'unique', 'targetClass' => 'common\models\Video', 'on' => ['add'], 'message' => '该楼盘已存在', 'filter' => function ($query) {
  15. return $query->andWhere(['del' => $this->setDel]);
  16. }],
  17. [['title', 'hid'], 'required', 'message' => '不能为空'],
  18. ['sort', 'default', 'value' => 0],
  19. [['thumb', 'source', 'key_words'], 'string', 'max' => 50],
  20. ['allow', 'in', 'range' => [1, 2]],
  21. ['video_url', 'string', 'max' => 150],
  22. [['video_category', 'city', 'hid', 'sort'], 'number'],
  23. [['description', 'content'], 'string'],
  24. ['uid', 'number']
  25. ];
  26. }
  27. public function attributeLabels()
  28. {
  29. return [
  30. 'title' => '视频标题',
  31. 'thumb' => '封面图',
  32. 'video_url' => '视频路径',
  33. 'source' => '视频来源',
  34. 'key_words' => '关键词',
  35. 'city' => '所属城市',
  36. 'content' => '内容介绍',
  37. 'description' => '描述',
  38. 'sort' => '排序',
  39. 'allow' => '是否推荐',
  40. 'video_category' => '所属分类',
  41. ];
  42. }
  43. public function Authenticator($input)
  44. {
  45. $this->load($input, '');
  46. if (!$this->validate()) return $this->errors;
  47. return $this;
  48. }
  49. public function FindById($id)
  50. {
  51. return self::findOne($id);
  52. }
  53. //查看楼盘存在数据
  54. public function HidList()
  55. {
  56. $query = self::find();
  57. $query->andWhere(['del' => $this->setDel]);
  58. $query->andWhere(['hid' => $this->hid]);
  59. $query->select(['hid', 'video_url']);
  60. return $query->asArray()->all();
  61. }
  62. public function getList($input)
  63. {
  64. $query = $this->QueryFind();
  65. $query->select(['pfg_house.name as house_name', 'pfg_house.id as house_id', 'pfg_video.*', 'pfg_category_city.city_name', 'pfg_category_video.type_name']);
  66. $query = $this->LeftJoinWhere($query);
  67. $query = $this->LeftJoinCategoryCity($query);
  68. $query = $this->LeftJoinHouse($query);
  69. $query = $this->LeftJoinCategoryVideo($query);
  70. if (!empty($input)) {
  71. $query->offset = ($input['page'] - 1) * $input['limit'];
  72. $query->limit = $input['limit'];
  73. }
  74. return $query->orderBy(['pfg_video.create_at' => SORT_DESC])->asArray()->all();
  75. }
  76. public function Total()
  77. {
  78. $query = $this->QueryFind();
  79. $query = $this->LeftJoinWhere($query);
  80. $query = $this->LeftJoinCategoryCity($query);
  81. $query = $this->LeftJoinHouse($query);
  82. $query = $this->LeftJoinCategoryVideo($query);
  83. return $query->count();
  84. }
  85. /*
  86. * 区域分组
  87. * */
  88. public function GroupCity()
  89. {
  90. $query = self::find();
  91. $query->andWhere(['pfg_video.state' => 1]);
  92. $query->andWhere(['pfg_video.del' => 1]);
  93. $query->select(['pfg_category_city.city_name', 'pfg_video.city']);
  94. $query = $this->LeftJoinCategoryCity($query);
  95. $query->groupBy('pfg_video.city');
  96. return $query->asArray()->all();
  97. }
  98. /*
  99. * 前端视频首页
  100. * */
  101. public function homeList($input)
  102. {
  103. $query = self::find();
  104. $query->andWhere(['pfg_video.state' => 1]);
  105. $query->andWhere(['pfg_video.del' => 1]);
  106. $query->andFilterWhere(['pfg_video.city' => $this->city]);
  107. $query->andFilterWhere(['pfg_video.allow' => $this->allow]);
  108. $query->select(['pfg_house.name', 'pfg_house.sale_price', 'pfg_video.city', 'pfg_video.plays', 'pfg_video.thumbs_up', 'pfg_video.description', 'pfg_video.id', 'pfg_video.hid', 'pfg_house_detail.price_unit', 'pfg_video.thumb', 'pfg_video.video_url']);
  109. $query = $this->LeftJoinHouse($query);
  110. $query->leftJoin('pfg_house_detail', 'pfg_house.id = pfg_house_detail.hid');
  111. if (!empty($input)) {
  112. $query->offset = ($input['page'] - 1) * $input['limit'];
  113. $query->limit = $input['limit'];
  114. }
  115. return $query->asArray()->all();
  116. }
  117. //移动端搜索接口
  118. public function getText($post)
  119. {
  120. $query = self::find();
  121. $query->andWhere(['pfg_video.state' => 1]);
  122. $query->andWhere(['pfg_video.del' => 1]);
  123. $query->select(['pfg_house.name', 'pfg_house.sale_price', 'pfg_video.city', 'pfg_video.plays',
  124. 'pfg_video.thumbs_up', 'pfg_video.description', 'pfg_video.id', 'pfg_video.hid',
  125. 'pfg_video.thumb', 'pfg_video.video_url']);
  126. if (!empty($post['text'])) {
  127. $query->andWhere(['like', 'pfg_house.name', $post['text']]);
  128. }
  129. $query->leftJoin('pfg_house', 'pfg_video.hid = pfg_house.id');
  130. $query->leftJoin('pfg_house_detail', 'pfg_house.id = pfg_house_detail.hid');
  131. $query->orderBy(['pfg_video.create_at' => SORT_DESC]);
  132. return $query->asArray()->all();
  133. }
  134. /**
  135. *
  136. */
  137. public function homeListTotal()
  138. {
  139. $query = self::find();
  140. $query->andWhere(['pfg_video.state' => 1]);
  141. $query->andWhere(['pfg_video.del' => 1]);
  142. $query->andFilterWhere(['pfg_video.city' => $this->city]);
  143. $query = $this->LeftJoinHouse($query);
  144. $query->leftJoin('pfg_house_detail', 'pfg_house.id = pfg_house_detail.hid');
  145. return $query->count();
  146. }
  147. /**
  148. * 随机显示
  149. */
  150. public function RandList($limit = null, $is_push = null)
  151. {
  152. $query = self::find();
  153. $query->andWhere(['pfg_video.state' => 1]);
  154. $query->andWhere(['pfg_video.del' => 1]);
  155. $query->select(['pfg_house.name', 'pfg_category_city.city_name', 'pfg_house.sale_price', 'pfg_video.city', 'pfg_video.id', 'pfg_video.hid', 'pfg_house_detail.price_unit', 'pfg_video.thumb', 'pfg_house.thumb as img']);
  156. if (!empty($is_push)) {
  157. $query->andWhere(['pfg_house.is_push' => 2]);
  158. }
  159. $query = $this->LeftJoinHouse($query);
  160. $query->leftJoin('pfg_house_detail', 'pfg_house.id = pfg_house_detail.hid');
  161. $query->leftJoin('pfg_category_city', 'pfg_house.city = pfg_category_city.id');
  162. $query->limit = $limit;
  163. return $query->orderBy('rand()')->asArray()->all();
  164. }
  165. /**
  166. * @param $query
  167. * @return mixed
  168. */
  169. public function HomeFind()
  170. {
  171. $query = self::find();
  172. $query->andWhere(['pfg_video.state' => 1]);
  173. $query->andWhere(['pfg_video.del' => 1]);
  174. $query->andWhere(['pfg_video.id' => $this->id]);
  175. $query->select(['pfg_house.name', 'pfg_house.sale_price',
  176. 'pfg_video.city', 'pfg_video.id', 'pfg_video.hid',
  177. 'pfg_house_detail.price_unit', 'pfg_video.thumb',
  178. 'pfg_video.video_url', 'pfg_video.source', 'pfg_video.create_at',
  179. 'pfg_house_detail.open_time', 'pfg_house_detail.residential_type',
  180. 'pfg_house_detail.launch_time', 'pfg_house_detail.address', 'pfg_house_detail.info', 'pfg_house_detail.hid']);
  181. $query = $this->LeftJoinHouse($query);
  182. $query->leftJoin('pfg_house_detail', 'pfg_house.id = pfg_house_detail.hid');
  183. return $query->asArray()->one();
  184. }
  185. private function LeftJoinWhere($query)
  186. {
  187. $query->andFilterWhere(['pfg_video.del' => $this->setDel]);
  188. $query->andFilterWhere(['pfg_video.city' => $this->city]);
  189. $query->andFilterWhere(['pfg_video.video_category' => $this->video_category]);
  190. $query->andFilterWhere(['like', 'pfg_video.title', $this->title]);
  191. $query->andFilterWhere(['like', 'pfg_house.name', $this->hid]);
  192. return $query;
  193. }
  194. private function LeftJoinHouse($query)
  195. {
  196. return $query->leftJoin('pfg_house', 'pfg_video.hid = pfg_house.id');
  197. }
  198. private function LeftJoinCategoryVideo($query)
  199. {
  200. return $query->leftJoin('pfg_category_video', 'pfg_video.video_category = pfg_category_video.id');
  201. }
  202. private function LeftJoinCategoryCity($query)
  203. {
  204. return $query->leftJoin('pfg_category_city', 'pfg_video.city = pfg_category_city.id');
  205. }
  206. private function QueryFind()
  207. {
  208. return self::find();
  209. }
  210. }