Index.php 39 KB

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