Index.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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 = ['index','getAppShare','getWebsiteInfo','getInviteCode','getEdition','getInviteImg','tencentcall', 'getversion', 'getiosversion'];
  16. protected $noNeedRight = ['*'];
  17. public function index(){
  18. echo 'apisuccess';
  19. exit;
  20. }
  21. //首页。推荐/附近/新人。三个用户列表
  22. public function nearuser()
  23. {
  24. // if(empty($this->auth->longitude) || empty($this->auth->latitude)){
  25. // // $this->success('success',[]);
  26. // $this->error('请先开启定位');
  27. // }
  28. // $type = input('type', 0, 'intval'); //类型: 0附近 1缘分
  29. $type = input('type', 0, 'intval'); //类型: 0推荐 1附近 2新人
  30. $age_id = input('age_id', 0, 'intval'); //年龄段
  31. // $agemin = input('agemin', 0, 'intval'); //最小年龄
  32. // $agemax = input('agemax', 100, 'intval'); //最大年龄
  33. //经过地图测算和公式推算,经度纬度 0.1即为11公里
  34. $map = [
  35. 'user.gender' => $this->auth->gender == 1 ? 0 : 1,// 查询异性
  36. 'user.status' => 1,
  37. 'user.is_kefu' => 0,
  38. 'user.id' => ['neq',$this->auth->id],
  39. // 'user.cityname' => $this->auth->cityname,
  40. // 'user.longitude' => ['between',[$this->auth->longitude - 0.1,$this->auth->longitude + 0.1]],
  41. // 'user.latitude' => ['between',[$this->auth->latitude - 0.1,$this->auth->latitude + 0.1]],
  42. // 'user.is_online|user.is_livebc' => 1, //完全不考虑直播与语聊的权重,只用活跃做排序
  43. ];
  44. //排序
  45. $order = 'user.is_active desc, user.logintime desc';
  46. if (in_array($type,[0,1])) {
  47. if ($this->auth->gender == 1) {
  48. $order = 'user.is_active desc, user.logintime desc';
  49. } else {
  50. $order = 'user.is_active desc, user.logintime desc';
  51. }
  52. }
  53. if ($type == 0) {
  54. // $map['user.cityname'] = $this->auth->cityname; //同城
  55. if ($this->auth->gender == 1) {
  56. $map['user.is_recommend'] = 1;
  57. }
  58. //$order = 'user.is_active desc, uw.pay_money desc,uw.get_money desc';
  59. } elseif ($type == 1) {
  60. // $map['user.longitude'] = ['between',[$this->auth->longitude - 0.1,$this->auth->longitude + 0.1]];
  61. // $map['user.latitude'] = ['between',[$this->auth->latitude - 0.1,$this->auth->latitude + 0.1]];
  62. } else {
  63. $map['user.createtime'] = ['egt', time() - 86400 * 30];
  64. // $order = 'user.createtime desc';
  65. }
  66. if ($age_id > 0 && $age_id < 8) {
  67. if ($age_id == 1) {
  68. $agemin = 18;
  69. $agemax = 25;
  70. } elseif ($age_id == 2) {
  71. $agemin = 25;
  72. $agemax = 30;
  73. } elseif ($age_id == 3) {
  74. $agemin = 30;
  75. $agemax = 35;
  76. } elseif ($age_id == 4) {
  77. $agemin = 35;
  78. $agemax = 40;
  79. } elseif ($age_id == 5) {
  80. $agemin = 40;
  81. $agemax = 45;
  82. } elseif ($age_id == 6) {
  83. $agemin = 45;
  84. $agemax = 50;
  85. } elseif ($age_id == 7) {
  86. $agemin = 50;
  87. $agemax = 200;
  88. }
  89. $map['user.birthday'] = ['between', [time() - $agemax * 31536000, time() - $agemin * 31536000]];
  90. }
  91. //dump($map);
  92. $field = [
  93. 'user.id','user.nickname','user.birthday','user.height','user.longitude','user.latitude','user.avatar','user.bio','user.gender','user.idcard_status', 'user.real_status', 'user.job', 'user.is_active', 'user.wages', 'user.is_recommend', 'user.cityname', 'user.hometown_cityid', 'user.is_hideaddress'
  94. ];
  95. //$list = Db::name('user')->alias('user')->field($field)->where($map)->order($order)->autopage()->select();
  96. $list = Db::name('user')->alias('user')->field($field)
  97. //->join('user_wallet uw','uw.user_id = user.id','LEFT')
  98. ->where($map)->order($order)->autopage()->select();
  99. $list = list_domain_image($list,['avatar']);
  100. // $mt_enum_job = Db::name('enum_job'); //职业
  101. // $mt_enum_wages = Db::name('enum_wages'); //收入
  102. $mt_user_wallet = Db::name('user_wallet'); //vip
  103. $mt_user_greet = Db::name('user_greet'); //是否打过招呼
  104. // $mt_wealth_level = Db::name('wealth_level'); //财富等级
  105. // $mt_charm_level = Db::name('charm_level'); //魅力等级
  106. $mt_area = Db::name('area'); //城市
  107. $time = time();
  108. $hometown_cityid = [];//城市ids
  109. $user_to_id = [];//打招呼ids
  110. foreach ($list as $key=>$val){
  111. $hometown_cityid[] = $val['hometown_cityid'];
  112. $user_to_id[] = $val['id'];
  113. }
  114. // 城市
  115. $mt_areas = $mt_area->field(['id','name'])->whereIn('id',$hometown_cityid)->select();
  116. $mt_areas = array_column($mt_areas ?? [],'name','id');
  117. // 是否打过招呼
  118. $mt_user_greets = $mt_user_greet->field(['user_to_id','count(id) as num'])->where('user_id', $this->auth->id)->whereIn('user_to_id',$user_to_id)->group('user_to_id')->select();
  119. $mt_user_greets = array_column($mt_user_greets ?? [],'num','user_to_id');
  120. // 是否是vip
  121. $mt_user_wallets = $mt_user_wallet->field(['id','user_id','vip_endtime','pay_money'])->whereIn('user_id',$user_to_id)->select();
  122. // 财富等级
  123. // $mt_wealth_levels = $mt_wealth_level->order('id desc')->column('value,image');
  124. // 魅力等级
  125. // $mt_charm_levels = $mt_charm_level->order('id desc')->column('value,image');
  126. foreach($list as $key => &$v) {
  127. if ($this->auth->gender == 1) { //用户是男的
  128. $age = birthtime_to_age($v['birthday']);
  129. // $job = $mt_enum_job->where(['id' => $v['job_id']])->value('name');
  130. // $v['desc'] = $distance . ' · ' . $age . '岁';
  131. $v['desc'] = '';
  132. if ($age > 0) {
  133. $v['desc'] = $age . '岁';
  134. } else {
  135. $v['desc'] = '18岁';
  136. }
  137. if ($v['height']) {
  138. $v['desc'] .= ' | ' . $v['height'];
  139. }
  140. // if ($job) {
  141. // $v['desc'] .= ' · ' . $job;
  142. // }
  143. if ($type == 1) {
  144. // $distance = $this->calc_map_distance([$this->auth->longitude, $this->auth->latitude], [$v['longitude'], $v['latitude']]);
  145. // $v['desc'] .= ' | ' . $distance;
  146. $v['desc'] .= ' | 10km+';
  147. }
  148. } else {
  149. if ($type != 1) {
  150. $v['desc'] = $v['bio'] ?: '暂未设置个性签名';
  151. } else {
  152. $age = birthtime_to_age($v['birthday']);
  153. // $wages = $mt_enum_wages->where(['id' => $v['wages_id']])->value('name');
  154. // $v['desc'] = $distance . ' · ' . $age . '岁';
  155. $v['desc'] = '';
  156. if ($age > 0) {
  157. $v['desc'] = $age . '岁';
  158. } else {
  159. $v['desc'] = '18岁';
  160. }
  161. if ($v['hometown_cityid']) {
  162. $hometown_city = $mt_areas[$v['hometown_cityid']] ?? '';
  163. $hometown_city = ($hometown_city && $v['is_hideaddress'] == 0) ? $hometown_city : '';
  164. if ($hometown_city) {
  165. $v['desc'] .= ' | ' . $hometown_city;
  166. }
  167. }
  168. // if ($wages) {
  169. // $v['desc'] .= ' · ' . $wages;
  170. // }
  171. }
  172. }
  173. //查询是否打过招呼
  174. $count = $mt_user_greets[$v['id']] ?? 0;
  175. if ($count) {
  176. $v['is_chat'] = 1; //是否打过招呼: 1是 0否
  177. } else {
  178. $v['is_chat'] = 0; //是否打过招呼: 1是 0否
  179. }
  180. $vip_endtime = 0;
  181. $pay_money = 0;
  182. foreach ($mt_user_wallets as $kk=>$vv){
  183. if ($vv['user_id'] == $v['id']) {
  184. $vip_endtime = $vv['vip_endtime'];
  185. $pay_money = $vv['pay_money'];
  186. break;
  187. }
  188. }
  189. if ($vip_endtime >= $time) {
  190. $v['is_vip'] = 1; //是否是vip: 1是 0否
  191. } else {
  192. $v['is_vip'] = 0; //是否是vip: 1是 0否
  193. }
  194. //查询财富等级
  195. /*if (!empty($mt_wealth_levels)) {
  196. $name = '';
  197. foreach ($mt_wealth_levels as $kkk=>$vvv){
  198. if ($pay_money > $kkk){
  199. $name = localpath_to_netpath($vvv);
  200. break;
  201. }
  202. }
  203. $v['wealth_level'] = $name;
  204. } else {
  205. $v['wealth_level'] = '';
  206. }*/
  207. //查询魅力等级
  208. /*if (!empty($mt_charm_levels)) {
  209. $name = '';
  210. foreach ($mt_charm_levels as $kkk=>$vvv){
  211. if ($pay_money > $kkk){
  212. $name = localpath_to_netpath($vvv);
  213. break;
  214. }
  215. }
  216. $v['charm_level'] = $name;
  217. } else {
  218. $v['charm_level'] = '';
  219. }*/
  220. }
  221. $this->success('success',$list);
  222. }
  223. //轮播图
  224. public function banner() {
  225. $type = input('type', 0, 'intval'); //类型:0=交友轮播图,1=动态轮播图
  226. $list = Db::name('banner')->field('id, title, image, url')->where(['status' => 1, 'type' => $type])->order('weigh', 'desc')->select();
  227. $list = list_domain_image($list, ['image']);
  228. $this->success('轮播图', $list);
  229. }
  230. //筛选年龄段
  231. public function agerange() {
  232. $list = [
  233. [
  234. 'id' => 0,
  235. 'title' => '不限'
  236. ],
  237. [
  238. 'id' => 1,
  239. 'title' => '18-25岁'
  240. ],
  241. [
  242. 'id' => 2,
  243. 'title' => '25-30岁'
  244. ],
  245. [
  246. 'id' => 3,
  247. 'title' => '30-35岁'
  248. ],
  249. [
  250. 'id' => 4,
  251. 'title' => '35-40岁'
  252. ],
  253. [
  254. 'id' => 5,
  255. 'title' => '40-45岁'
  256. ],
  257. [
  258. 'id' => 6,
  259. 'title' => '45-50岁'
  260. ],
  261. [
  262. 'id' => 7,
  263. 'title' => '50岁以上'
  264. ]
  265. ];
  266. $this->success('筛选年龄段', $list);
  267. }
  268. /**
  269. * calc_map_distance() , 根据地图上的两个点各自的x,y坐标,计算出2点之间的直线距离
  270. * @param array $point_1 第1个点的x,y坐标 array( 101 , 202 )
  271. * @param array $point_2 第2个点的x,y坐标 array( 101 , 202 )
  272. * @param bool $calc_as_string 是否计算为字符串公里距离 , 如果未否返回数字
  273. * @return float | false | string
  274. */
  275. private function calc_map_distance( $point_1=array( ) , $point_2=array( ) , $calc_as_string=false ) {
  276. if( empty( $point_1 ) || empty( $point_2 ) ){
  277. return false;
  278. }
  279. // 经纬度不存在,或者经纬度超过最大范围 +-180 , +-90 ,返回false
  280. $p1_x = $point_1[0];
  281. $p1_y = $point_1[1];
  282. $p2_x = $point_2[0];
  283. $p2_y = $point_2[1];
  284. if(
  285. $p1_x < -180 || $p1_x > 180
  286. || $p2_x < -180 || $p2_x > 180
  287. || $p1_y < -90 || $p1_y > 90
  288. || $p2_y < -90 || $p2_y > 90
  289. || $p1_x == '' || $p1_y == ''
  290. || $p2_x == '' || $p2_y == ''
  291. ){
  292. return '距离未知';
  293. }
  294. // 根据2点各自的坐标,计算2点之间直线距离的公式
  295. $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);
  296. // 是否计算为字符串公里距离
  297. if( !$calc_as_string ){
  298. return (string)round( $distance / 1000 , 1 ) . 'km';
  299. }
  300. // 如果计算为字符串公里距离
  301. if( $distance / 1000 > 1 ){
  302. $k = (string)round( $distance / 1000 , 1 );
  303. $m = (string)$distance % 1000 ;
  304. // $distance = "{$k}公里{$m}米";
  305. $distance = "{$k}km";
  306. }
  307. else{
  308. $distance = "{$distance}m";
  309. }
  310. return $distance;
  311. }
  312. //女号私信异性完成任务
  313. public function girlchattask() {
  314. if ($this->auth->gender != 0) { //只有女生可以
  315. $this->error('您的网络开小差啦~');
  316. }
  317. //检测用户
  318. $to_user_id = input_post('to_user_id');
  319. $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();
  320. if(!$to_user_info){
  321. $this->error('不存在的用户');
  322. }
  323. if ($to_user_info['is_kefu'] == 1 || $this->auth->is_kefu == 1) { //我是客服或者对方是客服
  324. $this->success('success');
  325. }
  326. if ($to_user_info['gender'] != 1) {
  327. $this->error('性别异常~');
  328. }
  329. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,23);
  330. if($task_rs === false){
  331. $this->error('完成任务赠送奖励失败');
  332. }
  333. $this->success('success');
  334. }
  335. //腾讯内容审核回调方法
  336. public function tencentcall() {
  337. $content = file_get_contents('php://input');
  338. $content = json_decode($content, true);
  339. error_log(print_r($content, 1) . PHP_EOL, 3, './tencentcall3.txt');
  340. if (isset($content['Scene']) && $content['CtxcbResult'] == 1) { //语音文件: 只返回违规的数据; 处理方式: 撤回
  341. $tenim = new Tenim;
  342. $rs = $tenim->withdraw_message($content['From_Account'], $content['ContactItem']['To_Account'], $content['MsgID']);
  343. // error_log(print_r($rs, 1) . PHP_EOL, 3, './tencentcall4.txt');
  344. } elseif (isset($content['TaskId'])) { //音视频通话: 返回所有数据; 处理方式: 强制退出im, 清空token
  345. if ($content['Status'] == 'RUNNING') {
  346. //该字段用于返回所查询内容的任务状态。取值:FINISH(任务已完成)、PENDING (任务等待中)、RUNNING (任务进行中)、ERROR (任务出错)、CANCELLED (任务已取消)。
  347. if ($content['ImageSegments']) { //图片(视频)审核结果
  348. $image_info = $content['ImageSegments'][0]['Result'];
  349. if ($image_info['Label'] != 'Normal') {
  350. //该字段用于返回检测结果所对应的恶意标签。返回值:Porn:色情,Abuse:谩骂,Ad:广告,Custom:自定义违规;以及其他令人反感、不安全或不适宜的内容类型。
  351. $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
  352. //获取违规用户id
  353. $url = explode('?', $url);
  354. $url = $url[0];
  355. $user_id_url = explode('/', $url);
  356. $user_id_url = $user_id_url[count($user_id_url) - 1];
  357. $user_id_arr = explode('_', $user_id_url);
  358. $user_id = $user_id_arr[2];
  359. //退出im
  360. $tenIm = new Tenim();
  361. $tenIm->loginoutim($user_id);
  362. //清空token
  363. Token::clear($user_id);
  364. $tiaoshi = $user_id . '---' . $content['TaskId'] . '---' .$image_info['Label'] .'---'. date('Y-m-d H:i:s');
  365. error_log(print_r($tiaoshi, 1) . PHP_EOL, 3, './dayin1.txt');
  366. }
  367. } elseif ($content['AudioSegments']) { //音频审核结果
  368. $audio_info = $content['AudioSegments'][0]['Result'];
  369. if ($audio_info['Label'] != 'Normal') {
  370. //该字段用于返回检测结果所对应的恶意标签。返回值:Porn:色情,Abuse:谩骂,Ad:广告,Custom:自定义违规;以及其他令人反感、不安全或不适宜的内容类型。
  371. $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
  372. //获取违规用户id
  373. $url = explode('?', $url);
  374. $url = $url[0];
  375. $user_id_url = explode('/', $url);
  376. $user_id_url = $user_id_url[count($user_id_url) - 1];
  377. $user_id_arr = explode('_', $user_id_url);
  378. $user_id = $user_id_arr[2];
  379. //退出im
  380. $tenIm = new Tenim();
  381. $tenIm->loginoutim($user_id);
  382. //清空token
  383. Token::clear($user_id);
  384. $tiaoshi = $user_id . '---' . $content['TaskId'] . '---' .$audio_info['Label'] .'---'. date('Y-m-d H:i:s');
  385. error_log(print_r($tiaoshi, 1) . PHP_EOL, 3, './dayin2.txt');
  386. }
  387. }
  388. }
  389. }
  390. }
  391. //头条
  392. public function headlines() {
  393. $time = strtotime(date('Y-m-d', time()));
  394. //聊天送礼物
  395. $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();
  396. //动态送礼物
  397. $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();
  398. $list = array_merge($list1, $list2);
  399. if ($list) {
  400. $mt_user = Db::name('user');
  401. foreach ($list as &$v) {
  402. $user_info= $mt_user->field('nickname, avatar')->where(['id' => $v['user_id']])->find();
  403. $v['from_nickname'] = '有缘人';//$user_info['nickname'];
  404. $v['avatar'] = one_domain_image($user_info['avatar']);
  405. $v['to_nickname'] = '有缘人';//$mt_user->where(['id' => $v['user_to_id']])->value('nickname');
  406. }
  407. }
  408. $this->success('头条', $list);
  409. }
  410. //首页顶部分类名称
  411. public function typename() {
  412. $typename = config('site.typename');
  413. $typename = explode(',', $typename);
  414. $data[] = $typename[0] ? : '推荐';
  415. $data[] = $typename[1] ? : '附近';
  416. $data[] = $typename[2] ? : '新人';
  417. $this->success('sussess', $data);
  418. }
  419. }