Match.php 30 KB

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