Usercenter.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use app\common\model\wallet;
  6. use Redis;
  7. /**
  8. * 会员中心,不是个人中心
  9. */
  10. class Usercenter extends Api
  11. {
  12. protected $noNeedLogin = ['test','testredis'];
  13. protected $noNeedRight = '*';
  14. protected $allowFields = [
  15. 'id',
  16. 'username',
  17. 'nickname',
  18. //'truename',//
  19. 'email',
  20. 'mobile',
  21. 'avatar',
  22. 'real_status',
  23. 'gender',
  24. 'height',
  25. 'weight',
  26. 'birthday',
  27. 'bio',
  28. 'audio_bio',
  29. //'alipay_account',//
  30. 'idcard_status',
  31. 'longitude',
  32. 'latitude',
  33. 'cityname',
  34. 'photo_images',
  35. 'education_id',
  36. 'hobby_ids',
  37. 'job_id',
  38. 'marital_id',
  39. 'tag_ids',
  40. 'wages_id',
  41. 'hometown_cityid',
  42. ];
  43. public function testredis(){
  44. //redis_matching_set(1,125);
  45. dump(redis_matching_get(1));
  46. $a = cache('?mt_matching_uid_1','',['type'=>'Redis']);
  47. dump($a);
  48. }
  49. public function test(){
  50. $a = [1,4,10,22,66,36,102,45,23,52,35,76,7];
  51. $b = [1,10,7,102];
  52. $c = [10,102];
  53. //dump(array_intersect($a,$b));
  54. $data = array_merge($c,$b);
  55. dump($data);
  56. dump(array_flip(array_flip($data)));
  57. dump(array_flip([]));
  58. }
  59. //获取他人用户信息,留下足迹
  60. public function getuserinfo(){
  61. $uid = input_post('uid',0);
  62. $userinfo = Db::name('user')->field($this->allowFields)->where('id',$uid)->find();
  63. if(!$userinfo){
  64. $this->error('不存在的用户');
  65. }
  66. //
  67. $userinfo = info_domain_image($userinfo,['avatar','photo_images']);
  68. $idcard_confirm = Db::name('user_idconfirm')->where('user_id',$uid)->find();
  69. $new_data = [
  70. 'age' => birthtime_to_age($userinfo['birthday']),
  71. 'truename' => ($userinfo['idcard_status'] == 1 && isset($idcard_confirm['truename'])) ? $idcard_confirm['truename'] : '',
  72. 'alipay_account' => ($userinfo['idcard_status'] == 1 && isset($idcard_confirm['alipay_account'])) ? $idcard_confirm['alipay_account'] : '',
  73. ];
  74. $userinfo = array_merge($userinfo,$new_data);
  75. //枚举
  76. $userinfo['education'] = Db::name('enum_education')->where('id',$userinfo['education_id'])->value('name');
  77. $userinfo['hobby'] = Db::name('enum_hobby')->where('id','IN',$userinfo['hobby_ids'])->field(['id','name'])->select();
  78. $userinfo['job'] = Db::name('enum_job')->where('id',$userinfo['job_id'])->value('name');
  79. $userinfo['marital'] = Db::name('enum_marital')->where('id',$userinfo['marital_id'])->value('name');
  80. $userinfo['tag'] = Db::name('enum_tag')->where('id','IN',$userinfo['tag_ids'])->field(['id','name'])->select();
  81. $userinfo['wages'] = Db::name('enum_wages')->where('id',$userinfo['wages_id'])->value('name');
  82. //家乡
  83. $userinfo['hometown_city'] = Db::name('area')->where('id',$userinfo['hometown_cityid'])->value('name');
  84. //vip
  85. $userinfo['vip_endtime'] = Db::name('user_wallet')->where('user_id',$uid)->value('vip_endtime');
  86. $userinfo['is_vip'] = $userinfo['vip_endtime'] > time() ? 1 : 0;
  87. //是否喜欢和关注
  88. $is_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>$uid])->find();
  89. $userinfo['is_follow'] = $is_follow ? 1 : 0;
  90. $is_like = Db::name('user_like')->where(['uid'=>$this->auth->id,'like_uid'=>$uid])->find();
  91. $userinfo['is_like'] = $is_like ? 1 : 0;
  92. //是否拉黑
  93. $is_black = Db::name('user_black')->where(['uid'=>$this->auth->id,'black_uid'=>$uid])->find();
  94. $userinfo['is_black'] = $is_black ? 1 : 0;
  95. //关注人数,粉丝人数
  96. $follow_num = Db::name('user_follow')->where(['uid'=>$this->auth->id])->count('id');
  97. $fans_num = Db::name('user_follow')->where(['follow_uid'=>$this->auth->id])->count('id');
  98. $userinfo['follow_num'] = $follow_num;
  99. $userinfo['fans_num'] = $fans_num;
  100. //查看别人信息,就要留下痕迹
  101. $data = [
  102. 'uid' => $this->auth->id,
  103. 'to_uid' => $uid,
  104. ];
  105. $check = Db::name('user_visit')->where($data)->find();
  106. if($check){
  107. Db::name('user_visit')->where($data)->update(['number'=>$check['number']+1,'updatetime'=>time()]);
  108. }else{
  109. $data['number'] = 1;
  110. $data['updatetime'] = time();
  111. Db::name('user_visit')->insertGetId($data);
  112. }
  113. $this->success('success',$userinfo);
  114. }
  115. //同城
  116. public function samecity(){
  117. $gender = input_post('gender','all');
  118. $agemin = input_post('agemin',0);
  119. $agemax = input_post('agemax',100);
  120. if(empty($this->auth->cityname) || empty($this->auth->longitude) || empty($this->auth->latitude)){
  121. // $this->success('success',[]);
  122. }
  123. $map = [
  124. 'user.status' => 1,
  125. // 'user.cityname' => $this->auth->cityname,
  126. 'user.id' => ['neq',$this->auth->id],
  127. // 'user.longitude' => ['neq',''],
  128. // 'user.latitude' => ['neq',''],
  129. 'user.is_online|user.is_livebc' => 1,
  130. ];
  131. if($gender != 'all'){
  132. $map['user.gender'] = $gender;
  133. }
  134. $map['user.birthday'] = ['between',[time() - $agemax * 31536000,time() - $agemin * 31536000]];
  135. //dump($map);
  136. $field = [
  137. 'user.id','user.username','user.nickname','user.birthday','user.height','user.longitude','user.latitude','user.avatar','user.audio_bio','user.bio','user.gender'
  138. ];
  139. $list = Db::name('user')->alias('user')->field($field)->where($map)->orderRaw('rand()')->autopage()->select();
  140. //dump($list);
  141. $list = list_domain_image($list,['avatar']);
  142. foreach($list as $key => $one){
  143. $one['age'] = birthtime_to_age($one['birthday']);
  144. // $one['distance'] = $this->calc_map_distance([$this->auth->longitude,$this->auth->latitude],[$one['longitude'],$one['latitude']]);
  145. $one['distance'] = rand(0,10).'公里';
  146. $list[$key] = $one;
  147. }
  148. $this->success('success',$list);
  149. }
  150. //附近
  151. public function nearuser(){
  152. $gender = input_post('gender','all');
  153. $agemin = input_post('agemin',0);
  154. $agemax = input_post('agemax',100);
  155. if(empty($this->auth->cityname) || empty($this->auth->longitude) || empty($this->auth->latitude)){
  156. // $this->success('success',[]);
  157. }
  158. //经过地图测算和公式推算,经度纬度 0.1即为11公里
  159. $map = [
  160. 'user.status' => 1,
  161. ////'user.cityname' => $this->auth->cityname,
  162. 'user.id' => ['neq',$this->auth->id],
  163. // 'user.longitude' => ['between',[$this->auth->longitude - 0.1,$this->auth->longitude + 0.1]],
  164. // 'user.latitude' => ['between',[$this->auth->latitude - 0.1,$this->auth->latitude + 0.1]],
  165. 'user.is_online|user.is_livebc' => 1,
  166. ];
  167. if($gender != 'all'){
  168. $map['user.gender'] = $gender;
  169. }
  170. $map['user.birthday'] = ['between',[time() - $agemax * 31536000,time() - $agemin * 31536000]];
  171. //dump($map);
  172. $field = [
  173. 'user.id','user.username','user.nickname','user.birthday','user.height','user.longitude','user.latitude','user.avatar','user.audio_bio','user.bio','user.gender'
  174. ];
  175. $list = Db::name('user')->alias('user')->field($field)->where($map)->orderRaw('rand()')->autopage()->select();
  176. //dump($list);exit;
  177. $list = list_domain_image($list,['avatar']);
  178. foreach($list as $key => $one){
  179. $one['age'] = birthtime_to_age($one['birthday']);
  180. //$one['distance'] = $this->calc_map_distance([$this->auth->longitude,$this->auth->latitude],[$one['longitude'],$one['latitude']]);
  181. $one['distance'] = rand(0,10).'公里';
  182. $list[$key] = $one;
  183. }
  184. $this->success('success',$list);
  185. }
  186. //视频通话每分钟调用一次
  187. public function video_onemin(){
  188. //检测用户
  189. $to_user_id = input_post('to_user_id');
  190. $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
  191. if(!$to_user_info){
  192. $this->error('不存在的用户');
  193. }
  194. //正常价格
  195. $price = config('site.video_min_price'); //扣费金币
  196. $bili = config('site.money_to_gold'); //兑换比例
  197. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  198. $money = bcdiv($price,$bili,2); //对应人民币
  199. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  200. //发起用户的分数,被发起用户的分数。按性别给分
  201. $auth_level = 0;
  202. $tous_level = 0;
  203. //打分
  204. if($this->auth->gender == 0 && $this->auth->real_status == 1){
  205. $auth_level = 30;//实名女最高
  206. }
  207. if($this->auth->gender == 0 && $this->auth->real_status != 1){
  208. $auth_level = 20;//未实名女次之
  209. }
  210. if($this->auth->gender == 1){
  211. $auth_level = 10;//男性最低
  212. }
  213. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
  214. $tous_level = 30;
  215. }
  216. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
  217. $tous_level = 20;
  218. }
  219. if($to_user_info['gender'] == 1){
  220. $tous_level = 10;
  221. }
  222. //同性不收钱
  223. //都是男的,不扣钱
  224. //都是实名认证的女性,不扣钱
  225. //都是未实名认证的女性,不扣钱
  226. if($auth_level == $tous_level){
  227. $price = 0;$money = 0;
  228. }
  229. Db::startTrans();
  230. //记录日志
  231. $data = [
  232. 'user_id' => $this->auth->id,
  233. 'price' => $price,
  234. 'createtime' => time(),
  235. 'to_user_id' => $to_user_id,
  236. 'money' => $money,
  237. ];
  238. $log_id = Db::name('user_match_video_log')->insertGetId($data);
  239. if(!$log_id){
  240. Db::rollback();
  241. $this->error('扣费失败');
  242. }
  243. //同性别,提前结束
  244. if($auth_level == $tous_level){
  245. Db::commit();
  246. $this->success('success');
  247. }
  248. //扣钱uid,收钱uid,收钱free_video
  249. //分数少扣钱,分数多收益
  250. if($auth_level < $tous_level){
  251. $kou_user = $this->auth->id;
  252. $get_user = $to_user_info['id'];
  253. $get_user_free = $to_user_info['free_video'];
  254. }else{
  255. $kou_user = $to_user_info['id'];
  256. $get_user = $this->auth->id;
  257. $get_user_free = $this->auth->free_video;
  258. }
  259. //有性别差,扣费
  260. if($price > 0){
  261. $rs = model('wallet')->lockChangeAccountRemain($kou_user,'gold',-$price,11,'','user_match_video_log',$log_id);
  262. if($rs['status'] === false){
  263. Db::rollback();
  264. $this->error($rs['msg']);
  265. }
  266. }
  267. //另一方加钱,0收费
  268. if($money > 0 && $get_user_free == 0){
  269. $rs = model('wallet')->lockChangeAccountRemain($get_user,'money',$money,21,'','user_match_video_log',$log_id);
  270. if($rs['status'] === false){
  271. Db::rollback();
  272. $this->error($rs['msg']);
  273. }
  274. }
  275. Db::commit();
  276. $this->success('success');
  277. }
  278. //语音通话每分钟调用一次
  279. public function audio_onemin(){
  280. //检测用户
  281. $to_user_id = input_post('to_user_id');
  282. $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
  283. if(!$to_user_info){
  284. $this->error('不存在的用户');
  285. }
  286. //正常价格
  287. $price = config('site.audio_min_price'); //扣费金币
  288. $bili = config('site.money_to_gold'); //兑换比例
  289. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  290. $money = bcdiv($price,$bili,2); //对应人民币
  291. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  292. //发起用户的分数,被发起用户的分数。按性别给分
  293. $auth_level = 0;
  294. $tous_level = 0;
  295. //打分
  296. if($this->auth->gender == 0 && $this->auth->real_status == 1){
  297. $auth_level = 30;//实名女最高
  298. }
  299. if($this->auth->gender == 0 && $this->auth->real_status != 1){
  300. $auth_level = 20;//未实名女次之
  301. }
  302. if($this->auth->gender == 1){
  303. $auth_level = 10;//男性最低
  304. }
  305. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
  306. $tous_level = 30;
  307. }
  308. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
  309. $tous_level = 20;
  310. }
  311. if($to_user_info['gender'] == 1){
  312. $tous_level = 10;
  313. }
  314. //同性不收钱
  315. //都是男的,不扣钱
  316. //都是实名认证的女性,不扣钱
  317. //都是未实名认证的女性,不扣钱
  318. if($auth_level == $tous_level){
  319. $price = 0;$money = 0;
  320. }
  321. Db::startTrans();
  322. //记录日志
  323. $data = [
  324. 'user_id' => $this->auth->id,
  325. 'price' => $price,
  326. 'createtime' => time(),
  327. 'to_user_id' => $to_user_id,
  328. 'money' => $money,
  329. ];
  330. $log_id = Db::name('user_match_audio_log')->insertGetId($data);
  331. if(!$log_id){
  332. Db::rollback();
  333. $this->error('扣费失败');
  334. }
  335. //同性别,提前结束
  336. if($auth_level == $tous_level){
  337. Db::commit();
  338. $this->success('success');
  339. }
  340. //扣钱uid,收钱uid,收钱free_video
  341. //分数少扣钱,分数多收益
  342. if($auth_level < $tous_level){
  343. $kou_user = $this->auth->id;
  344. $get_user = $to_user_info['id'];
  345. $get_user_free = $to_user_info['free_audio'];
  346. }else{
  347. $kou_user = $to_user_info['id'];
  348. $get_user = $this->auth->id;
  349. $get_user_free = $this->auth->free_audio;
  350. }
  351. //有性别差,扣费
  352. if($price > 0){
  353. $rs = model('wallet')->lockChangeAccountRemain($kou_user,'gold',-$price,12,'','user_match_audio_log',$log_id);
  354. if($rs['status'] === false){
  355. Db::rollback();
  356. $this->error($rs['msg']);
  357. }
  358. }
  359. //另一方加钱,0收费
  360. if($money > 0 && $get_user_free == 0){
  361. $rs = model('wallet')->lockChangeAccountRemain($get_user,'money',$money,22,'','user_match_audio_log',$log_id);
  362. if($rs['status'] === false){
  363. Db::rollback();
  364. $this->error($rs['msg']);
  365. }
  366. }
  367. Db::commit();
  368. $this->success('success');
  369. }
  370. //打字聊天每句话调用一次
  371. public function typing_once(){
  372. //检测用户
  373. $to_user_id = input_post('to_user_id');
  374. $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
  375. if(!$to_user_info){
  376. $this->error('不存在的用户');
  377. }
  378. //正常价格
  379. $price = config('site.typing_min_price'); //扣费金币
  380. $bili = config('site.money_to_gold'); //兑换比例
  381. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  382. $money = bcdiv($price,$bili,2); //对应人民币
  383. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  384. //发起用户的分数,被发起用户的分数。按性别给分
  385. $auth_level = 0;
  386. $tous_level = 0;
  387. //打分
  388. if($this->auth->gender == 0 && $this->auth->real_status == 1){
  389. $auth_level = 30;//实名女最高
  390. }
  391. if($this->auth->gender == 0 && $this->auth->real_status != 1){
  392. $auth_level = 20;//未实名女次之
  393. }
  394. if($this->auth->gender == 1){
  395. $auth_level = 10;//男性最低
  396. }
  397. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
  398. $tous_level = 30;
  399. }
  400. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
  401. $tous_level = 20;
  402. }
  403. if($to_user_info['gender'] == 1){
  404. $tous_level = 10;
  405. }
  406. //同性不收钱
  407. //都是男的,不扣钱
  408. //都是实名认证的女性,不扣钱
  409. //都是未实名认证的女性,不扣钱
  410. if($auth_level == $tous_level){
  411. $price = 0;$money = 0;
  412. }
  413. //特殊处理
  414. //实名女发起,其他性别接收,不扣钱
  415. if($this->auth->gender == 0 && $this->auth->real_status == 1){
  416. $price = 0;$money = 0;
  417. }
  418. Db::startTrans();
  419. //记录日志
  420. $data = [
  421. 'user_id' => $this->auth->id,
  422. 'price' => $price,
  423. 'createtime' => time(),
  424. 'to_user_id' => $to_user_id,
  425. 'money' => $money,
  426. ];
  427. $log_id = Db::name('user_match_typing_log')->insertGetId($data);
  428. if(!$log_id){
  429. Db::rollback();
  430. $this->error('扣费失败');
  431. }
  432. //同性别,提前结束
  433. if($auth_level == $tous_level){
  434. Db::commit();
  435. $this->success('success');
  436. }
  437. //零消费,零收益消费,提前结束,其实这条没必要,下面金钱操作还会过滤一次
  438. if($price == 0 && $money == 0){
  439. Db::commit();
  440. $this->success('success');
  441. }
  442. //扣钱uid,收钱uid,收钱free_video
  443. //分数少扣钱,分数多收益
  444. if($auth_level < $tous_level){
  445. $kou_user = $this->auth->id;
  446. $get_user = $to_user_info['id'];
  447. $get_user_free = $to_user_info['free_typing'];
  448. }else{
  449. $kou_user = $to_user_info['id'];
  450. $get_user = $this->auth->id;
  451. $get_user_free = $this->auth->free_typing;
  452. }
  453. //有性别差,扣费
  454. if($price > 0){
  455. $rs = model('wallet')->lockChangeAccountRemain($kou_user,'gold',-$price,13,'','user_match_typing_log',$log_id);
  456. if($rs['status'] === false){
  457. Db::rollback();
  458. $this->error($rs['msg']);
  459. }
  460. }
  461. //另一方加钱,0收费
  462. if($money > 0 && $get_user_free == 0){
  463. $rs = model('wallet')->lockChangeAccountRemain($get_user,'money',$money,23,'','user_match_typing_log',$log_id);
  464. if($rs['status'] === false){
  465. Db::rollback();
  466. $this->error($rs['msg']);
  467. }
  468. }
  469. //tag任务赠送金币
  470. //搭讪奖励
  471. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
  472. if($task_rs === false){
  473. Db::rollback();
  474. $this->error('完成任务赠送奖励失败');
  475. }
  476. Db::commit();
  477. $this->success('success');
  478. }
  479. //语音匹配
  480. public function getaudiouser(){
  481. //判断资格
  482. $start = strtotime(date('Y-m-d'));
  483. $end = $start + 86399;
  484. $map = [
  485. 'user_id' => $this->auth->id,
  486. 'createtime' => ['between',[$start,$end]],
  487. 'price' => 0,
  488. ];
  489. $check = Db::name('user_match_audio_log')->where($map)->find();
  490. //$check = true;
  491. //已经用掉免费的了,判断金额
  492. if($check){
  493. $price = config('site.audio_min_price');
  494. $gold = model('wallet')->getWallet($this->auth->id,'gold');
  495. if($gold < $price){
  496. $this->error('您的金币已经不足,请充值');
  497. }
  498. }
  499. //找到互关的人,排除
  500. $follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  501. //dump($follow_me);
  502. $my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  503. //dump($my_follow);exit;
  504. //给出备选用户
  505. $map = [
  506. 'status' =>1, //未封禁用户
  507. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  508. 'is_online' => 0, //不在语聊间的
  509. 'is_livebc' => 0, //不在直播的
  510. 'real_status' => 1, //真人认证
  511. 'idcard_status' => 1, //实名认证
  512. 'open_match_audio' => 1, //打开语聊开关
  513. 'id' => ['NOT IN',$my_follow] //不是好友的
  514. ];
  515. $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
  516. $lists = $this->fliter_user($lists,10);
  517. $result = [];
  518. if(!empty($lists)){
  519. foreach($lists as $key => $val){
  520. $result[] = ['id'=>$val];
  521. }
  522. }
  523. //tag任务赠送金币
  524. //语音匹配奖励 +5金币
  525. if(!empty($result)){
  526. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,11);
  527. if($task_rs === false){
  528. $this->error('完成任务赠送奖励失败');
  529. }
  530. }
  531. $this->success('success',$result);
  532. }
  533. //视频匹配
  534. public function getvideouser(){
  535. //判断资格
  536. $start = strtotime(date('Y-m-d'));
  537. $end = $start + 86399;
  538. $map = [
  539. 'user_id' => $this->auth->id,
  540. 'createtime' => ['between',[$start,$end]],
  541. 'price' => 0,
  542. ];
  543. $check = Db::name('user_match_video_log')->where($map)->find();
  544. //$check = true;
  545. //已经用掉免费的了,判断金额
  546. if($check){
  547. $price = config('site.video_min_price');
  548. $gold = model('wallet')->getWallet($this->auth->id,'gold');
  549. if($gold < $price){
  550. $this->error('您的金币已经不足,请充值');
  551. }
  552. }
  553. //找到互关的人,排除
  554. $follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  555. //dump($follow_me);
  556. $my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  557. //dump($my_follow);exit;
  558. //给出备选用户
  559. $map = [
  560. 'status' =>1, //未封禁用户
  561. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  562. 'is_online' => 0, //不在语聊间的
  563. 'is_livebc' => 0, //不在直播的
  564. 'real_status' => 1, //真人认证
  565. 'idcard_status' => 1, //实名认证
  566. 'open_match_video' => 1, //打开视频开关的
  567. 'id' => ['NOT IN',$my_follow] //不是好友的
  568. ];
  569. $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
  570. $lists = $this->fliter_user($lists,10);
  571. $result = [];
  572. if(!empty($lists)){
  573. foreach($lists as $key => $val){
  574. $result[] = ['id'=>$val];
  575. }
  576. }
  577. //tag任务赠送金币
  578. //视频匹配奖励 +5金币
  579. if(!empty($result)){
  580. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,12);
  581. if($task_rs === false){
  582. $this->error('完成任务赠送奖励失败');
  583. }
  584. }
  585. $this->success('success',$result);
  586. }
  587. //聊天匹配
  588. public function gettypinguser(){
  589. //找到互关的人,排除
  590. $follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  591. //dump($follow_me);
  592. $my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  593. //dump($my_follow);exit;
  594. //给出备选用户
  595. $map = [
  596. 'status' =>1, //未封禁用户
  597. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  598. //'real_status' => 1, //真人认证
  599. //'idcard_status' => 1, //实名认证
  600. //打开聊天开关的
  601. 'open_match_typing' => 1, //打开文字聊天开关的
  602. 'id' => ['NOT IN',$my_follow] //不是好友的
  603. ];
  604. $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
  605. //$lists = $this->fliter_user($lists,100);
  606. $lists = array_column($lists,'id');
  607. $result = [];
  608. if(!empty($lists)){
  609. /*foreach($lists as $key => $val){
  610. $result[] = ['id'=>$val];
  611. }*/
  612. $result = Db::name('user')->field('id,nickname,username,avatar,audio_bio')->where(['id'=>['IN',$lists]])->select();
  613. $result = list_domain_image($result,['avatar,audio_bio']);
  614. }
  615. //tag任务赠送金币
  616. //缘分匹配奖励 +5金币
  617. if(!empty($result)){
  618. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,10);
  619. if($task_rs === false){
  620. $this->error('完成任务赠送奖励失败');
  621. }
  622. }
  623. $this->success('success',$result);
  624. }
  625. //过滤规则
  626. private function fliter_user($lists,$number = 1){
  627. if(empty($lists)){
  628. return $lists;
  629. }
  630. //dump($lists);
  631. //过滤掉通话中的
  632. foreach($lists as $key => $val){
  633. if(redis_matching_get($val['id']) == 1){
  634. unset($lists[$key]);
  635. }
  636. }
  637. //预留全部
  638. $all_result = array_column($lists,'id');
  639. //dump($all_result);
  640. //提取同城的
  641. $citydata = [];
  642. foreach($lists as $key => $val){
  643. if( !empty($this->auth->cityname) && $this->auth->cityname == $val['cityname'] ){
  644. $citydata[] = $val['id'];
  645. }
  646. }
  647. //dump($citydata);
  648. //有标签交集的
  649. $tagdata = [];
  650. foreach($lists as $key => $val){
  651. if( !empty($this->auth->tag_ids) && !empty($val['tag_ids']) ){
  652. $auth_tag_ids = explode(',',$this->auth->tag_ids);
  653. $val_tag_ids = explode(',',$val['tag_ids']);
  654. if(count(array_intersect($auth_tag_ids,$val_tag_ids)) > 0){
  655. $tagdata[] = $val['id'];
  656. }
  657. }
  658. }
  659. //dump($tagdata);
  660. //双条件都满足
  661. $double_data = [];
  662. if(!empty($citydata) && !empty($tagdata)){
  663. $double_data = array_intersect($citydata,$tagdata);
  664. }
  665. //dump($double_data);
  666. if(count($double_data) >= $number){
  667. return $double_data;
  668. }
  669. //两种条件合并,去重。空数组合并没影响
  670. $merge_data = array_merge($citydata,$tagdata);
  671. $merge_data = array_flip(array_flip($merge_data));
  672. //dump($merge_data);
  673. if(count($merge_data) >= $number){
  674. return $merge_data;
  675. }
  676. return $all_result;
  677. }
  678. /**
  679. * 是否关注
  680. */
  681. public function isFollows() {
  682. $user_id = $this->request->request("user_id",0,"intval");
  683. if (!$user_id || $user_id<=0) {
  684. $this->error(__('Invalid parameters'));
  685. }
  686. $map = [
  687. 'uid' => $this->auth->id,
  688. 'follow_uid' => $user_id,
  689. ];
  690. $check = Db::name('user_follow')->where($map)->find();
  691. $data = [];
  692. if($check){
  693. $data["is_show_follow"] = 0;
  694. }else{
  695. $data["is_show_follow"] = 1;
  696. }
  697. $this->success("获取成功!",$data);
  698. }
  699. /**
  700. * 获取主播技能分类
  701. */
  702. public function getAnchorType() {
  703. $this->success("获取成功!",\app\common\model\UserAnchorType::select());
  704. }
  705. /**
  706. * 主播申请
  707. */
  708. public function anchorApply() {
  709. $this->error('不需要申请');
  710. /*$type_id = $this->request->request('type_id'); // 技能分类ID
  711. $desc = $this->request->request('desc'); // 申请备注
  712. if (!$type_id && !$desc) {
  713. $this->error(__('Invalid parameters'));
  714. }
  715. $useranchorModel = new \app\common\model\UserAnchor();
  716. $data = [];
  717. $data["user_id"] = $this->auth->id;
  718. $data["type_id"] = $type_id;
  719. if($useranchorModel->where($data)->find()) $this->error(__('您已申请过该类型的主播,请勿重复申请!'));
  720. $data["desc"] = $desc;
  721. $data["createtime"] = time();
  722. $res = $useranchorModel->insertGetId($data);
  723. if($res) {
  724. \app\common\model\User::update(["is_anchor"=>1],["id"=>$this->auth->id]);
  725. $this->success("申请发送成功!");
  726. } else {
  727. $this->error("网络错误,请稍后重试");
  728. }*/
  729. }
  730. /**
  731. * 获取当前用户信息
  732. */
  733. public function getMyUserInfo() {
  734. $userInfo = $this->auth->getUserinfo();
  735. //当月消费金额
  736. $redis = new Redis();
  737. $redisconfig = config("redis");
  738. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  739. $user_renew2 = $redis->get('user_renew2_'.$this->auth->id);
  740. $userInfo['user_renew2'] = empty($user_renew2)?0:intval($user_renew2);
  741. $this->success("获取成功!",$userInfo);
  742. }
  743. /**
  744. * calc_map_distance() , 根据地图上的两个点各自的x,y坐标,计算出2点之间的直线距离
  745. * @param array $point_1 第1个点的x,y坐标 array( 101 , 202 )
  746. * @param array $point_2 第2个点的x,y坐标 array( 101 , 202 )
  747. * @param bool $calc_as_string 是否计算为字符串公里距离 , 如果未否返回数字
  748. * @return float | false | string
  749. */
  750. private function calc_map_distance( $point_1=array( ) , $point_2=array( ) , $calc_as_string=false ) {
  751. if( empty( $point_1 ) || empty( $point_2 ) ){
  752. return false;
  753. }
  754. // 经纬度不存在,或者经纬度超过最大范围 +-180 , +-90 ,返回false
  755. $p1_x = $point_1[0];
  756. $p1_y = $point_1[1];
  757. $p2_x = $point_2[0];
  758. $p2_y = $point_2[1];
  759. if(
  760. $p1_x < -180 || $p1_x > 180
  761. || $p2_x < -180 || $p2_x > 180
  762. || $p1_y < -90 || $p1_y > 90
  763. || $p2_y < -90 || $p2_y > 90
  764. ){
  765. return '0公里';
  766. }
  767. // 根据2点各自的坐标,计算2点之间直线距离的公式
  768. $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);
  769. // 是否计算为字符串公里距离
  770. if( !$calc_as_string ){
  771. return (string)round( $distance / 1000 , 1 ) . '公里';
  772. }
  773. // 如果计算为字符串公里距离
  774. if( $distance / 1000 > 1 ){
  775. $k = (string)round( $distance / 1000 , 1 );
  776. $m = (string)$distance % 1000 ;
  777. $distance = "{$k}公里{$m}米";
  778. }
  779. else{
  780. $distance = "{$distance}米";
  781. }
  782. return $distance;
  783. }
  784. //地图api,根据两地坐标,获得两地距离,打卡用的
  785. //type=0直线,type=1开车
  786. private function getmapjuli($start_lon,$start_lat,$end_lon,$end_lat,$type = 0){
  787. $result = 0;
  788. $apiurl = 'https://restapi.amap.com/v3/distance?';
  789. $param = [
  790. 'key' => '398c424811d1a59beac2f915323d334e',
  791. 'origins' => $start_lon.','.$start_lat,
  792. 'destination' => $end_lon.','.$end_lat,
  793. 'type' => $type,
  794. 'output' => 'json',
  795. ];
  796. $apiurl .= http_build_query($param);
  797. $request_rs = json_decode(curl_get($apiurl),true);
  798. if(isset($request_rs['status']) && $request_rs['status'] == 1){
  799. if(isset($request_rs['results'][0]['distance']))
  800. {
  801. $result = $request_rs['results'][0]['distance'];
  802. }
  803. }
  804. //dump($result);
  805. return $result;
  806. }
  807. public function distance()
  808. {
  809. $a = $this->calc_map_distance([118.339282,35.028445],[118.437399,35.017438]);
  810. dump($a);
  811. $a = $this->calc_map_distance([118.339282,35.028445],[118.437399,35.017438],true);
  812. dump($a);
  813. $b = $this->getmapjuli(118.339282,35.028445,118.437399,35.017438,1);
  814. dump($b);
  815. $b = $this->getmapjuli(118.339282,35.028445,118.437399,35.017438,0);
  816. dump($b);
  817. }
  818. }