Usercenter.php 38 KB

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