Match.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  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. if(config('site.index_match_audio_switch') != 1){
  384. $this->error('该功能暂未开启');
  385. }
  386. //给出备选用户
  387. $map = [
  388. 'user.status' =>1, //未封禁用户
  389. 'user.gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  390. 'user.is_active' => 1, //在线的
  391. 'user.open_match_audio' => 1, //打开语聊开关
  392. ];
  393. if($this->auth->gender == 0){
  394. //或者未首充用户,且还有免费分钟数
  395. $map2['user.is_shouchong'] = 0;
  396. $map2['uw.audio_sec'] = ['gt',0];
  397. //男性要有最少一分钟的钱
  398. $map3['uw.gold'] = ['egt',$this->auth->match_audio_price];
  399. }else{
  400. $my_gold = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('gold');
  401. $map2['user.match_audio_price'] = ['elt',$my_gold];
  402. }
  403. $lists = Db::name('user')->alias('user')->field('user.id,user.gender,user.birthday,user.avatar,user.nickname,user.match_audio_price')
  404. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  405. ->where($map)->where($map2)->order('user.logintime desc')->page($this->page,100)->select();
  406. if(empty($lists) && $this->auth->gender == 0){
  407. $lists = Db::name('user')->alias('user')->field('user.id,user.gender,user.birthday,user.avatar,user.nickname,user.match_audio_price')
  408. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  409. ->where($map)->where($map3)->order('user.logintime desc')->page($this->page,100)->select();
  410. }
  411. if(!empty($lists)){
  412. foreach($lists as $key => &$val){
  413. $val = info_domain_image($val,['avatar']);
  414. $val['age'] = birthtime_to_age($val['birthday']);
  415. unset($val['birthday']);
  416. $val['match_audio_price'] = $this->auth->gender == 0 ? $this->auth->match_audio_price : $val['match_audio_price'];
  417. }
  418. }
  419. $this->success('success',$lists);
  420. }
  421. //视频匹配
  422. public function getvideouser(){
  423. if(config('site.index_match_video_switch') != 1){
  424. $this->error('该功能暂未开启');
  425. }
  426. //给出备选用户
  427. $map = [
  428. 'user.status' =>1, //未封禁用户
  429. 'user.gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  430. 'user.is_active' => 1, //在线的
  431. 'user.open_match_video' => 1, //打开语聊开关
  432. ];
  433. if($this->auth->gender == 0){
  434. //或者未首充用户,且还有免费分钟数
  435. $map2['user.is_shouchong'] = 0;
  436. $map2['uw.video_sec'] = ['gt',0];
  437. //男性要有最少一分钟的钱
  438. $map3['uw.gold'] = ['egt',$this->auth->match_video_price];
  439. }else{
  440. $my_gold = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('gold');
  441. $map2['user.match_video_price'] = ['elt',$my_gold];
  442. }
  443. $lists = Db::name('user')->alias('user')->field('user.id,user.gender,user.birthday,user.avatar,user.nickname,user.match_video_price')
  444. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  445. ->where($map)->where($map2)->order('user.logintime desc')->page($this->page,100)->select();
  446. if(empty($lists) && $this->auth->gender == 0){
  447. $lists = Db::name('user')->alias('user')->field('user.id,user.gender,user.birthday,user.avatar,user.nickname,user.match_video_price')
  448. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  449. ->where($map)->where($map3)->order('user.logintime desc')->page($this->page,100)->select();
  450. }
  451. if(!empty($lists)){
  452. foreach($lists as $key => &$val){
  453. $val = info_domain_image($val,['avatar']);
  454. $val['age'] = birthtime_to_age($val['birthday']);
  455. unset($val['birthday']);
  456. $val['match_video_price'] = $this->auth->gender == 0 ? $this->auth->match_video_price : $val['match_video_price'];
  457. }
  458. }
  459. $this->success('success',$lists);
  460. }
  461. //聊天匹配
  462. //没有用到
  463. public function gettypinguser(){
  464. //给出备选用户
  465. $map = [
  466. 'user.status' =>1, //未封禁用户
  467. 'user.gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  468. ];
  469. if($this->auth->gender == 0){
  470. //或者未首充用户,且还有免费分钟数
  471. $map2['user.is_shouchong'] = 0;
  472. $map2['uw.typing_times'] = ['gt',0];
  473. //男性要有最少一分钟的钱
  474. $map3['uw.gold'] = ['egt',$this->auth->match_typing_price];
  475. }else{
  476. $my_gold = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('gold');
  477. $map2['user.match_typing_price'] = ['elt',$my_gold];
  478. }
  479. $lists = Db::name('user')->alias('user')->field('user.id')
  480. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  481. ->where($map)->where($map2)->order('user.logintime desc')->page($this->page,100)->select();
  482. if(empty($lists) && $this->auth->gender == 0){
  483. $lists = Db::name('user')->alias('user')->field('user.id')
  484. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  485. ->where($map)->where($map3)->order('user.logintime desc')->page($this->page,100)->select();
  486. }
  487. $this->success('success',$lists);
  488. }
  489. //过滤规则
  490. private function fliter_user($lists){
  491. if(empty($lists)){
  492. return $lists;
  493. }
  494. //过滤掉通话中的
  495. foreach($lists as $key => $val){
  496. if(redis_matching_get($val['id']) == 1){
  497. unset($lists[$key]);
  498. }
  499. }
  500. return $lists;
  501. }
  502. //亲密度等级信息
  503. public function intimacylevel() {
  504. $user_id = input('user_id', 0, 'intval'); //对方id
  505. if (!$user_id) {
  506. $this->error('参数缺失');
  507. }
  508. if ($this->auth->id > $user_id) { //大的在后
  509. $where['uid'] = $user_id;
  510. $where['other_uid'] = $this->auth->id;
  511. } else { //小的在前
  512. $where['uid'] = $this->auth->id;
  513. $where['other_uid'] = $user_id;
  514. }
  515. $level = 0; //当前等级
  516. $level_name = ''; //当前等级名称
  517. $qinmi_sum = 0; //当前亲密度
  518. $next_level_diff = 0; //距下一等级亲密度差值
  519. $next_level_name = 0; //下一等级名称
  520. $next_level_value = 0;//下一等级亲密度值
  521. //亲密度等级列表
  522. $list = Db::name('intimacy_level')->field('name,level,value')->order('value')->select();
  523. //当前亲密度信息
  524. $user_intimacy_info = Db::name('user_intimacy')->where($where)->find();
  525. if ($user_intimacy_info) {
  526. //当前亲密度
  527. $qinmi_sum = $user_intimacy_info['value'];
  528. if ($list) {
  529. //当前等级信息
  530. $level_info = Db::name('intimacy_level')->where(['value' => ['elt', $user_intimacy_info['value']]])->order('level desc')->find();
  531. if ($level_info) {
  532. $level = $level_info['level'];
  533. $level_name = $level_info['name'];
  534. }
  535. //下一等级信息
  536. $next_level_info = Db::name('intimacy_level')->where(['value' => ['gt', $user_intimacy_info['value']]])->order('value')->find();
  537. if ($next_level_info) {
  538. $next_level_name = $next_level_info['name'];
  539. $next_level_value = $next_level_info['value'];
  540. $next_level_diff = $next_level_info['value'] - $user_intimacy_info['value'];
  541. }
  542. }
  543. } else {
  544. $next_level = Db::name('intimacy_level')->order('value')->find();
  545. $next_level_diff = $next_level['value'];
  546. $next_level_name = $next_level['name'];
  547. $next_level_value = $next_level['value'];
  548. }
  549. if ($list) {
  550. foreach ($list as &$v) {
  551. if ($v['level'] < $level) {
  552. $v['is_unlock'] = 1; //当前等级是否解锁: 1已解锁 2当前等级 3未解锁
  553. } elseif ($v['level'] == $level) {
  554. $v['is_unlock'] = 2;
  555. } else {
  556. $v['is_unlock'] = 3;
  557. }
  558. }
  559. }
  560. $data['level'] = $level; //当前等级
  561. $data['level_name'] = $level_name; //当前等级名称
  562. $data['qinmi_sum'] = $qinmi_sum; //当前亲密度
  563. $data['next_level_diff'] = $next_level_diff; //距下一等级亲密度差值
  564. $data['next_level_name'] = $next_level_name; //下一等级名称
  565. $data['next_level_value'] = $next_level_value; //下一等级亲密度值
  566. $data['level_list'] = $list; //等级列表
  567. $data['my_avatar'] = localpath_to_netpath($this->auth->avatar);
  568. $data['my_nickname'] = $this->auth->nickname;
  569. $other_user = Db::name('user')->field('avatar,nickname')->where('id',$user_id)->find();
  570. $data['other_avatar'] = localpath_to_netpath($other_user['avatar']);
  571. $data['other_nickname'] = $other_user['nickname'];
  572. $data['intimacy_rule'] = config('site.intimacy_rule');
  573. $this->success('亲密度等级信息', $data);
  574. }
  575. }