Index.php 34 KB

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