UserHisController.class.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. namespace bibidd\Controller;
  3. use Bibidd\Controller\CommonBaseController;
  4. class UserHisController extends CommonBaseController
  5. {
  6. /**
  7. * 添加历史
  8. * @return void
  9. */
  10. public function add_to_shoucang()
  11. {
  12. header('Content-Type:text/json;charset=utf-8');
  13. header('Access-Control-Allow-Origin:*');
  14. header("Access-Control-Allow-Headers:token,Origin, X-Requested-With, Content-Type, Accept");
  15. header('Access-Control-Allow-Methods:POST');
  16. header('Access-Control-Expose-Headers:*');
  17. if (!empty($_POST)) {
  18. $uid = $_POST['uid'];
  19. $type = $_POST['type'];
  20. $cid = $_POST['cid'];
  21. $article = $_POST['article']; //空则表示收藏1级漫画,非空则收集二级
  22. switch ($type) {
  23. case 'video':
  24. $video_info_list = M('video_list_test')->where("id=$cid")->field("time_chuo,site,uploader")->select();
  25. $video_time_chuo = $video_info_list[0]['time_chuo'];
  26. $video_type = $video_info_list[0]['uploader'];
  27. $video_list['uid'] = $uid;
  28. $video_list['vid'] = $cid;
  29. $video_list['time'] = time();
  30. $video_list['video_type'] = $video_type;
  31. $video_list['time_chuo'] = $video_time_chuo;
  32. $check_info = M("video_lishi")->where("uid='$uid' AND vid='$cid' AND video_type='$video_type'")->find();
  33. if(empty($check_info)) {
  34. $yn_add = M("video_lishi")->add($video_list);
  35. }
  36. break;
  37. case 'xiaoshuo':
  38. $video_list['uid'] = $uid;
  39. $video_list['vid'] = $cid;
  40. $video_list['time'] = time();
  41. $video_list['video_type'] = '色情小说';
  42. $check_info = M("video_lishi")->where("uid='$uid' AND vid='$cid' AND video_type='色情小说'")->find();
  43. if(empty($check_info))
  44. {
  45. $yn_add = M("video_lishi")->add($video_list);
  46. }
  47. break;
  48. case '有声小说':
  49. $video_info_list = M('video_list_test')->where("id=$cid")->field("time_chuo,site,uploader")->select();
  50. $video_list['time_chuo'] = $video_info_list[0]['time_chuo'];
  51. $video_list['uid'] = $uid;
  52. $video_list['vid'] = $cid;
  53. $video_list['time'] = time();
  54. $video_list['video_type'] = $type;
  55. $check_info = M("video_lishi")->where("uid='$uid' AND vid='$cid' AND video_type='$type'")->find();
  56. if(empty($check_info))
  57. {
  58. $yn_add = M("video_lishi")->add($video_list);
  59. }
  60. break;
  61. case 'manhua':
  62. $video_list['uid'] = $uid;
  63. $video_list['vid'] = $cid;
  64. $video_list['time'] = time();
  65. $video_list['video_type'] = null;
  66. $video_list['time_chuo'] = null;
  67. $video_list['attr1'] = $article;
  68. $yn_add = true;
  69. //判断是一级收藏还是二级收藏
  70. if (empty($article)) {
  71. //收藏一级
  72. $video_info_list = M('video_list_test')->where("id=$cid")->field("time_chuo,site,uploader,china_type")->select();
  73. $video_time_chuo = $video_info_list[0]['time_chuo'];
  74. $video_type = $video_info_list[0]['china_type'];
  75. $video_list['video_type'] = $video_type;
  76. $video_list['time_chuo'] = $video_time_chuo;
  77. //防止重复收藏
  78. $check_info = M("video_lishi")->where("uid=$uid and vid=$cid")->find();
  79. if (empty($check_info)) {
  80. M("video_lishi")->add($video_list);
  81. }
  82. break;
  83. }
  84. //二级收藏
  85. $detail_info = M("heiliao_haijiao_books")->where("id=$cid")->field("id,book_type,site_name")->find();
  86. if (!empty($detail_info))
  87. $video_list['video_type'] = $detail_info['book_type'];
  88. //防止重复收藏
  89. $check_info = M("video_lishi")->where("uid=$uid and vid=$cid and attr1='$article'")->find();
  90. if (empty($check_info)) {
  91. M("video_lishi")->add($video_list);
  92. }
  93. break;
  94. default:
  95. echo "type error";
  96. }
  97. if ($yn_add) {
  98. $data['message'] = 'ok';
  99. $data['code'] = '200';
  100. echo json_encode($data);
  101. } else {
  102. $data['message'] = 'error';
  103. echo json_encode($data);
  104. }
  105. } else {
  106. echo $this->returnData();
  107. }
  108. }
  109. /**
  110. * 收藏列表
  111. * @return void
  112. */
  113. public function shoucang_list()
  114. {
  115. header('Content-Type:text/json;charset=utf-8');
  116. header('Access-Control-Allow-Origin:*');
  117. header("Access-Control-Allow-Headers:token,Origin, X-Requested-With, Content-Type, Accept");
  118. header('Access-Control-Allow-Methods:POST');
  119. header('Access-Control-Expose-Headers:*');
  120. if (!empty($_POST)) {
  121. $uid = $_POST['uid'];
  122. $page = $_POST['page'];
  123. $one_size = empty($_POST['pageSize'])?30:$_POST['pageSize']; //每頁30行記錄
  124. $page_one = ($page - 1) * $one_size;
  125. $duifang_id_list_num = M("video_lishi")->where("uid=$uid")->count();
  126. //插入sql语句 的限制条件
  127. $new_array = array();
  128. //视频
  129. $duifang_id_list = M("video_lishi")->where("uid=$uid")->order("id desc")->LIMIT($page_one, $one_size)->select();
  130. //插入sql语句 的限制条件
  131. foreach ($duifang_id_list as $key => $value) {
  132. # code...
  133. $duifang_id = $value['vid'];
  134. $m_type = $value['video_type'];
  135. $duifang_id_list[$key]['uploader'] = $m_type;
  136. if ($m_type == '色情小说') {
  137. $duifang_id_list = M("novel_list")->where("id=$duifang_id")->select()[0];
  138. $duifang_id_list['did'] = $value['id'];
  139. array_push($new_array, $duifang_id_list);
  140. } else {
  141. $duifang_id_list = M('video_list_test')->where("id=$duifang_id")->select()[0];
  142. $duifang_id_list['did'] = $value['id'];
  143. array_push($new_array, $duifang_id_list);
  144. }
  145. }
  146. $data['code'] = '200';
  147. $data['message'] = 'ok';
  148. $data['data'] = $new_array;
  149. $data['all_num'] = $duifang_id_list_num;
  150. echo json_encode($data);
  151. } else {
  152. echo $this->returnData();
  153. }
  154. }
  155. public function del_by_id()
  156. {
  157. $this->addHeaders(); //添加头部请求
  158. $id = $_POST['id'];
  159. if(empty($id))
  160. {
  161. $this->returnDataAndSendMsg("标识不能为空");
  162. die();
  163. }
  164. $rs = M("video_lishi")->where("id='$id'")->delete();
  165. $data['code'] = '200';
  166. $data['message'] = 'ok';
  167. $data['data'] = $rs;
  168. echo json_encode($data);
  169. }
  170. }