Index.php 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442
  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. public function nearuser()
  507. {
  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.gender' => $this->auth->gender == 1 ? 0 : 1,// 查询异性
  520. 'user.status' => 1,
  521. 'user.is_kefu' => 0,
  522. 'user.id' => ['neq',$this->auth->id],
  523. // 'user.cityname' => $this->auth->cityname,
  524. // 'user.longitude' => ['between',[$this->auth->longitude - 0.1,$this->auth->longitude + 0.1]],
  525. // 'user.latitude' => ['between',[$this->auth->latitude - 0.1,$this->auth->latitude + 0.1]],
  526. // 'user.is_online|user.is_livebc' => 1, //完全不考虑直播与语聊的权重,只用活跃做排序
  527. // 'user.active_time' => ['gt',time()-86400],
  528. ];
  529. //排序
  530. $order = 'user.is_active desc, user.active_time desc';
  531. if (in_array($type,[0,1])) {
  532. if ($this->auth->gender == 1) {
  533. // $order = 'user.is_active desc, user.active_time desc, uw.get_money desc';
  534. $order = 'user.is_active desc, user.active_time desc';
  535. } else {
  536. // $order = 'user.is_active desc, user.active_time desc, uw.pay_money desc';
  537. $order = 'user.is_active desc, user.active_time desc';
  538. }
  539. }
  540. if ($type == 0) {
  541. // $map['user.cityname'] = $this->auth->cityname; //同城
  542. if ($this->auth->gender == 1) {
  543. $map['user.is_recommend'] = 1;
  544. }
  545. //$order = 'user.is_active desc, uw.pay_money desc,uw.get_money desc';
  546. } elseif ($type == 1) {
  547. // $map['user.longitude'] = ['between',[$this->auth->longitude - 0.1,$this->auth->longitude + 0.1]];
  548. // $map['user.latitude'] = ['between',[$this->auth->latitude - 0.1,$this->auth->latitude + 0.1]];
  549. } else {
  550. $map['user.createtime'] = ['egt', time() - 86400 * 30];
  551. // $order = 'user.createtime desc';
  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. $list = list_domain_image($list,['avatar']);
  587. $mt_enum_job = Db::name('enum_job'); //职业
  588. $mt_enum_wages = Db::name('enum_wages'); //收入
  589. $mt_user_wallet = Db::name('user_wallet'); //vip
  590. $mt_user_greet = Db::name('user_greet'); //是否打过招呼
  591. $mt_wealth_level = Db::name('wealth_level'); //财富等级
  592. $mt_area = Db::name('area'); //城市
  593. $time = time();
  594. $hometown_cityid = [];//城市ids
  595. $user_to_id = [];//打招呼ids
  596. foreach ($list as $key=>$val){
  597. $hometown_cityid[] = $val['hometown_cityid'];
  598. $user_to_id[] = $val['id'];
  599. }
  600. // 城市
  601. $mt_areas = $mt_area->field(['id','name'])->whereIn('id',$hometown_cityid)->select();
  602. $mt_areas = array_column($mt_areas ?? [],'name','id');
  603. // 是否打过招呼
  604. $mt_user_greets = $mt_user_greet->field(['user_to_id','count(id) as num'])->where('user_id', $this->auth->id)->whereIn('user_to_id',$user_to_id)->group('user_to_id')->select();
  605. $mt_user_greets = array_column($mt_user_greets ?? [],'num','user_to_id');
  606. // 是否是vip
  607. $mt_user_wallets = $mt_user_wallet->field(['id','user_id','vip_endtime','pay_money'])->whereIn('user_id',$user_to_id)->select();
  608. // 财富等级
  609. $mt_wealth_levels = $mt_wealth_level->order('id desc')->select();
  610. $mt_wealth_levels = array_column($mt_wealth_levels ?? [],'name','value');
  611. foreach($list as $key => &$v) {
  612. if ($this->auth->gender == 1) { //用户是男的
  613. $age = birthtime_to_age($v['birthday']);
  614. // $job = $mt_enum_job->where(['id' => $v['job_id']])->value('name');
  615. // $v['desc'] = $distance . ' · ' . $age . '岁';
  616. $v['desc'] = '';
  617. if ($age > 0) {
  618. $v['desc'] = $age . '岁';
  619. } else {
  620. $v['desc'] = '18岁';
  621. }
  622. if ($v['height']) {
  623. $v['desc'] .= ' | ' . $v['height'];
  624. }
  625. // if ($job) {
  626. // $v['desc'] .= ' · ' . $job;
  627. // }
  628. if ($type == 1) {
  629. // $distance = $this->calc_map_distance([$this->auth->longitude, $this->auth->latitude], [$v['longitude'], $v['latitude']]);
  630. // $v['desc'] .= ' | ' . $distance;
  631. $v['desc'] .= ' | 10km+';
  632. }
  633. } else {
  634. if ($type != 1) {
  635. $v['desc'] = $v['bio'] ?: '暂未设置个性签名';
  636. } else {
  637. $age = birthtime_to_age($v['birthday']);
  638. // $wages = $mt_enum_wages->where(['id' => $v['wages_id']])->value('name');
  639. // $v['desc'] = $distance . ' · ' . $age . '岁';
  640. $v['desc'] = '';
  641. if ($age > 0) {
  642. $v['desc'] = $age . '岁';
  643. } else {
  644. $v['desc'] = '18岁';
  645. }
  646. if ($v['hometown_cityid']) {
  647. $hometown_city = $mt_areas[$v['hometown_cityid']] ?? '';
  648. $hometown_city = ($hometown_city && $v['is_hideaddress'] == 0) ? $hometown_city : '';
  649. if ($hometown_city) {
  650. $v['desc'] .= ' | ' . $hometown_city;
  651. }
  652. }
  653. // if ($wages) {
  654. // $v['desc'] .= ' · ' . $wages;
  655. // }
  656. }
  657. }
  658. //查询是否打过招呼
  659. $count = $mt_user_greets[$v['id']] ?? 0;
  660. if ($count) {
  661. $v['is_chat'] = 1; //是否打过招呼: 1是 0否
  662. } else {
  663. $v['is_chat'] = 0; //是否打过招呼: 1是 0否
  664. }
  665. $vip_endtime = 0;
  666. $pay_money = 0;
  667. foreach ($mt_user_wallets as $kk=>$vv){
  668. if ($vv['user_id'] == $v['id']) {
  669. $vip_endtime = $vv['vip_endtime'];
  670. $pay_money = $vv['pay_money'];
  671. break;
  672. }
  673. }
  674. if ($vip_endtime >= $time) {
  675. $v['is_vip'] = 1; //是否是vip: 1是 0否
  676. } else {
  677. $v['is_vip'] = 0; //是否是vip: 1是 0否
  678. }
  679. //查询财富等级
  680. if (!empty($mt_wealth_levels)) {
  681. $name = '';
  682. foreach ($mt_wealth_levels as $kkk=>$vvv){
  683. if ($pay_money > $kkk){
  684. $name = $vvv;
  685. break;
  686. }
  687. }
  688. $v['wealth_level'] = $name;
  689. } else {
  690. $v['wealth_level'] = '';
  691. }
  692. }
  693. $this->success('success',$list);
  694. }
  695. public function nearuserbak0106()
  696. {
  697. // if(empty($this->auth->longitude) || empty($this->auth->latitude)){
  698. // // $this->success('success',[]);
  699. // $this->error('请先开启定位');
  700. // }
  701. // $type = input('type', 0, 'intval'); //类型: 0附近 1缘分
  702. $type = input('type', 0, 'intval'); //类型: 0推荐 1附近 2新人
  703. $age_id = input('age_id', 0, 'intval'); //年龄段
  704. // $agemin = input('agemin', 0, 'intval'); //最小年龄
  705. // $agemax = input('agemax', 100, 'intval'); //最大年龄
  706. //经过地图测算和公式推算,经度纬度 0.1即为11公里
  707. $map = [
  708. 'user.gender' => $this->auth->gender == 1 ? 0 : 1,// 查询异性
  709. 'user.status' => 1,
  710. ////'user.cityname' => $this->auth->cityname,
  711. 'user.id' => ['neq',$this->auth->id],
  712. 'user.is_kefu' => 0,
  713. // 'user.longitude' => ['between',[$this->auth->longitude - 0.1,$this->auth->longitude + 0.1]],
  714. // 'user.latitude' => ['between',[$this->auth->latitude - 0.1,$this->auth->latitude + 0.1]],
  715. // 'user.is_online|user.is_livebc' => 1, //完全不考虑直播与语聊的权重,只用活跃做排序
  716. // 'user.active_time' => ['gt',time()-86400],
  717. ];
  718. //排序
  719. $order = 'user.is_active desc, user.active_time desc';
  720. if (in_array($type,[0,1])) {
  721. if ($this->auth->gender == 1) {
  722. // $order = 'user.is_active desc, user.active_time desc, uw.get_money desc';
  723. $order = 'user.is_active desc, user.active_time desc';
  724. } else {
  725. // $order = 'user.is_active desc, user.active_time desc, uw.pay_money desc';
  726. $order = 'user.is_active desc, user.active_time desc';
  727. }
  728. }
  729. if ($type == 0) {
  730. // $map['user.cityname'] = $this->auth->cityname; //同城
  731. if ($this->auth->gender == 1) {
  732. $map['user.is_recommend'] = 1;
  733. }
  734. //$order = 'user.is_active desc, uw.pay_money desc,uw.get_money desc';
  735. } elseif ($type == 1) {
  736. // $map['user.longitude'] = ['between',[$this->auth->longitude - 0.1,$this->auth->longitude + 0.1]];
  737. // $map['user.latitude'] = ['between',[$this->auth->latitude - 0.1,$this->auth->latitude + 0.1]];
  738. } else {
  739. $map['user.createtime'] = ['egt', time() - 86400 * 30];
  740. // $order = 'user.createtime desc';
  741. }
  742. // if($this->auth->gender == 1){
  743. // $map['user.gender'] = 0;
  744. // } else {
  745. // $map['user.gender'] = 1;
  746. // }
  747. if ($age_id > 0 && $age_id < 8) {
  748. if ($age_id == 1) {
  749. $agemin = 18;
  750. $agemax = 25;
  751. } elseif ($age_id == 2) {
  752. $agemin = 25;
  753. $agemax = 30;
  754. } elseif ($age_id == 3) {
  755. $agemin = 30;
  756. $agemax = 35;
  757. } elseif ($age_id == 4) {
  758. $agemin = 35;
  759. $agemax = 40;
  760. } elseif ($age_id == 5) {
  761. $agemin = 40;
  762. $agemax = 45;
  763. } elseif ($age_id == 6) {
  764. $agemin = 45;
  765. $agemax = 50;
  766. } elseif ($age_id == 7) {
  767. $agemin = 50;
  768. $agemax = 200;
  769. }
  770. $map['user.birthday'] = ['between', [time() - $agemax * 31536000, time() - $agemin * 31536000]];
  771. }
  772. //dump($map);
  773. $field = [
  774. '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'
  775. ];
  776. //$list = Db::name('user')->alias('user')->field($field)->where($map)->order($order)->autopage()->select();
  777. $list = Db::name('user')->alias('user')->field($field)
  778. //->join('user_wallet uw','uw.user_id = user.id','LEFT')
  779. ->where($map)->order($order)->autopage()->select();
  780. //dump($list);exit;
  781. $list = list_domain_image($list,['avatar']);
  782. $mt_enum_job = Db::name('enum_job'); //职业
  783. $mt_enum_wages = Db::name('enum_wages'); //收入
  784. $mt_user_wallet = Db::name('user_wallet'); //vip
  785. $mt_user_greet = Db::name('user_greet'); //是否打过招呼
  786. $mt_wealth_level = Db::name('wealth_level'); //财富等级
  787. $mt_area = Db::name('area'); //城市
  788. $time = time();
  789. foreach($list as $key => &$v) {
  790. if ($this->auth->gender == 1) { //用户是男的
  791. $age = birthtime_to_age($v['birthday']);
  792. // $job = $mt_enum_job->where(['id' => $v['job_id']])->value('name');
  793. // $v['desc'] = $distance . ' · ' . $age . '岁';
  794. $v['desc'] = '';
  795. if ($age > 0) {
  796. $v['desc'] = $age . '岁';
  797. } else {
  798. $v['desc'] = '18岁';
  799. }
  800. if ($v['height']) {
  801. $v['desc'] .= ' | ' . $v['height'];
  802. }
  803. // if ($job) {
  804. // $v['desc'] .= ' · ' . $job;
  805. // }
  806. if ($type == 1) {
  807. // $distance = $this->calc_map_distance([$this->auth->longitude, $this->auth->latitude], [$v['longitude'], $v['latitude']]);
  808. // $v['desc'] .= ' | ' . $distance;
  809. $v['desc'] .= ' | 10km+';
  810. }
  811. } else {
  812. if ($type != 1) {
  813. $v['desc'] = $v['bio'] ?: '暂未设置个性签名';
  814. } else {
  815. $age = birthtime_to_age($v['birthday']);
  816. // $wages = $mt_enum_wages->where(['id' => $v['wages_id']])->value('name');
  817. // $v['desc'] = $distance . ' · ' . $age . '岁';
  818. $v['desc'] = '';
  819. if ($age > 0) {
  820. $v['desc'] = $age . '岁';
  821. } else {
  822. $v['desc'] = '18岁';
  823. }
  824. if ($v['hometown_cityid']) {
  825. $hometown_city = $mt_area->where('id',$v['hometown_cityid'])->value('name');
  826. $hometown_city = ($hometown_city && $v['is_hideaddress'] == 0) ? $hometown_city : '';
  827. if ($hometown_city) {
  828. $v['desc'] .= ' | ' . $hometown_city;
  829. }
  830. }
  831. // if ($wages) {
  832. // $v['desc'] .= ' · ' . $wages;
  833. // }
  834. }
  835. }
  836. //查询是否打过招呼
  837. $count = $mt_user_greet->where(['user_id' => $this->auth->id, 'user_to_id' => $v['id']])->count('id');
  838. if ($count) {
  839. $v['is_chat'] = 1; //是否打过招呼: 1是 0否
  840. } else {
  841. $v['is_chat'] = 0; //是否打过招呼: 1是 0否
  842. }
  843. $vip_endtime = $mt_user_wallet->where(['user_id' => $v['id']])->find();//->value('vip_endtime');
  844. if ($vip_endtime['vip_endtime'] >= $time) {
  845. $v['is_vip'] = 1; //是否是vip: 1是 0否
  846. } else {
  847. $v['is_vip'] = 0; //是否是vip: 1是 0否
  848. }
  849. //查询财富等级
  850. $wealth_level = $mt_wealth_level->where(['value' => ['elt', $vip_endtime['pay_money']]])->order('id desc')->find();
  851. if ($wealth_level) {
  852. $v['wealth_level'] = $wealth_level['name'];
  853. } else {
  854. $v['wealth_level'] = '';
  855. }
  856. }
  857. $this->success('success',$list);
  858. }
  859. //推荐/附近/新人
  860. public function nearuserbak(){
  861. // if(empty($this->auth->longitude) || empty($this->auth->latitude)){
  862. // // $this->success('success',[]);
  863. // $this->error('请先开启定位');
  864. // }
  865. // $type = input('type', 0, 'intval'); //类型: 0附近 1缘分
  866. $type = input('type', 0, 'intval'); //类型: 0推荐 1附近 2新人
  867. $age_id = input('age_id', 0, 'intval'); //年龄段
  868. // $agemin = input('agemin', 0, 'intval'); //最小年龄
  869. // $agemax = input('agemax', 100, 'intval'); //最大年龄
  870. //经过地图测算和公式推算,经度纬度 0.1即为11公里
  871. $map = [
  872. 'user.status' => 1,
  873. ////'user.cityname' => $this->auth->cityname,
  874. 'user.id' => ['neq',$this->auth->id],
  875. 'user.is_kefu' => 0,
  876. // 'user.longitude' => ['between',[$this->auth->longitude - 0.1,$this->auth->longitude + 0.1]],
  877. // 'user.latitude' => ['between',[$this->auth->latitude - 0.1,$this->auth->latitude + 0.1]],
  878. // 'user.is_online|user.is_livebc' => 1, //完全不考虑直播与语聊的权重,只用活跃做排序
  879. // 'user.active_time' => ['gt',time()-86400],
  880. ];
  881. //排序
  882. $order = 'user.is_active desc, user.active_time desc';
  883. if (in_array($type,[0,1])) {
  884. if ($this->auth->gender == 1) {
  885. //$order = 'user.is_active desc, user.active_time desc, uw.get_money desc';
  886. $order = 'user.is_active desc, user.active_time desc';
  887. } else {
  888. //$order = 'user.is_active desc, user.active_time desc, uw.pay_money desc';
  889. $order = 'user.is_active desc, user.active_time desc';
  890. }
  891. }
  892. if ($type == 0) {
  893. // $map['user.cityname'] = $this->auth->cityname; //同城
  894. if ($this->auth->gender == 1) {
  895. $map['user.is_recommend'] = 1;
  896. }
  897. //$order = 'user.is_active desc, uw.pay_money desc,uw.get_money desc';
  898. } elseif ($type == 1) {
  899. // $map['user.longitude'] = ['between',[$this->auth->longitude - 0.1,$this->auth->longitude + 0.1]];
  900. // $map['user.latitude'] = ['between',[$this->auth->latitude - 0.1,$this->auth->latitude + 0.1]];
  901. } else {
  902. $map['user.createtime'] = ['egt', time() - 86400 * 30];
  903. // $order = 'user.createtime desc';
  904. }
  905. if($this->auth->gender == 1){
  906. $map['user.gender'] = 0;
  907. } else {
  908. $map['user.gender'] = 1;
  909. }
  910. if ($age_id > 0 && $age_id < 8) {
  911. if ($age_id == 1) {
  912. $agemin = 18;
  913. $agemax = 25;
  914. } elseif ($age_id == 2) {
  915. $agemin = 25;
  916. $agemax = 30;
  917. } elseif ($age_id == 3) {
  918. $agemin = 30;
  919. $agemax = 35;
  920. } elseif ($age_id == 4) {
  921. $agemin = 35;
  922. $agemax = 40;
  923. } elseif ($age_id == 5) {
  924. $agemin = 40;
  925. $agemax = 45;
  926. } elseif ($age_id == 6) {
  927. $agemin = 45;
  928. $agemax = 50;
  929. } elseif ($age_id == 7) {
  930. $agemin = 50;
  931. $agemax = 200;
  932. }
  933. $map['user.birthday'] = ['between', [time() - $agemax * 31536000, time() - $agemin * 31536000]];
  934. }
  935. //dump($map);
  936. $field = [
  937. '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'
  938. ];
  939. //$list = Db::name('user')->alias('user')->field($field)->where($map)->order($order)->autopage()->select();
  940. $list = Db::name('user')->alias('user')->field($field)
  941. // ->join('user_wallet uw','uw.user_id = user.id','LEFT')
  942. ->where($map)->order($order)->autopage()->select();
  943. //dump($list);exit;
  944. $list = list_domain_image($list,['avatar']);
  945. $mt_enum_job = Db::name('enum_job'); //职业
  946. $mt_enum_wages = Db::name('enum_wages'); //收入
  947. $mt_user_wallet = Db::name('user_wallet'); //vip
  948. $mt_user_greet = Db::name('user_greet'); //是否打过招呼
  949. $mt_wealth_level = Db::name('wealth_level'); //财富等级
  950. $mt_area = Db::name('area'); //城市
  951. $time = time();
  952. foreach($list as $key => &$v) {
  953. if ($this->auth->gender == 1) { //用户是男的
  954. $age = birthtime_to_age($v['birthday']);
  955. // $job = $mt_enum_job->where(['id' => $v['job_id']])->value('name');
  956. // $v['desc'] = $distance . ' · ' . $age . '岁';
  957. $v['desc'] = '';
  958. if ($age > 0) {
  959. $v['desc'] = $age . '岁';
  960. } else {
  961. $v['desc'] = '18岁';
  962. }
  963. if ($v['height']) {
  964. $v['desc'] .= ' | ' . $v['height'];
  965. }
  966. // if ($job) {
  967. // $v['desc'] .= ' · ' . $job;
  968. // }
  969. if ($type == 1) {
  970. // $distance = $this->calc_map_distance([$this->auth->longitude, $this->auth->latitude], [$v['longitude'], $v['latitude']]);
  971. // $v['desc'] .= ' | ' . $distance;
  972. $v['desc'] .= ' | 10km+';
  973. }
  974. } else {
  975. if ($type != 1) {
  976. $v['desc'] = $v['bio'] ?: '暂未设置个性签名';
  977. } else {
  978. $age = birthtime_to_age($v['birthday']);
  979. // $wages = $mt_enum_wages->where(['id' => $v['wages_id']])->value('name');
  980. // $v['desc'] = $distance . ' · ' . $age . '岁';
  981. $v['desc'] = '';
  982. if ($age > 0) {
  983. $v['desc'] = $age . '岁';
  984. } else {
  985. $v['desc'] = '18岁';
  986. }
  987. if ($v['hometown_cityid']) {
  988. $hometown_city = $mt_area->where('id',$v['hometown_cityid'])->value('name');
  989. $hometown_city = ($hometown_city && $v['is_hideaddress'] == 0) ? $hometown_city : '';
  990. if ($hometown_city) {
  991. $v['desc'] .= ' | ' . $hometown_city;
  992. }
  993. }
  994. // if ($wages) {
  995. // $v['desc'] .= ' · ' . $wages;
  996. // }
  997. }
  998. }
  999. //查询是否打过招呼
  1000. $count = $mt_user_greet->where(['user_id' => $this->auth->id, 'user_to_id' => $v['id']])->count('id');
  1001. if ($count) {
  1002. $v['is_chat'] = 1; //是否打过招呼: 1是 0否
  1003. } else {
  1004. $v['is_chat'] = 0; //是否打过招呼: 1是 0否
  1005. }
  1006. $vip_endtime = $mt_user_wallet->where(['user_id' => $v['id']])->find();//->value('vip_endtime');
  1007. if ($vip_endtime['vip_endtime'] >= $time) {
  1008. $v['is_vip'] = 1; //是否是vip: 1是 0否
  1009. } else {
  1010. $v['is_vip'] = 0; //是否是vip: 1是 0否
  1011. }
  1012. //查询财富等级
  1013. $wealth_level = $mt_wealth_level->where(['value' => ['elt', $vip_endtime['pay_money']]])->order('id desc')->find();
  1014. if ($wealth_level) {
  1015. $v['wealth_level'] = $wealth_level['name'];
  1016. } else {
  1017. $v['wealth_level'] = '';
  1018. }
  1019. }
  1020. $this->success('success',$list);
  1021. }
  1022. /**
  1023. * calc_map_distance() , 根据地图上的两个点各自的x,y坐标,计算出2点之间的直线距离
  1024. * @param array $point_1 第1个点的x,y坐标 array( 101 , 202 )
  1025. * @param array $point_2 第2个点的x,y坐标 array( 101 , 202 )
  1026. * @param bool $calc_as_string 是否计算为字符串公里距离 , 如果未否返回数字
  1027. * @return float | false | string
  1028. */
  1029. private function calc_map_distance( $point_1=array( ) , $point_2=array( ) , $calc_as_string=false ) {
  1030. if( empty( $point_1 ) || empty( $point_2 ) ){
  1031. return false;
  1032. }
  1033. // 经纬度不存在,或者经纬度超过最大范围 +-180 , +-90 ,返回false
  1034. $p1_x = $point_1[0];
  1035. $p1_y = $point_1[1];
  1036. $p2_x = $point_2[0];
  1037. $p2_y = $point_2[1];
  1038. if(
  1039. $p1_x < -180 || $p1_x > 180
  1040. || $p2_x < -180 || $p2_x > 180
  1041. || $p1_y < -90 || $p1_y > 90
  1042. || $p2_y < -90 || $p2_y > 90
  1043. || $p1_x == '' || $p1_y == ''
  1044. || $p2_x == '' || $p2_y == ''
  1045. ){
  1046. return '距离未知';
  1047. }
  1048. // 根据2点各自的坐标,计算2点之间直线距离的公式
  1049. $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);
  1050. // 是否计算为字符串公里距离
  1051. if( !$calc_as_string ){
  1052. return (string)round( $distance / 1000 , 1 ) . 'km';
  1053. }
  1054. // 如果计算为字符串公里距离
  1055. if( $distance / 1000 > 1 ){
  1056. $k = (string)round( $distance / 1000 , 1 );
  1057. $m = (string)$distance % 1000 ;
  1058. // $distance = "{$k}公里{$m}米";
  1059. $distance = "{$k}km";
  1060. }
  1061. else{
  1062. $distance = "{$distance}m";
  1063. }
  1064. return $distance;
  1065. }
  1066. //打招呼/搭讪
  1067. public function greet() {
  1068. if ($this->auth->gender == 0 && $this->auth->real_status != 1 && $this->auth->idcard_status != 1) {
  1069. $this->error('请先完成实名认证或真人认证');
  1070. }
  1071. $other_uid = input('user_id', 0, 'intval');
  1072. if(!$other_uid) {
  1073. $this->error(__('Invalid parameters'));
  1074. }
  1075. if($other_uid == $this->auth->id){
  1076. $this->error('这是您自己');
  1077. }
  1078. $checkuser = Db::name('user')->find($other_uid);
  1079. if(empty($checkuser)) {
  1080. $this->error('此用户不存在');
  1081. }
  1082. $map = [
  1083. 'user_id' => $this->auth->id,
  1084. 'user_to_id' => $other_uid,
  1085. ];
  1086. // 取消限制 2023年12月14日 18点47分
  1087. // $check = Db::name('user_greet')->where($map)->find();
  1088. // if($check){
  1089. // $this->error('已经打过招呼了');
  1090. // }
  1091. $map['createtime'] = time();
  1092. Db::startTrans();
  1093. $id = Db::name('user_greet')->insertGetId($map);
  1094. if (!$id) {
  1095. Db::rollback();
  1096. $this->error('您的网络开小差了~');
  1097. }
  1098. //tag任务赠送金币
  1099. //搭讪奖励
  1100. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,24);
  1101. if($task_rs === false){
  1102. Db::rollback();
  1103. $this->error('完成任务赠送奖励失败');
  1104. }
  1105. Db::commit();
  1106. $gift_greet = Db::name('gift_greet')->find();
  1107. if ($gift_greet) {
  1108. $gift_greet['special'] = one_domain_image($gift_greet['special']);
  1109. $gift_greet['image'] = one_domain_image($gift_greet['image']);
  1110. } else {
  1111. $gift_greet = (object)[];
  1112. }
  1113. $this->success('操作成功', $gift_greet);
  1114. }
  1115. //女号私信异性完成任务
  1116. public function girlchattask() {
  1117. if ($this->auth->gender != 0) { //只有女生可以
  1118. $this->error('您的网络开小差啦~');
  1119. }
  1120. //检测用户
  1121. $to_user_id = input_post('to_user_id');
  1122. $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();
  1123. if(!$to_user_info){
  1124. $this->error('不存在的用户');
  1125. }
  1126. if ($to_user_info['is_kefu'] == 1 || $this->auth->is_kefu == 1) { //我是客服或者对方是客服
  1127. $this->success('success');
  1128. }
  1129. if ($to_user_info['gender'] != 1) {
  1130. $this->error('性别异常~');
  1131. }
  1132. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,23);
  1133. if($task_rs === false){
  1134. $this->error('完成任务赠送奖励失败');
  1135. }
  1136. $this->success('success');
  1137. }
  1138. //腾讯内容审核回调方法
  1139. public function tencentcall() {
  1140. $content = file_get_contents('php://input');
  1141. $content = json_decode($content, true);
  1142. error_log(print_r($content, 1) . PHP_EOL, 3, './tencentcall3.txt');
  1143. if (isset($content['Scene']) && $content['CtxcbResult'] == 1) { //语音文件: 只返回违规的数据; 处理方式: 撤回
  1144. $tenim = new Tenim;
  1145. $rs = $tenim->withdraw_message($content['From_Account'], $content['ContactItem']['To_Account'], $content['MsgID']);
  1146. // error_log(print_r($rs, 1) . PHP_EOL, 3, './tencentcall4.txt');
  1147. } elseif (isset($content['TaskId'])) { //音视频通话: 返回所有数据; 处理方式: 强制退出im, 清空token
  1148. if ($content['Status'] == 'RUNNING') {
  1149. //该字段用于返回所查询内容的任务状态。取值:FINISH(任务已完成)、PENDING (任务等待中)、RUNNING (任务进行中)、ERROR (任务出错)、CANCELLED (任务已取消)。
  1150. if ($content['ImageSegments']) { //图片(视频)审核结果
  1151. $image_info = $content['ImageSegments'][0]['Result'];
  1152. if ($image_info['Label'] != 'Normal') {
  1153. //该字段用于返回检测结果所对应的恶意标签。返回值:Porn:色情,Abuse:谩骂,Ad:广告,Custom:自定义违规;以及其他令人反感、不安全或不适宜的内容类型。
  1154. $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
  1155. //获取违规用户id
  1156. $url = explode('?', $url);
  1157. $url = $url[0];
  1158. $user_id_url = explode('/', $url);
  1159. $user_id_url = $user_id_url[count($user_id_url) - 1];
  1160. $user_id_arr = explode('_', $user_id_url);
  1161. $user_id = $user_id_arr[2];
  1162. //退出im
  1163. $tenIm = new Tenim();
  1164. $tenIm->loginoutim($user_id);
  1165. //清空token
  1166. Token::clear($user_id);
  1167. $tiaoshi = $user_id . '---' . $content['TaskId'] . '---' .$image_info['Label'] .'---'. date('Y-m-d H:i:s');
  1168. error_log(print_r($tiaoshi, 1) . PHP_EOL, 3, './dayin1.txt');
  1169. }
  1170. } elseif ($content['AudioSegments']) { //音频审核结果
  1171. $audio_info = $content['AudioSegments'][0]['Result'];
  1172. if ($audio_info['Label'] != 'Normal') {
  1173. //该字段用于返回检测结果所对应的恶意标签。返回值:Porn:色情,Abuse:谩骂,Ad:广告,Custom:自定义违规;以及其他令人反感、不安全或不适宜的内容类型。
  1174. $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
  1175. //获取违规用户id
  1176. $url = explode('?', $url);
  1177. $url = $url[0];
  1178. $user_id_url = explode('/', $url);
  1179. $user_id_url = $user_id_url[count($user_id_url) - 1];
  1180. $user_id_arr = explode('_', $user_id_url);
  1181. $user_id = $user_id_arr[2];
  1182. //退出im
  1183. $tenIm = new Tenim();
  1184. $tenIm->loginoutim($user_id);
  1185. //清空token
  1186. Token::clear($user_id);
  1187. $tiaoshi = $user_id . '---' . $content['TaskId'] . '---' .$audio_info['Label'] .'---'. date('Y-m-d H:i:s');
  1188. error_log(print_r($tiaoshi, 1) . PHP_EOL, 3, './dayin2.txt');
  1189. }
  1190. }
  1191. }
  1192. }
  1193. }
  1194. //头条
  1195. public function headlines() {
  1196. $time = strtotime(date('Y-m-d', time()));
  1197. //聊天送礼物
  1198. $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();
  1199. //动态送礼物
  1200. $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();
  1201. $list = array_merge($list1, $list2);
  1202. if ($list) {
  1203. $mt_user = Db::name('user');
  1204. foreach ($list as &$v) {
  1205. $user_info= $mt_user->field('nickname, avatar')->where(['id' => $v['user_id']])->find();
  1206. $v['from_nickname'] = '有缘人';//$user_info['nickname'];
  1207. $v['avatar'] = one_domain_image($user_info['avatar']);
  1208. $v['to_nickname'] = '有缘人';//$mt_user->where(['id' => $v['user_to_id']])->value('nickname');
  1209. }
  1210. }
  1211. $this->success('头条', $list);
  1212. }
  1213. //查询每天弹出搭讪框次数
  1214. public function freegreetnum() {
  1215. $user = $this->auth->getUser();
  1216. if (isset($user['is_kefu']) && $user['is_kefu'] == 1){
  1217. $data['free_greet_num'] = 0;
  1218. $data['vip_free_greet_num'] = 0;
  1219. $data['boy_free_greet_num'] = 0;
  1220. $data['boy_vip_free_greet_num'] = 0;
  1221. }else{
  1222. //非会员每天弹出搭讪框次数
  1223. $data['free_greet_num'] = config('site.free_greet_num') > 0 ? config('site.free_greet_num') : 5;
  1224. //vip每天弹出搭讪框次数
  1225. $data['vip_free_greet_num'] = config('site.vip_free_greet_num') > 0 ? config('site.vip_free_greet_num') : 5;
  1226. // 男性 非会员每天弹出搭讪框次数
  1227. $data['boy_free_greet_num'] = config('site.boy_free_greet_num') > 0 ? config('site.boy_free_greet_num') : 1;
  1228. // 男性 vip每天弹出搭讪框次数
  1229. $data['boy_vip_free_greet_num'] = config('site.boy_vip_free_greet_num') > 0 ? config('site.boy_vip_free_greet_num') : 1;
  1230. }
  1231. $this->success('success', $data);
  1232. }
  1233. /**
  1234. * 男性打招呼内容
  1235. * @return void
  1236. * @throws \think\db\exception\DataNotFoundException
  1237. * @throws \think\db\exception\ModelNotFoundException
  1238. * @throws \think\exception\DbException
  1239. */
  1240. public function greetBoy()
  1241. {
  1242. $data = Db::name('user_greet_boy')->select();
  1243. $this->success('success', $data);
  1244. }
  1245. //首页顶部分类名称
  1246. public function typename() {
  1247. $typename = config('site.typename');
  1248. $typename = explode(',', $typename);
  1249. $data[] = $typename[0] ? : '推荐';
  1250. $data[] = $typename[1] ? : '附近';
  1251. $data[] = $typename[2] ? : '新人';
  1252. $this->success('sussess', $data);
  1253. }
  1254. //获取版本更新信息
  1255. public function getversion() {
  1256. // 获取二维码
  1257. $is_force = config("site.is_force"); //是否强制更新 1是 0否
  1258. $apk_url = config("site.apk_url"); //下载链接
  1259. $apk_name = config("site.apk_name"); //apk更新标题
  1260. $apk_desc = config("site.apk_desc"); //apk更新描述
  1261. $version_code = config("site.version_code"); //版本迭代号
  1262. $data['is_force'] = $is_force;
  1263. $data['apk_url'] = $apk_url;
  1264. $data['apk_name'] = $apk_name;
  1265. $data['apk_desc'] = $apk_desc;
  1266. $data['version_code'] = $version_code;
  1267. $this->success('Success', $data);
  1268. }
  1269. // 获取版本更新信息(知心app)
  1270. public function getversionZx() {
  1271. // 获取二维码
  1272. $is_force = config("site.is_force_zx"); //是否强制更新 1是 0否
  1273. $apk_url = config("site.apk_url_zx"); //下载链接
  1274. $apk_name = config("site.apk_name_zx"); //apk更新标题
  1275. $apk_desc = config("site.apk_desc_zx"); //apk更新描述
  1276. $version_code = config("site.version_code_zx"); //版本迭代号
  1277. $data['is_force'] = $is_force;
  1278. $data['apk_url'] = $apk_url;
  1279. $data['apk_name'] = str_replace('知音','知心',$apk_name);
  1280. $data['apk_desc'] = $apk_desc;
  1281. $data['version_code'] = $version_code;
  1282. $this->success('Success', $data);
  1283. }
  1284. //获取ios版本更新信息
  1285. public function getiosversion() {
  1286. // 获取二维码
  1287. $is_force = config("site.ios_is_force"); //是否强制更新 1是 0否
  1288. $apk_url = config("site.ios_apk_url"); //下载链接
  1289. $apk_name = config("site.ios_apk_name"); //apk更新标题
  1290. $apk_desc = config("site.ios_apk_desc"); //apk更新描述
  1291. $version_code = config("site.ios_version_code"); //版本迭代号
  1292. $data['is_force'] = $is_force;
  1293. $data['apk_url'] = $apk_url;
  1294. $data['apk_name'] = $apk_name;
  1295. $data['apk_desc'] = $apk_desc;
  1296. $data['version_code'] = $version_code;
  1297. $this->success('Success', $data);
  1298. }
  1299. }