Index.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  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. $type = input('type', 0, 'intval'); //类型: 0推荐 1附近 2新人
  25. $age_id = input('age_id', 0, 'intval'); //年龄段
  26. $map = [
  27. 'user.gender' => $this->auth->gender == 1 ? 0 : 1,// 查询异性
  28. 'user.status' => 1,
  29. 'user.is_kefu' => 0,
  30. 'user.id' => ['neq',$this->auth->id],
  31. ];
  32. //排序
  33. $order = 'user.is_active desc, user.logintime desc';
  34. if ($type == 0) {
  35. if ($this->auth->gender == 1) {
  36. $map['user.is_recommend'] = 1;
  37. }
  38. } elseif ($type == 1) {
  39. } else {
  40. $map['user.createtime'] = ['egt', time() - 86400 * 30];
  41. }
  42. if ($age_id > 0 && $age_id < 8) {
  43. if ($age_id == 1) {
  44. $agemin = 18;
  45. $agemax = 25;
  46. } elseif ($age_id == 2) {
  47. $agemin = 25;
  48. $agemax = 30;
  49. } elseif ($age_id == 3) {
  50. $agemin = 30;
  51. $agemax = 35;
  52. } elseif ($age_id == 4) {
  53. $agemin = 35;
  54. $agemax = 40;
  55. } elseif ($age_id == 5) {
  56. $agemin = 40;
  57. $agemax = 45;
  58. } elseif ($age_id == 6) {
  59. $agemin = 45;
  60. $agemax = 50;
  61. } elseif ($age_id == 7) {
  62. $agemin = 50;
  63. $agemax = 200;
  64. }
  65. $map['user.birthday'] = ['between', [time() - $agemax * 31536000, time() - $agemin * 31536000]];
  66. }
  67. $field = [
  68. 'user.id','user.nickname','user.birthday','user.height','user.avatar','user.bio','user.gender','user.idcard_status', 'user.real_status',
  69. 'user.is_active','user.is_recommend', 'user.cityname','user.is_hideaddress','uw.vip_endtime','uw.vip_level'
  70. ];
  71. $list = Db::name('user')->alias('user')->field($field)
  72. ->join('user_wallet uw','uw.user_id = user.id','LEFT')
  73. ->where($map)->order($order)->autopage()->select();
  74. $list = list_domain_image($list,['avatar']);
  75. //ids
  76. $user_to_id = array_column($list,'id');
  77. // 是否打过招呼
  78. $mt_user_greet = Db::name('user_greet')->where('user_id', $this->auth->id)->whereIn('user_to_id',$user_to_id)->group('user_to_id')->column('user_to_id');
  79. foreach($list as $key => &$v) {
  80. //年龄
  81. $age = birthtime_to_age($v['birthday']);
  82. $age = $age > 0 ? $age : 18;
  83. $v['age'] = $age;
  84. $v['birthday'] = $age;
  85. $v['bio'] = $v['bio'] ? $v['bio'] : '暂未设置个性签名';
  86. //拼接年龄与身高
  87. $v['desc'] = $age . '岁';
  88. if ($v['height']) {
  89. $v['desc'] .= ' | ' . $v['height'];
  90. }
  91. if ($type == 2) {
  92. $v['desc'] = $v['bio'];
  93. }
  94. //VIP
  95. $v['is_vip'] = $this->is_vip($v['vip_endtime'],$v['vip_level']);
  96. //是否打过招呼: 1是 0否
  97. $v['is_chat'] = in_array($v['id'],$mt_user_greet) ? 1 : 0;
  98. }
  99. $this->success('success',$list);
  100. }
  101. //轮播图
  102. public function banner() {
  103. $type = input('type', 0, 'intval'); //类型:0=交友轮播图,1=动态轮播图
  104. $list = Db::name('banner')->field('id, title, image, url')->where(['status' => 1, 'type' => $type])->order('weigh', 'desc')->select();
  105. $list = list_domain_image($list, ['image']);
  106. $this->success('轮播图', $list);
  107. }
  108. //筛选年龄段
  109. public function agerange() {
  110. $list = [
  111. [
  112. 'id' => 0,
  113. 'title' => '不限'
  114. ],
  115. [
  116. 'id' => 1,
  117. 'title' => '18-25岁'
  118. ],
  119. [
  120. 'id' => 2,
  121. 'title' => '25-30岁'
  122. ],
  123. [
  124. 'id' => 3,
  125. 'title' => '30-35岁'
  126. ],
  127. [
  128. 'id' => 4,
  129. 'title' => '35-40岁'
  130. ],
  131. [
  132. 'id' => 5,
  133. 'title' => '40-45岁'
  134. ],
  135. [
  136. 'id' => 6,
  137. 'title' => '45-50岁'
  138. ],
  139. [
  140. 'id' => 7,
  141. 'title' => '50岁以上'
  142. ]
  143. ];
  144. $this->success('筛选年龄段', $list);
  145. }
  146. /**
  147. * calc_map_distance() , 根据地图上的两个点各自的x,y坐标,计算出2点之间的直线距离
  148. * @param array $point_1 第1个点的x,y坐标 array( 101 , 202 )
  149. * @param array $point_2 第2个点的x,y坐标 array( 101 , 202 )
  150. * @param bool $calc_as_string 是否计算为字符串公里距离 , 如果未否返回数字
  151. * @return float | false | string
  152. */
  153. private function calc_map_distance( $point_1=array( ) , $point_2=array( ) , $calc_as_string=false ) {
  154. if( empty( $point_1 ) || empty( $point_2 ) ){
  155. return false;
  156. }
  157. // 经纬度不存在,或者经纬度超过最大范围 +-180 , +-90 ,返回false
  158. $p1_x = $point_1[0];
  159. $p1_y = $point_1[1];
  160. $p2_x = $point_2[0];
  161. $p2_y = $point_2[1];
  162. if(
  163. $p1_x < -180 || $p1_x > 180
  164. || $p2_x < -180 || $p2_x > 180
  165. || $p1_y < -90 || $p1_y > 90
  166. || $p2_y < -90 || $p2_y > 90
  167. || $p1_x == '' || $p1_y == ''
  168. || $p2_x == '' || $p2_y == ''
  169. ){
  170. return '距离未知';
  171. }
  172. // 根据2点各自的坐标,计算2点之间直线距离的公式
  173. $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);
  174. // 是否计算为字符串公里距离
  175. if( !$calc_as_string ){
  176. return (string)round( $distance / 1000 , 1 ) . 'km';
  177. }
  178. // 如果计算为字符串公里距离
  179. if( $distance / 1000 > 1 ){
  180. $k = (string)round( $distance / 1000 , 1 );
  181. $m = (string)$distance % 1000 ;
  182. // $distance = "{$k}公里{$m}米";
  183. $distance = "{$k}km";
  184. }
  185. else{
  186. $distance = "{$distance}m";
  187. }
  188. return $distance;
  189. }
  190. //女号私信异性完成任务
  191. public function girlchattask() {
  192. if ($this->auth->gender != 0) { //只有女生可以
  193. $this->error('您的网络开小差啦~');
  194. }
  195. //检测用户
  196. $to_user_id = input_post('to_user_id');
  197. $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();
  198. if(!$to_user_info){
  199. $this->error('不存在的用户');
  200. }
  201. if ($to_user_info['is_kefu'] == 1 || $this->auth->is_kefu == 1) { //我是客服或者对方是客服
  202. $this->success('success');
  203. }
  204. if ($to_user_info['gender'] != 1) {
  205. $this->error('性别异常~');
  206. }
  207. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,23);
  208. if($task_rs === false){
  209. $this->error('完成任务赠送奖励失败');
  210. }
  211. $this->success('success');
  212. }
  213. //腾讯内容审核回调方法
  214. public function tencentcall() {
  215. $content = file_get_contents('php://input');
  216. $content = json_decode($content, true);
  217. error_log(print_r($content, 1) . PHP_EOL, 3, './tencentcall3.txt');
  218. if (isset($content['Scene']) && $content['CtxcbResult'] == 1) { //语音文件: 只返回违规的数据; 处理方式: 撤回
  219. $tenim = new Tenim;
  220. $rs = $tenim->withdraw_message($content['From_Account'], $content['ContactItem']['To_Account'], $content['MsgID']);
  221. // error_log(print_r($rs, 1) . PHP_EOL, 3, './tencentcall4.txt');
  222. } elseif (isset($content['TaskId'])) { //音视频通话: 返回所有数据; 处理方式: 强制退出im, 清空token
  223. if ($content['Status'] == 'RUNNING') {
  224. //该字段用于返回所查询内容的任务状态。取值:FINISH(任务已完成)、PENDING (任务等待中)、RUNNING (任务进行中)、ERROR (任务出错)、CANCELLED (任务已取消)。
  225. if ($content['ImageSegments']) { //图片(视频)审核结果
  226. $image_info = $content['ImageSegments'][0]['Result'];
  227. if ($image_info['Label'] != 'Normal') {
  228. //该字段用于返回检测结果所对应的恶意标签。返回值:Porn:色情,Abuse:谩骂,Ad:广告,Custom:自定义违规;以及其他令人反感、不安全或不适宜的内容类型。
  229. $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
  230. //获取违规用户id
  231. $url = explode('?', $url);
  232. $url = $url[0];
  233. $user_id_url = explode('/', $url);
  234. $user_id_url = $user_id_url[count($user_id_url) - 1];
  235. $user_id_arr = explode('_', $user_id_url);
  236. $user_id = $user_id_arr[2];
  237. //退出im
  238. $tenIm = new Tenim();
  239. $tenIm->loginoutim($user_id);
  240. //清空token
  241. Token::clear($user_id);
  242. $tiaoshi = $user_id . '---' . $content['TaskId'] . '---' .$image_info['Label'] .'---'. date('Y-m-d H:i:s');
  243. error_log(print_r($tiaoshi, 1) . PHP_EOL, 3, './dayin1.txt');
  244. }
  245. } elseif ($content['AudioSegments']) { //音频审核结果
  246. $audio_info = $content['AudioSegments'][0]['Result'];
  247. if ($audio_info['Label'] != 'Normal') {
  248. //该字段用于返回检测结果所对应的恶意标签。返回值:Porn:色情,Abuse:谩骂,Ad:广告,Custom:自定义违规;以及其他令人反感、不安全或不适宜的内容类型。
  249. $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
  250. //获取违规用户id
  251. $url = explode('?', $url);
  252. $url = $url[0];
  253. $user_id_url = explode('/', $url);
  254. $user_id_url = $user_id_url[count($user_id_url) - 1];
  255. $user_id_arr = explode('_', $user_id_url);
  256. $user_id = $user_id_arr[2];
  257. //退出im
  258. $tenIm = new Tenim();
  259. $tenIm->loginoutim($user_id);
  260. //清空token
  261. Token::clear($user_id);
  262. $tiaoshi = $user_id . '---' . $content['TaskId'] . '---' .$audio_info['Label'] .'---'. date('Y-m-d H:i:s');
  263. error_log(print_r($tiaoshi, 1) . PHP_EOL, 3, './dayin2.txt');
  264. }
  265. }
  266. }
  267. }
  268. }
  269. //头条
  270. public function headlines() {
  271. $time = strtotime(date('Y-m-d', time()));
  272. //聊天送礼物
  273. $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();
  274. //动态送礼物
  275. $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();
  276. $list = array_merge($list1, $list2);
  277. if ($list) {
  278. $mt_user = Db::name('user');
  279. foreach ($list as &$v) {
  280. $user_info= $mt_user->field('nickname, avatar')->where(['id' => $v['user_id']])->find();
  281. $v['from_nickname'] = '有缘人';//$user_info['nickname'];
  282. $v['avatar'] = one_domain_image($user_info['avatar']);
  283. $v['to_nickname'] = '有缘人';//$mt_user->where(['id' => $v['user_to_id']])->value('nickname');
  284. }
  285. }
  286. $this->success('头条', $list);
  287. }
  288. //首页顶部分类名称
  289. public function typename() {
  290. $typename = config('site.typename');
  291. $typename = explode(',', $typename);
  292. $data[] = $typename[0] ? : '推荐';
  293. $data[] = $typename[1] ? : '附近';
  294. $data[] = $typename[2] ? : '新人';
  295. $this->success('sussess', $data);
  296. }
  297. }