Index.php 41 KB

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