Match.php 34 KB

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