Usercenter.php 26 KB

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