123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- <?php
- namespace app\api\controller;
- use app\common\model\GoodsOrderItem;
- use app\common\model\PlatformMessage;
- use app\common\model\StoreBanner;
- use app\common\model\UserCollect;
- use app\common\model\VideoCate;
- use app\common\model\VideoGoods;
- use app\common\model\VideoIntro;
- use library\tools\Data;
- /**
- * @title 视频专栏
- * @controller Video
- * @group base
- */
- class Video extends Base
- {
- public function initialize()
- {
- parent::initialize();
- parent::setUid();
- }
- /**
- * @title 获取分类
- * @desc 获取分类
- * @author qc
- * @url /api/Video/getCateTree
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @return name:id type:int default:-- desc:分类id
- * @return name:logo type:string default:-- desc:图标
- * @return name:title type:string default:0 desc:分类名称
- */
- public function getCateTree()
- {
- $list = VideoCate::where(['is_deleted'=>0])->field('id,logo,title,pid')->order('sort desc')->select()->toArray();
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 获取轮播图(没有就不用)
- * @desc 获取轮播图
- * @author qc
- * @url /api/Video/getBanner
- * @method GET
- * @header name:Authorization require:1 desc:Token
- * @param name:num type:int default:5 desc:查询数量
- * @return name:cover type:srting default:-- desc:图片路径
- * @return name:link type:srting default:-- desc:链接
- */
- public function getBanner()
- {
- $num = input('get.num',5);
- $list = StoreBanner::where(['place'=>3,'is_deleted'=>0])
- ->field('id,cover,link')
- ->limit(0,$num)
- ->order('sort desc ,id desc')
- ->select()->toArray();
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 获取视频列表
- * @desc 获取视频列表
- * @author qc
- * @method GET
- * @url /api/Video/getVideoList
- * @header name:Authorization require:1 desc:Token
- * @param name:title type:string default:-- desc:标题
- * @param name:first_classify type:int default:0 desc:视频一级分类
- * @return name:title type:string default:-- desc:标题
- * @return name:cover type:string default:-- desc:封面
- * @return name:video_url type:string default:-- desc:视频地址
- * @return name:first_classify type:int default:-- desc:视频一级分类
- * @return name:second_classify type:int default:-- desc:视频二级分类
- * @return name:is_top type:int default:-- desc:是否置顶(0否,1是)
- * @return name:read_num type:int default:-- desc:阅读量
- * @return name:is_collect type:int default:-- desc:是否收藏
- */
- public function getVideoList()
- {
- $sel_where = [];
- $sel_where[] = ['is_deleted','=',0];
- $sel_where[] = ['status','=',1];
- $title = input('get.title');
- $first_classify = input('get.first_classify');
- if($title) $sel_where[] = ['title','like','%'.$title.'%'];
- if($first_classify) $sel_where[] = ['first_classify','=',$first_classify];
- $list = VideoIntro::where($sel_where)
- ->order('is_top desc,sort desc ,id desc')
- ->limit($this->off_set,$this->page)->select()->toArray();
- array_walk($list,function ($v,$k){
- $v['is_collect'] = UserCollect::checkCollectByType($this->user_id,3,$v['id']);
- });
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 获取最新条视频
- * @desc 获取最新条视频
- * @author qc
- * @method GET
- * @url /api/Video/getNewVideo
- * @header name:Authorization require:1 desc:Token
- * @return name:title type:string default:-- desc:标题
- * @return name:cover type:string default:-- desc:封面
- * @return name:video_url type:string default:-- desc:视频地址
- * @return name:first_classify type:int default:-- desc:视频一级分类
- * @return name:second_classify type:int default:-- desc:视频二级分类
- * @return name:is_top type:int default:-- desc:是否置顶(0否,1是)
- * @return name:read_num type:int default:-- desc:阅读量
- * @return name:is_collect type:int default:-- desc:是否收藏
- */
- public function getNewVideo()
- {
- $sel_where = [];
- $sel_where[] = ['is_deleted','=',0];
- $sel_where[] = ['status','=',1];
- $list = VideoIntro::where($sel_where)
- ->order('id desc')
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- array_walk($list,function ($v,$k){
- $v['is_collect'] = UserCollect::checkCollectByType($this->user_id,3,$v['id']);
- });
- if(!empty($list) && $this->user_id){
- $relation_id = PlatformMessage::where(['type'=>1])->max('id');// 最新的一条视频推荐
- // 更新最新视频阅读
- 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]);
- }
- $this->success('ok',['list'=>$list]);
- }
- /**
- * @title 获取视频详情
- * @desc 获取视频详情
- * @author qc
- * @method GET
- * @url /api/Video/getVideoDetail
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:0 desc:视频id
- * @return name:title type:string default:-- desc:标题
- * @return name:cover type:string default:-- desc:封面
- * @return name:video_url type:string default:-- desc:视频地址
- * @return name:first_classify type:int default:-- desc:视频一级分类
- * @return name:is_top type:int default:-- desc:是否置顶(0否,1是)
- * @return name:read_num type:int default:-- desc:阅读量
- * @return name:is_collect type:int default:-- desc:是否收藏
- */
- public function getVideoDetail()
- {
- $sel_where = [];
- $sel_where[] = ['is_deleted','=',0];
- $sel_where[] = ['status','=',1];
- $sel_where[] = ['id','=',input('get.id')];
- $detail = VideoIntro::where($sel_where)
- ->order('is_top desc,sort desc ,id desc')->find();
- if(!$detail)$this->error('该视频已下线');
- $detail['is_collect'] = UserCollect::checkCollectByType($this->user_id,3,$detail->id);
- $this->success('ok',['detail'=>$detail]);
- }
- /**
- * @title 获取视频相关商品
- * @desc 获取视频相关商品
- * @author qc
- * @method GET
- * @url /api/Video/getVideoGoods
- * @header name:Authorization require:1 desc:Token
- * @param name:id type:int default:0 desc:视频id(不传查全部的视频商品)
- * @param name:page type:int default:1 desc:页数
- * @param name:page_num type:int default:20 desc:每页数量
- * @return name:id type:int default:-- desc:视频相关商品记录id
- * @return name:line_price type:float default:-- desc:下划线价格
- * @return name:video_id type:string default:-- desc:视频id
- * @return name:goods_set type:array default:-- desc:商品信息
- * @return name:goods_set.name type:string default:-- desc:商品名称
- * @return name:goods_set.cover type:string default:-- desc:商品封面
- * @return name:goods_set.low_price type:float default:-- desc:最低价格
- */
- public function getVideoGoods()
- {
- $id = input('get.id');
- if($id){
- $list = VideoGoods::with('goodsSet')->limit($this->off_set,$this->page_num)->select()->toArray();
- }else{
- $list = VideoGoods::with('goodsSet')->where(['video_id'=>$id])->limit($this->off_set,$this->page_num)->select()->toArray();
- }
- array_walk($list,function (&$v,$k){
- $v['line_price'] = GoodsOrderItem::where('goods_id',$v['goods_id'])->max('original_price');
- });
- $this->success('ok',['list'=>$list]);
- }
- }
|