Usercenter.php 40 KB

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