Match.php 25 KB

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