Index.php 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use fast\Random;
  5. use think\Db;
  6. use \think\Log;
  7. use Redis;
  8. use app\common\library\Sms as Smslib;
  9. use app\common\library\Token;
  10. /**
  11. * 首页接口
  12. */
  13. class Index extends Api
  14. {
  15. protected $noNeedLogin = ['zhiyint_registration','index','contactus','tcpTest','getAppShare','getWebsiteInfo','getUserCharmRankList','getPartyHotList','searchUsers','getInviteCode','getEdition','getInviteImg','getWebsiteInfoForMini','getBankList','getSwitch','getBootAnimation', 'tencentcall', 'getversion', 'getversionZx', 'getiosversion'];
  16. protected $noNeedRight = ['*'];
  17. public function index(){
  18. echo 'apisuccess';
  19. exit;
  20. }
  21. /**
  22. * 首页
  23. *
  24. */
  25. public function outMemberFromRoom()
  26. {
  27. // 强制关闭需要退出正在房间的用户
  28. $tenim = new \app\api\controller\Tenim();
  29. $tenim->outMemberFromRoom(4);
  30. $this->success('请求成功');
  31. }
  32. protected function getRealIpAddr() {
  33. if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
  34. {
  35. $ip=$_SERVER['HTTP_CLIENT_IP'];
  36. }
  37. elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
  38. {
  39. $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
  40. }
  41. else
  42. {
  43. $ip=$_SERVER['REMOTE_ADDR'];
  44. }
  45. return $ip;
  46. }
  47. /**
  48. * 三方接口
  49. *
  50. */
  51. public function zhiyint_registration()
  52. {
  53. $iparr = ["182.37.138.94","18.162.169.63","18.166.207.228","18.167.62.130","18.163.198.60","18.163.33.249","16.163.157.213", "43.198.99.226", "43.198.98.100", "18.163.210.144", "18.167.165.212", "18.166.28.150", "16.163.99.187", "18.163.210.126", "43.198.84.109", "18.163.182.173", "16.162.109.227", "16.162.87.8", "18.162.111.92", "18.166.214.252"];
  54. $ip = $this->getRealIpAddr();
  55. if(!in_array($ip,$iparr)) {
  56. echo json_encode(['error' => "IP not found"]); exit;
  57. }
  58. $UserId = $this->request->request("UserId",'');
  59. $data = json_decode(file_get_contents('php://input'), true);
  60. $UserId = $data['UserId'];
  61. if($UserId)
  62. {
  63. $times = Db::name("user")->where("username",$UserId)->value("createtime");
  64. if(!$times)
  65. {
  66. echo json_encode(['error' => "User ID not found"]); exit;
  67. }
  68. $data = [
  69. 'RegistrationTime' => date("Y-m-d H:i:s",$times)
  70. ];
  71. echo json_encode($data); exit;
  72. }
  73. $data = [
  74. 'error' => "User ID not found"
  75. ];
  76. echo json_encode($data);
  77. }
  78. // /**
  79. // * 生成不重复的随机数字字母组合
  80. // */
  81. // function getUinqueNo($length = 8) {
  82. // $newid = Random::build("alnum",$length);
  83. //// if(in_array($newid,$nos)) {
  84. //// $this->getUinqueNo(8);
  85. //// }
  86. // return $newid;
  87. // }
  88. /**
  89. * 获取用户协议等
  90. */
  91. public function getWebsiteInfo() {
  92. $params = $this->request->request("params"); //内容
  93. if($params == "boxGiftLogo") {
  94. echo $this->success("获取成功!",$this->httpurl(config("site.".$params)));
  95. exit;
  96. }
  97. echo "<html><body>";
  98. echo config("site.".$params);
  99. echo "</body></html>";exit;
  100. }
  101. /**
  102. * 获取用户协议等 小程序
  103. */
  104. public function getWebsiteInfoForMini() {
  105. $params = $this->request->request("params"); //内容
  106. $res = config("site.".$params);
  107. if($params == "boxGiftLogo") $res = $this->httpurl(config("site.".$params));
  108. $this->success("获取成功!",$res);
  109. }
  110. /**
  111. * 联系我们
  112. */
  113. public function contactus() {
  114. $list = \app\common\model\Config::where(["group"=>"basic","name"=>["in",["email","mobile"]]])->select();
  115. $data = [];
  116. foreach($list as $k => $v) {
  117. $v["name"] == "email" && $data["email"] = $v["value"];
  118. $v["name"] == "mobile" && $data["mobile"] = $v["value"];
  119. }
  120. $this->success("获取成功!",$data);
  121. }
  122. /*
  123. * 获取系统消息列表
  124. */
  125. public function getMessage() {
  126. $page = $this->request->request('page',1); // 分页
  127. $pageNum = $this->request->request('pageNum',10); // 分页
  128. // 分页搜索构建
  129. $pageStart = ($page-1)*$pageNum;
  130. $flag = $this->request->request("flag",1,"intval"); //标识:1=只取一条,0=全部
  131. $user_id = $this->auth->id;
  132. $obj = \app\common\model\Message::where(["user_id"=>$user_id])->order("createtime","desc")->limit($pageStart,$pageNum);
  133. if($flag == 1) {
  134. $list = $obj->find();
  135. $list || $list = [];
  136. $list && $list["createtime"] = $this->get_last_time($list["createtime"]);
  137. } else {
  138. $list = $obj->select();
  139. if($list) foreach($list as $k => &$v) {
  140. $v["createtime"] = $this->get_last_time($v["createtime"]);
  141. }
  142. }
  143. $this->success("获取成功!",$list);
  144. }
  145. /**
  146. * 删除系统消息
  147. */
  148. public function delMessage() {
  149. $id = $this->request->request("id",0,"intval"); //消息ID
  150. if($id <= 0) {
  151. $this->error("参数传入错误!");
  152. }
  153. $res = \app\common\model\Message::where(["id"=>$id,"user_id"=>$this->auth->id])->delete();
  154. if($res) {
  155. $this->success("删除成功!");
  156. } else {
  157. $this->error("删除失败!");
  158. }
  159. }
  160. /**
  161. * 获取主播魅力值排行
  162. */
  163. public function getUserCharmRankList() {
  164. $time = $this->request->request("time",0,"intval"); //时间筛选 1=小时榜,2=今日榜,3=本周榜,4=月榜
  165. if(!in_array($time,[1,2,3,4])) {
  166. $this->error("参数传入错误!");
  167. }
  168. $hour = strtotime(date("Y-m-d H:00:00"));
  169. $today = strtotime(date("Y-m-d 00:00:00"));
  170. $weekend = strtotime('monday this week');
  171. // $weekend = mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y"));
  172. $month = strtotime(date("Y-m-01 00:00:00"));
  173. // 剩余时间
  174. $thistime = time();
  175. switch ($time) {
  176. case 1:
  177. $redtime = 3600-($thistime - $hour);
  178. break;
  179. case 2:
  180. $redtime = 3600*24-($thistime - $today);
  181. break;
  182. case 3:
  183. $redtime = 3600*24*7-($thistime - $weekend);
  184. break;
  185. case 4:
  186. $monthend = mktime(23,59,59,date("m"),date("t"),date("Y"));
  187. $redtime = ($monthend - $month)-($thistime - $month);
  188. break;
  189. }
  190. $timeArr = [1=>$hour,2=>$today,3=>$weekend,4=>$month];
  191. $where = [];
  192. $where["a.createtime"] = ["gt",$timeArr[$time]];
  193. $list = \app\common\model\UserCharmRank::alias("a")
  194. ->field("p.id,sum(a.charm) as charm,u.avatar,u.nickname,u.gender,u.level")
  195. ->where($where)
  196. ->join("hx_user u","u.id = a.user_id")
  197. ->join("hx_party p","p.user_id = a.user_id")
  198. ->group("a.user_id")
  199. ->order("charm","desc")
  200. ->limit(100)
  201. ->select();
  202. $data = [];
  203. $data["redtime"] = $redtime;
  204. $data["data"] = $list;
  205. $this->success("获取成功!",$data);
  206. }
  207. /**
  208. * 获取派对热度排序
  209. */
  210. public function getPartyHotList() {
  211. // 剩余时间
  212. $thistime = time();
  213. $hour = strtotime(date("Y-m-d H:00:00"));
  214. $redtime = 3600-($thistime - $hour);
  215. $where = [];
  216. $where["a.createtime"] = ["gt",$hour];
  217. $where["p.room_type"] = 1;
  218. $list = \app\common\model\PartyHot::alias("a")
  219. ->field("sum(a.hot) as hot,p.id,u.avatar,p.party_name,p.party_logo")
  220. ->where($where)
  221. ->join("hx_party p","p.id = a.party_id")
  222. ->join("hx_user u","u.id = p.user_id")
  223. ->group("a.party_id")
  224. ->order("hot","desc")
  225. ->limit(100)
  226. ->select();
  227. $data = [];
  228. $data["redtime"] = $redtime;
  229. $data["data"] = $list;
  230. $this->success("获取成功!",$data);
  231. }
  232. /**
  233. * 首页搜索
  234. */
  235. public function searchUsers() {
  236. $search = $this->request->request("search"); //关键词筛选
  237. if(!$search) {
  238. $this->error("请输入搜索内容!");
  239. }
  240. // 搜索派对
  241. global $whereOr;
  242. $where = [];
  243. $whereOr["party_id"] = $search;
  244. $whereOr["party_name"] = ["like","%$search%"];
  245. $where["room_type"] = 1;
  246. $partyList = \app\common\model\Party::field("id,party_logo,party_id,party_name")
  247. ->where($where)
  248. ->where(function ($query) {
  249. global $whereOr;
  250. $query->whereOr($whereOr);
  251. })->order("party_hot","desc")->select();
  252. // 搜索直播间
  253. global $whereOrlive;
  254. $where = [];
  255. $whereOrlive["party_id"] = $search;
  256. $whereOrlive["party_name"] = ["like","%$search%"];
  257. $where["room_type"] = 2;
  258. $liveList = \app\common\model\Party::field("id,party_logo,party_id,party_name")
  259. ->where($where)
  260. ->where(function ($query) {
  261. global $whereOrlive;
  262. $query->whereOr($whereOrlive);
  263. })
  264. ->order("party_hot","desc")->select();
  265. // 相关用户
  266. $where = [];
  267. $where["a.nickname"] = ["like","%$search%"];
  268. $where["a.u_id"] = $search;
  269. $userList = \app\common\model\User::alias("a")->field("id,avatar,nickname,u_id,f.fans")
  270. ->join("hx_view_fans f","f.user_id = a.id","left")
  271. ->order("a.is_online,a.noble,a.level")
  272. ->whereOr($where)->select();
  273. $res = [];
  274. $res["partylist"] = $partyList;
  275. $res["livelist"] = $liveList;
  276. $res["userlist"] = $userList;
  277. $this->success("获取成功!",$res);
  278. }
  279. /**
  280. * 获取下载二维码和邀请码
  281. */
  282. public function getInviteCode() {
  283. // 获取二维码
  284. $qrcode = $this->httpurl(config("site.qrcode"));
  285. $miniqrcode = $this->httpurl(config("site.miniqrcode"));
  286. // 获取用户邀请码
  287. $inviteCode = \app\common\model\User::where(["id"=>$this->auth->id])->value("invite_no");
  288. $host = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"];
  289. $downlowdLink = $host."/index/index/appJump?t=wlt".rand(10,999).Random::alpha(8);
  290. $this->success("获取成功!",["qrcode"=>$qrcode,"miniqrcode"=>$miniqrcode,"inviteCode"=>$inviteCode,"downlowdLink"=>$downlowdLink]);
  291. }
  292. /**
  293. * 获取app分享海报
  294. */
  295. public function getAppShare() {
  296. $this->success("获取成功!",["url"=>$this->httpurl(config("site.appShare"))]);
  297. }
  298. /**
  299. * 获取开机动画(暂时关闭)
  300. */
  301. private function getBootAnimation() {
  302. $this->success("获取成功!",["url"=>$this->httpurl(config("site.bootAnimationUrl")),"time"=>floatval(config("site.bootAnimationTime"))]);
  303. }
  304. /**
  305. * 获取版本更新信息
  306. */
  307. public function getEdition() {
  308. // 获取二维码
  309. $is_force = config("site.is_force");
  310. $apkUrl = config("site.apk_url");
  311. $apkName = config("site.apkName");
  312. $desc = config("site.desc");
  313. $versionCode = config("site.versionCode");
  314. $this->success("获取成功!",["versionCode"=>$versionCode,"isForceUpdate"=>$is_force,"apkUrl"=>$apkUrl,"apkName"=>$apkName,"desc"=>$desc]);
  315. }
  316. /**
  317. * 获取邀请图片
  318. */
  319. public function getInviteImg() {
  320. $plat = $this->request->request("plat",1); //平台:1=小程序,2=app
  321. if(!in_array($plat,[1,2])) $this->error("参数错误");
  322. // 获取用户的邀请码
  323. $invitecode = \app\common\model\User::where(["id"=>$this->auth->id])->value("invite_no");
  324. // 文字图片合成
  325. $bigImgPath = $this->httpurlLocal('/assets/img/inviteimg.jpeg');
  326. $img = imagecreatefromstring(file_get_contents($bigImgPath));
  327. //字体文件
  328. $font = realpath('./assets/fonts/lato/lato-black.ttf');
  329. //字体颜色(RGB)
  330. $black = imagecolorallocate($img, 217, 76, 41);
  331. //字体大小
  332. $fontSize = 30;
  333. //旋转角度
  334. $circleSize = 0;
  335. //左边距
  336. $left = 275;
  337. //上边距
  338. $top = 540;
  339. imagefttext($img, $fontSize, $circleSize, $left, $top, $black, $font, $invitecode);
  340. $filename = date("YmdH").".jpeg";
  341. $path = "/uploads/qrcode/".$filename;
  342. $file = $_SERVER['DOCUMENT_ROOT'] . $path;//打开文件准备写入
  343. list($bgWidth, $bgHight, $bgType) = getimagesize($bigImgPath);
  344. switch ($bgType) {
  345. case 1://gif
  346. header('Content-Type:image/gif');
  347. imagegif($img,$file);
  348. break;
  349. case 2://jpg
  350. header('Content-Type:image/jpg');
  351. imagejpeg($img,$file);
  352. break;
  353. case 3://jpg
  354. header('Content-Type:image/png');
  355. imagepng($img,$file);
  356. break;
  357. default:
  358. break;
  359. }
  360. //销毁照片
  361. imagedestroy($img);
  362. // 图片和二维码合成
  363. $qrcode = $plat == 1 ? config("site.miniqrcode"):config("site.qrcode");
  364. $background = $file;
  365. $target = $this->httpurl($qrcode);
  366. $background_iamge = imagecreatefromstring(file_get_contents($background));
  367. $target_image = imagecreatefromstring(file_get_contents($target));
  368. list($target_width, $target_height, $target_type) = getimagesize($target);
  369. imagecopymerge($background_iamge , $target_image , 250, 700, 0, 0, $target_width, $target_height, 100);
  370. list($background_width, $background_height, $background_type) = getimagesize($background);
  371. switch ($background_type) {
  372. case 1://gif
  373. header('Content-Type:image/gif');
  374. imagegif($background_iamge,$file);
  375. break;
  376. case 2://jpg
  377. header('Content-Type:image/jpg');
  378. imagejpeg($background_iamge,$file);
  379. break;
  380. case 3://jpg
  381. header('Content-Type:image/png');
  382. imagepng($background_iamge,$file);
  383. break;
  384. default:
  385. break;
  386. }
  387. $savepath = $this->httpurlLocal($path);
  388. $this->success("获取成功!",$savepath);
  389. }
  390. /**
  391. * 获取银行列表
  392. */
  393. public function getBankList() {
  394. $this->success("获取成功!",["banklist"=>\app\common\model\Bank::select()]);
  395. }
  396. /**
  397. * 获取开关配置
  398. */
  399. public function getSwitch() {
  400. $this->success("获取成功!",["switch"=>config("site.switch")]);
  401. }
  402. /**
  403. * 评论时间转换
  404. * @param null $time
  405. * @return false|string
  406. */
  407. private function get_last_time($time = NULL) {
  408. $text = '';
  409. $time = $time === NULL || $time > time() ? time() : intval($time);
  410. $t = time() - $time; //时间差 (秒)
  411. $y = date('Y', $time)-date('Y', time());//是否跨年
  412. switch($t){
  413. case $t == 0:
  414. $text = '刚刚';
  415. break;
  416. case $t < 60:
  417. $text = $t . '秒前'; // 一分钟内
  418. break;
  419. case $t < 60 * 60:
  420. $text = floor($t / 60) . '分钟前'; //一小时内
  421. break;
  422. case $t < 60 * 60 * 24:
  423. $text = floor($t / (60 * 60)) . '小时前'; // 一天内
  424. break;
  425. case $t < 60 * 60 * 24 * 3:
  426. $text = floor($time/(60*60*24)) ==1 ?'昨天 ' . date('H:i', $time) : '前天 ' . date('H:i', $time) ; //昨天和前天
  427. break;
  428. case $t < 60 * 60 * 24 * 30:
  429. $text = date('m月d日 H:i', $time); //一个月内
  430. break;
  431. case $t < 60 * 60 * 24 * 365&&$y==0:
  432. $text = date('m月d日', $time); //一年内
  433. break;
  434. default:
  435. $text = date('Y年m月d日', $time); //一年以前
  436. break;
  437. }
  438. return $text;
  439. }
  440. //轮播图
  441. public function banner() {
  442. $type = input('type', 0, 'intval'); //类型:0=交友轮播图,1=动态轮播图
  443. $list = Db::name('banner')->field('id, title, image, url')->where(['status' => 1, 'type' => $type])->order('weigh', 'desc')->select();
  444. $list = list_domain_image($list, ['image']);
  445. $this->success('轮播图', $list);
  446. }
  447. //谁看过我汇总
  448. public function visitlist(){
  449. $time = Db::name('user_visit_time')->where(['user_id' => $this->auth->id])->value('visittime');
  450. $where = [];
  451. if ($time) {
  452. $where['updatetime'] = ['gt', $time];
  453. }
  454. $list = [];
  455. $count = Db::name('user_visit')->where(['to_uid' => $this->auth->id])->where($where)->count('id');
  456. if ($count) {
  457. $uid_list = Db::name('user_visit')->field('uid')->where(['to_uid' => $this->auth->id])->where($where)->limit(9)->column('uid');
  458. $mt_user = Db::name('user');
  459. foreach ($uid_list as &$v) {
  460. $avatar = $mt_user->where(['id' => $v])->value('avatar');
  461. $list[] = one_domain_image($avatar);
  462. }
  463. }
  464. $data['count'] = $count;
  465. $data['list'] = $list;
  466. $this->success('success',$data);
  467. }
  468. //筛选年龄段
  469. public function agerange() {
  470. $list = [
  471. [
  472. 'id' => 0,
  473. 'title' => '不限'
  474. ],
  475. [
  476. 'id' => 1,
  477. 'title' => '18-25岁'
  478. ],
  479. [
  480. 'id' => 2,
  481. 'title' => '25-30岁'
  482. ],
  483. [
  484. 'id' => 3,
  485. 'title' => '30-35岁'
  486. ],
  487. [
  488. 'id' => 4,
  489. 'title' => '35-40岁'
  490. ],
  491. [
  492. 'id' => 5,
  493. 'title' => '40-45岁'
  494. ],
  495. [
  496. 'id' => 6,
  497. 'title' => '45-50岁'
  498. ],
  499. [
  500. 'id' => 7,
  501. 'title' => '50岁以上'
  502. ]
  503. ];
  504. $this->success('筛选年龄段', $list);
  505. }
  506. //推荐/附近/新人
  507. public function nearuser(){
  508. // if(empty($this->auth->longitude) || empty($this->auth->latitude)){
  509. // // $this->success('success',[]);
  510. // $this->error('请先开启定位');
  511. // }
  512. // $type = input('type', 0, 'intval'); //类型: 0附近 1缘分
  513. $type = input('type', 0, 'intval'); //类型: 0推荐 1附近 2新人
  514. $age_id = input('age_id', 0, 'intval'); //年龄段
  515. // $agemin = input('agemin', 0, 'intval'); //最小年龄
  516. // $agemax = input('agemax', 100, 'intval'); //最大年龄
  517. //经过地图测算和公式推算,经度纬度 0.1即为11公里
  518. $map = [
  519. 'user.status' => 1,
  520. ////'user.cityname' => $this->auth->cityname,
  521. 'user.id' => ['neq',$this->auth->id],
  522. 'user.is_kefu' => 0,
  523. // 'user.longitude' => ['between',[$this->auth->longitude - 0.1,$this->auth->longitude + 0.1]],
  524. // 'user.latitude' => ['between',[$this->auth->latitude - 0.1,$this->auth->latitude + 0.1]],
  525. // 'user.is_online|user.is_livebc' => 1, //完全不考虑直播与语聊的权重,只用活跃做排序
  526. // 'user.active_time' => ['gt',time()-86400],
  527. ];
  528. //排序
  529. $order = 'user.is_active desc, user.active_time desc';
  530. if (in_array($type,[0,1])) {
  531. if ($this->auth->gender == 1) {
  532. //$order = 'user.is_active desc, user.active_time desc, uw.get_money desc';
  533. $order = 'user.is_active desc, user.active_time desc';
  534. } else {
  535. //$order = 'user.is_active desc, user.active_time desc, uw.pay_money desc';
  536. $order = 'user.is_active desc, user.active_time desc';
  537. }
  538. }
  539. if ($type == 0) {
  540. // $map['user.cityname'] = $this->auth->cityname; //同城
  541. if ($this->auth->gender == 1) {
  542. $map['user.is_recommend'] = 1;
  543. }
  544. //$order = 'user.is_active desc, uw.pay_money desc,uw.get_money desc';
  545. } elseif ($type == 1) {
  546. // $map['user.longitude'] = ['between',[$this->auth->longitude - 0.1,$this->auth->longitude + 0.1]];
  547. // $map['user.latitude'] = ['between',[$this->auth->latitude - 0.1,$this->auth->latitude + 0.1]];
  548. } else {
  549. $map['user.createtime'] = ['egt', time() - 86400 * 30];
  550. // $order = 'user.createtime desc';
  551. }
  552. if($this->auth->gender == 1){
  553. $map['user.gender'] = 0;
  554. } else {
  555. $map['user.gender'] = 1;
  556. }
  557. if ($age_id > 0 && $age_id < 8) {
  558. if ($age_id == 1) {
  559. $agemin = 18;
  560. $agemax = 25;
  561. } elseif ($age_id == 2) {
  562. $agemin = 25;
  563. $agemax = 30;
  564. } elseif ($age_id == 3) {
  565. $agemin = 30;
  566. $agemax = 35;
  567. } elseif ($age_id == 4) {
  568. $agemin = 35;
  569. $agemax = 40;
  570. } elseif ($age_id == 5) {
  571. $agemin = 40;
  572. $agemax = 45;
  573. } elseif ($age_id == 6) {
  574. $agemin = 45;
  575. $agemax = 50;
  576. } elseif ($age_id == 7) {
  577. $agemin = 50;
  578. $agemax = 200;
  579. }
  580. $map['user.birthday'] = ['between', [time() - $agemax * 31536000, time() - $agemin * 31536000]];
  581. }
  582. //dump($map);
  583. $field = [
  584. 'user.id','user.nickname','user.birthday','user.height','user.longitude','user.latitude','user.avatar','user.bio','user.gender','user.idcard_status', 'user.real_status', 'user.job_id', 'user.is_active', 'user.wages_id', 'user.is_recommend', 'user.cityname', 'user.hometown_cityid', 'user.is_hideaddress'
  585. ];
  586. //$list = Db::name('user')->alias('user')->field($field)->where($map)->order($order)->autopage()->select();
  587. $list = Db::name('user')->alias('user')->field($field)
  588. // ->join('user_wallet uw','uw.user_id = user.id','LEFT')
  589. ->where($map)->order($order)->autopage()->select();
  590. //dump($list);exit;
  591. $list = list_domain_image($list,['avatar']);
  592. $mt_enum_job = Db::name('enum_job'); //职业
  593. $mt_enum_wages = Db::name('enum_wages'); //收入
  594. $mt_user_wallet = Db::name('user_wallet'); //vip
  595. $mt_user_greet = Db::name('user_greet'); //是否打过招呼
  596. $mt_wealth_level = Db::name('wealth_level'); //财富等级
  597. $mt_area = Db::name('area'); //城市
  598. $time = time();
  599. foreach($list as $key => &$v) {
  600. if ($this->auth->gender == 1) { //用户是男的
  601. $age = birthtime_to_age($v['birthday']);
  602. // $job = $mt_enum_job->where(['id' => $v['job_id']])->value('name');
  603. // $v['desc'] = $distance . ' · ' . $age . '岁';
  604. $v['desc'] = '';
  605. if ($age > 0) {
  606. $v['desc'] = $age . '岁';
  607. } else {
  608. $v['desc'] = '18岁';
  609. }
  610. if ($v['height']) {
  611. $v['desc'] .= ' | ' . $v['height'];
  612. }
  613. // if ($job) {
  614. // $v['desc'] .= ' · ' . $job;
  615. // }
  616. if ($type == 1) {
  617. // $distance = $this->calc_map_distance([$this->auth->longitude, $this->auth->latitude], [$v['longitude'], $v['latitude']]);
  618. // $v['desc'] .= ' | ' . $distance;
  619. $v['desc'] .= ' | 10km+';
  620. }
  621. } else {
  622. if ($type != 1) {
  623. $v['desc'] = $v['bio'] ?: '暂未设置个性签名';
  624. } else {
  625. $age = birthtime_to_age($v['birthday']);
  626. // $wages = $mt_enum_wages->where(['id' => $v['wages_id']])->value('name');
  627. // $v['desc'] = $distance . ' · ' . $age . '岁';
  628. $v['desc'] = '';
  629. if ($age > 0) {
  630. $v['desc'] = $age . '岁';
  631. } else {
  632. $v['desc'] = '18岁';
  633. }
  634. if ($v['hometown_cityid']) {
  635. $hometown_city = $mt_area->where('id',$v['hometown_cityid'])->value('name');
  636. $hometown_city = ($hometown_city && $v['is_hideaddress'] == 0) ? $hometown_city : '';
  637. if ($hometown_city) {
  638. $v['desc'] .= ' | ' . $hometown_city;
  639. }
  640. }
  641. // if ($wages) {
  642. // $v['desc'] .= ' · ' . $wages;
  643. // }
  644. }
  645. }
  646. //查询是否打过招呼
  647. $count = $mt_user_greet->where(['user_id' => $this->auth->id, 'user_to_id' => $v['id']])->count('id');
  648. if ($count) {
  649. $v['is_chat'] = 1; //是否打过招呼: 1是 0否
  650. } else {
  651. $v['is_chat'] = 0; //是否打过招呼: 1是 0否
  652. }
  653. $vip_endtime = $mt_user_wallet->where(['user_id' => $v['id']])->find();//->value('vip_endtime');
  654. if ($vip_endtime['vip_endtime'] >= $time) {
  655. $v['is_vip'] = 1; //是否是vip: 1是 0否
  656. } else {
  657. $v['is_vip'] = 0; //是否是vip: 1是 0否
  658. }
  659. //查询财富等级
  660. $wealth_level = $mt_wealth_level->where(['value' => ['elt', $vip_endtime['pay_money']]])->order('id desc')->find();
  661. if ($wealth_level) {
  662. $v['wealth_level'] = $wealth_level['name'];
  663. } else {
  664. $v['wealth_level'] = '';
  665. }
  666. }
  667. $this->success('success',$list);
  668. }
  669. /**
  670. * calc_map_distance() , 根据地图上的两个点各自的x,y坐标,计算出2点之间的直线距离
  671. * @param array $point_1 第1个点的x,y坐标 array( 101 , 202 )
  672. * @param array $point_2 第2个点的x,y坐标 array( 101 , 202 )
  673. * @param bool $calc_as_string 是否计算为字符串公里距离 , 如果未否返回数字
  674. * @return float | false | string
  675. */
  676. private function calc_map_distance( $point_1=array( ) , $point_2=array( ) , $calc_as_string=false ) {
  677. if( empty( $point_1 ) || empty( $point_2 ) ){
  678. return false;
  679. }
  680. // 经纬度不存在,或者经纬度超过最大范围 +-180 , +-90 ,返回false
  681. $p1_x = $point_1[0];
  682. $p1_y = $point_1[1];
  683. $p2_x = $point_2[0];
  684. $p2_y = $point_2[1];
  685. if(
  686. $p1_x < -180 || $p1_x > 180
  687. || $p2_x < -180 || $p2_x > 180
  688. || $p1_y < -90 || $p1_y > 90
  689. || $p2_y < -90 || $p2_y > 90
  690. || $p1_x == '' || $p1_y == ''
  691. || $p2_x == '' || $p2_y == ''
  692. ){
  693. return '距离未知';
  694. }
  695. // 根据2点各自的坐标,计算2点之间直线距离的公式
  696. $distance = round(6378.138*2*asin(sqrt(pow(sin(( $p1_x *pi()/180-$p2_x*pi()/180)/2),2)+cos( $p1_x *pi()/180)*cos($p2_x*pi()/180)* pow(sin(( $p1_y *pi()/180-$p2_y*pi()/180)/2),2)))*1000);
  697. // 是否计算为字符串公里距离
  698. if( !$calc_as_string ){
  699. return (string)round( $distance / 1000 , 1 ) . 'km';
  700. }
  701. // 如果计算为字符串公里距离
  702. if( $distance / 1000 > 1 ){
  703. $k = (string)round( $distance / 1000 , 1 );
  704. $m = (string)$distance % 1000 ;
  705. // $distance = "{$k}公里{$m}米";
  706. $distance = "{$k}km";
  707. }
  708. else{
  709. $distance = "{$distance}m";
  710. }
  711. return $distance;
  712. }
  713. //打招呼/搭讪
  714. public function greet() {
  715. if ($this->auth->gender == 0 && $this->auth->real_status != 1 && $this->auth->idcard_status != 1) {
  716. $this->error('请先完成实名认证或真人认证');
  717. }
  718. $other_uid = input('user_id', 0, 'intval');
  719. if(!$other_uid) {
  720. $this->error(__('Invalid parameters'));
  721. }
  722. if($other_uid == $this->auth->id){
  723. $this->error('这是您自己');
  724. }
  725. $checkuser = Db::name('user')->find($other_uid);
  726. if(empty($checkuser)) {
  727. $this->error('此用户不存在');
  728. }
  729. $map = [
  730. 'user_id' => $this->auth->id,
  731. 'user_to_id' => $other_uid,
  732. ];
  733. // 取消限制 2023年12月14日 18点47分
  734. // $check = Db::name('user_greet')->where($map)->find();
  735. // if($check){
  736. // $this->error('已经打过招呼了');
  737. // }
  738. $map['createtime'] = time();
  739. Db::startTrans();
  740. $id = Db::name('user_greet')->insertGetId($map);
  741. if (!$id) {
  742. Db::rollback();
  743. $this->error('您的网络开小差了~');
  744. }
  745. //tag任务赠送金币
  746. //搭讪奖励
  747. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,24);
  748. if($task_rs === false){
  749. Db::rollback();
  750. $this->error('完成任务赠送奖励失败');
  751. }
  752. Db::commit();
  753. $gift_greet = Db::name('gift_greet')->find();
  754. if ($gift_greet) {
  755. $gift_greet['special'] = one_domain_image($gift_greet['special']);
  756. $gift_greet['image'] = one_domain_image($gift_greet['image']);
  757. } else {
  758. $gift_greet = (object)[];
  759. }
  760. $this->success('操作成功', $gift_greet);
  761. }
  762. //女号私信异性完成任务
  763. public function girlchattask() {
  764. if ($this->auth->gender != 0) { //只有女生可以
  765. $this->error('您的网络开小差啦~');
  766. }
  767. //检测用户
  768. $to_user_id = input_post('to_user_id');
  769. $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing,chat_price,is_kefu')->where('id',$to_user_id)->find();
  770. if(!$to_user_info){
  771. $this->error('不存在的用户');
  772. }
  773. if ($to_user_info['is_kefu'] == 1 || $this->auth->is_kefu == 1) { //我是客服或者对方是客服
  774. $this->success('success');
  775. }
  776. if ($to_user_info['gender'] != 1) {
  777. $this->error('性别异常~');
  778. }
  779. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,23);
  780. if($task_rs === false){
  781. $this->error('完成任务赠送奖励失败');
  782. }
  783. $this->success('success');
  784. }
  785. //腾讯内容审核回调方法
  786. public function tencentcall() {
  787. $content = file_get_contents('php://input');
  788. $content = json_decode($content, true);
  789. error_log(print_r($content, 1) . PHP_EOL, 3, './tencentcall3.txt');
  790. if (isset($content['Scene']) && $content['CtxcbResult'] == 1) { //语音文件: 只返回违规的数据; 处理方式: 撤回
  791. $tenim = new Tenim;
  792. $rs = $tenim->withdraw_message($content['From_Account'], $content['ContactItem']['To_Account'], $content['MsgID']);
  793. // error_log(print_r($rs, 1) . PHP_EOL, 3, './tencentcall4.txt');
  794. } elseif (isset($content['TaskId'])) { //音视频通话: 返回所有数据; 处理方式: 强制退出im, 清空token
  795. if ($content['Status'] == 'RUNNING') {
  796. //该字段用于返回所查询内容的任务状态。取值:FINISH(任务已完成)、PENDING (任务等待中)、RUNNING (任务进行中)、ERROR (任务出错)、CANCELLED (任务已取消)。
  797. if ($content['ImageSegments']) { //图片(视频)审核结果
  798. $image_info = $content['ImageSegments'][0]['Result'];
  799. if ($image_info['Label'] != 'Normal') {
  800. //该字段用于返回检测结果所对应的恶意标签。返回值:Porn:色情,Abuse:谩骂,Ad:广告,Custom:自定义违规;以及其他令人反感、不安全或不适宜的内容类型。
  801. $url = $image_info['Url']; //图片地址https://cos.ap-guangzhou.myqcloud.com/tianyu-cms-ap-guangzhou-1312781550/segment-/trtc/1400758343/screenshot_1431291856_2_1669880705.jpg?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIDU2hLdl3CBZnuZ1rugInQEXxleKiEtIgHzkXoQu9u_1LZ_Cr9CmyRstQ34Fs_0ktH%2F20221201%2Fap-guangzhou%2Fs3%2Faws4_request&X-Amz-Date=20221201T074505Z&X-Amz-Expires=43200&X-Amz-Security-Token=HuyqAZVXXBWnWFOJZNLYInkTvVfFNqRab1d55d6d8642abaaa3d1c727ba06bd0eg37ybZOWCCsEawceCDvRAt1WL91GOzLIcdyC_DDX80alqE3M1GoQfUYRBETYm7eFxQ_wylmfSaomUU5hylq3twTxz9joT9g2rLfXhBmPeuvBia3n30gHeJtUeHJ7kaKjTDzZzPcq-B3t6hRximMVjKfQ9rKnJpjJGDKh-yqIpEUvyqFFl6Cf3d4lDoF87xwAAPya7Q2tMfZsMCyfgIMEqghMnGgWDMn9fMvDLl_82uGt8kK2TBGVymmeSx9GDGrDqBNo-hMC_EFR9jEUs87aDaD_gTNr2vLypRx87GnJhYCW7i-ExcfDfayKjXWy8LZeOtkc2Y0qDvzrEqcf5GtNBLPhgDzkbRyFgiWe99WsIrXH4RMlONiFitvvNAmWGvbv&X-Amz-SignedHeaders=host&X-Amz-Signature=e3b2a479c08d3fae95782e4bd62d88242726e095a771c28f38ccc7ed96c79d56
  802. //获取违规用户id
  803. $url = explode('?', $url);
  804. $url = $url[0];
  805. $user_id_url = explode('/', $url);
  806. $user_id_url = $user_id_url[count($user_id_url) - 1];
  807. $user_id_arr = explode('_', $user_id_url);
  808. $user_id = $user_id_arr[2];
  809. //退出im
  810. $tenIm = new Tenim();
  811. $tenIm->loginoutim($user_id);
  812. //清空token
  813. Token::clear($user_id);
  814. $tiaoshi = $user_id . '---' . $content['TaskId'] . '---' .$image_info['Label'] .'---'. date('Y-m-d H:i:s');
  815. error_log(print_r($tiaoshi, 1) . PHP_EOL, 3, './dayin1.txt');
  816. }
  817. } elseif ($content['AudioSegments']) { //音频审核结果
  818. $audio_info = $content['AudioSegments'][0]['Result'];
  819. if ($audio_info['Label'] != 'Normal') {
  820. //该字段用于返回检测结果所对应的恶意标签。返回值:Porn:色情,Abuse:谩骂,Ad:广告,Custom:自定义违规;以及其他令人反感、不安全或不适宜的内容类型。
  821. $url = $audio_info['Url']; //音频地址https://cos.ap-guangzhou.myqcloud.com/tianyu-cms-ap-guangzhou-1312781550/segment-/trtc/1400758343/audio_1431291856_354_1669880708.mp3?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIDU2hLdl3CBZnuZ1rugInQEXxleKiEtIgHzkXoQu9u_1LZ_Cr9CmyRstQ34Fs_0ktH%2F20221201%2Fap-guangzhou%2Fs3%2Faws4_request&X-Amz-Date=20221201T074520Z&X-Amz-Expires=43200&X-Amz-Security-Token=HuyqAZVXXBWnWFOJZNLYInkTvVfFNqRab1d55d6d8642abaaa3d1c727ba06bd0eg37ybZOWCCsEawceCDvRAt1WL91GOzLIcdyC_DDX80alqE3M1GoQfUYRBETYm7eFxQ_wylmfSaomUU5hylq3twTxz9joT9g2rLfXhBmPeuvBia3n30gHeJtUeHJ7kaKjTDzZzPcq-B3t6hRximMVjKfQ9rKnJpjJGDKh-yqIpEUvyqFFl6Cf3d4lDoF87xwAAPya7Q2tMfZsMCyfgIMEqghMnGgWDMn9fMvDLl_82uGt8kK2TBGVymmeSx9GDGrDqBNo-hMC_EFR9jEUs87aDaD_gTNr2vLypRx87GnJhYCW7i-ExcfDfayKjXWy8LZeOtkc2Y0qDvzrEqcf5GtNBLPhgDzkbRyFgiWe99WsIrXH4RMlONiFitvvNAmWGvbv&X-Amz-SignedHeaders=host&X-Amz-Signature=b1965689653813b59824647292565ec9297a7e81950bb88d8cbeb95f8393c1ca
  822. //获取违规用户id
  823. $url = explode('?', $url);
  824. $url = $url[0];
  825. $user_id_url = explode('/', $url);
  826. $user_id_url = $user_id_url[count($user_id_url) - 1];
  827. $user_id_arr = explode('_', $user_id_url);
  828. $user_id = $user_id_arr[2];
  829. //退出im
  830. $tenIm = new Tenim();
  831. $tenIm->loginoutim($user_id);
  832. //清空token
  833. Token::clear($user_id);
  834. $tiaoshi = $user_id . '---' . $content['TaskId'] . '---' .$audio_info['Label'] .'---'. date('Y-m-d H:i:s');
  835. error_log(print_r($tiaoshi, 1) . PHP_EOL, 3, './dayin2.txt');
  836. }
  837. }
  838. }
  839. }
  840. }
  841. //头条
  842. public function headlines() {
  843. $time = strtotime(date('Y-m-d', time()));
  844. //聊天送礼物
  845. $list1 = Db::name('gift_user_typing')->field('id, user_id, user_to_id, gift_name')->where(['createtime' => ['egt', $time]])->order('price desc, id desc')/*->page($this->page, $this->listrow)*/->select();
  846. //动态送礼物
  847. $list2 = Db::name('gift_user_dongtai')->field('id, user_id, user_to_id, gift_name')->where(['createtime' => ['egt', $time]])->order('price desc, id desc')/*->page($this->page, $this->listrow)*/->select();
  848. $list = array_merge($list1, $list2);
  849. if ($list) {
  850. $mt_user = Db::name('user');
  851. foreach ($list as &$v) {
  852. $user_info= $mt_user->field('nickname, avatar')->where(['id' => $v['user_id']])->find();
  853. $v['from_nickname'] = '有缘人';//$user_info['nickname'];
  854. $v['avatar'] = one_domain_image($user_info['avatar']);
  855. $v['to_nickname'] = '有缘人';//$mt_user->where(['id' => $v['user_to_id']])->value('nickname');
  856. }
  857. }
  858. $this->success('头条', $list);
  859. }
  860. //查询每天弹出搭讪框次数
  861. public function freegreetnum() {
  862. $user = $this->auth->getUser();
  863. if (isset($user['is_kefu']) && $user['is_kefu'] == 1){
  864. $data['free_greet_num'] = 0;
  865. $data['vip_free_greet_num'] = 0;
  866. $data['boy_free_greet_num'] = 0;
  867. $data['boy_vip_free_greet_num'] = 0;
  868. }else{
  869. //非会员每天弹出搭讪框次数
  870. $data['free_greet_num'] = config('site.free_greet_num') > 0 ? config('site.free_greet_num') : 5;
  871. //vip每天弹出搭讪框次数
  872. $data['vip_free_greet_num'] = config('site.vip_free_greet_num') > 0 ? config('site.vip_free_greet_num') : 5;
  873. // 男性 非会员每天弹出搭讪框次数
  874. $data['boy_free_greet_num'] = config('site.boy_free_greet_num') > 0 ? config('site.boy_free_greet_num') : 1;
  875. // 男性 vip每天弹出搭讪框次数
  876. $data['boy_vip_free_greet_num'] = config('site.boy_vip_free_greet_num') > 0 ? config('site.boy_vip_free_greet_num') : 1;
  877. }
  878. $this->success('success', $data);
  879. }
  880. /**
  881. * 男性打招呼内容
  882. * @return void
  883. * @throws \think\db\exception\DataNotFoundException
  884. * @throws \think\db\exception\ModelNotFoundException
  885. * @throws \think\exception\DbException
  886. */
  887. public function greetBoy()
  888. {
  889. $data = Db::name('user_greet_boy')->select();
  890. $this->success('success', $data);
  891. }
  892. //首页顶部分类名称
  893. public function typename() {
  894. $typename = config('site.typename');
  895. $typename = explode(',', $typename);
  896. $data[] = $typename[0] ? : '推荐';
  897. $data[] = $typename[1] ? : '附近';
  898. $data[] = $typename[2] ? : '新人';
  899. $this->success('sussess', $data);
  900. }
  901. //获取版本更新信息
  902. public function getversion() {
  903. // 获取二维码
  904. $is_force = config("site.is_force"); //是否强制更新 1是 0否
  905. $apk_url = config("site.apk_url"); //下载链接
  906. $apk_name = config("site.apk_name"); //apk更新标题
  907. $apk_desc = config("site.apk_desc"); //apk更新描述
  908. $version_code = config("site.version_code"); //版本迭代号
  909. $data['is_force'] = $is_force;
  910. $data['apk_url'] = $apk_url;
  911. $data['apk_name'] = $apk_name;
  912. $data['apk_desc'] = $apk_desc;
  913. $data['version_code'] = $version_code;
  914. $this->success('Success', $data);
  915. }
  916. // 获取版本更新信息(知心app)
  917. public function getversionZx() {
  918. // 获取二维码
  919. $is_force = config("site.is_force_zx"); //是否强制更新 1是 0否
  920. $apk_url = config("site.apk_url_zx"); //下载链接
  921. $apk_name = config("site.apk_name_zx"); //apk更新标题
  922. $apk_desc = config("site.apk_desc_zx"); //apk更新描述
  923. $version_code = config("site.version_code_zx"); //版本迭代号
  924. $data['is_force'] = $is_force;
  925. $data['apk_url'] = $apk_url;
  926. $data['apk_name'] = str_replace('知音','知心',$apk_name);
  927. $data['apk_desc'] = $apk_desc;
  928. $data['version_code'] = $version_code;
  929. $this->success('Success', $data);
  930. }
  931. //获取ios版本更新信息
  932. public function getiosversion() {
  933. // 获取二维码
  934. $is_force = config("site.ios_is_force"); //是否强制更新 1是 0否
  935. $apk_url = config("site.ios_apk_url"); //下载链接
  936. $apk_name = config("site.ios_apk_name"); //apk更新标题
  937. $apk_desc = config("site.ios_apk_desc"); //apk更新描述
  938. $version_code = config("site.ios_version_code"); //版本迭代号
  939. $data['is_force'] = $is_force;
  940. $data['apk_url'] = $apk_url;
  941. $data['apk_name'] = $apk_name;
  942. $data['apk_desc'] = $apk_desc;
  943. $data['version_code'] = $version_code;
  944. $this->success('Success', $data);
  945. }
  946. }