Index.php 42 KB

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