12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use fast\Random;
- use think\Db;
- use \think\Log;
- use Redis;
- use app\common\library\Sms as Smslib;
- use app\common\library\Token;
- /**
- * 首页接口
- */
- class Index extends Api
- {
- protected $noNeedLogin = ['zhiyint_registration','index','contactus','tcpTest','getAppShare','getWebsiteInfo','getUserCharmRankList','getPartyHotList','searchUsers','getInviteCode','getEdition','getInviteImg','getWebsiteInfoForMini','getBankList','getSwitch','getBootAnimation', 'tencentcall', 'getversion', 'getversionZx', 'getiosversion'];
- protected $noNeedRight = ['*'];
- public function index(){
- echo 'apisuccess';
- exit;
- }
- //推荐/附近/新人
- public function nearuser()
- {
- // if(empty($this->auth->longitude) || empty($this->auth->latitude)){
- // // $this->success('success',[]);
- // $this->error('请先开启定位');
- // }
- // $type = input('type', 0, 'intval'); //类型: 0附近 1缘分
- $type = input('type', 0, 'intval'); //类型: 0推荐 1附近 2新人
- $age_id = input('age_id', 0, 'intval'); //年龄段
- // $agemin = input('agemin', 0, 'intval'); //最小年龄
- // $agemax = input('agemax', 100, 'intval'); //最大年龄
- //经过地图测算和公式推算,经度纬度 0.1即为11公里
- $map = [
- 'user.gender' => $this->auth->gender == 1 ? 0 : 1,// 查询异性
- 'user.status' => 1,
- 'user.is_kefu' => 0,
- 'user.id' => ['neq',$this->auth->id],
- // 'user.cityname' => $this->auth->cityname,
- // 'user.longitude' => ['between',[$this->auth->longitude - 0.1,$this->auth->longitude + 0.1]],
- // 'user.latitude' => ['between',[$this->auth->latitude - 0.1,$this->auth->latitude + 0.1]],
- // 'user.is_online|user.is_livebc' => 1, //完全不考虑直播与语聊的权重,只用活跃做排序
- // 'user.active_time' => ['gt',time()-86400],
- ];
- //排序
- $order = 'user.is_active desc, user.active_time desc';
- if (in_array($type,[0,1])) {
- if ($this->auth->gender == 1) {
- // $order = 'user.is_active desc, user.active_time desc, uw.get_money desc';
- $order = 'user.is_active desc, user.active_time desc';
- } else {
- // $order = 'user.is_active desc, user.active_time desc, uw.pay_money desc';
- $order = 'user.is_active desc, user.active_time desc';
- }
- }
- if ($type == 0) {
- // $map['user.cityname'] = $this->auth->cityname; //同城
- if ($this->auth->gender == 1) {
- $map['user.is_recommend'] = 1;
- }
- //$order = 'user.is_active desc, uw.pay_money desc,uw.get_money desc';
- } elseif ($type == 1) {
- // $map['user.longitude'] = ['between',[$this->auth->longitude - 0.1,$this->auth->longitude + 0.1]];
- // $map['user.latitude'] = ['between',[$this->auth->latitude - 0.1,$this->auth->latitude + 0.1]];
- } else {
- $map['user.createtime'] = ['egt', time() - 86400 * 30];
- // $order = 'user.createtime desc';
- }
- if ($age_id > 0 && $age_id < 8) {
- if ($age_id == 1) {
- $agemin = 18;
- $agemax = 25;
- } elseif ($age_id == 2) {
- $agemin = 25;
- $agemax = 30;
- } elseif ($age_id == 3) {
- $agemin = 30;
- $agemax = 35;
- } elseif ($age_id == 4) {
- $agemin = 35;
- $agemax = 40;
- } elseif ($age_id == 5) {
- $agemin = 40;
- $agemax = 45;
- } elseif ($age_id == 6) {
- $agemin = 45;
- $agemax = 50;
- } elseif ($age_id == 7) {
- $agemin = 50;
- $agemax = 200;
- }
- $map['user.birthday'] = ['between', [time() - $agemax * 31536000, time() - $agemin * 31536000]];
- }
- //dump($map);
- $field = [
- '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'
- ];
- //$list = Db::name('user')->alias('user')->field($field)->where($map)->order($order)->autopage()->select();
- $list = Db::name('user')->alias('user')->field($field)
- //->join('user_wallet uw','uw.user_id = user.id','LEFT')
- ->where($map)->order($order)->autopage()->select();
- $list = list_domain_image($list,['avatar']);
- $mt_enum_job = Db::name('enum_job'); //职业
- $mt_enum_wages = Db::name('enum_wages'); //收入
- $mt_user_wallet = Db::name('user_wallet'); //vip
- $mt_user_greet = Db::name('user_greet'); //是否打过招呼
- $mt_wealth_level = Db::name('wealth_level'); //财富等级
- $mt_area = Db::name('area'); //城市
- $time = time();
- $hometown_cityid = [];//城市ids
- $user_to_id = [];//打招呼ids
- foreach ($list as $key=>$val){
- $hometown_cityid[] = $val['hometown_cityid'];
- $user_to_id[] = $val['id'];
- }
- // 城市
- $mt_areas = $mt_area->field(['id','name'])->whereIn('id',$hometown_cityid)->select();
- $mt_areas = array_column($mt_areas ?? [],'name','id');
- // 是否打过招呼
- $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();
- $mt_user_greets = array_column($mt_user_greets ?? [],'num','user_to_id');
- // 是否是vip
- $mt_user_wallets = $mt_user_wallet->field(['id','user_id','vip_endtime','pay_money'])->whereIn('user_id',$user_to_id)->select();
- // 财富等级
- $mt_wealth_levels = $mt_wealth_level->order('id desc')->select();
- $mt_wealth_levels = array_column($mt_wealth_levels ?? [],'name','value');
- foreach($list as $key => &$v) {
- if ($this->auth->gender == 1) { //用户是男的
- $age = birthtime_to_age($v['birthday']);
- // $job = $mt_enum_job->where(['id' => $v['job_id']])->value('name');
- // $v['desc'] = $distance . ' · ' . $age . '岁';
- $v['desc'] = '';
- if ($age > 0) {
- $v['desc'] = $age . '岁';
- } else {
- $v['desc'] = '18岁';
- }
- if ($v['height']) {
- $v['desc'] .= ' | ' . $v['height'];
- }
- // if ($job) {
- // $v['desc'] .= ' · ' . $job;
- // }
- if ($type == 1) {
- // $distance = $this->calc_map_distance([$this->auth->longitude, $this->auth->latitude], [$v['longitude'], $v['latitude']]);
- // $v['desc'] .= ' | ' . $distance;
- $v['desc'] .= ' | 10km+';
- }
- } else {
- if ($type != 1) {
- $v['desc'] = $v['bio'] ?: '暂未设置个性签名';
- } else {
- $age = birthtime_to_age($v['birthday']);
- // $wages = $mt_enum_wages->where(['id' => $v['wages_id']])->value('name');
- // $v['desc'] = $distance . ' · ' . $age . '岁';
- $v['desc'] = '';
- if ($age > 0) {
- $v['desc'] = $age . '岁';
- } else {
- $v['desc'] = '18岁';
- }
- if ($v['hometown_cityid']) {
- $hometown_city = $mt_areas[$v['hometown_cityid']] ?? '';
- $hometown_city = ($hometown_city && $v['is_hideaddress'] == 0) ? $hometown_city : '';
- if ($hometown_city) {
- $v['desc'] .= ' | ' . $hometown_city;
- }
- }
- // if ($wages) {
- // $v['desc'] .= ' · ' . $wages;
- // }
- }
- }
- //查询是否打过招呼
- $count = $mt_user_greets[$v['id']] ?? 0;
- if ($count) {
- $v['is_chat'] = 1; //是否打过招呼: 1是 0否
- } else {
- $v['is_chat'] = 0; //是否打过招呼: 1是 0否
- }
- $vip_endtime = 0;
- $pay_money = 0;
- foreach ($mt_user_wallets as $kk=>$vv){
- if ($vv['user_id'] == $v['id']) {
- $vip_endtime = $vv['vip_endtime'];
- $pay_money = $vv['pay_money'];
- break;
- }
- }
- if ($vip_endtime >= $time) {
- $v['is_vip'] = 1; //是否是vip: 1是 0否
- } else {
- $v['is_vip'] = 0; //是否是vip: 1是 0否
- }
- //查询财富等级
- if (!empty($mt_wealth_levels)) {
- $name = '';
- foreach ($mt_wealth_levels as $kkk=>$vvv){
- if ($pay_money > $kkk){
- $name = $vvv;
- break;
- }
- }
- $v['wealth_level'] = $name;
- } else {
- $v['wealth_level'] = '';
- }
- }
- $this->success('success',$list);
- }
- protected function getRealIpAddr() {
- if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
- {
- $ip=$_SERVER['HTTP_CLIENT_IP'];
- }
- elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
- {
- $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
- }
- else
- {
- $ip=$_SERVER['REMOTE_ADDR'];
- }
- return $ip;
- }
- /**
- * 三方接口
- *
- */
- public function zhiyint_registration()
- {
- $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"];
- $ip = $this->getRealIpAddr();
- if(!in_array($ip,$iparr)) {
- echo json_encode(['error' => "IP not found"]); exit;
- }
- $UserId = $this->request->request("UserId",'');
- $data = json_decode(file_get_contents('php://input'), true);
- $UserId = $data['UserId'];
- if($UserId)
- {
- $times = Db::name("user")->where("username",$UserId)->value("createtime");
- if(!$times)
- {
- echo json_encode(['error' => "User ID not found"]); exit;
- }
- $data = [
- 'RegistrationTime' => date("Y-m-d H:i:s",$times)
- ];
- echo json_encode($data); exit;
- }
- $data = [
- 'error' => "User ID not found"
- ];
- echo json_encode($data);
- }
- // /**
- // * 生成不重复的随机数字字母组合
- // */
- // function getUinqueNo($length = 8) {
- // $newid = Random::build("alnum",$length);
- //// if(in_array($newid,$nos)) {
- //// $this->getUinqueNo(8);
- //// }
- // return $newid;
- // }
- /**
- * 获取用户协议等 小程序
- */
- public function getWebsiteInfoForMini() {
- $params = $this->request->request("params"); //内容
- $res = config("site.".$params);
- if($params == "boxGiftLogo") $res = $this->httpurl(config("site.".$params));
- $this->success("获取成功!",$res);
- }
- /**
- * 联系我们
- */
- public function contactus() {
- $list = \app\common\model\Config::where(["group"=>"basic","name"=>["in",["email","mobile"]]])->select();
- $data = [];
- foreach($list as $k => $v) {
- $v["name"] == "email" && $data["email"] = $v["value"];
- $v["name"] == "mobile" && $data["mobile"] = $v["value"];
- }
- $this->success("获取成功!",$data);
- }
- /*
- * 获取系统消息列表
- */
- public function getMessage() {
- $page = $this->request->request('page',1); // 分页
- $pageNum = $this->request->request('pageNum',10); // 分页
- // 分页搜索构建
- $pageStart = ($page-1)*$pageNum;
- $flag = $this->request->request("flag",1,"intval"); //标识:1=只取一条,0=全部
- $user_id = $this->auth->id;
- $obj = \app\common\model\Message::where(["user_id"=>$user_id])->order("createtime","desc")->limit($pageStart,$pageNum);
- if($flag == 1) {
- $list = $obj->find();
- $list || $list = [];
- $list && $list["createtime"] = $this->get_last_time($list["createtime"]);
- } else {
- $list = $obj->select();
- if($list) foreach($list as $k => &$v) {
- $v["createtime"] = $this->get_last_time($v["createtime"]);
- }
- }
- $this->success("获取成功!",$list);
- }
- /**
- * 删除系统消息
- */
- public function delMessage() {
- $id = $this->request->request("id",0,"intval"); //消息ID
- if($id <= 0) {
- $this->error("参数传入错误!");
- }
- $res = \app\common\model\Message::where(["id"=>$id,"user_id"=>$this->auth->id])->delete();
- if($res) {
- $this->success("删除成功!");
- } else {
- $this->error("删除失败!");
- }
- }
- /**
- * 获取主播魅力值排行
- */
- public function getUserCharmRankList() {
- $time = $this->request->request("time",0,"intval"); //时间筛选 1=小时榜,2=今日榜,3=本周榜,4=月榜
- if(!in_array($time,[1,2,3,4])) {
- $this->error("参数传入错误!");
- }
- $hour = strtotime(date("Y-m-d H:00:00"));
- $today = strtotime(date("Y-m-d 00:00:00"));
- $weekend = strtotime('monday this week');
- // $weekend = mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y"));
- $month = strtotime(date("Y-m-01 00:00:00"));
- // 剩余时间
- $thistime = time();
- switch ($time) {
- case 1:
- $redtime = 3600-($thistime - $hour);
- break;
- case 2:
- $redtime = 3600*24-($thistime - $today);
- break;
- case 3:
- $redtime = 3600*24*7-($thistime - $weekend);
- break;
- case 4:
- $monthend = mktime(23,59,59,date("m"),date("t"),date("Y"));
- $redtime = ($monthend - $month)-($thistime - $month);
- break;
- }
- $timeArr = [1=>$hour,2=>$today,3=>$weekend,4=>$month];
- $where = [];
- $where["a.createtime"] = ["gt",$timeArr[$time]];
- $list = \app\common\model\UserCharmRank::alias("a")
- ->field("p.id,sum(a.charm) as charm,u.avatar,u.nickname,u.gender,u.level")
- ->where($where)
- ->join("hx_user u","u.id = a.user_id")
- ->join("hx_party p","p.user_id = a.user_id")
- ->group("a.user_id")
- ->order("charm","desc")
- ->limit(100)
- ->select();
- $data = [];
- $data["redtime"] = $redtime;
- $data["data"] = $list;
- $this->success("获取成功!",$data);
- }
- /**
- * 获取派对热度排序
- */
- public function getPartyHotList() {
- // 剩余时间
- $thistime = time();
- $hour = strtotime(date("Y-m-d H:00:00"));
- $redtime = 3600-($thistime - $hour);
- $where = [];
- $where["a.createtime"] = ["gt",$hour];
- $where["p.room_type"] = 1;
- $list = \app\common\model\PartyHot::alias("a")
- ->field("sum(a.hot) as hot,p.id,u.avatar,p.party_name,p.party_logo")
- ->where($where)
- ->join("hx_party p","p.id = a.party_id")
- ->join("hx_user u","u.id = p.user_id")
- ->group("a.party_id")
- ->order("hot","desc")
- ->limit(100)
- ->select();
- $data = [];
- $data["redtime"] = $redtime;
- $data["data"] = $list;
- $this->success("获取成功!",$data);
- }
- /**
- * 首页搜索
- */
- public function searchUsers() {
- $search = $this->request->request("search"); //关键词筛选
- if(!$search) {
- $this->error("请输入搜索内容!");
- }
- // 搜索派对
- global $whereOr;
- $where = [];
- $whereOr["party_id"] = $search;
- $whereOr["party_name"] = ["like","%$search%"];
- $where["room_type"] = 1;
- $partyList = \app\common\model\Party::field("id,party_logo,party_id,party_name")
- ->where($where)
- ->where(function ($query) {
- global $whereOr;
- $query->whereOr($whereOr);
- })->order("party_hot","desc")->select();
- // 搜索直播间
- global $whereOrlive;
- $where = [];
- $whereOrlive["party_id"] = $search;
- $whereOrlive["party_name"] = ["like","%$search%"];
- $where["room_type"] = 2;
- $liveList = \app\common\model\Party::field("id,party_logo,party_id,party_name")
- ->where($where)
- ->where(function ($query) {
- global $whereOrlive;
- $query->whereOr($whereOrlive);
- })
- ->order("party_hot","desc")->select();
- // 相关用户
- $where = [];
- $where["a.nickname"] = ["like","%$search%"];
- $where["a.u_id"] = $search;
- $userList = \app\common\model\User::alias("a")->field("id,avatar,nickname,u_id,f.fans")
- ->join("hx_view_fans f","f.user_id = a.id","left")
- ->order("a.is_online,a.noble,a.level")
- ->whereOr($where)->select();
- $res = [];
- $res["partylist"] = $partyList;
- $res["livelist"] = $liveList;
- $res["userlist"] = $userList;
- $this->success("获取成功!",$res);
- }
- /**
- * 获取下载二维码和邀请码
- */
- public function getInviteCode() {
- // 获取二维码
- $qrcode = $this->httpurl(config("site.qrcode"));
- $miniqrcode = $this->httpurl(config("site.miniqrcode"));
- // 获取用户邀请码
- $inviteCode = \app\common\model\User::where(["id"=>$this->auth->id])->value("invite_no");
- $host = $_SERVER["REQUEST_SCHEME"]."://".$_SERVER["HTTP_HOST"];
- $downlowdLink = $host."/index/index/appJump?t=wlt".rand(10,999).Random::alpha(8);
- $this->success("获取成功!",["qrcode"=>$qrcode,"miniqrcode"=>$miniqrcode,"inviteCode"=>$inviteCode,"downlowdLink"=>$downlowdLink]);
- }
- /**
- * 获取app分享海报
- */
- public function getAppShare() {
- $this->success("获取成功!",["url"=>$this->httpurl(config("site.appShare"))]);
- }
- /**
- * 获取开机动画(暂时关闭)
- */
- private function getBootAnimation() {
- $this->success("获取成功!",["url"=>$this->httpurl(config("site.bootAnimationUrl")),"time"=>floatval(config("site.bootAnimationTime"))]);
- }
- /**
- * 获取版本更新信息
- */
- public function getEdition() {
- // 获取二维码
- $is_force = config("site.is_force");
- $apkUrl = config("site.apk_url");
- $apkName = config("site.apkName");
- $desc = config("site.desc");
- $versionCode = config("site.versionCode");
- $this->success("获取成功!",["versionCode"=>$versionCode,"isForceUpdate"=>$is_force,"apkUrl"=>$apkUrl,"apkName"=>$apkName,"desc"=>$desc]);
- }
- /**
- * 获取邀请图片
- */
- public function getInviteImg() {
- $plat = $this->request->request("plat",1); //平台:1=小程序,2=app
- if(!in_array($plat,[1,2])) $this->error("参数错误");
- // 获取用户的邀请码
- $invitecode = \app\common\model\User::where(["id"=>$this->auth->id])->value("invite_no");
- // 文字图片合成
- $bigImgPath = $this->httpurlLocal('/assets/img/inviteimg.jpeg');
- $img = imagecreatefromstring(file_get_contents($bigImgPath));
- //字体文件
- $font = realpath('./assets/fonts/lato/lato-black.ttf');
- //字体颜色(RGB)
- $black = imagecolorallocate($img, 217, 76, 41);
- //字体大小
- $fontSize = 30;
- //旋转角度
- $circleSize = 0;
- //左边距
- $left = 275;
- //上边距
- $top = 540;
- imagefttext($img, $fontSize, $circleSize, $left, $top, $black, $font, $invitecode);
- $filename = date("YmdH").".jpeg";
- $path = "/uploads/qrcode/".$filename;
- $file = $_SERVER['DOCUMENT_ROOT'] . $path;//打开文件准备写入
- list($bgWidth, $bgHight, $bgType) = getimagesize($bigImgPath);
- switch ($bgType) {
- case 1://gif
- header('Content-Type:image/gif');
- imagegif($img,$file);
- break;
- case 2://jpg
- header('Content-Type:image/jpg');
- imagejpeg($img,$file);
- break;
- case 3://jpg
- header('Content-Type:image/png');
- imagepng($img,$file);
- break;
- default:
- break;
- }
- //销毁照片
- imagedestroy($img);
- // 图片和二维码合成
- $qrcode = $plat == 1 ? config("site.miniqrcode"):config("site.qrcode");
- $background = $file;
- $target = $this->httpurl($qrcode);
- $background_iamge = imagecreatefromstring(file_get_contents($background));
- $target_image = imagecreatefromstring(file_get_contents($target));
- list($target_width, $target_height, $target_type) = getimagesize($target);
- imagecopymerge($background_iamge , $target_image , 250, 700, 0, 0, $target_width, $target_height, 100);
- list($background_width, $background_height, $background_type) = getimagesize($background);
- switch ($background_type) {
- case 1://gif
- header('Content-Type:image/gif');
- imagegif($background_iamge,$file);
- break;
- case 2://jpg
- header('Content-Type:image/jpg');
- imagejpeg($background_iamge,$file);
- break;
- case 3://jpg
- header('Content-Type:image/png');
- imagepng($background_iamge,$file);
- break;
- default:
- break;
- }
- $savepath = $this->httpurlLocal($path);
- $this->success("获取成功!",$savepath);
- }
- /**
- * 获取银行列表
- */
- public function getBankList() {
- $this->success("获取成功!",["banklist"=>\app\common\model\Bank::select()]);
- }
- /**
- * 获取开关配置
- */
- public function getSwitch() {
- $this->success("获取成功!",["switch"=>config("site.switch")]);
- }
- /**
- * 评论时间转换
- * @param null $time
- * @return false|string
- */
- private function get_last_time($time = NULL) {
- $text = '';
- $time = $time === NULL || $time > time() ? time() : intval($time);
- $t = time() - $time; //时间差 (秒)
- $y = date('Y', $time)-date('Y', time());//是否跨年
- switch($t){
- case $t == 0:
- $text = '刚刚';
- break;
- case $t < 60:
- $text = $t . '秒前'; // 一分钟内
- break;
- case $t < 60 * 60:
- $text = floor($t / 60) . '分钟前'; //一小时内
- break;
- case $t < 60 * 60 * 24:
- $text = floor($t / (60 * 60)) . '小时前'; // 一天内
- break;
- case $t < 60 * 60 * 24 * 3:
- $text = floor($time/(60*60*24)) ==1 ?'昨天 ' . date('H:i', $time) : '前天 ' . date('H:i', $time) ; //昨天和前天
- break;
- case $t < 60 * 60 * 24 * 30:
- $text = date('m月d日 H:i', $time); //一个月内
- break;
- case $t < 60 * 60 * 24 * 365&&$y==0:
- $text = date('m月d日', $time); //一年内
- break;
- default:
- $text = date('Y年m月d日', $time); //一年以前
- break;
- }
- return $text;
- }
- //轮播图
- public function banner() {
- $type = input('type', 0, 'intval'); //类型:0=交友轮播图,1=动态轮播图
- $list = Db::name('banner')->field('id, title, image, url')->where(['status' => 1, 'type' => $type])->order('weigh', 'desc')->select();
- $list = list_domain_image($list, ['image']);
- $this->success('轮播图', $list);
- }
- //谁看过我汇总
- public function visitlist(){
- $time = Db::name('user_visit_time')->where(['user_id' => $this->auth->id])->value('visittime');
- $where = [];
- if ($time) {
- $where['updatetime'] = ['gt', $time];
- }
- $list = [];
- $count = Db::name('user_visit')->where(['to_uid' => $this->auth->id])->where($where)->count('id');
- if ($count) {
- $uid_list = Db::name('user_visit')->field('uid')->where(['to_uid' => $this->auth->id])->where($where)->limit(9)->column('uid');
- $mt_user = Db::name('user');
- foreach ($uid_list as &$v) {
- $avatar = $mt_user->where(['id' => $v])->value('avatar');
- $list[] = one_domain_image($avatar);
- }
- }
- $data['count'] = $count;
- $data['list'] = $list;
- $this->success('success',$data);
- }
- //筛选年龄段
- public function agerange() {
- $list = [
- [
- 'id' => 0,
- 'title' => '不限'
- ],
- [
- 'id' => 1,
- 'title' => '18-25岁'
- ],
- [
- 'id' => 2,
- 'title' => '25-30岁'
- ],
- [
- 'id' => 3,
- 'title' => '30-35岁'
- ],
- [
- 'id' => 4,
- 'title' => '35-40岁'
- ],
- [
- 'id' => 5,
- 'title' => '40-45岁'
- ],
- [
- 'id' => 6,
- 'title' => '45-50岁'
- ],
- [
- 'id' => 7,
- 'title' => '50岁以上'
- ]
- ];
- $this->success('筛选年龄段', $list);
- }
- /**
- * calc_map_distance() , 根据地图上的两个点各自的x,y坐标,计算出2点之间的直线距离
- * @param array $point_1 第1个点的x,y坐标 array( 101 , 202 )
- * @param array $point_2 第2个点的x,y坐标 array( 101 , 202 )
- * @param bool $calc_as_string 是否计算为字符串公里距离 , 如果未否返回数字
- * @return float | false | string
- */
- private function calc_map_distance( $point_1=array( ) , $point_2=array( ) , $calc_as_string=false ) {
- if( empty( $point_1 ) || empty( $point_2 ) ){
- return false;
- }
- // 经纬度不存在,或者经纬度超过最大范围 +-180 , +-90 ,返回false
- $p1_x = $point_1[0];
- $p1_y = $point_1[1];
- $p2_x = $point_2[0];
- $p2_y = $point_2[1];
- if(
- $p1_x < -180 || $p1_x > 180
- || $p2_x < -180 || $p2_x > 180
- || $p1_y < -90 || $p1_y > 90
- || $p2_y < -90 || $p2_y > 90
- || $p1_x == '' || $p1_y == ''
- || $p2_x == '' || $p2_y == ''
- ){
- return '距离未知';
- }
- // 根据2点各自的坐标,计算2点之间直线距离的公式
- $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);
- // 是否计算为字符串公里距离
- if( !$calc_as_string ){
- return (string)round( $distance / 1000 , 1 ) . 'km';
- }
- // 如果计算为字符串公里距离
- if( $distance / 1000 > 1 ){
- $k = (string)round( $distance / 1000 , 1 );
- $m = (string)$distance % 1000 ;
- // $distance = "{$k}公里{$m}米";
- $distance = "{$k}km";
- }
- else{
- $distance = "{$distance}m";
- }
- return $distance;
- }
- //打招呼/搭讪
- public function greet() {
- if ($this->auth->gender == 0 && $this->auth->real_status != 1 && $this->auth->idcard_status != 1) {
- $this->error('请先完成实名认证或真人认证');
- }
- $other_uid = input('user_id', 0, 'intval');
- if(!$other_uid) {
- $this->error(__('Invalid parameters'));
- }
- if($other_uid == $this->auth->id){
- $this->error('这是您自己');
- }
- $checkuser = Db::name('user')->find($other_uid);
- if(empty($checkuser)) {
- $this->error('此用户不存在');
- }
- $map = [
- 'user_id' => $this->auth->id,
- 'user_to_id' => $other_uid,
- ];
- // 取消限制 2023年12月14日 18点47分
- // $check = Db::name('user_greet')->where($map)->find();
- // if($check){
- // $this->error('已经打过招呼了');
- // }
- $map['createtime'] = time();
- Db::startTrans();
- $id = Db::name('user_greet')->insertGetId($map);
- if (!$id) {
- Db::rollback();
- $this->error('您的网络开小差了~');
- }
- //tag任务赠送金币
- //搭讪奖励
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,24);
- if($task_rs === false){
- Db::rollback();
- $this->error('完成任务赠送奖励失败');
- }
- Db::commit();
- $gift_greet = Db::name('gift_greet')->find();
- if ($gift_greet) {
- $gift_greet['special'] = one_domain_image($gift_greet['special']);
- $gift_greet['image'] = one_domain_image($gift_greet['image']);
- } else {
- $gift_greet = (object)[];
- }
- $this->success('操作成功', $gift_greet);
- }
-
- //女号私信异性完成任务
- public function girlchattask() {
- if ($this->auth->gender != 0) { //只有女生可以
- $this->error('您的网络开小差啦~');
- }
- //检测用户
- $to_user_id = input_post('to_user_id');
- $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();
- if(!$to_user_info){
- $this->error('不存在的用户');
- }
- if ($to_user_info['is_kefu'] == 1 || $this->auth->is_kefu == 1) { //我是客服或者对方是客服
- $this->success('success');
- }
- if ($to_user_info['gender'] != 1) {
- $this->error('性别异常~');
- }
- $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,23);
- if($task_rs === false){
- $this->error('完成任务赠送奖励失败');
- }
- $this->success('success');
- }
- //腾讯内容审核回调方法
- public function tencentcall() {
- $content = file_get_contents('php://input');
- $content = json_decode($content, true);
- error_log(print_r($content, 1) . PHP_EOL, 3, './tencentcall3.txt');
- if (isset($content['Scene']) && $content['CtxcbResult'] == 1) { //语音文件: 只返回违规的数据; 处理方式: 撤回
- $tenim = new Tenim;
- $rs = $tenim->withdraw_message($content['From_Account'], $content['ContactItem']['To_Account'], $content['MsgID']);
- // error_log(print_r($rs, 1) . PHP_EOL, 3, './tencentcall4.txt');
- } elseif (isset($content['TaskId'])) { //音视频通话: 返回所有数据; 处理方式: 强制退出im, 清空token
- if ($content['Status'] == 'RUNNING') {
- //该字段用于返回所查询内容的任务状态。取值:FINISH(任务已完成)、PENDING (任务等待中)、RUNNING (任务进行中)、ERROR (任务出错)、CANCELLED (任务已取消)。
- if ($content['ImageSegments']) { //图片(视频)审核结果
- $image_info = $content['ImageSegments'][0]['Result'];
- if ($image_info['Label'] != 'Normal') {
- //该字段用于返回检测结果所对应的恶意标签。返回值:Porn:色情,Abuse:谩骂,Ad:广告,Custom:自定义违规;以及其他令人反感、不安全或不适宜的内容类型。
- $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
- //获取违规用户id
- $url = explode('?', $url);
- $url = $url[0];
- $user_id_url = explode('/', $url);
- $user_id_url = $user_id_url[count($user_id_url) - 1];
- $user_id_arr = explode('_', $user_id_url);
- $user_id = $user_id_arr[2];
- //退出im
- $tenIm = new Tenim();
- $tenIm->loginoutim($user_id);
- //清空token
- Token::clear($user_id);
- $tiaoshi = $user_id . '---' . $content['TaskId'] . '---' .$image_info['Label'] .'---'. date('Y-m-d H:i:s');
- error_log(print_r($tiaoshi, 1) . PHP_EOL, 3, './dayin1.txt');
- }
- } elseif ($content['AudioSegments']) { //音频审核结果
- $audio_info = $content['AudioSegments'][0]['Result'];
- if ($audio_info['Label'] != 'Normal') {
- //该字段用于返回检测结果所对应的恶意标签。返回值:Porn:色情,Abuse:谩骂,Ad:广告,Custom:自定义违规;以及其他令人反感、不安全或不适宜的内容类型。
- $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
- //获取违规用户id
- $url = explode('?', $url);
- $url = $url[0];
- $user_id_url = explode('/', $url);
- $user_id_url = $user_id_url[count($user_id_url) - 1];
- $user_id_arr = explode('_', $user_id_url);
- $user_id = $user_id_arr[2];
- //退出im
- $tenIm = new Tenim();
- $tenIm->loginoutim($user_id);
- //清空token
- Token::clear($user_id);
- $tiaoshi = $user_id . '---' . $content['TaskId'] . '---' .$audio_info['Label'] .'---'. date('Y-m-d H:i:s');
- error_log(print_r($tiaoshi, 1) . PHP_EOL, 3, './dayin2.txt');
- }
- }
- }
- }
- }
-
- //头条
- public function headlines() {
- $time = strtotime(date('Y-m-d', time()));
- //聊天送礼物
- $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();
- //动态送礼物
- $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();
- $list = array_merge($list1, $list2);
- if ($list) {
- $mt_user = Db::name('user');
- foreach ($list as &$v) {
- $user_info= $mt_user->field('nickname, avatar')->where(['id' => $v['user_id']])->find();
- $v['from_nickname'] = '有缘人';//$user_info['nickname'];
- $v['avatar'] = one_domain_image($user_info['avatar']);
- $v['to_nickname'] = '有缘人';//$mt_user->where(['id' => $v['user_to_id']])->value('nickname');
- }
- }
- $this->success('头条', $list);
- }
- //查询每天弹出搭讪框次数
- public function freegreetnum() {
- $user = $this->auth->getUser();
- if (isset($user['is_kefu']) && $user['is_kefu'] == 1){
- $data['free_greet_num'] = 0;
- $data['vip_free_greet_num'] = 0;
- $data['boy_free_greet_num'] = 0;
- $data['boy_vip_free_greet_num'] = 0;
- }else{
- //非会员每天弹出搭讪框次数
- $data['free_greet_num'] = config('site.free_greet_num') > 0 ? config('site.free_greet_num') : 5;
- //vip每天弹出搭讪框次数
- $data['vip_free_greet_num'] = config('site.vip_free_greet_num') > 0 ? config('site.vip_free_greet_num') : 5;
- // 男性 非会员每天弹出搭讪框次数
- $data['boy_free_greet_num'] = config('site.boy_free_greet_num') > 0 ? config('site.boy_free_greet_num') : 1;
- // 男性 vip每天弹出搭讪框次数
- $data['boy_vip_free_greet_num'] = config('site.boy_vip_free_greet_num') > 0 ? config('site.boy_vip_free_greet_num') : 1;
- }
- $this->success('success', $data);
- }
-
- /**
- * 男性打招呼内容
- * @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function greetBoy()
- {
- $data = Db::name('user_greet_boy')->select();
- $this->success('success', $data);
- }
- //首页顶部分类名称
- public function typename() {
- $typename = config('site.typename');
- $typename = explode(',', $typename);
- $data[] = $typename[0] ? : '推荐';
- $data[] = $typename[1] ? : '附近';
- $data[] = $typename[2] ? : '新人';
- $this->success('sussess', $data);
- }
- //获取版本更新信息
- public function getversion() {
- // 获取二维码
- $is_force = config("site.is_force"); //是否强制更新 1是 0否
- $apk_url = config("site.apk_url"); //下载链接
- $apk_name = config("site.apk_name"); //apk更新标题
- $apk_desc = config("site.apk_desc"); //apk更新描述
- $version_code = config("site.version_code"); //版本迭代号
- $data['is_force'] = $is_force;
- $data['apk_url'] = $apk_url;
- $data['apk_name'] = $apk_name;
- $data['apk_desc'] = $apk_desc;
- $data['version_code'] = $version_code;
- $this->success('Success', $data);
- }
-
- // 获取版本更新信息(知心app)
- public function getversionZx() {
- // 获取二维码
- $is_force = config("site.is_force_zx"); //是否强制更新 1是 0否
- $apk_url = config("site.apk_url_zx"); //下载链接
- $apk_name = config("site.apk_name_zx"); //apk更新标题
- $apk_desc = config("site.apk_desc_zx"); //apk更新描述
- $version_code = config("site.version_code_zx"); //版本迭代号
- $data['is_force'] = $is_force;
- $data['apk_url'] = $apk_url;
- $data['apk_name'] = str_replace('知音','知心',$apk_name);
- $data['apk_desc'] = $apk_desc;
- $data['version_code'] = $version_code;
- $this->success('Success', $data);
- }
- //获取ios版本更新信息
- public function getiosversion() {
- // 获取二维码
- $is_force = config("site.ios_is_force"); //是否强制更新 1是 0否
- $apk_url = config("site.ios_apk_url"); //下载链接
- $apk_name = config("site.ios_apk_name"); //apk更新标题
- $apk_desc = config("site.ios_apk_desc"); //apk更新描述
- $version_code = config("site.ios_version_code"); //版本迭代号
- $data['is_force'] = $is_force;
- $data['apk_url'] = $apk_url;
- $data['apk_name'] = $apk_name;
- $data['apk_desc'] = $apk_desc;
- $data['version_code'] = $version_code;
- $this->success('Success', $data);
- }
- }
|