Match.php 32 KB

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