Eyemargin.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <?php
  2. namespace app\api\controller;
  3. use Limen\Redisun\Examples\HashModel;
  4. use Limen\Redisun\Examples\StringModel;
  5. use think\Db;
  6. use think\Cache;
  7. /**
  8. * 眼缘接口
  9. */
  10. class Eyemargin extends Common
  11. {
  12. protected $noNeedLogin = [];
  13. protected $noNeedRight = '*';
  14. public function _initialize()
  15. {
  16. parent::_initialize();
  17. }
  18. /**
  19. * 发布眼缘
  20. */
  21. public function addFate() {
  22. $eye_type = $this->request->request('eye_type'); // 动态类型
  23. $content = $this->request->request('content'); // 内容
  24. if (!in_array($eye_type,[1,2]) || !$content) {
  25. $this->error(__('Invalid parameters'));
  26. }
  27. $str_arr = sensitive($content);
  28. if($str_arr['count'] > 0) {
  29. $this->error(__('发布内容存在敏感词汇:'.$str_arr['sensitiveWord'].' 请重新编辑后发布!'));
  30. }
  31. // 判断当前用户是否实名认证
  32. $userAuthInfo = \app\common\model\UserAuth::userIsAuth($this->auth->id);
  33. if($userAuthInfo['status'] == 0) $this->error($userAuthInfo['msg']);
  34. $data = [];
  35. $data["user_id"] = $this->auth->id;
  36. $data["eye_type"] = $eye_type;
  37. $data["content"] = $content;
  38. if($eye_type == 2) {
  39. $cover = $this->request->request('cover'); // 影集封面图
  40. $album = $this->request->request('album'); // 影集图片
  41. $music = $this->request->request('music'); // 背景音乐
  42. if(!$cover || !$album || !$music) {
  43. $this->error(__('Invalid parameters'));
  44. }
  45. $data['cover'] = $cover;
  46. $data['album'] = $album;
  47. $data['music'] = $music;
  48. } elseif($eye_type == 1) {
  49. $video = $this->request->request('video'); // 视频文件
  50. if(!$video) {
  51. $this->error(__('视频图片缺失!'));
  52. }
  53. $cover = $this->request->request('cover'); // 影集封面图
  54. $data['cover'] = $cover;
  55. // $video_cover = str_replace("https://","http://",$video);
  56. // $cover = 'uploads/video_cover/'.date('Ymd').date('His').rand(1000,9999).'.png';
  57. // getVideoCover($video_cover,2,$cover);
  58. // $full_cover = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"].'/'.$cover;
  59. // $data['cover'] = $full_cover;
  60. $data['video'] = $video;
  61. }
  62. $eyemarginModel = new \app\common\model\Eyemargin();
  63. $data["createtime"] = time();
  64. // 判断是否是第一个视频
  65. $info = $eyemarginModel->where(['user_id'=>$this->auth->id,'status'=>['in',[0,1]]])->find();
  66. if(!$info) {
  67. $data['is_main'] = 1;
  68. $msg = "恭喜,视频已发布审核中!温馨提示:长按可以取消或者修改'推荐'短视频,推荐的视频会展示给同城好友哦";
  69. } else {
  70. $msg = "发布成功!请耐心等待审核!";
  71. }
  72. $res = $eyemarginModel->insertGetId($data);
  73. if($res) {
  74. $this->success($msg);
  75. } else {
  76. $this->error("网络错误,请稍后重试");
  77. }
  78. }
  79. /**
  80. * 当数据为空时
  81. * @param $is_goddess
  82. * @param $is_new
  83. * @param $redis_ids
  84. * @param $field
  85. * @param $user_id
  86. * @return false|mixed|\PDOStatement|string|\think\Collection
  87. */
  88. private function getFateInfo($redis_ids,$field,$user_id,&$common_where) {
  89. $redis_ids && $common_where['a.id'] = ['notin',implode(',',$redis_ids)];
  90. // 按照距离排序
  91. $where = [];
  92. $where = array_merge($where,$common_where);
  93. $a = \app\common\model\Eyemargin::getDistanceList($this->auth->lng,$this->auth->lat,$field,$where,$user_id);
  94. return $a;
  95. }
  96. /**
  97. * 获取眼缘视频/影集
  98. */
  99. public function getFate() {
  100. $is_goddess = $this->request->request('is_goddess'); // 是否女神:1=是,0=否
  101. $is_new = $this->request->request('is_new'); // 是否新人:1=是,0=否
  102. $is_neal = $this->request->request('is_neal'); // 是否附近:1=是,0=否
  103. if (!in_array($is_goddess,[0,1]) && !in_array($is_new,[0,1]) && !in_array($is_neal,[0,1])) {
  104. $this->error(__('请选择展示tab!'));
  105. }
  106. $pageNum = $this->request->request('pageNum',10); // 每页显示条数
  107. $user_id = $this->auth->id;
  108. $user_id_redis = 'u_'.$user_id;
  109. $redis_ids = json_decode(Cache::get($user_id_redis),true);
  110. $time = time() - 30*86400;
  111. $common_where = [];
  112. $common_where['a.is_main'] = 1;
  113. $common_where['a.status'] = 1;
  114. $common_where['u.city'] = $this->auth->city;
  115. $is_goddess && $common_where['u.is_goddess'] = 1;
  116. $is_new && $common_where['u.createtime'] = ['gt',$time];
  117. $common_where['a.status'] = 1;
  118. $field = "a.*,u.avatar,u.city_name,u.district_name,u.nickname,u.is_goddess,u.is_auth,vipStatus(u.vip_duetime) as is_vip,
  119. u.age,u.constellation,u.hobby_ids,u.profession,u.declaration,u.lng,u.lat";
  120. $list = [];
  121. $a = $this->getFateInfo($redis_ids,$field,$user_id,$common_where);
  122. if(!$a) {
  123. Cache::rm($user_id_redis);
  124. unset($common_where['a.id']);
  125. $redis_ids = [];
  126. $a = $this->getFateInfo($redis_ids,$field,$user_id,$common_where);
  127. }
  128. // 女神
  129. $where = [];
  130. $where['u.is_goddess'] = 1;
  131. $where = array_merge($where,$common_where);
  132. $b = \app\common\model\Eyemargin::getDistanceList($this->auth->lng,$this->auth->lat,$field,$where,$user_id);
  133. // 喜好 期望对象
  134. $expect = $this->auth->expect_ids;
  135. $user_ids =\app\common\model\Expect::getTagsByExpect($expect);
  136. if($user_ids) {
  137. $where = [];
  138. $where['u.id'] = ['in',implode(',',$user_ids)];
  139. $where = array_merge($where,$common_where);
  140. $c = \app\common\model\Eyemargin::getDistanceList($this->auth->lng,$this->auth->lat,$field,$where,$user_id);
  141. } else {
  142. $c = [];
  143. }
  144. // 新人
  145. $where = [];
  146. $where['u.createtime'] = ['gt',$time];
  147. $where = array_merge($where,$common_where);
  148. $d = \app\common\model\Eyemargin::getDistanceList($this->auth->lng,$this->auth->lat,$field,$where,$user_id);
  149. // 剩余
  150. // 三数组合并
  151. $bcd = \app\common\model\Eyemargin::arrayMerge($b,$c,$d);
  152. $e = array_diff($a,$bcd);
  153. // 附近
  154. $num_a = floor(config("site.nearbyTheOne") * 0.01 * $pageNum);
  155. $num_bcd = floor(config("site.nearbyTheTwo") * 0.01 * $pageNum);
  156. $num_e = $pageNum - $num_a - $num_bcd;
  157. // 先做好去重
  158. $a = array_slice($a,0,$pageNum);
  159. $bcd = array_diff($bcd,$a);
  160. $e = array_diff($e,array_merge($bcd,$a));
  161. $count_a = count($a);
  162. $count_e = count($e);
  163. $count_bcd = count($bcd);
  164. if($count_a <= ($num_a+$num_bcd+$num_e)) {
  165. $list = $a;
  166. }
  167. if($count_a >= $num_a && $count_bcd >= $num_bcd && $count_e >= $num_e) {
  168. $list_a = array_slice($a,0,$num_a);
  169. $list_bcd = array_slice($bcd,0,$num_bcd);
  170. $list_e = array_slice($e,0,$num_e);
  171. $list = \app\common\model\Eyemargin::arrayMerge($list_a,$list_bcd,$list_e);
  172. }
  173. // 10 = 10 =
  174. if($count_a >= $num_a && $count_bcd >= $num_bcd && $count_e < $num_e) {
  175. $list_a = array_slice($a,0,$pageNum-$num_bcd - $count_e);
  176. $list_bcd = array_slice($bcd,0,$num_bcd);
  177. $list_e = $e;
  178. $list = \app\common\model\Eyemargin::arrayMerge($list_a,$list_bcd,$list_e);
  179. }
  180. if($count_a >= $num_a && $count_bcd < $num_bcd && $count_e < $num_e) {
  181. $list_a = array_slice($a,0,$pageNum-$count_bcd-$count_e);
  182. $list_bcd = $bcd;
  183. $list_e = $e;
  184. $list = \app\common\model\Eyemargin::arrayMerge($list_a,$list_bcd,$list_e);
  185. }
  186. if($count_a >= $num_a && $count_bcd < $num_bcd && $count_e >= $num_e) {
  187. $list_a = array_slice($a,0,$pageNum-$count_bcd-$num_e);
  188. $list_bcd = $bcd;
  189. $list_e = array_slice($e,0,$num_e);
  190. $list = \app\common\model\Eyemargin::arrayMerge($list_a,$list_bcd,$list_e);
  191. }
  192. if($list) {
  193. // 收集眼缘ID
  194. $ids = array_column($list, 'id');
  195. if($redis_ids) {
  196. $redis_ids = array_merge($redis_ids,$ids);
  197. } else {
  198. $redis_ids = $ids;
  199. }
  200. Cache::set($user_id_redis,json_encode($redis_ids));
  201. } else {
  202. Cache::rm($user_id_redis);
  203. }
  204. $this->success("获取成功!",$list);
  205. }
  206. /**
  207. * 判断当前用户是否已经把我加到黑名单
  208. */
  209. public function isBlackUser() {
  210. $user_id = $this->request->request('user_id'); // 用户ID
  211. if(!$user_id) $this->error("参数缺失!");
  212. $where = [];
  213. $where['user_id'] = $user_id;
  214. $where['black_user_id'] = $this->auth->id;
  215. $blackInfo = \app\common\model\UserBlacklist::where($where)->find();
  216. if($blackInfo) {
  217. $this->success("获取成功!",['is_black'=>1]);
  218. } else {
  219. $this->success("获取成功!",['is_black'=>0]);
  220. }
  221. }
  222. }