Match.php 36 KB

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