123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
- namespace app\api\controller;
- use app\common\model\UserCollect;
- use app\common\model\VideoUrl;
- use think\Db;
- use library\tools\Data;
- class Collect extends Base
- {
- public function initialize()
- {
- parent::initialize();
- parent::checkLogin();
- }
-
- public function userCollect()
- {
- $coll_type = input('post.coll_type',1);
- $url_id = input('post.coll_id',0);
- $video_id = VideoUrl::where('id',$url_id)->value('video_id');
- $collect_check = UserCollect::where(['user_id'=>$this->user_id,'coll_type'=>$coll_type,'coll_id'=>$video_id,'children_id'=>$url_id])->find();
- if($collect_check) {
- UserCollect::where(['user_id'=>$this->user_id,'coll_type'=>$coll_type,'coll_id'=>$video_id,'children_id'=>$url_id])->delete();
- $this->success('取消收藏成功',['status'=>0]);
- }else{
- Data::save('UserCollect', [
- 'user_id'=>$this->user_id,
- 'coll_type'=>$coll_type,
- 'coll_id'=>$video_id,
- 'children_id'=>$url_id,
- 'create_int'=>time()],'user_id',['user_id'=>$this->user_id,'coll_type'=>$coll_type, 'coll_id'=>$video_id,'children_id'=>$url_id]);
- $this->success('收藏成功',['status'=>1]);
- }
- }
-
- public function getUserCollectList()
- {
- $coll_type = input('get.coll_type',1);
- $sel_where = [];
- $sel_where[] = ['coll_type','=',$coll_type];
- $sel_where[] = ['user_id','=',$this->user_id];
- if(!in_array($coll_type,[1,2,3])) $this->error('收藏类型有误');
- $with = ['','videoItem','datumItem','articleItem'];
- $list = UserCollect::with($with[$coll_type])
- ->field('id,create_at,coll_type')
- ->where($sel_where)
- ->limit($this->off_set,$this->page_num)
- ->select()->toArray();
- $this->success('ok',['list'=>$list]);
- }
-
- public function cancelCollect()
- {
- $ids = input('post.ids','');
- if(!$ids) $this->error('请选择要取消收藏的记录');
- UserCollect::where('id','in',$ids)->where('user_id','=',$this->user_id)->delete();
- $this->success('取消成功');
- }
-
- public function cancelCollectByType()
- {
- $coll_type = input('post.coll_type',1);
- $coll_id = input('get.coll_id',0);
- UserCollect::where(['user_id'=>$this->user_id,'coll_type'=>$coll_type,'coll_id'=>$coll_id])->delete();
- $this->success('取消成功');
- }
- }
|