Usercenter.php 39 KB

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