Match.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  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. //因为接受者拿不到发起者的uid,废弃了
  13. //视频和语音,接收方使用,如果是性别劣势方,检查钱是否够用
  14. public function video_audio_moneycheck(){
  15. //检测用户,发起方的uid
  16. $to_user_id = input_post('from_user_id');
  17. $to_user_info = Db::name('user')->field('id,real_status,gender')->where('id',$to_user_id)->find();
  18. if(!$to_user_info){
  19. $this->error('不存在的用户');
  20. }
  21. //扣费金币
  22. $type = input_post('type','video'); //类型
  23. $price = $type == 'video' ? config('site.video_min_price') : config('site.audio_min_price');
  24. //发起用户的分数,被发起用户的分数。按性别给分
  25. $auth_level = 0;
  26. $tous_level = 0;
  27. //打分
  28. if($this->auth->gender == 0 && $this->auth->real_status == 1){
  29. $auth_level = 30;//实名女最高
  30. }
  31. if($this->auth->gender == 0 && $this->auth->real_status != 1){
  32. $auth_level = 20;//未实名女次之
  33. }
  34. if($this->auth->gender == 1){
  35. $auth_level = 10;//男性最低
  36. }
  37. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
  38. $tous_level = 30;
  39. }
  40. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
  41. $tous_level = 20;
  42. }
  43. if($to_user_info['gender'] == 1){
  44. $tous_level = 10;
  45. }
  46. //同性不收钱
  47. //都是男的,不扣钱
  48. //都是实名认证的女性,不扣钱
  49. //都是未实名认证的女性,不扣钱
  50. if($auth_level == $tous_level){
  51. $price = 0;
  52. $this->success('success');
  53. }
  54. //扣钱uid,收钱uid,收钱free_video
  55. //分数少扣钱,分数多收益
  56. if($auth_level < $tous_level){
  57. $kou_user = $this->auth->id;
  58. }else{
  59. $kou_user = $to_user_info['id'];
  60. }
  61. //需要扣我的(接收方的)钱,判断钱是否够
  62. if($price > 0 && $kou_user == $this->auth->id){
  63. Db::startTrans();
  64. $gold = model('wallet')->getWallet($kou_user,'gold');
  65. if(bccomp($price,$gold) == 1){
  66. Db::rollback();
  67. $this->error('金币不足');
  68. }
  69. Db::commit();
  70. }
  71. $this->success('success');
  72. }
  73. //视频通话每分钟调用一次
  74. public function video_onemin(){
  75. //检测用户
  76. $to_user_id = input_post('to_user_id');
  77. $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
  78. if(!$to_user_info){
  79. $this->error('不存在的用户');
  80. }
  81. //正常价格
  82. $price = config('site.video_min_price'); //扣费金币
  83. $bili = config('site.money_to_gold'); //兑换比例
  84. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  85. $money = bcdiv($price,$bili,2); //对应人民币
  86. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  87. //发起用户的分数,被发起用户的分数。按性别给分
  88. $auth_level = 0;
  89. $tous_level = 0;
  90. //打分
  91. if($this->auth->gender == 0 && $this->auth->real_status == 1){
  92. $auth_level = 30;//实名女最高
  93. }
  94. if($this->auth->gender == 0 && $this->auth->real_status != 1){
  95. $auth_level = 20;//未实名女次之
  96. }
  97. if($this->auth->gender == 1){
  98. $auth_level = 10;//男性最低
  99. }
  100. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
  101. $tous_level = 30;
  102. }
  103. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
  104. $tous_level = 20;
  105. }
  106. if($to_user_info['gender'] == 1){
  107. $tous_level = 10;
  108. }
  109. //同性不收钱
  110. //都是男的,不扣钱
  111. //都是实名认证的女性,不扣钱
  112. //都是未实名认证的女性,不扣钱
  113. if($auth_level == $tous_level){
  114. $price = 0;$money = 0;
  115. }
  116. Db::startTrans();
  117. //记录日志
  118. $data = [
  119. 'user_id' => $this->auth->id,
  120. 'price' => $price,
  121. 'createtime' => time(),
  122. 'to_user_id' => $to_user_id,
  123. 'money' => $money,
  124. ];
  125. $log_id = Db::name('user_match_video_log')->insertGetId($data);
  126. if(!$log_id){
  127. Db::rollback();
  128. $this->error('扣费失败');
  129. }
  130. //同性别,提前结束
  131. if($auth_level == $tous_level){
  132. Db::commit();
  133. $this->success('success');
  134. }
  135. //扣钱uid,收钱uid,收钱free_video
  136. //分数少扣钱,分数多收益
  137. if($auth_level < $tous_level){
  138. $kou_user = $this->auth->id;
  139. $get_user = $to_user_info['id'];
  140. $get_user_free = $to_user_info['free_video'];
  141. }else{
  142. $kou_user = $to_user_info['id'];
  143. $get_user = $this->auth->id;
  144. $get_user_free = $this->auth->free_video;
  145. }
  146. //需要扣别人的钱,判断钱是否购
  147. if($price > 0 && $kou_user != $this->auth->id){
  148. $gold = model('wallet')->getWallet($kou_user,'gold');
  149. if(bccomp($price,$gold) == 1){
  150. Db::rollback();
  151. $this->error('对方金币不足');
  152. }
  153. }
  154. //有性别差,扣费
  155. if($price > 0){
  156. $rs = model('wallet')->lockChangeAccountRemain($kou_user, $get_user,'gold',-$price,11,'','user_match_video_log',$log_id);
  157. if($rs['status'] === false){
  158. Db::rollback();
  159. $this->error($rs['msg']);
  160. }
  161. }
  162. //另一方加钱,0收费
  163. if($money > 0 && $get_user_free == 0){
  164. $rs = model('wallet')->lockChangeAccountRemain($get_user,$kou_user,'money',$money,21,'','user_match_video_log',$log_id);
  165. if($rs['status'] === false){
  166. Db::rollback();
  167. $this->error($rs['msg']);
  168. }
  169. }
  170. Db::commit();
  171. $this->success('success');
  172. }
  173. //语音通话每分钟调用一次
  174. public function audio_onemin(){
  175. //检测用户
  176. $to_user_id = input_post('to_user_id');
  177. $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
  178. if(!$to_user_info){
  179. $this->error('不存在的用户');
  180. }
  181. //正常价格
  182. $price = config('site.audio_min_price'); //扣费金币
  183. $bili = config('site.money_to_gold'); //兑换比例
  184. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  185. $money = bcdiv($price,$bili,2); //对应人民币
  186. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  187. //发起用户的分数,被发起用户的分数。按性别给分
  188. $auth_level = 0;
  189. $tous_level = 0;
  190. //打分
  191. if($this->auth->gender == 0 && $this->auth->real_status == 1){
  192. $auth_level = 30;//实名女最高
  193. }
  194. if($this->auth->gender == 0 && $this->auth->real_status != 1){
  195. $auth_level = 20;//未实名女次之
  196. }
  197. if($this->auth->gender == 1){
  198. $auth_level = 10;//男性最低
  199. }
  200. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
  201. $tous_level = 30;
  202. }
  203. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
  204. $tous_level = 20;
  205. }
  206. if($to_user_info['gender'] == 1){
  207. $tous_level = 10;
  208. }
  209. //同性不收钱
  210. //都是男的,不扣钱
  211. //都是实名认证的女性,不扣钱
  212. //都是未实名认证的女性,不扣钱
  213. if($auth_level == $tous_level){
  214. $price = 0;$money = 0;
  215. }
  216. Db::startTrans();
  217. //记录日志
  218. $data = [
  219. 'user_id' => $this->auth->id,
  220. 'price' => $price,
  221. 'createtime' => time(),
  222. 'to_user_id' => $to_user_id,
  223. 'money' => $money,
  224. ];
  225. $log_id = Db::name('user_match_audio_log')->insertGetId($data);
  226. if(!$log_id){
  227. Db::rollback();
  228. $this->error('扣费失败');
  229. }
  230. //同性别,提前结束
  231. if($auth_level == $tous_level){
  232. Db::commit();
  233. $this->success('success');
  234. }
  235. //扣钱uid,收钱uid,收钱free_video
  236. //分数少扣钱,分数多收益
  237. if($auth_level < $tous_level){
  238. $kou_user = $this->auth->id;
  239. $get_user = $to_user_info['id'];
  240. $get_user_free = $to_user_info['free_audio'];
  241. }else{
  242. $kou_user = $to_user_info['id'];
  243. $get_user = $this->auth->id;
  244. $get_user_free = $this->auth->free_audio;
  245. }
  246. //需要扣别人的钱,判断钱是否购
  247. if($price > 0 && $kou_user != $this->auth->id){
  248. $gold = model('wallet')->getWallet($kou_user,'gold');
  249. if(bccomp($price,$gold) == 1){
  250. Db::rollback();
  251. $this->error('对方金币不足');
  252. }
  253. }
  254. //有性别差,扣费
  255. if($price > 0){
  256. $rs = model('wallet')->lockChangeAccountRemain($kou_user,$get_user,'gold',-$price,12,'','user_match_audio_log',$log_id);
  257. if($rs['status'] === false){
  258. Db::rollback();
  259. $this->error($rs['msg']);
  260. }
  261. }
  262. //另一方加钱,0收费
  263. if($money > 0 && $get_user_free == 0){
  264. $rs = model('wallet')->lockChangeAccountRemain($get_user, $kou_user,'money',$money,22,'','user_match_audio_log',$log_id);
  265. if($rs['status'] === false){
  266. Db::rollback();
  267. $this->error($rs['msg']);
  268. }
  269. }
  270. Db::commit();
  271. $this->success('success');
  272. }
  273. //打字聊天每句话调用一次
  274. public function typing_once(){
  275. //检测用户
  276. $to_user_id = input_post('to_user_id');
  277. $to_user_info = Db::name('user')->field('id,real_status,gender,free_video,free_audio,free_typing')->where('id',$to_user_id)->find();
  278. if(!$to_user_info){
  279. $this->error('不存在的用户');
  280. }
  281. //正常价格
  282. $price = config('site.typing_min_price'); //扣费金币
  283. $bili = config('site.money_to_gold'); //兑换比例
  284. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  285. $money = bcdiv($price,$bili,2); //对应人民币
  286. $money = bcdiv(bcmul($money,100 - $gift_plat_scale,2),100,2); //抽成后收益
  287. //发起用户的分数,被发起用户的分数。按性别给分
  288. $auth_level = 0;
  289. $tous_level = 0;
  290. //打分
  291. if($this->auth->gender == 0 && $this->auth->real_status == 1){
  292. $auth_level = 30;//实名女最高
  293. }
  294. if($this->auth->gender == 0 && $this->auth->real_status != 1){
  295. $auth_level = 20;//未实名女次之
  296. }
  297. if($this->auth->gender == 1){
  298. $auth_level = 10;//男性最低
  299. }
  300. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] == 1){
  301. $tous_level = 30;
  302. }
  303. if($to_user_info['gender'] == 0 && $to_user_info['real_status'] != 1){
  304. $tous_level = 20;
  305. }
  306. if($to_user_info['gender'] == 1){
  307. $tous_level = 10;
  308. }
  309. //同性不收钱
  310. //都是男的,不扣钱
  311. //都是实名认证的女性,不扣钱
  312. //都是未实名认证的女性,不扣钱
  313. if($auth_level == $tous_level){
  314. $price = 0;$money = 0;
  315. }
  316. //性别优势的人发起,免费
  317. if($auth_level > $tous_level){
  318. $price = 0;$money = 0;
  319. }
  320. Db::startTrans();
  321. //记录日志
  322. $data = [
  323. 'user_id' => $this->auth->id,
  324. 'price' => $price,
  325. 'createtime' => time(),
  326. 'to_user_id' => $to_user_id,
  327. 'money' => $money,
  328. ];
  329. $log_id = Db::name('user_match_typing_log')->insertGetId($data);
  330. if(!$log_id){
  331. Db::rollback();
  332. $this->error('扣费失败');
  333. }
  334. //同性别,提前结束
  335. if($auth_level == $tous_level){
  336. Db::commit();
  337. $this->success('success');
  338. }
  339. //零消费,零收益消费,提前结束,其实这条没必要,下面金钱操作还会过滤一次
  340. if($price == 0 && $money == 0){
  341. Db::commit();
  342. $this->success('success');
  343. }
  344. //扣钱uid,收钱uid,收钱free_video
  345. //分数少扣钱,分数多收益
  346. if($auth_level < $tous_level){
  347. $kou_user = $this->auth->id;
  348. $get_user = $to_user_info['id'];
  349. $get_user_free = $to_user_info['free_typing'];
  350. }else{
  351. //这种已经没有了
  352. $kou_user = $to_user_info['id'];
  353. $get_user = $this->auth->id;
  354. $get_user_free = $this->auth->free_typing;
  355. }
  356. //有性别差,扣费
  357. if($price > 0){
  358. $rs = model('wallet')->lockChangeAccountRemain($kou_user,$get_user,'gold',-$price,13,'','user_match_typing_log',$log_id);
  359. if($rs['status'] === false){
  360. Db::rollback();
  361. $this->error($rs['msg']);
  362. }
  363. }
  364. //另一方加钱,0收费
  365. if($money > 0 && $get_user_free == 0){
  366. $rs = model('wallet')->lockChangeAccountRemain($get_user,$kou_user,'money',$money,23,'','user_match_typing_log',$log_id);
  367. if($rs['status'] === false){
  368. Db::rollback();
  369. $this->error($rs['msg']);
  370. }
  371. }
  372. //tag任务赠送金币
  373. //搭讪奖励
  374. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
  375. if($task_rs === false){
  376. Db::rollback();
  377. $this->error('完成任务赠送奖励失败');
  378. }
  379. Db::commit();
  380. $this->success('success');
  381. }
  382. //语音匹配
  383. public function getaudiouser(){
  384. //判断资格
  385. /*$start = strtotime(date('Y-m-d'));
  386. $end = $start + 86399;
  387. $map = [
  388. 'user_id' => $this->auth->id,
  389. 'createtime' => ['between',[$start,$end]],
  390. 'price' => 0,
  391. ];
  392. $check = Db::name('user_match_audio_log')->where($map)->find();*/
  393. $check = true;
  394. //已经用掉免费的了,判断金额
  395. if($check){
  396. $price = config('site.audio_min_price');
  397. $gold = model('wallet')->getWallet($this->auth->id,'gold');
  398. if($gold < $price){
  399. $this->error('您的金币已经不足,请充值');
  400. }
  401. }
  402. //找到互关的人,排除
  403. //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  404. //dump($follow_me);
  405. //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  406. //dump($my_follow);exit;
  407. //给出备选用户
  408. $map = [
  409. 'status' =>1, //未封禁用户
  410. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  411. 'is_online' => 0, //不在语聊间的
  412. 'is_livebc' => 0, //不在直播的
  413. 'is_active' => 1, //在线的
  414. //'real_status' => 1, //真人认证
  415. //'idcard_status' => 1, //实名认证
  416. 'open_match_audio' => 1, //打开语聊开关
  417. //'id' => ['NOT IN',$my_follow] //不是好友的
  418. ];
  419. $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
  420. $lists = $this->fliter_user($lists,10);
  421. $result = [];
  422. if(!empty($lists)){
  423. foreach($lists as $key => $val){
  424. $result[] = ['id'=>$val];
  425. }
  426. }
  427. //tag任务赠送金币
  428. //语音匹配奖励 +5金币
  429. if(!empty($result)){
  430. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,11);
  431. if($task_rs === false){
  432. $this->error('完成任务赠送奖励失败');
  433. }
  434. }
  435. $this->success('success',$result);
  436. }
  437. //视频匹配
  438. public function getvideouser(){
  439. //判断资格
  440. /*$start = strtotime(date('Y-m-d'));
  441. $end = $start + 86399;
  442. $map = [
  443. 'user_id' => $this->auth->id,
  444. 'createtime' => ['between',[$start,$end]],
  445. 'price' => 0,
  446. ];
  447. $check = Db::name('user_match_video_log')->where($map)->find();*/
  448. $check = true;
  449. //已经用掉免费的了,判断金额
  450. if($check){
  451. $price = config('site.video_min_price');
  452. $gold = model('wallet')->getWallet($this->auth->id,'gold');
  453. if($gold < $price){
  454. $this->error('您的金币已经不足,请充值');
  455. }
  456. }
  457. //找到互关的人,排除
  458. //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  459. //dump($follow_me);
  460. //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  461. //dump($my_follow);exit;
  462. //给出备选用户
  463. $map = [
  464. 'status' =>1, //未封禁用户
  465. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  466. 'is_online' => 0, //不在语聊间的
  467. 'is_livebc' => 0, //不在直播的
  468. 'is_active' => 1, //在线的
  469. //'real_status' => 1, //真人认证
  470. //'idcard_status' => 1, //实名认证
  471. 'open_match_video' => 1, //打开视频开关的
  472. // 'id' => ['NOT IN',$my_follow] //不是好友的
  473. ];
  474. $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
  475. $lists = $this->fliter_user($lists,10);
  476. $result = [];
  477. if(!empty($lists)){
  478. foreach($lists as $key => $val){
  479. $result[] = ['id'=>$val];
  480. }
  481. }
  482. //tag任务赠送金币
  483. //视频匹配奖励 +5金币
  484. if(!empty($result)){
  485. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,12);
  486. if($task_rs === false){
  487. $this->error('完成任务赠送奖励失败');
  488. }
  489. }
  490. $this->success('success',$result);
  491. }
  492. //聊天匹配
  493. public function gettypinguser(){
  494. //找到互关的人,排除
  495. //$follow_me = Db::name('user_follow')->where('follow_uid',$this->auth->id)->column('uid');
  496. //dump($follow_me);
  497. //$my_follow = Db::name('user_follow')->where(['uid'=>$this->auth->id,'follow_uid'=>['IN',$follow_me]])->column('follow_uid');
  498. //dump($my_follow);exit;
  499. //给出备选用户
  500. $map = [
  501. 'status' =>1, //未封禁用户
  502. 'gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  503. //'real_status' => 1, //真人认证
  504. //'idcard_status' => 1, //实名认证
  505. //'is_active' => 1, //在线的
  506. //打开聊天开关的
  507. 'open_match_typing' => 1, //打开文字聊天开关的
  508. //'id' => ['NOT IN',$my_follow] //不是好友的
  509. ];
  510. $lists = Db::name('user')->field('id,cityname,status,gender,real_status,tag_ids')->where($map)->order('logintime desc')->page($this->page,100)->select();
  511. //$lists = $this->fliter_user($lists,100);
  512. $lists = array_column($lists,'id');
  513. $result = [];
  514. if(!empty($lists)){
  515. /*foreach($lists as $key => $val){
  516. $result[] = ['id'=>$val];
  517. }*/
  518. $result = Db::name('user')->field('id,nickname,username,avatar,audio_bio')->where(['id'=>['IN',$lists]])->select();
  519. $result = list_domain_image($result,['avatar,audio_bio']);
  520. }
  521. //tag任务赠送金币
  522. //缘分匹配奖励 +5金币
  523. if(!empty($result)){
  524. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,10);
  525. if($task_rs === false){
  526. $this->error('完成任务赠送奖励失败');
  527. }
  528. }
  529. $this->success('success',$result);
  530. }
  531. //过滤规则
  532. private function fliter_user($lists,$number = 1){
  533. if(empty($lists)){
  534. return $lists;
  535. }
  536. //dump($lists);
  537. //过滤掉通话中的
  538. foreach($lists as $key => $val){
  539. if(redis_matching_get($val['id']) == 1){
  540. unset($lists[$key]);
  541. }
  542. }
  543. //预留全部
  544. $all_result = array_column($lists,'id');
  545. //dump($all_result);
  546. //提取同城的
  547. $citydata = [];
  548. foreach($lists as $key => $val){
  549. if( !empty($this->auth->cityname) && $this->auth->cityname == $val['cityname'] ){
  550. $citydata[] = $val['id'];
  551. }
  552. }
  553. //dump($citydata);
  554. //有标签交集的
  555. $tagdata = [];
  556. foreach($lists as $key => $val){
  557. if( !empty($this->auth->tag_ids) && !empty($val['tag_ids']) ){
  558. $auth_tag_ids = explode(',',$this->auth->tag_ids);
  559. $val_tag_ids = explode(',',$val['tag_ids']);
  560. if(count(array_intersect($auth_tag_ids,$val_tag_ids)) > 0){
  561. $tagdata[] = $val['id'];
  562. }
  563. }
  564. }
  565. //dump($tagdata);
  566. //双条件都满足
  567. $double_data = [];
  568. if(!empty($citydata) && !empty($tagdata)){
  569. $double_data = array_intersect($citydata,$tagdata);
  570. }
  571. //dump($double_data);
  572. if(count($double_data) >= $number){
  573. return $double_data;
  574. }
  575. //两种条件合并,去重。空数组合并没影响
  576. $merge_data = array_merge($citydata,$tagdata);
  577. $merge_data = array_flip(array_flip($merge_data));
  578. //dump($merge_data);
  579. if(count($merge_data) >= $number){
  580. return $merge_data;
  581. }
  582. return $all_result;
  583. }
  584. //亲密度等级信息
  585. public function intimacylevel() {
  586. $user_id = input('user_id', 0, 'intval'); //对方id
  587. if (!$user_id) {
  588. $this->error('参数缺失');
  589. }
  590. if ($this->auth->gender == 0) { //女用户
  591. $where['uid'] = $user_id;
  592. $where['other_uid'] = $this->auth->id;
  593. } else { //男用户
  594. $where['uid'] = $this->auth->id;
  595. $where['other_uid'] = $user_id;
  596. }
  597. $level = 0; //当前等级
  598. $level_name = ''; //当前等级名称
  599. $qinmi_sum = 0; //当前亲密度
  600. $next_level_diff = 0; //距下一等级亲密度差值
  601. $next_level_name = 0; //下一等级名称
  602. $next_level_value = 0;//下一等级亲密度值
  603. //亲密度等级列表
  604. $list = Db::name('intimacy_level')->field('name,level,value')->order('value')->select();
  605. //当前亲密度信息
  606. $user_intimacy_info = Db::name('user_intimacy')->where($where)->find();
  607. if ($user_intimacy_info) {
  608. //当前亲密度
  609. $qinmi_sum = $user_intimacy_info['value'];
  610. if ($list) {
  611. //当前等级信息
  612. $level_info = Db::name('intimacy_level')->where(['value' => ['elt', $user_intimacy_info['value']]])->order('level desc')->find();
  613. if ($level_info) {
  614. $level = $level_info['level'];
  615. $level_name = $level_info['name'];
  616. }
  617. //下一等级信息
  618. $next_level_info = Db::name('intimacy_level')->where(['value' => ['gt', $user_intimacy_info['value']]])->order('value')->find();
  619. if ($next_level_info) {
  620. $next_level_name = $next_level_info['name'];
  621. $next_level_value = $next_level_info['value'];
  622. $next_level_diff = $next_level_info['value'] - $user_intimacy_info['value'];
  623. }
  624. }
  625. } else {
  626. $next_level = Db::name('intimacy_level')->order('value')->find();
  627. $next_level_diff = $next_level['value'];
  628. $next_level_name = $next_level['name'];
  629. $next_level_value = $next_level['value'];
  630. }
  631. if ($list) {
  632. foreach ($list as &$v) {
  633. if ($v['level'] < $level) {
  634. $v['is_unlock'] = 1; //当前等级是否解锁: 1已解锁 2当前等级 3未解锁
  635. } elseif ($v['level'] == $level) {
  636. $v['is_unlock'] = 2;
  637. } else {
  638. $v['is_unlock'] = 3;
  639. }
  640. }
  641. }
  642. $data['level'] = $level; //当前等级
  643. $data['level_name'] = $level_name; //当前等级名称
  644. $data['qinmi_sum'] = $qinmi_sum; //当前亲密度
  645. $data['next_level_diff'] = $next_level_diff; //距下一等级亲密度差值
  646. $data['next_level_name'] = $next_level_name; //下一等级名称
  647. $data['next_level_value'] = $next_level_value; //下一等级亲密度值
  648. $data['level_list'] = $list; //等级列表
  649. $this->success('亲密度等级信息', $data);
  650. }
  651. public function test(){
  652. $this->addintimacy(1,3,20);
  653. }
  654. //增加亲密度,顺带升级
  655. public function addintimacy($uid = 0, $other_uid = 0, $value = 0) {
  656. //增加亲密度
  657. $level_remark = ''; //亲密度等级是否变动: 0未变动 >0是亲密度等级
  658. $user_intimacy_info = Db::name('user_intimacy')->where(['uid' => $uid, 'other_uid' => $other_uid])->find();
  659. if ($user_intimacy_info) {
  660. $user_intimacy_data['value'] = $user_intimacy_info['value'] + $value;
  661. $level = Db::name('intimacy_level')->where(['value' => ['elt', $user_intimacy_data['value']]])->order('level desc')->find();
  662. if ($level) {
  663. $user_intimacy_data['level'] = $level['level'];
  664. if ($level['level'] != $user_intimacy_info['level']) {
  665. $level_remark = "恭喜你们亲密度达到".$level['level']."级,获得称号'".$level['name']."'";
  666. }
  667. }
  668. $user_intimacy_rs = Db::name('user_intimacy')->where(['uid' => $uid, 'other_uid' => $other_uid])->setField($user_intimacy_data);
  669. } else {
  670. $user_intimacy_data['uid'] = $uid;
  671. $user_intimacy_data['other_uid'] = $other_uid;
  672. $user_intimacy_data['value'] = $value;
  673. $level = Db::name('intimacy_level')->where(['value' => ['elt', $value]])->order('level desc')->find();
  674. if ($level) {
  675. $user_intimacy_data['level'] = $level['level'];
  676. $level_remark = "恭喜你们亲密度达到".$level['level']."级,获得称号'".$level['name']."'";
  677. }
  678. $user_intimacy_rs = Db::name('user_intimacy')->insertGetId($user_intimacy_data);
  679. }
  680. return ['status' => $user_intimacy_rs, 'level_remark' => $level_remark];
  681. }
  682. }