Match.php 36 KB

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