Match.php 36 KB

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