Match.php 34 KB

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