Match.php 33 KB

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