Usercenter.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use app\common\model\wallet;
  6. use Redis;
  7. /**
  8. * 会员中心,不是个人中心
  9. */
  10. class Usercenter extends Api
  11. {
  12. protected $noNeedLogin = ['test','testredis'];
  13. protected $noNeedRight = '*';
  14. protected $allowFields = [
  15. 'id',
  16. 'username',
  17. 'nickname',
  18. //'truename',//
  19. 'email',
  20. 'mobile',
  21. 'avatar',
  22. 'real_status',
  23. 'gender',
  24. 'height',
  25. 'weight',
  26. 'birthday',
  27. 'bio',
  28. 'audio_bio',
  29. //'alipay_account',//
  30. 'idcard_status',
  31. 'longitude',
  32. 'latitude',
  33. 'cityname',
  34. 'photo_images',
  35. 'education_id',
  36. 'hobby_ids',
  37. 'job_id',
  38. 'marital_id',
  39. 'tag_ids',
  40. 'wages_id',
  41. 'hometown_cityid',
  42. ];
  43. public function testredis(){
  44. //redis_matching_set(1,125);
  45. dump(redis_matching_get(1));
  46. $a = cache('?mt_matching_uid_1','',['type'=>'Redis']);
  47. dump($a);
  48. }
  49. public function test(){
  50. $a = [1,4,10,22,66,36,102,45,23,52,35,76,7];
  51. $b = [1,10,7,102];
  52. $c = [10,102];
  53. //dump(array_intersect($a,$b));
  54. $data = array_merge($c,$b);
  55. dump($data);
  56. dump(array_flip(array_flip($data)));
  57. dump(array_flip([]));
  58. }
  59. //获取他人用户信息,留下足迹
  60. public function getuserinfo(){
  61. $uid = input_post('uid',0);
  62. $userinfo = Db::name('user')->field($this->allowFields)->where('id',$uid)->find();
  63. if(!$userinfo){
  64. $this->error('不存在的用户');
  65. }
  66. //
  67. $userinfo = info_domain_image($userinfo,['avatar','photo_images']);
  68. $idcard_confirm = Db::name('user_idconfirm')->where('user_id',$uid)->find();
  69. $new_data = [
  70. 'age' => birthtime_to_age($userinfo['birthday']),
  71. 'truename' => ($userinfo['idcard_status'] == 1 && isset($idcard_confirm['truename'])) ? $idcard_confirm['truename'] : '',
  72. 'alipay_account' => ($userinfo['idcard_status'] == 1 && isset($idcard_confirm['alipay_account'])) ? $idcard_confirm['alipay_account'] : '',
  73. ];
  74. $userinfo = array_merge($userinfo,$new_data);
  75. //枚举
  76. $userinfo['education'] = Db::name('enum_education')->where('id',$userinfo['education_id'])->value('name');
  77. $userinfo['hobby'] = Db::name('enum_hobby')->where('id','IN',$userinfo['hobby_ids'])->field(['id','name'])->select();
  78. $userinfo['job'] = Db::name('enum_job')->where('id',$userinfo['job_id'])->value('name');
  79. $userinfo['marital'] = Db::name('enum_marital')->where('id',$userinfo['marital_id'])->value('name');
  80. $userinfo['tag'] = Db::name('enum_tag')->where('id','IN',$userinfo['tag_ids'])->field(['id','name'])->select();
  81. $userinfo['wages'] = Db::name('enum_wages')->where('id',$userinfo['wages_id'])->value('name');
  82. //家乡
  83. $userinfo['hometown_city'] = Db::name('area')->where('id',$userinfo['hometown_cityid'])->value('name');
  84. //vip
  85. $userinfo['vip_endtime'] = Db::name('user_wallet')->where('user_id',$uid)->value('vip_endtime');
  86. $userinfo['is_vip'] = $userinfo['vip_endtime'] > time() ? 1 : 0;
  87. //是否喜欢和关注
  88. $is_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>$uid])->find();
  89. $userinfo['is_follow'] = $is_follow ? 1 : 0;
  90. $is_like = Db::name('user_like')->where(['uid'=>$this->auth->id,'like_uid'=>$uid])->find();
  91. $userinfo['is_like'] = $is_like ? 1 : 0;
  92. //是否拉黑
  93. $is_black = Db::name('user_black')->where(['uid'=>$this->auth->id,'black_uid'=>$uid])->find();
  94. $userinfo['is_black'] = $is_black ? 1 : 0;
  95. //关注人数,粉丝人数
  96. $follow_num = Db::name('user_follow')->where(['uid'=>$this->auth->id])->count('id');
  97. $fans_num = Db::name('user_follow')->where(['follow_uid'=>$this->auth->id])->count('id');
  98. $userinfo['follow_num'] = $follow_num;
  99. $userinfo['fans_num'] = $fans_num;
  100. //查看别人信息,就要留下痕迹
  101. $data = [
  102. 'uid' => $this->auth->id,
  103. 'to_uid' => $uid,
  104. ];
  105. $check = Db::name('user_visit')->where($data)->find();
  106. if($check){
  107. Db::name('user_visit')->where($data)->update(['number'=>$check['number']+1,'updatetime'=>time()]);
  108. }else{
  109. $data['number'] = 1;
  110. $data['updatetime'] = time();
  111. Db::name('user_visit')->insertGetId($data);
  112. }
  113. $this->success('success',$userinfo);
  114. }
  115. //同城
  116. public function samecity(){
  117. $gender = input_post('gender','all');
  118. $agemin = input_post('agemin',0);
  119. $agemax = input_post('agemax',100);
  120. if(empty($this->auth->cityname) || empty($this->auth->longitude) || empty($this->auth->latitude)){
  121. $this->success('success',[]);
  122. }
  123. $map = [
  124. 'user.status' => 1,
  125. 'user.cityname' => $this->auth->cityname,
  126. 'user.id' => ['neq',$this->auth->id],
  127. 'user.longitude' => ['neq',''],
  128. 'user.latitude' => ['neq',''],
  129. 'user.is_online|user.is_livebc' => 1,
  130. ];
  131. if($gender != 'all'){
  132. $map['user.gender'] = $gender;
  133. }
  134. $map['user.birthday'] = ['between',[time() - $agemax * 31536000,time() - $agemin * 31536000]];
  135. //dump($map);
  136. $field = [
  137. 'user.id','user.username','user.nickname','user.birthday','user.height','user.longitude','user.latitude','user.avatar','user.audio_bio','user.bio','user.gender'
  138. ];
  139. $list = Db::name('user')->alias('user')->field($field)->where($map)->orderRaw('rand()')->autopage()->select();
  140. //dump($list);
  141. $list = list_domain_image($list,['avatar']);
  142. foreach($list as $key => $one){
  143. $one['age'] = birthtime_to_age($one['birthday']);
  144. $one['distance'] = $this->calc_map_distance([$this->auth->longitude,$this->auth->latitude],[$one['longitude'],$one['latitude']]);
  145. $list[$key] = $one;
  146. }
  147. $this->success('success',$list);
  148. }
  149. //附近
  150. public function nearuser(){
  151. $gender = input_post('gender','all');
  152. $agemin = input_post('agemin',0);
  153. $agemax = input_post('agemax',100);
  154. if(empty($this->auth->cityname) || empty($this->auth->longitude) || empty($this->auth->latitude)){
  155. $this->success('success',[]);
  156. }
  157. //经过地图测算和公式推算,经度纬度 0.1即为11公里
  158. $map = [
  159. 'user.status' => 1,
  160. //'user.cityname' => $this->auth->cityname,
  161. 'user.id' => ['neq',$this->auth->id],
  162. 'user.longitude' => ['between',[$this->auth->longitude - 0.1,$this->auth->longitude + 0.1]],
  163. 'user.latitude' => ['between',[$this->auth->latitude - 0.1,$this->auth->latitude + 0.1]],
  164. 'user.is_online|user.is_livebc' => 1,
  165. ];
  166. if($gender != 'all'){
  167. $map['user.gender'] = $gender;
  168. }
  169. $map['user.birthday'] = ['between',[time() - $agemax * 31536000,time() - $agemin * 31536000]];
  170. //dump($map);
  171. $field = [
  172. 'user.id','user.username','user.nickname','user.birthday','user.height','user.longitude','user.latitude','user.avatar','user.audio_bio','user.bio','user.gender'
  173. ];
  174. $list = Db::name('user')->alias('user')->field($field)->where($map)->orderRaw('rand()')->autopage()->select();
  175. //dump($list);exit;
  176. $list = list_domain_image($list,['avatar']);
  177. foreach($list as $key => $one){
  178. $one['age'] = birthtime_to_age($one['birthday']);
  179. $one['distance'] = $this->calc_map_distance([$this->auth->longitude,$this->auth->latitude],[$one['longitude'],$one['latitude']]);
  180. $list[$key] = $one;
  181. }
  182. $this->success('success',$list);
  183. }
  184. //视频通话每分钟调用一次
  185. //女性不收费,互关不收费,设置不收费的也不收费
  186. public function video_onemin(){
  187. $to_user_id = input_post('to_user_id');
  188. $to_user_info = Db::name('user')->field('id,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
  189. if(!$to_user_info){
  190. $this->error('不存在的用户');
  191. }
  192. //先检查今天免费的一分钟
  193. $start = strtotime(date('Y-m-d'));
  194. $end = $start + 86399;
  195. $map = [
  196. 'user_id' => $this->auth->id,
  197. 'createtime' => ['between',[$start,$end]],
  198. 'price' => 0,
  199. ];
  200. $check = Db::name('user_match_video_log')->where($map)->find();
  201. //设置价格
  202. $price = config('site.video_min_price');
  203. $price = empty($check) ? 0 : $price;
  204. $bili = config('site.money_to_gold');
  205. $money = bcdiv($price,$bili,2);
  206. Db::startTrans();
  207. //记录日志
  208. $data = [
  209. 'user_id' => $this->auth->id,
  210. 'price' => $price,
  211. 'createtime' => time(),
  212. 'to_user_id' => $to_user_id,
  213. ];
  214. $log_id = Db::name('user_match_video_log')->insertGetId($data);
  215. if(!$log_id){
  216. Db::rollback();
  217. $this->error('扣费失败');
  218. }
  219. //扣费
  220. //男的,或 未实名认证的女的 都要扣费
  221. if($price > 0 && (($this->auth->gender == 1) || ($this->auth->gender == 0 && $this->auth->idcard_status != 1))){
  222. $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$price,11,'','user_match_video_log',$log_id);
  223. if($rs['status'] === false){
  224. Db::rollback();
  225. $this->error($rs['msg']);
  226. }
  227. }
  228. //另一方加钱,0收费
  229. if($money > 0 && $to_user_info['gender'] == 0 && $to_user_info['free_video'] == 0){
  230. $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'money',$money,21,'','user_match_video_log',$log_id);
  231. if($rs['status'] === false){
  232. Db::rollback();
  233. $this->error($rs['msg']);
  234. }
  235. }
  236. Db::commit();
  237. $this->success('success');
  238. }
  239. //语音通话每分钟调用一次
  240. public function audio_onemin(){
  241. $to_user_id = input_post('to_user_id');
  242. $to_user_info = Db::name('user')->field('id,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
  243. if(!$to_user_info){
  244. $this->error('不存在的用户');
  245. }
  246. //先检查今天免费的一分钟
  247. $start = strtotime(date('Y-m-d'));
  248. $end = $start + 86399;
  249. $map = [
  250. 'user_id' => $this->auth->id,
  251. 'createtime' => ['between',[$start,$end]],
  252. 'price' => 0,
  253. ];
  254. $check = Db::name('user_match_audio_log')->where($map)->find();
  255. //设置价格
  256. $price = config('site.audio_min_price');
  257. $price = empty($check) ? 0 : $price;
  258. $bili = config('site.money_to_gold');
  259. $money = bcdiv($price,$bili,2);
  260. Db::startTrans();
  261. //记录日志
  262. $data = [
  263. 'user_id' => $this->auth->id,
  264. 'price' => $price,
  265. 'createtime' => time(),
  266. 'to_user_id' => $to_user_id,
  267. ];
  268. $log_id = Db::name('user_match_audio_log')->insertGetId($data);
  269. if(!$log_id){
  270. Db::rollback();
  271. $this->error('扣费失败');
  272. }
  273. //扣费
  274. //男的,或 未实名认证的女的 都要扣费
  275. if($price > 0 && (($this->auth->gender == 1) || ($this->auth->gender == 0 && $this->auth->idcard_status != 1))){
  276. $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$price,12,'','user_match_audio_log',$log_id);
  277. if($rs['status'] === false){
  278. Db::rollback();
  279. $this->error($rs['msg']);
  280. }
  281. }
  282. //另一方加钱,0收费
  283. if($money > 0 && $to_user_info['gender'] == 0 && $to_user_info['free_audio'] == 0){
  284. $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'money',$money,22,'','user_match_audio_log',$log_id);
  285. if($rs['status'] === false){
  286. Db::rollback();
  287. $this->error($rs['msg']);
  288. }
  289. }
  290. Db::commit();
  291. $this->success('success');
  292. }
  293. //打字聊天每句话调用一次
  294. public function typing_once(){
  295. $to_user_id = input_post('to_user_id');
  296. $to_user_info = Db::name('user')->field('id,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.typing_min_price');
  302. $bili = config('site.money_to_gold');
  303. $money = bcdiv($price,$bili,2);
  304. Db::startTrans();
  305. //记录日志
  306. $data = [
  307. 'user_id' => $this->auth->id,
  308. 'price' => $price,
  309. 'createtime' => time(),
  310. 'to_user_id' => $to_user_id,
  311. ];
  312. $log_id = Db::name('user_match_typing_log')->insertGetId($data);
  313. if(!$log_id){
  314. Db::rollback();
  315. $this->error('扣费失败');
  316. }
  317. //扣费
  318. //男的,或 未实名认证的女的 都要扣费
  319. if($price > 0 && (($this->auth->gender == 1) || ($this->auth->gender == 0 && $this->auth->idcard_status != 1))){
  320. $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$price,13,'','user_match_typing_log',$log_id);
  321. if($rs['status'] === false){
  322. Db::rollback();
  323. $this->error($rs['msg']);
  324. }
  325. }
  326. //另一方加钱,设置0收费
  327. if($money > 0 && $to_user_info['gender'] == 0 && $to_user_info['free_typing'] == 0){
  328. $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'money',$money,23,'','user_match_typing_log',$log_id);
  329. if($rs['status'] === false){
  330. Db::rollback();
  331. $this->error($rs['msg']);
  332. }
  333. }
  334. //tag任务赠送金币
  335. //搭讪奖励
  336. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
  337. if($task_rs === false){
  338. Db::rollback();
  339. $this->error('完成任务赠送奖励失败');
  340. }
  341. Db::commit();
  342. $this->success('success');
  343. }
  344. //语音匹配
  345. public function getaudiouser(){
  346. //判断资格
  347. $start = strtotime(date('Y-m-d'));
  348. $end = $start + 86399;
  349. $map = [
  350. 'user_id' => $this->auth->id,
  351. 'createtime' => ['between',[$start,$end]],
  352. 'price' => 0,
  353. ];
  354. $check = Db::name('user_match_audio_log')->where($map)->find();
  355. //$check = true;
  356. //已经用掉免费的了,判断金额
  357. if($check){
  358. $price = config('site.audio_min_price');
  359. $gold = model('wallet')->getWallet($this->auth->id,'gold');
  360. if($gold < $price){
  361. $this->error('您的金币已经不足,请充值');
  362. }
  363. }
  364. //找到互关的人,排除
  365. $follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  366. //dump($follow_me);
  367. $my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  368. //dump($my_follow);exit;
  369. //给出备选用户
  370. $map = [
  371. 'status' =>1, //未封禁用户
  372. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  373. 'is_online' => 0, //不在语聊间的
  374. 'is_livebc' => 0, //不在直播的
  375. 'real_status' => 1, //真人认证
  376. 'idcard_status' => 1, //实名认证
  377. 'open_match_audio' => 1, //打开语聊开关
  378. 'id' => ['NOT IN',$my_follow] //不是好友的
  379. ];
  380. $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
  381. $lists = $this->fliter_user($lists,10);
  382. $result = [];
  383. if(!empty($lists)){
  384. foreach($lists as $key => $val){
  385. $result[] = ['id'=>$val];
  386. }
  387. }
  388. //tag任务赠送金币
  389. //语音匹配奖励 +5金币
  390. if(!empty($result)){
  391. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,11);
  392. if($task_rs === false){
  393. $this->error('完成任务赠送奖励失败');
  394. }
  395. }
  396. $this->success('success',$result);
  397. }
  398. //视频匹配
  399. public function getvideouser(){
  400. //判断资格
  401. $start = strtotime(date('Y-m-d'));
  402. $end = $start + 86399;
  403. $map = [
  404. 'user_id' => $this->auth->id,
  405. 'createtime' => ['between',[$start,$end]],
  406. 'price' => 0,
  407. ];
  408. $check = Db::name('user_match_video_log')->where($map)->find();
  409. //$check = true;
  410. //已经用掉免费的了,判断金额
  411. if($check){
  412. $price = config('site.video_min_price');
  413. $gold = model('wallet')->getWallet($this->auth->id,'gold');
  414. if($gold < $price){
  415. $this->error('您的金币已经不足,请充值');
  416. }
  417. }
  418. //找到互关的人,排除
  419. $follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  420. //dump($follow_me);
  421. $my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  422. //dump($my_follow);exit;
  423. //给出备选用户
  424. $map = [
  425. 'status' =>1, //未封禁用户
  426. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  427. 'is_online' => 0, //不在语聊间的
  428. 'is_livebc' => 0, //不在直播的
  429. 'real_status' => 1, //真人认证
  430. 'idcard_status' => 1, //实名认证
  431. 'open_match_video' => 1, //打开视频开关的
  432. 'id' => ['NOT IN',$my_follow] //不是好友的
  433. ];
  434. $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
  435. $lists = $this->fliter_user($lists,10);
  436. $result = [];
  437. if(!empty($lists)){
  438. foreach($lists as $key => $val){
  439. $result[] = ['id'=>$val];
  440. }
  441. }
  442. //tag任务赠送金币
  443. //视频匹配奖励 +5金币
  444. if(!empty($result)){
  445. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,12);
  446. if($task_rs === false){
  447. $this->error('完成任务赠送奖励失败');
  448. }
  449. }
  450. $this->success('success',$result);
  451. }
  452. //聊天匹配
  453. public function gettypinguser(){
  454. //找到互关的人,排除
  455. $follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  456. //dump($follow_me);
  457. $my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  458. //dump($my_follow);exit;
  459. //给出备选用户
  460. $map = [
  461. 'status' =>1, //未封禁用户
  462. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  463. //'real_status' => 1, //真人认证
  464. //'idcard_status' => 1, //实名认证
  465. //打开聊天开关的
  466. 'open_match_typing' => 1, //打开文字聊天开关的
  467. 'id' => ['NOT IN',$my_follow] //不是好友的
  468. ];
  469. $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
  470. //$lists = $this->fliter_user($lists,100);
  471. $lists = array_column($lists,'id');
  472. $result = [];
  473. if(!empty($lists)){
  474. /*foreach($lists as $key => $val){
  475. $result[] = ['id'=>$val];
  476. }*/
  477. $result = Db::name('user')->field('id,nickname,username,avatar,audio_bio')->where(['id'=>['IN',$lists]])->select();
  478. $result = list_domain_image($result,['avatar,audio_bio']);
  479. }
  480. //tag任务赠送金币
  481. //缘分匹配奖励 +5金币
  482. if(!empty($result)){
  483. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,10);
  484. if($task_rs === false){
  485. $this->error('完成任务赠送奖励失败');
  486. }
  487. }
  488. $this->success('success',$result);
  489. }
  490. //过滤规则
  491. private function fliter_user($lists,$number = 1){
  492. if(empty($lists)){
  493. return $lists;
  494. }
  495. //dump($lists);
  496. //过滤掉通话中的
  497. foreach($lists as $key => $val){
  498. if(redis_matching_get($val['id']) == 1){
  499. unset($lists[$key]);
  500. }
  501. }
  502. //预留全部
  503. $all_result = array_column($lists,'id');
  504. //dump($all_result);
  505. //提取同城的
  506. $citydata = [];
  507. foreach($lists as $key => $val){
  508. if( !empty($this->auth->cityname) && $this->auth->cityname == $val['cityname'] ){
  509. $citydata[] = $val['id'];
  510. }
  511. }
  512. //dump($citydata);
  513. //有标签交集的
  514. $tagdata = [];
  515. foreach($lists as $key => $val){
  516. if( !empty($this->auth->tag_ids) && !empty($val['tag_ids']) ){
  517. $auth_tag_ids = explode(',',$this->auth->tag_ids);
  518. $val_tag_ids = explode(',',$val['tag_ids']);
  519. if(count(array_intersect($auth_tag_ids,$val_tag_ids)) > 0){
  520. $tagdata[] = $val['id'];
  521. }
  522. }
  523. }
  524. //dump($tagdata);
  525. //双条件都满足
  526. $double_data = [];
  527. if(!empty($citydata) && !empty($tagdata)){
  528. $double_data = array_intersect($citydata,$tagdata);
  529. }
  530. //dump($double_data);
  531. if(count($double_data) >= $number){
  532. return $double_data;
  533. }
  534. //两种条件合并,去重。空数组合并没影响
  535. $merge_data = array_merge($citydata,$tagdata);
  536. $merge_data = array_flip(array_flip($merge_data));
  537. //dump($merge_data);
  538. if(count($merge_data) >= $number){
  539. return $merge_data;
  540. }
  541. return $all_result;
  542. }
  543. /**
  544. * 是否关注
  545. */
  546. public function isFollows() {
  547. $user_id = $this->request->request("user_id",0,"intval");
  548. if (!$user_id || $user_id<=0) {
  549. $this->error(__('Invalid parameters'));
  550. }
  551. $map = [
  552. 'uid' => $this->auth->id,
  553. 'follow_uid' => $user_id,
  554. ];
  555. $check = Db::name('user_follow')->where($map)->find();
  556. $data = [];
  557. if($check){
  558. $data["is_show_follow"] = 0;
  559. }else{
  560. $data["is_show_follow"] = 1;
  561. }
  562. $this->success("获取成功!",$data);
  563. }
  564. /**
  565. * 获取主播技能分类
  566. */
  567. public function getAnchorType() {
  568. $this->success("获取成功!",\app\common\model\UserAnchorType::select());
  569. }
  570. /**
  571. * 主播申请
  572. */
  573. public function anchorApply() {
  574. $this->error('不需要申请');
  575. /*$type_id = $this->request->request('type_id'); // 技能分类ID
  576. $desc = $this->request->request('desc'); // 申请备注
  577. if (!$type_id && !$desc) {
  578. $this->error(__('Invalid parameters'));
  579. }
  580. $useranchorModel = new \app\common\model\UserAnchor();
  581. $data = [];
  582. $data["user_id"] = $this->auth->id;
  583. $data["type_id"] = $type_id;
  584. if($useranchorModel->where($data)->find()) $this->error(__('您已申请过该类型的主播,请勿重复申请!'));
  585. $data["desc"] = $desc;
  586. $data["createtime"] = time();
  587. $res = $useranchorModel->insertGetId($data);
  588. if($res) {
  589. \app\common\model\User::update(["is_anchor"=>1],["id"=>$this->auth->id]);
  590. $this->success("申请发送成功!");
  591. } else {
  592. $this->error("网络错误,请稍后重试");
  593. }*/
  594. }
  595. /**
  596. * 获取当前用户信息
  597. */
  598. public function getMyUserInfo() {
  599. $userInfo = $this->auth->getUserinfo();
  600. //当月消费金额
  601. $redis = new Redis();
  602. $redisconfig = config("redis");
  603. $redis->connect($redisconfig["host"], $redisconfig["port"]);
  604. $user_renew2 = $redis->get('user_renew2_'.$this->auth->id);
  605. $userInfo['user_renew2'] = empty($user_renew2)?0:intval($user_renew2);
  606. $this->success("获取成功!",$userInfo);
  607. }
  608. /**
  609. * calc_map_distance() , 根据地图上的两个点各自的x,y坐标,计算出2点之间的直线距离
  610. * @param array $point_1 第1个点的x,y坐标 array( 101 , 202 )
  611. * @param array $point_2 第2个点的x,y坐标 array( 101 , 202 )
  612. * @param bool $calc_as_string 是否计算为字符串公里距离 , 如果未否返回数字
  613. * @return float | false | string
  614. */
  615. private function calc_map_distance( $point_1=array( ) , $point_2=array( ) , $calc_as_string=false ) {
  616. if( empty( $point_1 ) || empty( $point_2 ) ){
  617. return false;
  618. }
  619. // 经纬度不存在,或者经纬度超过最大范围 +-180 , +-90 ,返回false
  620. $p1_x = $point_1[0];
  621. $p1_y = $point_1[1];
  622. $p2_x = $point_2[0];
  623. $p2_y = $point_2[1];
  624. if(
  625. $p1_x < -180 || $p1_x > 180
  626. || $p2_x < -180 || $p2_x > 180
  627. || $p1_y < -90 || $p1_y > 90
  628. || $p2_y < -90 || $p2_y > 90
  629. ){
  630. return '0公里';
  631. }
  632. // 根据2点各自的坐标,计算2点之间直线距离的公式
  633. $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);
  634. // 是否计算为字符串公里距离
  635. if( !$calc_as_string ){
  636. return (string)round( $distance / 1000 , 1 ) . '公里';
  637. }
  638. // 如果计算为字符串公里距离
  639. if( $distance / 1000 > 1 ){
  640. $k = (string)round( $distance / 1000 , 1 );
  641. $m = (string)$distance % 1000 ;
  642. $distance = "{$k}公里{$m}米";
  643. }
  644. else{
  645. $distance = "{$distance}米";
  646. }
  647. return $distance;
  648. }
  649. //地图api,根据两地坐标,获得两地距离,打卡用的
  650. //type=0直线,type=1开车
  651. private function getmapjuli($start_lon,$start_lat,$end_lon,$end_lat,$type = 0){
  652. $result = 0;
  653. $apiurl = 'https://restapi.amap.com/v3/distance?';
  654. $param = [
  655. 'key' => '398c424811d1a59beac2f915323d334e',
  656. 'origins' => $start_lon.','.$start_lat,
  657. 'destination' => $end_lon.','.$end_lat,
  658. 'type' => $type,
  659. 'output' => 'json',
  660. ];
  661. $apiurl .= http_build_query($param);
  662. $request_rs = json_decode(curl_get($apiurl),true);
  663. if(isset($request_rs['status']) && $request_rs['status'] == 1){
  664. if(isset($request_rs['results'][0]['distance']))
  665. {
  666. $result = $request_rs['results'][0]['distance'];
  667. }
  668. }
  669. //dump($result);
  670. return $result;
  671. }
  672. public function distance()
  673. {
  674. $a = $this->calc_map_distance([118.339282,35.028445],[118.437399,35.017438]);
  675. dump($a);
  676. $a = $this->calc_map_distance([118.339282,35.028445],[118.437399,35.017438],true);
  677. dump($a);
  678. $b = $this->getmapjuli(118.339282,35.028445,118.437399,35.017438,1);
  679. dump($b);
  680. $b = $this->getmapjuli(118.339282,35.028445,118.437399,35.017438,0);
  681. dump($b);
  682. }
  683. }