Match.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. /**
  6. * 匹配 与 匹配的收费
  7. */
  8. class Match extends Api
  9. {
  10. protected $noNeedLogin = ['*'];
  11. protected $noNeedRight = ['*'];
  12. //视频通话记录
  13. public function video_log(){
  14. if($this->auth->gender == 0){
  15. $list = Db::name('user_match_video_log')->alias('log')
  16. ->field('log.id,log.user_id as the_user_id,log.call_minutes,log.createtime,user.avatar,user.nickname')
  17. ->join('user','log.user_id = user.id','LEFT')
  18. ->where('log.to_user_id' , $this->auth->id)
  19. ->order('log.id desc')->autopage()->select();
  20. }else{
  21. $list = Db::name('user_match_video_log')->alias('log')
  22. ->field('log.id,log.to_user_id as the_user_id,log.call_minutes,log.createtime,user.avatar,user.nickname')
  23. ->join('user','log.to_user_id = user.id','LEFT')
  24. ->where('log.user_id' , $this->auth->id)
  25. ->order('log.id desc')->autopage()->select();
  26. }
  27. $list = list_domain_image($list,['avatar']);
  28. $this->success(1,$list);
  29. }
  30. //语音通话记录
  31. public function audio_log(){
  32. if($this->auth->gender == 0){
  33. $list = Db::name('user_match_audio_log')->alias('log')
  34. ->field('log.id,log.user_id as the_user_id,log.call_minutes,log.createtime,user.avatar,user.nickname')
  35. ->join('user','log.user_id = user.id','LEFT')
  36. ->where('log.to_user_id' , $this->auth->id)
  37. ->order('log.id desc')->autopage()->select();
  38. }else{
  39. $list = Db::name('user_match_audio_log')->alias('log')
  40. ->field('log.id,log.to_user_id as the_user_id,log.call_minutes,log.createtime,user.avatar,user.nickname')
  41. ->join('user','log.to_user_id = user.id','LEFT')
  42. ->where('log.user_id' , $this->auth->id)
  43. ->order('log.id desc')->autopage()->select();
  44. }
  45. $list = list_domain_image($list,['avatar']);
  46. $this->success(1,$list);
  47. }
  48. //视频通话每分钟调用一次
  49. public function video_onemin(){
  50. if ($this->auth->gender == 0) { //女生不花钱
  51. $this->error('您的网络开小差啦~');
  52. }
  53. //检测用户
  54. $request_id = input('request_id', '', 'trim'); //唯一请求标识
  55. $to_user_id = input_post('to_user_id');
  56. $to_user_info = Db::name('user')->field('id,username,intro_uid,gender,match_video_price')->where('id',$to_user_id)->find();
  57. if(!$to_user_info){
  58. $this->error('不存在的用户');
  59. }
  60. if ($to_user_info['gender'] != 0) {
  61. $this->error('同性不能聊天~');
  62. }
  63. //正常价格
  64. $price = $to_user_info['match_video_price']; //扣费金币
  65. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  66. $money = bcdiv(bcmul($price,100 - $gift_plat_scale,2),100,2); //抽成后收益
  67. Db::startTrans();
  68. //检查剩余分钟数
  69. $task_status = 0;//任务状态
  70. $user_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->lock(true)->find();
  71. if($user_wallet['video_sec'] >= 1){
  72. //扣分钟数
  73. $price = 0;
  74. //补贴给对方0.1金币
  75. $money = 0.1;
  76. }else{
  77. $task_status = 1;
  78. //需要扣别人的钱,判断钱是否购
  79. if($price > 0){
  80. $goldtotal = model('wallet')->getWallettotal($this->auth->id);
  81. if(bccomp($price,$goldtotal) == 1){
  82. Db::rollback();
  83. $this->error('金币不足');
  84. }
  85. }
  86. }
  87. //查询是否有匹配记录
  88. $user_match_video_log_info = [];
  89. if ($request_id) {
  90. $user_match_video_log_info = Db::name('user_match_video_log')->where(['user_id' => $this->auth->id, 'to_user_id' => $to_user_id, 'request_id' => $request_id])->find();
  91. }
  92. if ($user_match_video_log_info) {
  93. //修改记录日志
  94. $data = [
  95. 'price' => $user_match_video_log_info['price'] + $price,
  96. 'updatetime' => time(),
  97. 'money' => $user_match_video_log_info['money'] + $money,
  98. 'call_minutes' => $user_match_video_log_info['call_minutes'] + 1
  99. ];
  100. $log_id = Db::name('user_match_video_log')->where(['id' => $user_match_video_log_info['id']])->setField($data);
  101. if (!$log_id) {
  102. Db::rollback();
  103. $this->error('扣费失败');
  104. }
  105. } else {
  106. //添加记录日志
  107. $data = [
  108. 'user_id' => $this->auth->id,
  109. 'price' => $price,
  110. 'createtime' => time(),
  111. 'to_user_id' => $to_user_id,
  112. 'money' => $money,
  113. 'request_id' => $request_id,
  114. 'call_minutes' => 1
  115. ];
  116. $log_id = Db::name('user_match_video_log')->insertGetId($data);
  117. if (!$log_id) {
  118. Db::rollback();
  119. $this->error('扣费失败');
  120. }
  121. }
  122. //检查剩余分钟数
  123. if($user_wallet['video_sec'] >= 1){
  124. //扣分钟数
  125. $rs_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->update(['video_sec'=>$user_wallet['video_sec']-1]);
  126. if($rs_wallet === false){
  127. Db::rollback();
  128. $this->error('扣除分钟数失败');
  129. }
  130. //补贴给对方0.1金币
  131. $money = 0.1;
  132. $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'jewel',$money,21,$this->auth->username.'使用免费次数的补贴','user_match_video_log',$log_id);
  133. if($rs['status'] === false){
  134. Db::rollback();
  135. $this->error($rs['msg']);
  136. }
  137. }else{
  138. //有性别差,扣费
  139. if($price > 0){
  140. $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$price,11,'与'.$to_user_info['username'].'视频通话','user_match_video_log',$log_id);
  141. if($rs['status'] === false){
  142. Db::rollback();
  143. $this->error($rs['msg']);
  144. }
  145. }
  146. //另一方加钱,0收费
  147. if($money > 0){
  148. $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'jewel',$money,21,'与'.$this->auth->username.'视频通话','user_match_video_log',$log_id);
  149. if($rs['status'] === false){
  150. Db::rollback();
  151. $this->error($rs['msg']);
  152. }
  153. }
  154. //增加送礼用户的财富等级
  155. $res_wealth = \app\common\model\User::add_wealth_level($this->auth->id,$price);
  156. //增加获赠用户的魅力等级
  157. $res_wealth = \app\common\model\User::add_charm_level($to_user_id,$price);
  158. }
  159. //tag任务赠送金币
  160. //与1名异性语音通话奖励
  161. if($task_status == 1){
  162. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,11);
  163. if($task_rs === false){
  164. Db::rollback();
  165. $this->error('完成任务赠送奖励失败');
  166. }
  167. $task_rs = \app\common\model\TaskLog::tofinish($to_user_id,11);
  168. if($task_rs === false){
  169. Db::rollback();
  170. $this->error('完成任务赠送奖励失败');
  171. }
  172. }
  173. Db::commit();
  174. $rs = [
  175. 'get_jewel_value' => $data['money'],
  176. ];
  177. $this->success('success',$rs);
  178. }
  179. //语音通话每分钟调用一次
  180. public function audio_onemin(){
  181. if ($this->auth->gender == 0) { //女生不花钱
  182. $this->error('您的网络开小差啦~');
  183. }
  184. //检测用户
  185. $request_id = input('request_id', '', 'trim'); //唯一请求标识
  186. $to_user_id = input_post('to_user_id');
  187. $to_user_info = Db::name('user')->field('id,username,intro_uid,gender,match_audio_price')->where('id',$to_user_id)->find();
  188. if(!$to_user_info){
  189. $this->error('不存在的用户');
  190. }
  191. if ($to_user_info['gender'] != 0) {
  192. $this->error('同性不能聊天~');
  193. }
  194. //正常价格
  195. $price = $to_user_info['match_audio_price']; //扣费金币
  196. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  197. $money = bcdiv(bcmul($price,100 - $gift_plat_scale,2),100,2); //抽成后收益
  198. Db::startTrans();
  199. //检查剩余分钟数
  200. $task_status = 0;//任务状态
  201. $user_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->lock(true)->find();
  202. if($user_wallet['audio_sec'] >= 1){
  203. //扣分钟数
  204. $price = 0;
  205. //补贴给对方0.1金币
  206. $money = 0.1;
  207. }else{
  208. $task_status = 1;
  209. //需要扣别人的钱,判断钱是否购
  210. if($price > 0){
  211. $goldtotal = model('wallet')->getWallettotal($this->auth->id);
  212. if(bccomp($price,$goldtotal) == 1){
  213. Db::rollback();
  214. $this->error('金币不足');
  215. }
  216. }
  217. }
  218. //查询是否有匹配记录
  219. $user_match_audio_log_info = [];
  220. if ($request_id) {
  221. $user_match_audio_log_info = Db::name('user_match_audio_log')->where(['user_id' => $this->auth->id, 'to_user_id' => $to_user_id, 'request_id' => $request_id])->find();
  222. }
  223. if ($user_match_audio_log_info) {
  224. //修改记录日志
  225. $data = [
  226. 'price' => $user_match_audio_log_info['price'] + $price,
  227. 'updatetime' => time(),
  228. 'money' => $user_match_audio_log_info['money'] + $money,
  229. 'call_minutes' => $user_match_audio_log_info['call_minutes'] + 1
  230. ];
  231. $log_id = Db::name('user_match_audio_log')->where(['id' => $user_match_audio_log_info['id']])->setField($data);
  232. if (!$log_id) {
  233. Db::rollback();
  234. $this->error('扣费失败');
  235. }
  236. } else {
  237. //添加记录日志
  238. $data = [
  239. 'user_id' => $this->auth->id,
  240. 'price' => $price,
  241. 'createtime' => time(),
  242. 'to_user_id' => $to_user_id,
  243. 'money' => $money,
  244. 'request_id' => $request_id,
  245. 'call_minutes' => 1
  246. ];
  247. $log_id = Db::name('user_match_audio_log')->insertGetId($data);
  248. if (!$log_id) {
  249. Db::rollback();
  250. $this->error('扣费失败');
  251. }
  252. }
  253. //检查剩余分钟数
  254. if($user_wallet['audio_sec'] >= 1){
  255. //扣分钟数
  256. $rs_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->update(['audio_sec'=>$user_wallet['audio_sec']-1]);
  257. if($rs_wallet === false){
  258. Db::rollback();
  259. $this->error('扣除分钟数失败');
  260. }
  261. //补贴给对方0.1金币
  262. $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'jewel',$money,22,$this->auth->username.'使用免费次数的补贴','user_match_audio_log',$log_id);
  263. if($rs['status'] === false){
  264. Db::rollback();
  265. $this->error($rs['msg']);
  266. }
  267. }else{
  268. //有性别差,扣费
  269. if($price > 0){
  270. $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$price,12,'与'.$to_user_info['username'].'语音通话','user_match_audio_log',$log_id);
  271. if($rs['status'] === false){
  272. Db::rollback();
  273. $this->error($rs['msg']);
  274. }
  275. }
  276. //另一方加钱,0收费
  277. if($money > 0){
  278. $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'jewel',$money,22,'与'.$this->auth->username.'语音通话','user_match_audio_log',$log_id);
  279. if($rs['status'] === false){
  280. Db::rollback();
  281. $this->error($rs['msg']);
  282. }
  283. }
  284. //增加送礼用户的财富等级
  285. $res_wealth = \app\common\model\User::add_wealth_level($this->auth->id,$price);
  286. //增加获赠用户的魅力等级
  287. $res_wealth = \app\common\model\User::add_charm_level($to_user_id,$price);
  288. }
  289. //tag任务赠送金币
  290. //与1名异性语音通话奖励
  291. if($task_status == 1){
  292. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,11);
  293. if($task_rs === false){
  294. Db::rollback();
  295. $this->error('完成任务赠送奖励失败');
  296. }
  297. $task_rs = \app\common\model\TaskLog::tofinish($to_user_id,11);
  298. if($task_rs === false){
  299. Db::rollback();
  300. $this->error('完成任务赠送奖励失败');
  301. }
  302. }
  303. Db::commit();
  304. $rs = [
  305. 'get_jewel_value' => $data['money'],
  306. ];
  307. $this->success('success',$rs);
  308. }
  309. //打字聊天每句话调用一次
  310. public function typing_once(){
  311. if ($this->auth->gender == 0) { //女生不花钱
  312. $this->error('您的网络开小差啦~');
  313. }
  314. //检测用户
  315. $to_user_id = input_post('to_user_id');
  316. $to_user_info = Db::name('user')->field('id,username,intro_uid,gender,match_typing_price')->where('id',$to_user_id)->find();
  317. if(!$to_user_info){
  318. $this->error('不存在的用户');
  319. }
  320. if ($to_user_info['gender'] != 0) {
  321. $this->error('同性不能聊天~');
  322. }
  323. //正常价格
  324. $price = $to_user_info['match_typing_price']; //扣费金币
  325. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  326. $money = bcdiv(bcmul($price,100 - $gift_plat_scale,2),100,2); //抽成后收益
  327. Db::startTrans();
  328. //检查剩余分钟数
  329. $user_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->lock(true)->find();
  330. if($user_wallet['typing_times'] >= 1){
  331. //扣分钟数
  332. $price = 0;
  333. //补贴给对方0.1金币
  334. $money = 0.1;
  335. }else{
  336. //需要扣别人的钱,判断钱是否购
  337. if($price > 0){
  338. $goldtotal = model('wallet')->getWallettotal($this->auth->id);
  339. if(bccomp($price,$goldtotal) == 1){
  340. Db::rollback();
  341. $this->error('金币不足');
  342. }
  343. }
  344. }
  345. //添加记录日志
  346. $data = [
  347. 'user_id' => $this->auth->id,
  348. 'price' => $price,
  349. 'createtime' => time(),
  350. 'to_user_id' => $to_user_id,
  351. 'money' => $money,
  352. ];
  353. $log_id = Db::name('user_match_typing_log')->insertGetId($data);
  354. if (!$log_id) {
  355. Db::rollback();
  356. $this->error('扣费失败');
  357. }
  358. //检查剩余分钟数
  359. if($user_wallet['typing_times'] >= 1){
  360. //扣分钟数
  361. $rs_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->update(['typing_times'=>$user_wallet['typing_times']-1]);
  362. if($rs_wallet === false){
  363. Db::rollback();
  364. $this->error('扣除免费次数失败');
  365. }
  366. //补贴给对方0.1金币
  367. $money = 0.1;
  368. $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'jewel',$money,23,$this->auth->username.'使用免费次数的补贴','user_match_typing_log',$log_id);
  369. if($rs['status'] === false){
  370. Db::rollback();
  371. $this->error($rs['msg']);
  372. }
  373. }else{
  374. //有性别差,扣费
  375. if($price > 0){
  376. $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$price,13,'与'.$to_user_info['username'].'聊天','user_match_typing_log',$log_id);
  377. if($rs['status'] === false){
  378. Db::rollback();
  379. $this->error($rs['msg']);
  380. }
  381. }
  382. //另一方加钱,0收费
  383. if($money > 0){
  384. $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'jewel',$money,23,'与'.$this->auth->username.'聊天','user_match_typing_log',$log_id);
  385. if($rs['status'] === false){
  386. Db::rollback();
  387. $this->error($rs['msg']);
  388. }
  389. }
  390. //增加送礼用户的财富等级
  391. $res_wealth = \app\common\model\User::add_wealth_level($this->auth->id,$price);
  392. //增加获赠用户的魅力等级
  393. $res_wealth = \app\common\model\User::add_charm_level($to_user_id,$price);
  394. }
  395. Db::commit();
  396. $rs = [
  397. 'get_jewel_value' => $money,
  398. ];
  399. $this->success('success',$rs);
  400. }
  401. //语音匹配
  402. public function getaudiouser(){
  403. if(config('site.index_match_audio_switch') != 1){
  404. $this->error('该功能暂未开启');
  405. }
  406. //给出备选用户
  407. $map = [
  408. 'user.status' =>1, //未封禁用户
  409. 'user.gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  410. 'user.is_active' => 1, //在线的
  411. 'user.open_match_audio' => 1, //打开语聊开关
  412. ];
  413. if($this->auth->gender == 0){
  414. //或者未首充用户,且还有免费分钟数
  415. $map2['user.is_shouchong'] = 0;
  416. $map2['uw.audio_sec'] = ['gt',0];
  417. //男性要有最少一分钟的钱
  418. $map3['uw.gold'] = ['egt',$this->auth->match_audio_price];
  419. }else{
  420. $my_gold = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('gold');
  421. $map2['user.match_audio_price'] = ['elt',$my_gold];
  422. }
  423. $lists = Db::name('user')->alias('user')->field('user.id,user.gender,user.birthday,user.avatar,user.nickname,user.match_audio_price')
  424. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  425. ->where($map)->where($map2)->order('user.logintime desc')->page($this->page,100)->select();
  426. if(empty($lists) && $this->auth->gender == 0){
  427. $lists = Db::name('user')->alias('user')->field('user.id,user.gender,user.birthday,user.avatar,user.nickname,user.match_audio_price')
  428. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  429. ->where($map)->where($map3)->order('user.logintime desc')->page($this->page,100)->select();
  430. }
  431. if(!empty($lists)){
  432. foreach($lists as $key => &$val){
  433. $val = info_domain_image($val,['avatar']);
  434. $val['age'] = birthtime_to_age($val['birthday']);
  435. unset($val['birthday']);
  436. $val['match_audio_price'] = $this->auth->gender == 0 ? $this->auth->match_audio_price : $val['match_audio_price'];
  437. }
  438. }
  439. $this->success('success',$lists);
  440. }
  441. //视频匹配
  442. public function getvideouser(){
  443. if(config('site.index_match_video_switch') != 1){
  444. $this->error('该功能暂未开启');
  445. }
  446. //给出备选用户
  447. $map = [
  448. 'user.status' =>1, //未封禁用户
  449. 'user.gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  450. 'user.is_active' => 1, //在线的
  451. 'user.open_match_video' => 1, //打开语聊开关
  452. ];
  453. if($this->auth->gender == 0){
  454. //或者未首充用户,且还有免费分钟数
  455. $map2['user.is_shouchong'] = 0;
  456. $map2['uw.video_sec'] = ['gt',0];
  457. //男性要有最少一分钟的钱
  458. $map3['uw.gold'] = ['egt',$this->auth->match_video_price];
  459. }else{
  460. $my_gold = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('gold');
  461. $map2['user.match_video_price'] = ['elt',$my_gold];
  462. }
  463. $lists = Db::name('user')->alias('user')->field('user.id,user.gender,user.birthday,user.avatar,user.nickname,user.match_video_price')
  464. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  465. ->where($map)->where($map2)->order('user.logintime desc')->page($this->page,100)->select();
  466. if(empty($lists) && $this->auth->gender == 0){
  467. $lists = Db::name('user')->alias('user')->field('user.id,user.gender,user.birthday,user.avatar,user.nickname,user.match_video_price')
  468. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  469. ->where($map)->where($map3)->order('user.logintime desc')->page($this->page,100)->select();
  470. }
  471. if(!empty($lists)){
  472. foreach($lists as $key => &$val){
  473. $val = info_domain_image($val,['avatar']);
  474. $val['age'] = birthtime_to_age($val['birthday']);
  475. unset($val['birthday']);
  476. $val['match_video_price'] = $this->auth->gender == 0 ? $this->auth->match_video_price : $val['match_video_price'];
  477. }
  478. }
  479. $this->success('success',$lists);
  480. }
  481. //聊天匹配
  482. //没有用到
  483. public function gettypinguser(){
  484. //给出备选用户
  485. $map = [
  486. 'user.status' =>1, //未封禁用户
  487. 'user.gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  488. ];
  489. if($this->auth->gender == 0){
  490. //或者未首充用户,且还有免费分钟数
  491. $map2['user.is_shouchong'] = 0;
  492. $map2['uw.typing_times'] = ['gt',0];
  493. //男性要有最少一分钟的钱
  494. $map3['uw.gold'] = ['egt',$this->auth->match_typing_price];
  495. }else{
  496. $my_gold = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('gold');
  497. $map2['user.match_typing_price'] = ['elt',$my_gold];
  498. }
  499. $lists = Db::name('user')->alias('user')->field('user.id')
  500. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  501. ->where($map)->where($map2)->order('user.logintime desc')->page($this->page,100)->select();
  502. if(empty($lists) && $this->auth->gender == 0){
  503. $lists = Db::name('user')->alias('user')->field('user.id')
  504. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  505. ->where($map)->where($map3)->order('user.logintime desc')->page($this->page,100)->select();
  506. }
  507. $this->success('success',$lists);
  508. }
  509. //过滤规则
  510. private function fliter_user($lists){
  511. if(empty($lists)){
  512. return $lists;
  513. }
  514. //过滤掉通话中的
  515. foreach($lists as $key => $val){
  516. if(redis_matching_get($val['id']) == 1){
  517. unset($lists[$key]);
  518. }
  519. }
  520. return $lists;
  521. }
  522. //亲密度等级信息
  523. public function intimacylevel() {
  524. $user_id = input('user_id', 0, 'intval'); //对方id
  525. if (!$user_id) {
  526. $this->error('参数缺失');
  527. }
  528. if ($this->auth->id > $user_id) { //大的在后
  529. $where['uid'] = $user_id;
  530. $where['other_uid'] = $this->auth->id;
  531. } else { //小的在前
  532. $where['uid'] = $this->auth->id;
  533. $where['other_uid'] = $user_id;
  534. }
  535. $level = 0; //当前等级
  536. $level_name = ''; //当前等级名称
  537. $qinmi_sum = 0; //当前亲密度
  538. $next_level_diff = 0; //距下一等级亲密度差值
  539. $next_level_name = 0; //下一等级名称
  540. $next_level_value = 0;//下一等级亲密度值
  541. //亲密度等级列表
  542. $list = Db::name('intimacy_level')->field('name,level,value')->order('value')->select();
  543. //当前亲密度信息
  544. $user_intimacy_info = Db::name('user_intimacy')->where($where)->find();
  545. if ($user_intimacy_info) {
  546. //当前亲密度
  547. $qinmi_sum = $user_intimacy_info['value'];
  548. //当前等级信息
  549. $level_info = Db::name('intimacy_level')->where(['value' => ['elt', $user_intimacy_info['value']]])->order('level desc')->find();
  550. if ($level_info) {
  551. $level = $level_info['level'];
  552. $level_name = $level_info['name'];
  553. }
  554. //下一等级信息
  555. $next_level_info = Db::name('intimacy_level')->where(['value' => ['gt', $user_intimacy_info['value']]])->order('value')->find();
  556. if ($next_level_info) {
  557. $next_level_name = $next_level_info['name'];
  558. $next_level_value = $next_level_info['value'];
  559. $next_level_diff = $next_level_info['value'] - $user_intimacy_info['value'];
  560. }
  561. } else {
  562. $level = 1; //当前等级
  563. $level_name = '初级'; //当前等级名称
  564. $qinmi_sum = 0; //当前亲密度
  565. $next_level = Db::name('intimacy_level')->where('level',2)->find();
  566. $next_level_diff = $next_level['value'];
  567. $next_level_name = $next_level['name'];
  568. $next_level_value = $next_level['value'];
  569. }
  570. if ($list) {
  571. foreach ($list as &$v) {
  572. if ($v['level'] < $level) {
  573. $v['is_unlock'] = 1; //当前等级是否解锁: 1已解锁 2当前等级 3未解锁
  574. } elseif ($v['level'] == $level) {
  575. $v['is_unlock'] = 2;
  576. } else {
  577. $v['is_unlock'] = 3;
  578. }
  579. }
  580. }
  581. $data['level'] = $level; //当前等级
  582. $data['level_name'] = $level_name; //当前等级名称
  583. $data['qinmi_sum'] = $qinmi_sum; //当前亲密度
  584. $data['next_level_diff'] = $next_level_diff; //距下一等级亲密度差值
  585. $data['next_level_name'] = $next_level_name; //下一等级名称
  586. $data['next_level_value'] = $next_level_value; //下一等级亲密度值
  587. $data['level_list'] = $list; //等级列表
  588. $data['my_avatar'] = localpath_to_netpath($this->auth->avatar);
  589. $data['my_nickname'] = $this->auth->nickname;
  590. $other_user = Db::name('user')->field('avatar,nickname')->where('id',$user_id)->find();
  591. $data['other_avatar'] = localpath_to_netpath($other_user['avatar']);
  592. $data['other_nickname'] = $other_user['nickname'];
  593. $data['intimacy_rule'] = config('site.intimacy_rule');
  594. $this->success('亲密度等级信息', $data);
  595. }
  596. }