Match.php 29 KB

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