Match.php 29 KB

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