Video.php 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\GoodsOrderItem;
  4. use app\common\model\PlatformMessage;
  5. use app\common\model\StoreBanner;
  6. use app\common\model\UserCollect;
  7. use app\common\model\VideoCate;
  8. use app\common\model\VideoGoods;
  9. use app\common\model\VideoIntro;
  10. use library\tools\Data;
  11. /**
  12. * @title 视频专栏
  13. * @controller Video
  14. * @group base
  15. */
  16. class Video extends Base
  17. {
  18. public function initialize()
  19. {
  20. parent::initialize();
  21. parent::setUid();
  22. }
  23. /**
  24. * @title 获取分类
  25. * @desc 获取分类
  26. * @author qc
  27. * @url /api/Video/getCateTree
  28. * @method GET
  29. * @header name:Authorization require:1 desc:Token
  30. * @return name:id type:int default:-- desc:分类id
  31. * @return name:logo type:string default:-- desc:图标
  32. * @return name:title type:string default:0 desc:分类名称
  33. */
  34. public function getCateTree()
  35. {
  36. $list = VideoCate::where(['is_deleted'=>0])->field('id,logo,title,pid')->order('sort desc')->select()->toArray();
  37. $this->success('ok',['list'=>$list]);
  38. }
  39. /**
  40. * @title 获取轮播图(没有就不用)
  41. * @desc 获取轮播图
  42. * @author qc
  43. * @url /api/Video/getBanner
  44. * @method GET
  45. * @header name:Authorization require:1 desc:Token
  46. * @param name:num type:int default:5 desc:查询数量
  47. * @return name:cover type:srting default:-- desc:图片路径
  48. * @return name:link type:srting default:-- desc:链接
  49. */
  50. public function getBanner()
  51. {
  52. $num = input('get.num',5);
  53. $list = StoreBanner::where(['place'=>3,'is_deleted'=>0])
  54. ->field('id,cover,link')
  55. ->limit(0,$num)
  56. ->order('sort desc ,id desc')
  57. ->select()->toArray();
  58. $this->success('ok',['list'=>$list]);
  59. }
  60. /**
  61. * @title 获取视频列表
  62. * @desc 获取视频列表
  63. * @author qc
  64. * @method GET
  65. * @url /api/Video/getVideoList
  66. * @header name:Authorization require:1 desc:Token
  67. * @param name:title type:string default:-- desc:标题
  68. * @param name:first_classify type:int default:0 desc:视频一级分类
  69. * @return name:title type:string default:-- desc:标题
  70. * @return name:cover type:string default:-- desc:封面
  71. * @return name:video_url type:string default:-- desc:视频地址
  72. * @return name:first_classify type:int default:-- desc:视频一级分类
  73. * @return name:second_classify type:int default:-- desc:视频二级分类
  74. * @return name:is_top type:int default:-- desc:是否置顶(0否,1是)
  75. * @return name:read_num type:int default:-- desc:阅读量
  76. * @return name:is_collect type:int default:-- desc:是否收藏
  77. */
  78. public function getVideoList()
  79. {
  80. $sel_where = [];
  81. $sel_where[] = ['is_deleted','=',0];
  82. $sel_where[] = ['status','=',1];
  83. $title = input('get.title');
  84. $first_classify = input('get.first_classify');
  85. if($title) $sel_where[] = ['title','like','%'.$title.'%'];
  86. if($first_classify) $sel_where[] = ['first_classify','=',$first_classify];
  87. $list = VideoIntro::where($sel_where)
  88. ->order('is_top desc,sort desc ,id desc')
  89. ->limit($this->off_set,$this->page)->select()->toArray();
  90. array_walk($list,function ($v,$k){
  91. $v['is_collect'] = UserCollect::checkCollectByType($this->user_id,3,$v['id']);
  92. });
  93. $this->success('ok',['list'=>$list]);
  94. }
  95. /**
  96. * @title 获取最新条视频
  97. * @desc 获取最新条视频
  98. * @author qc
  99. * @method GET
  100. * @url /api/Video/getNewVideo
  101. * @header name:Authorization require:1 desc:Token
  102. * @return name:title type:string default:-- desc:标题
  103. * @return name:cover type:string default:-- desc:封面
  104. * @return name:video_url type:string default:-- desc:视频地址
  105. * @return name:first_classify type:int default:-- desc:视频一级分类
  106. * @return name:second_classify type:int default:-- desc:视频二级分类
  107. * @return name:is_top type:int default:-- desc:是否置顶(0否,1是)
  108. * @return name:read_num type:int default:-- desc:阅读量
  109. * @return name:is_collect type:int default:-- desc:是否收藏
  110. */
  111. public function getNewVideo()
  112. {
  113. $sel_where = [];
  114. $sel_where[] = ['is_deleted','=',0];
  115. $sel_where[] = ['status','=',1];
  116. $list = VideoIntro::where($sel_where)
  117. ->order('id desc')
  118. ->limit($this->off_set,$this->page_num)
  119. ->select()->toArray();
  120. array_walk($list,function ($v,$k){
  121. $v['is_collect'] = UserCollect::checkCollectByType($this->user_id,3,$v['id']);
  122. });
  123. if(!empty($list) && $this->user_id){
  124. $relation_id = PlatformMessage::where(['type'=>1])->max('id');// 最新的一条视频推荐
  125. // 更新最新视频阅读
  126. Data::save('PlatformReadLog',['user_id'=>$this->user_id,'type'=>1,'relation_id'=>$relation_id,'create_at'=>date('Y-m-d H:i:s')],'user_id',['user_id'=>$this->user_id,'type'=>1,'relation_id'=>$relation_id]);
  127. }
  128. $this->success('ok',['list'=>$list]);
  129. }
  130. /**
  131. * @title 获取视频详情
  132. * @desc 获取视频详情
  133. * @author qc
  134. * @method GET
  135. * @url /api/Video/getVideoDetail
  136. * @header name:Authorization require:1 desc:Token
  137. * @param name:id type:int default:0 desc:视频id
  138. * @return name:title type:string default:-- desc:标题
  139. * @return name:cover type:string default:-- desc:封面
  140. * @return name:video_url type:string default:-- desc:视频地址
  141. * @return name:first_classify type:int default:-- desc:视频一级分类
  142. * @return name:is_top type:int default:-- desc:是否置顶(0否,1是)
  143. * @return name:read_num type:int default:-- desc:阅读量
  144. * @return name:is_collect type:int default:-- desc:是否收藏
  145. */
  146. public function getVideoDetail()
  147. {
  148. $sel_where = [];
  149. $sel_where[] = ['is_deleted','=',0];
  150. $sel_where[] = ['status','=',1];
  151. $sel_where[] = ['id','=',input('get.id')];
  152. $detail = VideoIntro::where($sel_where)
  153. ->order('is_top desc,sort desc ,id desc')->find();
  154. if(!$detail)$this->error('该视频已下线');
  155. $detail['is_collect'] = UserCollect::checkCollectByType($this->user_id,3,$detail->id);
  156. $this->success('ok',['detail'=>$detail]);
  157. }
  158. /**
  159. * @title 获取视频相关商品
  160. * @desc 获取视频相关商品
  161. * @author qc
  162. * @method GET
  163. * @url /api/Video/getVideoGoods
  164. * @header name:Authorization require:1 desc:Token
  165. * @param name:id type:int default:0 desc:视频id(不传查全部的视频商品)
  166. * @param name:page type:int default:1 desc:页数
  167. * @param name:page_num type:int default:20 desc:每页数量
  168. * @return name:id type:int default:-- desc:视频相关商品记录id
  169. * @return name:line_price type:float default:-- desc:下划线价格
  170. * @return name:video_id type:string default:-- desc:视频id
  171. * @return name:goods_set type:array default:-- desc:商品信息
  172. * @return name:goods_set.name type:string default:-- desc:商品名称
  173. * @return name:goods_set.cover type:string default:-- desc:商品封面
  174. * @return name:goods_set.low_price type:float default:-- desc:最低价格
  175. */
  176. public function getVideoGoods()
  177. {
  178. $id = input('get.id');
  179. if($id){
  180. $list = VideoGoods::with('goodsSet')->limit($this->off_set,$this->page_num)->select()->toArray();
  181. }else{
  182. $list = VideoGoods::with('goodsSet')->where(['video_id'=>$id])->limit($this->off_set,$this->page_num)->select()->toArray();
  183. }
  184. array_walk($list,function (&$v,$k){
  185. $v['line_price'] = GoodsOrderItem::where('goods_id',$v['goods_id'])->max('original_price');
  186. });
  187. $this->success('ok',['list'=>$list]);
  188. }
  189. }