Match.php 26 KB

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