Usercenter.php 38 KB

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