Collect.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\model\UserCollect;
  4. use app\common\model\VideoUrl;
  5. use think\Db;
  6. use library\tools\Data;
  7. /**
  8. * @title 收藏
  9. * @controller Collect
  10. * @group base
  11. */
  12. class Collect extends Base
  13. {
  14. public function initialize()
  15. {
  16. parent::initialize();
  17. parent::checkLogin();
  18. }
  19. /**
  20. * @title 收藏列表批量操作或是单个取消【所有收藏模块】
  21. * @desc 收藏列表批量操作或是单个取消
  22. * @author qc
  23. * @method POST
  24. * @url /api/Collect/cancelCollect
  25. * @header name:Authorization require:1 desc:Token
  26. * @param name:ids type:string : default:'' desc:需要删除的id记录(多个用逗号隔开)
  27. */
  28. public function cancelCollect()
  29. {
  30. $ids = input('post.ids','');
  31. if(!$ids) $this->error('请选择要取消收藏的记录');
  32. UserCollect::where('id','in',$ids)->where('user_id','=',$this->user_id)->delete();
  33. $this->success('取消成功');
  34. }
  35. /**
  36. * @title 用户视频收藏【弃用!!!视频收藏放到视频模块/api/Video/videoCollect】
  37. * @desc 用户视频收藏
  38. * @author qc
  39. * @method POST
  40. * @url /api/Collect/userCollect
  41. * @header name:Authorization require:1 desc:Token
  42. * @param name:coll_type type:int require:1 default:-- desc:类型(1平台视频2用户视频)
  43. * @param name:coll_id type:int require:1 default:-- desc:收藏id(平台视频点赞用video_arr的iD)
  44. * @param name:status type:int default:0 desc:收藏状态(0取消收藏【未收藏】,1收藏)
  45. */
  46. public function userCollect()
  47. {
  48. $coll_type = input('post.coll_type',1);
  49. $url_id = input('post.coll_id',0);
  50. $video_id = VideoUrl::where('id',$url_id)->value('video_id');
  51. $collect_check = UserCollect::where(['user_id'=>$this->user_id,'coll_type'=>$coll_type,'coll_id'=>$video_id,'children_id'=>$url_id])->find();
  52. if($collect_check) {
  53. UserCollect::where(['user_id'=>$this->user_id,'coll_type'=>$coll_type,'coll_id'=>$video_id,'children_id'=>$url_id])->delete();
  54. $this->success('取消收藏成功',['status'=>0]);
  55. }else{
  56. Data::save('UserCollect', [
  57. 'user_id'=>$this->user_id,
  58. 'coll_type'=>$coll_type,
  59. 'coll_id'=>$video_id,
  60. 'children_id'=>$url_id,
  61. 'create_int'=>time()],'user_id',['user_id'=>$this->user_id,'coll_type'=>$coll_type, 'coll_id'=>$video_id,'children_id'=>$url_id]);
  62. $this->success('收藏成功',['status'=>1]);
  63. }
  64. }
  65. /**
  66. * @title 获取用户收藏列表【弃用!!!都放到对应模块】
  67. * @desc 获取用户收藏列表
  68. * @author qc
  69. * @method GET
  70. * @url /api/Collect/getUserCollectList
  71. * @header name:Authorization require:1 desc:Token
  72. * @param name:page type:int default:1 desc:页数
  73. * @param name:page_num type:int : default:20 desc:每页数
  74. * @param name:coll_type type:int require:1 default:-- desc:类型(1平台视频,2资料,3图文)
  75. * @return name:id type:int default:-- desc:记录id
  76. * @return name:create_at type:string default:-- desc:收藏时间
  77. * @return name:coll_type type:int default:-- desc:收藏类型(1平台视频)
  78. * @return name:video_item type:array default:-- desc:收藏详情(coll_type=1平台视频)
  79. * @return name:video_item.video_id type:int default:-- desc:视频记录id
  80. * @return name:video_item.id type:int default:-- desc:视频详情【url_arr】id
  81. * @return name:video_item.cover type:string default:-- desc:视频详情封面
  82. * @return name:video_item.url type:string default:-- desc:视频详情链接
  83. * @return name:video_item.title type:string default:-- desc:视频详标题
  84. * @return name:datum_item type:array default:-- desc:收藏详情(coll_type=2资料)
  85. * @return name:datum_item.datum_id type:int default:-- desc:资料记录id
  86. * @return name:datum_item.id type:int default:-- desc:资料详情id
  87. * @return name:datum_item.url type:string default:-- desc:资料地址
  88. * @return name:datum_item.title type:string default:-- desc:资料标题
  89. * @return name:article_item type:array default:-- desc:收藏详情(coll_type=3图文)
  90. * @return name:article_item.article_id type:int default:-- desc:图文记录id
  91. * @return name:article_item.id type:int default:-- desc:图文详情id
  92. * @return name:article_item.cover type:string default:-- desc:封面
  93. * @return name:article_item.images type:string default:-- desc:图片(多张用|隔开)
  94. * @return name:article_item.content type:string default:-- desc:图文内容
  95. */
  96. public function getUserCollectList()
  97. {
  98. $coll_type = input('get.coll_type',1);
  99. $sel_where = [];
  100. $sel_where[] = ['coll_type','=',$coll_type];
  101. $sel_where[] = ['user_id','=',$this->user_id];
  102. if(!in_array($coll_type,[1,2,3])) $this->error('收藏类型有误');
  103. $with = ['','videoItem','datumItem','articleItem'];
  104. $list = UserCollect::with($with[$coll_type])
  105. ->field('id,create_at,coll_type')
  106. ->where($sel_where)
  107. ->limit($this->off_set,$this->page_num)
  108. ->select()->toArray();
  109. $this->success('ok',['list'=>$list]);
  110. }
  111. }