Match.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848
  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,2),100,2); //抽成后收益
  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){
  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' => $user_match_video_log_info['money'] + $money,
  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,2),100,2); //抽成后收益
  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){
  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' => $user_match_audio_log_info['money'] + $money,
  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. $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'jewel',$money,22,$this->auth->username.'使用免费次数的补贴','user_match_audio_log',$log_id);
  304. if($rs['status'] === false){
  305. Db::rollback();
  306. $this->error($rs['msg']);
  307. }
  308. }else{
  309. //有性别差,扣费
  310. if($price > 0){
  311. $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$price,12,'与'.$to_user_info['username'].'语音通话','user_match_audio_log',$log_id);
  312. if($rs['status'] === false){
  313. Db::rollback();
  314. $this->error($rs['msg']);
  315. }
  316. }
  317. //另一方加钱,0收费
  318. if($money > 0){
  319. $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'jewel',$money,22,'与'.$this->auth->username.'语音通话','user_match_audio_log',$log_id);
  320. if($rs['status'] === false){
  321. Db::rollback();
  322. $this->error($rs['msg']);
  323. }
  324. }
  325. //增加送礼用户的财富等级
  326. $res_wealth = \app\common\model\User::add_wealth_level($this->auth->id,$price);
  327. //增加获赠用户的魅力等级
  328. $res_wealth = \app\common\model\User::add_charm_level($to_user_id,$price);
  329. //增加亲密度
  330. if ($this->auth->id > $to_user_id) { //大的在后
  331. \app\common\model\User::add_intimacy($to_user_id,$this->auth->id,$price);
  332. } else { //小的在前
  333. \app\common\model\User::add_intimacy($this->auth->id,$to_user_id,$price);
  334. }
  335. }
  336. //tag任务赠送金币
  337. //与1名异性语音通话奖励
  338. if($task_status == 1){
  339. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,11);
  340. if($task_rs === false){
  341. Db::rollback();
  342. $this->error('完成任务赠送奖励失败');
  343. }
  344. $task_rs = \app\common\model\TaskLog::tofinish($to_user_id,11);
  345. if($task_rs === false){
  346. Db::rollback();
  347. $this->error('完成任务赠送奖励失败');
  348. }
  349. }
  350. Db::commit();
  351. $rs = [
  352. 'get_jewel_value' => $data['money'],
  353. 'next_minute' => $next_minute,
  354. ];
  355. $this->success('success',$rs);
  356. }
  357. //打字聊天每句话调用一次
  358. public function typing_once(){
  359. if ($this->auth->gender == 0) { //女生不花钱
  360. $this->error('您的网络开小差啦~');
  361. }
  362. //检测用户
  363. $to_user_id = input_post('to_user_id');
  364. $to_user_info = Db::name('user')->field('id,username,intro_uid,gender,match_typing_price')->where('id',$to_user_id)->find();
  365. if(!$to_user_info){
  366. $this->error('不存在的用户');
  367. }
  368. //客服不收钱
  369. $kefu_ids = config('site.kefu_user_ids');
  370. if(in_array($to_user_id,explode(',',$kefu_ids)) || in_array($this->auth->id,explode(',',$kefu_ids))){
  371. $rs = [
  372. 'get_jewel_value' => 0,
  373. 'next_minute' => 1, //1=足够下一分钟,0=不足够下一分钟
  374. ];
  375. $this->success('success',$rs);
  376. }
  377. if ($to_user_info['gender'] != 0) {
  378. $this->error('同性不能聊天~');
  379. }
  380. //正常价格
  381. $price = $to_user_info['match_typing_price']; //扣费金币
  382. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  383. $money = bcdiv(bcmul($price,100 - $gift_plat_scale,2),100,2); //抽成后收益
  384. Db::startTrans();
  385. //检查剩余分钟数
  386. $next_minute = 0;//默认不足下一分钟
  387. $user_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->lock(true)->find();
  388. if($user_wallet['typing_times'] >= 1){
  389. //扣分钟数
  390. $price = 0;
  391. //补贴给对方0.1金币
  392. $money = 0.1;
  393. if($user_wallet['video_sec'] > 1){
  394. $next_minute = 1;
  395. }
  396. }else{
  397. //需要扣别人的钱,判断钱是否购
  398. if($price > 0){
  399. $goldtotal = model('wallet')->getWallettotal($this->auth->id);
  400. if(bccomp($price,$goldtotal) == 1){
  401. Db::rollback();
  402. $this->error('金币不足');
  403. }
  404. }
  405. if($goldtotal - $price > $price){
  406. $next_minute = 1;
  407. }
  408. }
  409. //添加记录日志
  410. $data = [
  411. 'user_id' => $this->auth->id,
  412. 'price' => $price,
  413. 'createtime' => time(),
  414. 'to_user_id' => $to_user_id,
  415. 'money' => $money,
  416. ];
  417. $log_id = Db::name('user_match_typing_log')->insertGetId($data);
  418. if (!$log_id) {
  419. Db::rollback();
  420. $this->error('扣费失败');
  421. }
  422. //检查剩余分钟数
  423. if($user_wallet['typing_times'] >= 1){
  424. //扣分钟数
  425. $rs_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->update(['typing_times'=>$user_wallet['typing_times']-1]);
  426. if($rs_wallet === false){
  427. Db::rollback();
  428. $this->error('扣除免费次数失败');
  429. }
  430. //补贴给对方0.1金币
  431. $money = 0.1;
  432. $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'jewel',$money,23,$this->auth->username.'使用免费次数的补贴','user_match_typing_log',$log_id);
  433. if($rs['status'] === false){
  434. Db::rollback();
  435. $this->error($rs['msg']);
  436. }
  437. }else{
  438. //有性别差,扣费
  439. if($price > 0){
  440. $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$price,13,'与'.$to_user_info['username'].'聊天','user_match_typing_log',$log_id);
  441. if($rs['status'] === false){
  442. Db::rollback();
  443. $this->error($rs['msg']);
  444. }
  445. }
  446. //另一方加钱,0收费
  447. if($money > 0){
  448. $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'jewel',$money,23,'与'.$this->auth->username.'聊天','user_match_typing_log',$log_id);
  449. if($rs['status'] === false){
  450. Db::rollback();
  451. $this->error($rs['msg']);
  452. }
  453. }
  454. //增加送礼用户的财富等级
  455. $res_wealth = \app\common\model\User::add_wealth_level($this->auth->id,$price);
  456. //增加获赠用户的魅力等级
  457. $res_wealth = \app\common\model\User::add_charm_level($to_user_id,$price);
  458. //增加亲密度
  459. if ($this->auth->id > $to_user_id) { //大的在后
  460. \app\common\model\User::add_intimacy($to_user_id,$this->auth->id,$price);
  461. } else { //小的在前
  462. \app\common\model\User::add_intimacy($this->auth->id,$to_user_id,$price);
  463. }
  464. }
  465. Db::commit();
  466. $rs = [
  467. 'get_jewel_value' => $money,
  468. 'next_minute' => $next_minute,
  469. ];
  470. $this->success('success',$rs);
  471. }
  472. //语音匹配
  473. public function getaudiouser(){
  474. if(config('site.index_match_audio_switch') != 1){
  475. $this->error('该功能暂未开启');
  476. }
  477. //客服
  478. $kefu_ids = config('site.kefu_user_ids');
  479. //给出备选用户
  480. $map = [
  481. 'user.status' =>1, //未封禁用户
  482. 'user.gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  483. 'user.is_active' => 1, //在线的
  484. 'user.open_match_audio' => 1, //打开语聊开关
  485. 'user.id' => ['NOTIN',$kefu_ids], //排除客服
  486. ];
  487. if($this->auth->gender == 0){
  488. //或者未首充用户,且还有免费分钟数
  489. $map2['user.is_shouchong'] = 0;
  490. $map2['uw.audio_sec'] = ['gt',0];
  491. //男性要有最少一分钟的钱
  492. $map3['uw.gold'] = ['egt',$this->auth->match_audio_price];
  493. }else{
  494. $my_gold = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('gold');
  495. $map2['user.match_audio_price'] = ['elt',$my_gold];
  496. }
  497. $lists = Db::name('user')->alias('user')->field('user.id,user.gender,user.birthday,user.avatar,user.nickname,user.match_audio_price')
  498. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  499. ->where($map)->where($map2)->order('user.logintime desc')->page($this->page,100)->select();
  500. if(empty($lists) && $this->auth->gender == 0){
  501. $lists = Db::name('user')->alias('user')->field('user.id,user.gender,user.birthday,user.avatar,user.nickname,user.match_audio_price')
  502. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  503. ->where($map)->where($map3)->order('user.logintime desc')->page($this->page,100)->select();
  504. }
  505. if(!empty($lists)){
  506. foreach($lists as $key => &$val){
  507. $val = info_domain_image($val,['avatar']);
  508. $val['age'] = birthtime_to_age($val['birthday']);
  509. unset($val['birthday']);
  510. $val['match_audio_price'] = $this->auth->gender == 0 ? $this->auth->match_audio_price : $val['match_audio_price'];
  511. }
  512. }
  513. $this->success('success',$lists);
  514. }
  515. //视频匹配
  516. public function getvideouser(){
  517. if(config('site.index_match_video_switch') != 1){
  518. $this->error('该功能暂未开启');
  519. }
  520. //客服
  521. $kefu_ids = config('site.kefu_user_ids');
  522. //给出备选用户
  523. $map = [
  524. 'user.status' =>1, //未封禁用户
  525. 'user.gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  526. 'user.is_active' => 1, //在线的
  527. 'user.open_match_video' => 1, //打开语聊开关
  528. 'user.id' => ['NOTIN',$kefu_ids], //排除客服
  529. ];
  530. if($this->auth->gender == 0){
  531. //或者未首充用户,且还有免费分钟数
  532. $map2['user.is_shouchong'] = 0;
  533. $map2['uw.video_sec'] = ['gt',0];
  534. //男性要有最少一分钟的钱
  535. $map3['uw.gold'] = ['egt',$this->auth->match_video_price];
  536. }else{
  537. $my_gold = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('gold');
  538. $map2['user.match_video_price'] = ['elt',$my_gold];
  539. }
  540. $lists = Db::name('user')->alias('user')->field('user.id,user.gender,user.birthday,user.avatar,user.nickname,user.match_video_price')
  541. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  542. ->where($map)->where($map2)->order('user.logintime desc')->page($this->page,100)->select();
  543. if(empty($lists) && $this->auth->gender == 0){
  544. $lists = Db::name('user')->alias('user')->field('user.id,user.gender,user.birthday,user.avatar,user.nickname,user.match_video_price')
  545. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  546. ->where($map)->where($map3)->order('user.logintime desc')->page($this->page,100)->select();
  547. }
  548. if(!empty($lists)){
  549. foreach($lists as $key => &$val){
  550. $val = info_domain_image($val,['avatar']);
  551. $val['age'] = birthtime_to_age($val['birthday']);
  552. unset($val['birthday']);
  553. $val['match_video_price'] = $this->auth->gender == 0 ? $this->auth->match_video_price : $val['match_video_price'];
  554. }
  555. }
  556. $this->success('success',$lists);
  557. }
  558. //亲密度等级信息
  559. public function intimacylevel() {
  560. $user_id = input('user_id', 0, 'intval'); //对方id
  561. if (!$user_id) {
  562. $this->error('参数缺失');
  563. }
  564. if ($this->auth->id > $user_id) { //大的在后
  565. $where['uid'] = $user_id;
  566. $where['other_uid'] = $this->auth->id;
  567. } else { //小的在前
  568. $where['uid'] = $this->auth->id;
  569. $where['other_uid'] = $user_id;
  570. }
  571. $level = 0; //当前等级
  572. $level_name = ''; //当前等级名称
  573. $qinmi_sum = 0; //当前亲密度
  574. $next_level_diff = 0; //距下一等级亲密度差值
  575. $next_level_name = 0; //下一等级名称
  576. $next_level_value = 0;//下一等级亲密度值
  577. //亲密度等级列表
  578. $list = Db::name('intimacy_level')->field('name,info,level,value')->order('value')->select();
  579. //当前亲密度信息
  580. $user_intimacy_info = Db::name('user_intimacy')->where($where)->find();
  581. if ($user_intimacy_info) {
  582. //当前亲密度
  583. $qinmi_sum = $user_intimacy_info['value'];
  584. //当前等级信息
  585. $level_info = Db::name('intimacy_level')->where(['value' => ['elt', $user_intimacy_info['value']]])->order('level desc')->find();
  586. if ($level_info) {
  587. $level = $level_info['level'];
  588. $level_name = $level_info['name'];
  589. }
  590. //下一等级信息
  591. $next_level_info = Db::name('intimacy_level')->where(['value' => ['gt', $user_intimacy_info['value']]])->order('value')->find();
  592. if ($next_level_info) {
  593. $next_level_name = $next_level_info['name'];
  594. $next_level_value = $next_level_info['value'];
  595. $next_level_diff = $next_level_info['value'] - $user_intimacy_info['value'];
  596. }
  597. } else {
  598. $level = 1; //当前等级
  599. $level_name = '初级'; //当前等级名称
  600. $qinmi_sum = 0; //当前亲密度
  601. $next_level_info = Db::name('intimacy_level')->where('level',2)->find();
  602. $next_level_diff = $next_level_info['value'];
  603. $next_level_name = $next_level_info['name'];
  604. $next_level_value = $next_level_info['value'];
  605. }
  606. if ($list) {
  607. foreach ($list as &$v) {
  608. if ($v['level'] < $level) {
  609. $v['is_unlock'] = 1; //当前等级是否解锁: 1已解锁 2当前等级 3未解锁
  610. } elseif ($v['level'] == $level) {
  611. $v['is_unlock'] = 2;
  612. } else {
  613. $v['is_unlock'] = 3;
  614. }
  615. }
  616. }
  617. $data['level'] = $level; //当前等级
  618. $data['level_name'] = $level_name; //当前等级名称
  619. $data['qinmi_sum'] = $qinmi_sum; //当前亲密度
  620. $data['next_level_diff'] = $next_level_diff; //距下一等级亲密度差值
  621. $data['next_level_name'] = $next_level_name; //下一等级名称
  622. $data['next_level_value'] = $next_level_value; //下一等级亲密度值
  623. $data['level_list'] = $list; //等级列表
  624. $data['my_avatar'] = localpath_to_netpath($this->auth->avatar);
  625. $data['my_nickname'] = $this->auth->nickname;
  626. $other_user = Db::name('user')->field('avatar,nickname')->where('id',$user_id)->find();
  627. $data['other_avatar'] = localpath_to_netpath($other_user['avatar']);
  628. $data['other_nickname'] = $other_user['nickname'];
  629. $data['intimacy_rule'] = config('site.intimacy_rule');
  630. $this->success('亲密度等级信息', $data);
  631. }
  632. //与你有缘 推送搭讪人
  633. public function getindex_dashan(){
  634. //客服
  635. $kefu_ids = config('site.kefu_user_ids');
  636. //强制条件
  637. $map = [
  638. 'user.status' =>1, //未封禁用户
  639. 'user.gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  640. 'user.id' => ['NOTIN',$kefu_ids], //排除客服
  641. ];
  642. //找到没聊过的人
  643. if ($this->auth->gender == 1) {
  644. $where = [
  645. 'user_id' => $this->auth->id,
  646. ];
  647. $uids = Db::name('user_match_typing_log')->where($where)->column('to_user_id');
  648. }else{
  649. $where = [
  650. 'to_user_id' => $this->auth->id,
  651. ];
  652. $uids = Db::name('user_match_typing_log')->where($where)->column('user_id');
  653. }
  654. $map2 = [
  655. 'user.id' => ['NOTIN',$uids],
  656. ];
  657. $lists = Db::name('user')->alias('user')->field('user.id,user.gender,user.birthday,user.avatar,user.nickname')
  658. ->where($map)->where($map2)->order('user.logintime desc')->limit(6)->select();
  659. if(empty($lists)){
  660. $lists = Db::name('user')->alias('user')->field('user.id,user.gender,user.birthday,user.avatar,user.nickname')
  661. ->where($map)->order('user.logintime desc')->limit(6)->select();
  662. }
  663. if(!empty($lists)){
  664. foreach($lists as $key => &$val){
  665. $val = info_domain_image($val,['avatar']);
  666. $val['age'] = birthtime_to_age($val['birthday']);
  667. unset($val['birthday']);
  668. }
  669. }
  670. $this->success('success',$lists);
  671. }
  672. //聊天匹配
  673. public function gettypinguser(){
  674. exit;//不需要这个接口
  675. //给出备选用户
  676. $map = [
  677. 'user.status' =>1, //未封禁用户
  678. 'user.gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  679. ];
  680. if($this->auth->gender == 0){
  681. //或者未首充用户,且还有免费分钟数
  682. $map2['user.is_shouchong'] = 0;
  683. $map2['uw.typing_times'] = ['gt',0];
  684. //男性要有最少一分钟的钱
  685. $map3['uw.gold'] = ['egt',$this->auth->match_typing_price];
  686. }else{
  687. $my_gold = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('gold');
  688. $map2['user.match_typing_price'] = ['elt',$my_gold];
  689. }
  690. $lists = Db::name('user')->alias('user')->field('user.id')
  691. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  692. ->where($map)->where($map2)->order('user.logintime desc')->page($this->page,100)->select();
  693. if(empty($lists) && $this->auth->gender == 0){
  694. $lists = Db::name('user')->alias('user')->field('user.id')
  695. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  696. ->where($map)->where($map3)->order('user.logintime desc')->page($this->page,100)->select();
  697. }
  698. $this->success('success',$lists);
  699. }
  700. //////////////////////////////////////////////////////////////
  701. //过滤规则
  702. private function fliter_user($lists){
  703. if(empty($lists)){
  704. return $lists;
  705. }
  706. //过滤掉通话中的
  707. foreach($lists as $key => $val){
  708. if(redis_matching_get($val['id']) == 1){
  709. unset($lists[$key]);
  710. }
  711. }
  712. return $lists;
  713. }
  714. }