Index.php 36 KB

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