Index.php 42 KB

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