Usercenter.php 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  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. 'user.is_active' => 1,//完全不考虑直播与语聊的权重,只用活跃做排序
  131. ];
  132. if($gender != 'all'){
  133. $map['user.gender'] = $gender;
  134. }
  135. $map['user.birthday'] = ['between',[time() - $agemax * 31536000,time() - $agemin * 31536000]];
  136. //dump($map);
  137. $field = [
  138. 'user.id','user.username','user.nickname','user.birthday','user.height','user.longitude','user.latitude','user.avatar','user.audio_bio','user.bio','user.gender'
  139. ];
  140. $list = Db::name('user')->alias('user')->field($field)->where($map)->order('active_time desc')->autopage()->select();
  141. //dump($list);
  142. $list = list_domain_image($list,['avatar']);
  143. foreach($list as $key => $one){
  144. $one['age'] = birthtime_to_age($one['birthday']);
  145. // $one['distance'] = $this->calc_map_distance([$this->auth->longitude,$this->auth->latitude],[$one['longitude'],$one['latitude']]);
  146. $one['distance'] = rand(0,10).'km';
  147. $list[$key] = $one;
  148. }
  149. $this->success('success',$list);
  150. }
  151. //附近
  152. public function nearuser(){
  153. $gender = input_post('gender','all');
  154. $agemin = input_post('agemin',0);
  155. $agemax = input_post('agemax',100);
  156. if(empty($this->auth->cityname) || empty($this->auth->longitude) || empty($this->auth->latitude)){
  157. // $this->success('success',[]);
  158. }
  159. //经过地图测算和公式推算,经度纬度 0.1即为11公里
  160. $map = [
  161. 'user.status' => 1,
  162. ////'user.cityname' => $this->auth->cityname,
  163. 'user.id' => ['neq',$this->auth->id],
  164. // 'user.longitude' => ['between',[$this->auth->longitude - 0.1,$this->auth->longitude + 0.1]],
  165. // 'user.latitude' => ['between',[$this->auth->latitude - 0.1,$this->auth->latitude + 0.1]],
  166. // 'user.is_online|user.is_livebc' => 1, //完全不考虑直播与语聊的权重,只用活跃做排序
  167. 'user.is_active' => 1,//完全不考虑直播与语聊的权重,只用活跃做排序
  168. ];
  169. if($gender != 'all'){
  170. $map['user.gender'] = $gender;
  171. }
  172. $map['user.birthday'] = ['between',[time() - $agemax * 31536000,time() - $agemin * 31536000]];
  173. //dump($map);
  174. $field = [
  175. 'user.id','user.username','user.nickname','user.birthday','user.height','user.longitude','user.latitude','user.avatar','user.audio_bio','user.bio','user.gender'
  176. ];
  177. $list = Db::name('user')->alias('user')->field($field)->where($map)->order('active_time desc')->autopage()->select();
  178. //dump($list);exit;
  179. $list = list_domain_image($list,['avatar']);
  180. foreach($list as $key => $one){
  181. $one['age'] = birthtime_to_age($one['birthday']);
  182. //$one['distance'] = $this->calc_map_distance([$this->auth->longitude,$this->auth->latitude],[$one['longitude'],$one['latitude']]);
  183. $one['distance'] = rand(0,10).'km';
  184. $list[$key] = $one;
  185. }
  186. $this->success('success',$list);
  187. }
  188. //视频和语音,接收方使用,如果是性别劣势方,检查钱是否够用
  189. public function video_audio_moneycheck(){
  190. //检测用户,发起方的uid
  191. $to_user_id = input_post('from_user_id');
  192. $to_user_info = Db::name('user')->field('id,real_status,gender')->where('id',$to_user_id)->find();
  193. if(!$to_user_info){
  194. $this->error('不存在的用户');
  195. }
  196. //扣费金币
  197. $type = input_post('type','video'); //类型
  198. $price = $type == 'video' ? config('site.video_min_price') : config('site.audio_min_price');
  199. //发起用户的分数,被发起用户的分数。按性别给分
  200. $auth_level = 0;
  201. $tous_level = 0;
  202. //打分
  203. if($this->auth->gender == 0 && $this->auth->real_status == 1){
  204. $auth_level = 30;//实名女最高
  205. }
  206. if($this->auth->gender == 0 && $this->auth->real_status != 1){
  207. $auth_level = 20;//未实名女次之
  208. }
  209. if($this->auth->gender == 1){
  210. $auth_level = 10;//男性最低
  211. }
  212. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
  213. $tous_level = 30;
  214. }
  215. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
  216. $tous_level = 20;
  217. }
  218. if($to_user_info['gender'] == 1){
  219. $tous_level = 10;
  220. }
  221. //同性不收钱
  222. //都是男的,不扣钱
  223. //都是实名认证的女性,不扣钱
  224. //都是未实名认证的女性,不扣钱
  225. if($auth_level == $tous_level){
  226. $price = 0;
  227. $this->success('success');
  228. }
  229. //扣钱uid,收钱uid,收钱free_video
  230. //分数少扣钱,分数多收益
  231. if($auth_level < $tous_level){
  232. $kou_user = $this->auth->id;
  233. }else{
  234. $kou_user = $to_user_info['id'];
  235. }
  236. //需要扣我的(接收方的)钱,判断钱是否够
  237. if($price > 0 && $kou_user == $this->auth->id){
  238. Db::startTrans();
  239. $gold = model('wallet')->getWallet($kou_user,'gold');
  240. if(bccomp($price,$gold) == 1){
  241. Db::rollback();
  242. $this->error('金币不足');
  243. }
  244. Db::commit();
  245. }
  246. $this->success('success');
  247. }
  248. //视频通话每分钟调用一次
  249. public function video_onemin(){
  250. //检测用户
  251. $to_user_id = input_post('to_user_id');
  252. $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
  253. if(!$to_user_info){
  254. $this->error('不存在的用户');
  255. }
  256. //正常价格
  257. $price = config('site.video_min_price'); //扣费金币
  258. $bili = config('site.money_to_gold'); //兑换比例
  259. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  260. $money = bcdiv($price,$bili,2); //对应人民币
  261. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  262. //发起用户的分数,被发起用户的分数。按性别给分
  263. $auth_level = 0;
  264. $tous_level = 0;
  265. //打分
  266. if($this->auth->gender == 0 && $this->auth->real_status == 1){
  267. $auth_level = 30;//实名女最高
  268. }
  269. if($this->auth->gender == 0 && $this->auth->real_status != 1){
  270. $auth_level = 20;//未实名女次之
  271. }
  272. if($this->auth->gender == 1){
  273. $auth_level = 10;//男性最低
  274. }
  275. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
  276. $tous_level = 30;
  277. }
  278. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
  279. $tous_level = 20;
  280. }
  281. if($to_user_info['gender'] == 1){
  282. $tous_level = 10;
  283. }
  284. //同性不收钱
  285. //都是男的,不扣钱
  286. //都是实名认证的女性,不扣钱
  287. //都是未实名认证的女性,不扣钱
  288. if($auth_level == $tous_level){
  289. $price = 0;$money = 0;
  290. }
  291. Db::startTrans();
  292. //记录日志
  293. $data = [
  294. 'user_id' => $this->auth->id,
  295. 'price' => $price,
  296. 'createtime' => time(),
  297. 'to_user_id' => $to_user_id,
  298. 'money' => $money,
  299. ];
  300. $log_id = Db::name('user_match_video_log')->insertGetId($data);
  301. if(!$log_id){
  302. Db::rollback();
  303. $this->error('扣费失败');
  304. }
  305. //同性别,提前结束
  306. if($auth_level == $tous_level){
  307. Db::commit();
  308. $this->success('success');
  309. }
  310. //扣钱uid,收钱uid,收钱free_video
  311. //分数少扣钱,分数多收益
  312. if($auth_level < $tous_level){
  313. $kou_user = $this->auth->id;
  314. $get_user = $to_user_info['id'];
  315. $get_user_free = $to_user_info['free_video'];
  316. }else{
  317. $kou_user = $to_user_info['id'];
  318. $get_user = $this->auth->id;
  319. $get_user_free = $this->auth->free_video;
  320. }
  321. //需要扣别人的钱,判断钱是否购
  322. if($price > 0 && $kou_user != $this->auth->id){
  323. $gold = model('wallet')->getWallet($kou_user,'gold');
  324. if(bccomp($price,$gold) == 1){
  325. Db::rollback();
  326. $this->error('对方金币不足');
  327. }
  328. }
  329. //有性别差,扣费
  330. if($price > 0){
  331. $rs = model('wallet')->lockChangeAccountRemain($kou_user,'gold',-$price,11,'','user_match_video_log',$log_id);
  332. if($rs['status'] === false){
  333. Db::rollback();
  334. $this->error($rs['msg']);
  335. }
  336. }
  337. //另一方加钱,0收费
  338. if($money > 0 && $get_user_free == 0){
  339. $rs = model('wallet')->lockChangeAccountRemain($get_user,'money',$money,21,'','user_match_video_log',$log_id);
  340. if($rs['status'] === false){
  341. Db::rollback();
  342. $this->error($rs['msg']);
  343. }
  344. }
  345. Db::commit();
  346. $this->success('success');
  347. }
  348. //语音通话每分钟调用一次
  349. public function audio_onemin(){
  350. //检测用户
  351. $to_user_id = input_post('to_user_id');
  352. $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
  353. if(!$to_user_info){
  354. $this->error('不存在的用户');
  355. }
  356. //正常价格
  357. $price = config('site.audio_min_price'); //扣费金币
  358. $bili = config('site.money_to_gold'); //兑换比例
  359. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  360. $money = bcdiv($price,$bili,2); //对应人民币
  361. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  362. //发起用户的分数,被发起用户的分数。按性别给分
  363. $auth_level = 0;
  364. $tous_level = 0;
  365. //打分
  366. if($this->auth->gender == 0 && $this->auth->real_status == 1){
  367. $auth_level = 30;//实名女最高
  368. }
  369. if($this->auth->gender == 0 && $this->auth->real_status != 1){
  370. $auth_level = 20;//未实名女次之
  371. }
  372. if($this->auth->gender == 1){
  373. $auth_level = 10;//男性最低
  374. }
  375. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
  376. $tous_level = 30;
  377. }
  378. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
  379. $tous_level = 20;
  380. }
  381. if($to_user_info['gender'] == 1){
  382. $tous_level = 10;
  383. }
  384. //同性不收钱
  385. //都是男的,不扣钱
  386. //都是实名认证的女性,不扣钱
  387. //都是未实名认证的女性,不扣钱
  388. if($auth_level == $tous_level){
  389. $price = 0;$money = 0;
  390. }
  391. Db::startTrans();
  392. //记录日志
  393. $data = [
  394. 'user_id' => $this->auth->id,
  395. 'price' => $price,
  396. 'createtime' => time(),
  397. 'to_user_id' => $to_user_id,
  398. 'money' => $money,
  399. ];
  400. $log_id = Db::name('user_match_audio_log')->insertGetId($data);
  401. if(!$log_id){
  402. Db::rollback();
  403. $this->error('扣费失败');
  404. }
  405. //同性别,提前结束
  406. if($auth_level == $tous_level){
  407. Db::commit();
  408. $this->success('success');
  409. }
  410. //扣钱uid,收钱uid,收钱free_video
  411. //分数少扣钱,分数多收益
  412. if($auth_level < $tous_level){
  413. $kou_user = $this->auth->id;
  414. $get_user = $to_user_info['id'];
  415. $get_user_free = $to_user_info['free_audio'];
  416. }else{
  417. $kou_user = $to_user_info['id'];
  418. $get_user = $this->auth->id;
  419. $get_user_free = $this->auth->free_audio;
  420. }
  421. //需要扣别人的钱,判断钱是否购
  422. if($price > 0 && $kou_user != $this->auth->id){
  423. $gold = model('wallet')->getWallet($kou_user,'gold');
  424. if(bccomp($price,$gold) == 1){
  425. Db::rollback();
  426. $this->error('对方金币不足');
  427. }
  428. }
  429. //有性别差,扣费
  430. if($price > 0){
  431. $rs = model('wallet')->lockChangeAccountRemain($kou_user,'gold',-$price,12,'','user_match_audio_log',$log_id);
  432. if($rs['status'] === false){
  433. Db::rollback();
  434. $this->error($rs['msg']);
  435. }
  436. }
  437. //另一方加钱,0收费
  438. if($money > 0 && $get_user_free == 0){
  439. $rs = model('wallet')->lockChangeAccountRemain($get_user,'money',$money,22,'','user_match_audio_log',$log_id);
  440. if($rs['status'] === false){
  441. Db::rollback();
  442. $this->error($rs['msg']);
  443. }
  444. }
  445. Db::commit();
  446. $this->success('success');
  447. }
  448. //打字聊天每句话调用一次
  449. public function typing_once(){
  450. //检测用户
  451. $to_user_id = input_post('to_user_id');
  452. $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
  453. if(!$to_user_info){
  454. $this->error('不存在的用户');
  455. }
  456. //正常价格
  457. $price = config('site.typing_min_price'); //扣费金币
  458. $bili = config('site.money_to_gold'); //兑换比例
  459. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  460. $money = bcdiv($price,$bili,2); //对应人民币
  461. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  462. //发起用户的分数,被发起用户的分数。按性别给分
  463. $auth_level = 0;
  464. $tous_level = 0;
  465. //打分
  466. if($this->auth->gender == 0 && $this->auth->real_status == 1){
  467. $auth_level = 30;//实名女最高
  468. }
  469. if($this->auth->gender == 0 && $this->auth->real_status != 1){
  470. $auth_level = 20;//未实名女次之
  471. }
  472. if($this->auth->gender == 1){
  473. $auth_level = 10;//男性最低
  474. }
  475. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
  476. $tous_level = 30;
  477. }
  478. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
  479. $tous_level = 20;
  480. }
  481. if($to_user_info['gender'] == 1){
  482. $tous_level = 10;
  483. }
  484. //同性不收钱
  485. //都是男的,不扣钱
  486. //都是实名认证的女性,不扣钱
  487. //都是未实名认证的女性,不扣钱
  488. if($auth_level == $tous_level){
  489. $price = 0;$money = 0;
  490. }
  491. //性别优势的人发起,免费
  492. if($auth_level > $tous_level){
  493. $price = 0;$money = 0;
  494. }
  495. Db::startTrans();
  496. //记录日志
  497. $data = [
  498. 'user_id' => $this->auth->id,
  499. 'price' => $price,
  500. 'createtime' => time(),
  501. 'to_user_id' => $to_user_id,
  502. 'money' => $money,
  503. ];
  504. $log_id = Db::name('user_match_typing_log')->insertGetId($data);
  505. if(!$log_id){
  506. Db::rollback();
  507. $this->error('扣费失败');
  508. }
  509. //同性别,提前结束
  510. if($auth_level == $tous_level){
  511. Db::commit();
  512. $this->success('success');
  513. }
  514. //零消费,零收益消费,提前结束,其实这条没必要,下面金钱操作还会过滤一次
  515. if($price == 0 && $money == 0){
  516. Db::commit();
  517. $this->success('success');
  518. }
  519. //扣钱uid,收钱uid,收钱free_video
  520. //分数少扣钱,分数多收益
  521. if($auth_level < $tous_level){
  522. $kou_user = $this->auth->id;
  523. $get_user = $to_user_info['id'];
  524. $get_user_free = $to_user_info['free_typing'];
  525. }else{
  526. //这种已经没有了
  527. $kou_user = $to_user_info['id'];
  528. $get_user = $this->auth->id;
  529. $get_user_free = $this->auth->free_typing;
  530. }
  531. //有性别差,扣费
  532. if($price > 0){
  533. $rs = model('wallet')->lockChangeAccountRemain($kou_user,'gold',-$price,13,'','user_match_typing_log',$log_id);
  534. if($rs['status'] === false){
  535. Db::rollback();
  536. $this->error($rs['msg']);
  537. }
  538. }
  539. //另一方加钱,0收费
  540. if($money > 0 && $get_user_free == 0){
  541. $rs = model('wallet')->lockChangeAccountRemain($get_user,'money',$money,23,'','user_match_typing_log',$log_id);
  542. if($rs['status'] === false){
  543. Db::rollback();
  544. $this->error($rs['msg']);
  545. }
  546. }
  547. //tag任务赠送金币
  548. //搭讪奖励
  549. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
  550. if($task_rs === false){
  551. Db::rollback();
  552. $this->error('完成任务赠送奖励失败');
  553. }
  554. Db::commit();
  555. $this->success('success');
  556. }
  557. //语音匹配
  558. public function getaudiouser(){
  559. //判断资格
  560. /*$start = strtotime(date('Y-m-d'));
  561. $end = $start + 86399;
  562. $map = [
  563. 'user_id' => $this->auth->id,
  564. 'createtime' => ['between',[$start,$end]],
  565. 'price' => 0,
  566. ];
  567. $check = Db::name('user_match_audio_log')->where($map)->find();*/
  568. $check = true;
  569. //已经用掉免费的了,判断金额
  570. if($check){
  571. $price = config('site.audio_min_price');
  572. $gold = model('wallet')->getWallet($this->auth->id,'gold');
  573. if($gold < $price){
  574. $this->error('您的金币已经不足,请充值');
  575. }
  576. }
  577. //找到互关的人,排除
  578. $follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  579. //dump($follow_me);
  580. $my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  581. //dump($my_follow);exit;
  582. //给出备选用户
  583. $map = [
  584. 'status' =>1, //未封禁用户
  585. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  586. 'is_online' => 0, //不在语聊间的
  587. 'is_livebc' => 0, //不在直播的
  588. 'is_active' => 1, //在线的
  589. //'real_status' => 1, //真人认证
  590. //'idcard_status' => 1, //实名认证
  591. 'open_match_audio' => 1, //打开语聊开关
  592. 'id' => ['NOT IN',$my_follow] //不是好友的
  593. ];
  594. $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
  595. $lists = $this->fliter_user($lists,10);
  596. $result = [];
  597. if(!empty($lists)){
  598. foreach($lists as $key => $val){
  599. $result[] = ['id'=>$val];
  600. }
  601. }
  602. //tag任务赠送金币
  603. //语音匹配奖励 +5金币
  604. if(!empty($result)){
  605. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,11);
  606. if($task_rs === false){
  607. $this->error('完成任务赠送奖励失败');
  608. }
  609. }
  610. $this->success('success',$result);
  611. }
  612. //视频匹配
  613. public function getvideouser(){
  614. //判断资格
  615. /*$start = strtotime(date('Y-m-d'));
  616. $end = $start + 86399;
  617. $map = [
  618. 'user_id' => $this->auth->id,
  619. 'createtime' => ['between',[$start,$end]],
  620. 'price' => 0,
  621. ];
  622. $check = Db::name('user_match_video_log')->where($map)->find();*/
  623. $check = true;
  624. //已经用掉免费的了,判断金额
  625. if($check){
  626. $price = config('site.video_min_price');
  627. $gold = model('wallet')->getWallet($this->auth->id,'gold');
  628. if($gold < $price){
  629. $this->error('您的金币已经不足,请充值');
  630. }
  631. }
  632. //找到互关的人,排除
  633. $follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  634. //dump($follow_me);
  635. $my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  636. //dump($my_follow);exit;
  637. //给出备选用户
  638. $map = [
  639. 'status' =>1, //未封禁用户
  640. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  641. 'is_online' => 0, //不在语聊间的
  642. 'is_livebc' => 0, //不在直播的
  643. 'is_active' => 1, //在线的
  644. //'real_status' => 1, //真人认证
  645. //'idcard_status' => 1, //实名认证
  646. 'open_match_video' => 1, //打开视频开关的
  647. 'id' => ['NOT IN',$my_follow] //不是好友的
  648. ];
  649. $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
  650. $lists = $this->fliter_user($lists,10);
  651. $result = [];
  652. if(!empty($lists)){
  653. foreach($lists as $key => $val){
  654. $result[] = ['id'=>$val];
  655. }
  656. }
  657. //tag任务赠送金币
  658. //视频匹配奖励 +5金币
  659. if(!empty($result)){
  660. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,12);
  661. if($task_rs === false){
  662. $this->error('完成任务赠送奖励失败');
  663. }
  664. }
  665. $this->success('success',$result);
  666. }
  667. //聊天匹配
  668. public function gettypinguser(){
  669. //找到互关的人,排除
  670. $follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  671. //dump($follow_me);
  672. $my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  673. //dump($my_follow);exit;
  674. //给出备选用户
  675. $map = [
  676. 'status' =>1, //未封禁用户
  677. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  678. //'real_status' => 1, //真人认证
  679. //'idcard_status' => 1, //实名认证
  680. //'is_active' => 1, //在线的
  681. //打开聊天开关的
  682. 'open_match_typing' => 1, //打开文字聊天开关的
  683. 'id' => ['NOT IN',$my_follow] //不是好友的
  684. ];
  685. $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
  686. //$lists = $this->fliter_user($lists,100);
  687. $lists = array_column($lists,'id');
  688. $result = [];
  689. if(!empty($lists)){
  690. /*foreach($lists as $key => $val){
  691. $result[] = ['id'=>$val];
  692. }*/
  693. $result = Db::name('user')->field('id,nickname,username,avatar,audio_bio')->where(['id'=>['IN',$lists]])->select();
  694. $result = list_domain_image($result,['avatar,audio_bio']);
  695. }
  696. //tag任务赠送金币
  697. //缘分匹配奖励 +5金币
  698. if(!empty($result)){
  699. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,10);
  700. if($task_rs === false){
  701. $this->error('完成任务赠送奖励失败');
  702. }
  703. }
  704. $this->success('success',$result);
  705. }
  706. //过滤规则
  707. private function fliter_user($lists,$number = 1){
  708. if(empty($lists)){
  709. return $lists;
  710. }
  711. //dump($lists);
  712. //过滤掉通话中的
  713. foreach($lists as $key => $val){
  714. if(redis_matching_get($val['id']) == 1){
  715. unset($lists[$key]);
  716. }
  717. }
  718. //预留全部
  719. $all_result = array_column($lists,'id');
  720. //dump($all_result);
  721. //提取同城的
  722. $citydata = [];
  723. foreach($lists as $key => $val){
  724. if( !empty($this->auth->cityname) && $this->auth->cityname == $val['cityname'] ){
  725. $citydata[] = $val['id'];
  726. }
  727. }
  728. //dump($citydata);
  729. //有标签交集的
  730. $tagdata = [];
  731. foreach($lists as $key => $val){
  732. if( !empty($this->auth->tag_ids) && !empty($val['tag_ids']) ){
  733. $auth_tag_ids = explode(',',$this->auth->tag_ids);
  734. $val_tag_ids = explode(',',$val['tag_ids']);
  735. if(count(array_intersect($auth_tag_ids,$val_tag_ids)) > 0){
  736. $tagdata[] = $val['id'];
  737. }
  738. }
  739. }
  740. //dump($tagdata);
  741. //双条件都满足
  742. $double_data = [];
  743. if(!empty($citydata) && !empty($tagdata)){
  744. $double_data = array_intersect($citydata,$tagdata);
  745. }
  746. //dump($double_data);
  747. if(count($double_data) >= $number){
  748. return $double_data;
  749. }
  750. //两种条件合并,去重。空数组合并没影响
  751. $merge_data = array_merge($citydata,$tagdata);
  752. $merge_data = array_flip(array_flip($merge_data));
  753. //dump($merge_data);
  754. if(count($merge_data) >= $number){
  755. return $merge_data;
  756. }
  757. return $all_result;
  758. }
  759. /**
  760. * 是否关注
  761. */
  762. public function isFollows() {
  763. $user_id = $this->request->request("user_id",0,"intval");
  764. if (!$user_id || $user_id<=0) {
  765. $this->error(__('Invalid parameters'));
  766. }
  767. $map = [
  768. 'uid' => $this->auth->id,
  769. 'follow_uid' => $user_id,
  770. ];
  771. $check = Db::name('user_follow')->where($map)->find();
  772. $data = [];
  773. if($check){
  774. $data["is_show_follow"] = 0;
  775. }else{
  776. $data["is_show_follow"] = 1;
  777. }
  778. $this->success("获取成功!",$data);
  779. }
  780. /**
  781. * 获取主播技能分类
  782. */
  783. public function getAnchorType() {
  784. $this->success("获取成功!",\app\common\model\UserAnchorType::select());
  785. }
  786. /**
  787. * 主播申请
  788. */
  789. public function anchorApply() {
  790. $this->error('不需要申请');
  791. /*$type_id = $this->request->request('type_id'); // 技能分类ID
  792. $desc = $this->request->request('desc'); // 申请备注
  793. if (!$type_id && !$desc) {
  794. $this->error(__('Invalid parameters'));
  795. }
  796. $useranchorModel = new \app\common\model\UserAnchor();
  797. $data = [];
  798. $data["user_id"] = $this->auth->id;
  799. $data["type_id"] = $type_id;
  800. if($useranchorModel->where($data)->find()) $this->error(__('您已申请过该类型的主播,请勿重复申请!'));
  801. $data["desc"] = $desc;
  802. $data["createtime"] = time();
  803. $res = $useranchorModel->insertGetId($data);
  804. if($res) {
  805. \app\common\model\User::update(["is_anchor"=>1],["id"=>$this->auth->id]);
  806. $this->success("申请发送成功!");
  807. } else {
  808. $this->error("网络错误,请稍后重试");
  809. }*/
  810. }
  811. /**
  812. * 获取当前用户信息
  813. */
  814. public function getMyUserInfo() {
  815. $userInfo = $this->auth->getUserinfo();
  816. //当月消费金额
  817. $redis = new Redis();
  818. $redisconfig = config("redis");
  819. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  820. $user_renew2 = $redis->get('user_renew2_'.$this->auth->id);
  821. $userInfo['user_renew2'] = empty($user_renew2)?0:intval($user_renew2);
  822. $this->success("获取成功!",$userInfo);
  823. }
  824. /**
  825. * calc_map_distance() , 根据地图上的两个点各自的x,y坐标,计算出2点之间的直线距离
  826. * @param array $point_1 第1个点的x,y坐标 array( 101 , 202 )
  827. * @param array $point_2 第2个点的x,y坐标 array( 101 , 202 )
  828. * @param bool $calc_as_string 是否计算为字符串公里距离 , 如果未否返回数字
  829. * @return float | false | string
  830. */
  831. private function calc_map_distance( $point_1=array( ) , $point_2=array( ) , $calc_as_string=false ) {
  832. if( empty( $point_1 ) || empty( $point_2 ) ){
  833. return false;
  834. }
  835. // 经纬度不存在,或者经纬度超过最大范围 +-180 , +-90 ,返回false
  836. $p1_x = $point_1[0];
  837. $p1_y = $point_1[1];
  838. $p2_x = $point_2[0];
  839. $p2_y = $point_2[1];
  840. if(
  841. $p1_x < -180 || $p1_x > 180
  842. || $p2_x < -180 || $p2_x > 180
  843. || $p1_y < -90 || $p1_y > 90
  844. || $p2_y < -90 || $p2_y > 90
  845. ){
  846. return '0公里';
  847. }
  848. // 根据2点各自的坐标,计算2点之间直线距离的公式
  849. $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);
  850. // 是否计算为字符串公里距离
  851. if( !$calc_as_string ){
  852. return (string)round( $distance / 1000 , 1 ) . '公里';
  853. }
  854. // 如果计算为字符串公里距离
  855. if( $distance / 1000 > 1 ){
  856. $k = (string)round( $distance / 1000 , 1 );
  857. $m = (string)$distance % 1000 ;
  858. $distance = "{$k}公里{$m}米";
  859. }
  860. else{
  861. $distance = "{$distance}米";
  862. }
  863. return $distance;
  864. }
  865. //地图api,根据两地坐标,获得两地距离,打卡用的
  866. //type=0直线,type=1开车
  867. private function getmapjuli($start_lon,$start_lat,$end_lon,$end_lat,$type = 0){
  868. $result = 0;
  869. $apiurl = 'https://restapi.amap.com/v3/distance?';
  870. $param = [
  871. 'key' => '398c424811d1a59beac2f915323d334e',
  872. 'origins' => $start_lon.','.$start_lat,
  873. 'destination' => $end_lon.','.$end_lat,
  874. 'type' => $type,
  875. 'output' => 'json',
  876. ];
  877. $apiurl .= http_build_query($param);
  878. $request_rs = json_decode(curl_get($apiurl),true);
  879. if(isset($request_rs['status']) && $request_rs['status'] == 1){
  880. if(isset($request_rs['results'][0]['distance']))
  881. {
  882. $result = $request_rs['results'][0]['distance'];
  883. }
  884. }
  885. //dump($result);
  886. return $result;
  887. }
  888. public function distance()
  889. {
  890. $a = $this->calc_map_distance([118.339282,35.028445],[118.437399,35.017438]);
  891. dump($a);
  892. $a = $this->calc_map_distance([118.339282,35.028445],[118.437399,35.017438],true);
  893. dump($a);
  894. $b = $this->getmapjuli(118.339282,35.028445,118.437399,35.017438,1);
  895. dump($b);
  896. $b = $this->getmapjuli(118.339282,35.028445,118.437399,35.017438,0);
  897. dump($b);
  898. }
  899. }