Match.php 28 KB

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