Index.php 42 KB

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