Usercenter.php 34 KB

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