Match.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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_onemin(){
  14. if ($this->auth->gender == 0) { //女生不花钱
  15. $this->error('您的网络开小差啦~');
  16. }
  17. //检测用户
  18. $request_id = input('request_id', '', 'trim'); //唯一请求标识
  19. $to_user_id = input_post('to_user_id');
  20. $to_user_info = Db::name('user')->field('id,intro_uid,gender,match_video_price')->where('id',$to_user_id)->find();
  21. if(!$to_user_info){
  22. $this->error('不存在的用户');
  23. }
  24. if ($to_user_info['gender'] != 0) {
  25. $this->error('同性不能聊天~');
  26. }
  27. //正常价格
  28. $price = $to_user_info['match_video_price']; //扣费金币
  29. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  30. $money = bcdiv(bcmul($price,100 - $gift_plat_scale,2),100,2); //抽成后收益
  31. Db::startTrans();
  32. //检查剩余分钟数
  33. $user_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->lock(true)->find();
  34. if($user_wallet['video_sec'] >= 1){
  35. //扣分钟数
  36. $price = 0;
  37. //补贴给对方0.1金币
  38. $money = 0.1;
  39. }else{
  40. //需要扣别人的钱,判断钱是否购
  41. if($price > 0){
  42. $goldtotal = model('wallet')->getWallettotal($this->auth->id);
  43. if(bccomp($price,$goldtotal) == 1){
  44. Db::rollback();
  45. $this->error('金币不足');
  46. }
  47. }
  48. }
  49. //查询是否有匹配记录
  50. $user_match_video_log_info = [];
  51. if ($request_id) {
  52. $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();
  53. }
  54. if ($user_match_video_log_info) {
  55. //修改记录日志
  56. $data = [
  57. 'price' => $user_match_video_log_info['price'] + $price,
  58. 'updatetime' => time(),
  59. 'money' => $user_match_video_log_info['money'] + $money,
  60. 'call_minutes' => $user_match_video_log_info['call_minutes'] + 1
  61. ];
  62. $log_id = Db::name('user_match_video_log')->where(['id' => $user_match_video_log_info['id']])->setField($data);
  63. if (!$log_id) {
  64. Db::rollback();
  65. $this->error('扣费失败');
  66. }
  67. } else {
  68. //添加记录日志
  69. $data = [
  70. 'user_id' => $this->auth->id,
  71. 'price' => $price,
  72. 'createtime' => time(),
  73. 'to_user_id' => $to_user_id,
  74. 'money' => $money,
  75. 'request_id' => $request_id,
  76. 'call_minutes' => 1
  77. ];
  78. $log_id = Db::name('user_match_video_log')->insertGetId($data);
  79. if (!$log_id) {
  80. Db::rollback();
  81. $this->error('扣费失败');
  82. }
  83. }
  84. //检查剩余分钟数
  85. if($user_wallet['video_sec'] >= 1){
  86. //扣分钟数
  87. $rs_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->update(['video_sec'=>$user_wallet['video_sec']-1]);
  88. if($rs_wallet === false){
  89. Db::rollback();
  90. $this->error('扣除分钟数失败');
  91. }
  92. //补贴给对方0.1金币
  93. $money = 0.1;
  94. $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'jewel',$money,21,'对方使用免费次数的补贴','user_match_video_log',$log_id);
  95. if($rs['status'] === false){
  96. Db::rollback();
  97. $this->error($rs['msg']);
  98. }
  99. }else{
  100. //有性别差,扣费
  101. if($price > 0){
  102. $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$price,11,'','user_match_video_log',$log_id);
  103. if($rs['status'] === false){
  104. Db::rollback();
  105. $this->error($rs['msg']);
  106. }
  107. }
  108. //另一方加钱,0收费
  109. if($money > 0){
  110. $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'jewel',$money,21,'','user_match_video_log',$log_id);
  111. if($rs['status'] === false){
  112. Db::rollback();
  113. $this->error($rs['msg']);
  114. }
  115. }
  116. }
  117. //tag任务赠送金币
  118. //与1名异性语音通话奖励
  119. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,11);
  120. if($task_rs === false){
  121. Db::rollback();
  122. $this->error('完成任务赠送奖励失败');
  123. }
  124. $task_rs = \app\common\model\TaskLog::tofinish($to_user_id,11);
  125. if($task_rs === false){
  126. Db::rollback();
  127. $this->error('完成任务赠送奖励失败');
  128. }
  129. Db::commit();
  130. $this->success('success');
  131. }
  132. //语音通话每分钟调用一次
  133. public function audio_onemin(){
  134. if ($this->auth->gender == 0) { //女生不花钱
  135. $this->error('您的网络开小差啦~');
  136. }
  137. //检测用户
  138. $request_id = input('request_id', '', 'trim'); //唯一请求标识
  139. $to_user_id = input_post('to_user_id');
  140. $to_user_info = Db::name('user')->field('id,intro_uid,gender,match_audio_price')->where('id',$to_user_id)->find();
  141. if(!$to_user_info){
  142. $this->error('不存在的用户');
  143. }
  144. if ($to_user_info['gender'] != 0) {
  145. $this->error('同性不能聊天~');
  146. }
  147. //正常价格
  148. $price = $to_user_info['match_audio_price']; //扣费金币
  149. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  150. $money = bcdiv(bcmul($price,100 - $gift_plat_scale,2),100,2); //抽成后收益
  151. Db::startTrans();
  152. //检查剩余分钟数
  153. $user_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->lock(true)->find();
  154. if($user_wallet['audio_sec'] >= 1){
  155. //扣分钟数
  156. $price = 0;
  157. //补贴给对方0.1金币
  158. $money = 0.1;
  159. }else{
  160. //需要扣别人的钱,判断钱是否购
  161. if($price > 0){
  162. $goldtotal = model('wallet')->getWallettotal($this->auth->id);
  163. if(bccomp($price,$goldtotal) == 1){
  164. Db::rollback();
  165. $this->error('金币不足');
  166. }
  167. }
  168. }
  169. //查询是否有匹配记录
  170. $user_match_audio_log_info = [];
  171. if ($request_id) {
  172. $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();
  173. }
  174. if ($user_match_audio_log_info) {
  175. //修改记录日志
  176. $data = [
  177. 'price' => $user_match_audio_log_info['price'] + $price,
  178. 'updatetime' => time(),
  179. 'money' => $user_match_audio_log_info['money'] + $money,
  180. 'call_minutes' => $user_match_audio_log_info['call_minutes'] + 1
  181. ];
  182. $log_id = Db::name('user_match_audio_log')->where(['id' => $user_match_audio_log_info['id']])->setField($data);
  183. if (!$log_id) {
  184. Db::rollback();
  185. $this->error('扣费失败');
  186. }
  187. } else {
  188. //添加记录日志
  189. $data = [
  190. 'user_id' => $this->auth->id,
  191. 'price' => $price,
  192. 'createtime' => time(),
  193. 'to_user_id' => $to_user_id,
  194. 'money' => $money,
  195. 'request_id' => $request_id,
  196. 'call_minutes' => 1
  197. ];
  198. $log_id = Db::name('user_match_audio_log')->insertGetId($data);
  199. if (!$log_id) {
  200. Db::rollback();
  201. $this->error('扣费失败');
  202. }
  203. }
  204. //检查剩余分钟数
  205. if($user_wallet['audio_sec'] >= 1){
  206. //扣分钟数
  207. $rs_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->update(['audio_sec'=>$user_wallet['audio_sec']-1]);
  208. if($rs_wallet === false){
  209. Db::rollback();
  210. $this->error('扣除分钟数失败');
  211. }
  212. //补贴给对方0.1金币
  213. $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'jewel',$money,22,'对方使用免费次数的补贴','user_match_audio_log',$log_id);
  214. if($rs['status'] === false){
  215. Db::rollback();
  216. $this->error($rs['msg']);
  217. }
  218. }else{
  219. //有性别差,扣费
  220. if($price > 0){
  221. $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$price,12,'','user_match_audio_log',$log_id);
  222. if($rs['status'] === false){
  223. Db::rollback();
  224. $this->error($rs['msg']);
  225. }
  226. }
  227. //另一方加钱,0收费
  228. if($money > 0){
  229. $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'jewel',$money,22,'','user_match_audio_log',$log_id);
  230. if($rs['status'] === false){
  231. Db::rollback();
  232. $this->error($rs['msg']);
  233. }
  234. }
  235. }
  236. //tag任务赠送金币
  237. //与1名异性语音通话奖励
  238. $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,11);
  239. if($task_rs === false){
  240. Db::rollback();
  241. $this->error('完成任务赠送奖励失败');
  242. }
  243. $task_rs = \app\common\model\TaskLog::tofinish($to_user_id,11);
  244. if($task_rs === false){
  245. Db::rollback();
  246. $this->error('完成任务赠送奖励失败');
  247. }
  248. Db::commit();
  249. $this->success('success');
  250. }
  251. //打字聊天每句话调用一次
  252. public function typing_once(){
  253. if ($this->auth->gender == 0) { //女生不花钱
  254. $this->error('您的网络开小差啦~');
  255. }
  256. //检测用户
  257. $to_user_id = input_post('to_user_id');
  258. $to_user_info = Db::name('user')->field('id,intro_uid,gender,match_typing_price')->where('id',$to_user_id)->find();
  259. if(!$to_user_info){
  260. $this->error('不存在的用户');
  261. }
  262. if ($to_user_info['gender'] != 0) {
  263. $this->error('同性不能聊天~');
  264. }
  265. //正常价格
  266. $price = $to_user_info['match_typing_price']; //扣费金币
  267. $gift_plat_scale = config('site.gift_plat_scale'); //抽成比例
  268. $money = bcdiv(bcmul($price,100 - $gift_plat_scale,2),100,2); //抽成后收益
  269. Db::startTrans();
  270. //检查剩余分钟数
  271. $user_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->lock(true)->find();
  272. if($user_wallet['typing_times'] >= 1){
  273. //扣分钟数
  274. $price = 0;
  275. //补贴给对方0.1金币
  276. $money = 0.1;
  277. }else{
  278. //需要扣别人的钱,判断钱是否购
  279. if($price > 0){
  280. $goldtotal = model('wallet')->getWallettotal($this->auth->id);
  281. if(bccomp($price,$goldtotal) == 1){
  282. Db::rollback();
  283. $this->error('金币不足');
  284. }
  285. }
  286. }
  287. //添加记录日志
  288. $data = [
  289. 'user_id' => $this->auth->id,
  290. 'price' => $price,
  291. 'createtime' => time(),
  292. 'to_user_id' => $to_user_id,
  293. 'money' => $money,
  294. ];
  295. $log_id = Db::name('user_match_typing_log')->insertGetId($data);
  296. if (!$log_id) {
  297. Db::rollback();
  298. $this->error('扣费失败');
  299. }
  300. //检查剩余分钟数
  301. if($user_wallet['typing_times'] >= 1){
  302. //扣分钟数
  303. $rs_wallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->update(['typing_times'=>$user_wallet['typing_times']-1]);
  304. if($rs_wallet === false){
  305. Db::rollback();
  306. $this->error('扣除免费次数失败');
  307. }
  308. //补贴给对方0.1金币
  309. $money = 0.1;
  310. $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'jewel',$money,23,'对方使用免费次数的补贴','user_match_typing_log',$log_id);
  311. if($rs['status'] === false){
  312. Db::rollback();
  313. $this->error($rs['msg']);
  314. }
  315. }else{
  316. //有性别差,扣费
  317. if($price > 0){
  318. $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$price,13,'','user_match_typing_log',$log_id);
  319. if($rs['status'] === false){
  320. Db::rollback();
  321. $this->error($rs['msg']);
  322. }
  323. }
  324. //另一方加钱,0收费
  325. if($money > 0){
  326. $rs = model('wallet')->lockChangeAccountRemain($to_user_id,'jewel',$money,23,'','user_match_typing_log',$log_id);
  327. if($rs['status'] === false){
  328. Db::rollback();
  329. $this->error($rs['msg']);
  330. }
  331. }
  332. }
  333. Db::commit();
  334. $this->success('success');
  335. }
  336. //语音匹配
  337. public function getaudiouser(){
  338. //给出备选用户
  339. $map = [
  340. 'user.status' =>1, //未封禁用户
  341. 'user.gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  342. 'user.is_active' => 1, //在线的
  343. 'user.open_match_audio' => 1, //打开语聊开关
  344. ];
  345. if($this->auth->gender == 0){
  346. //或者未首充用户,且还有免费分钟数
  347. $map2['user.is_shouchong'] = 0;
  348. $map2['uw.audio_sec'] = ['gt',0];
  349. //男性要有最少一分钟的钱
  350. $map3['uw.gold'] = ['egt',$this->auth->match_audio_price];
  351. }else{
  352. $my_gold = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('gold');
  353. $map2['user.match_audio_price'] = ['elt',$my_gold];
  354. }
  355. $lists = Db::name('user')->alias('user')->field('user.id,user.gender,user.birthday,user.avatar,user.nickname,user.match_audio_price')
  356. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  357. ->where($map)->where($map2)->order('user.logintime desc')->page($this->page,100)->select();
  358. if(empty($lists) && $this->auth->gender == 0){
  359. $lists = Db::name('user')->alias('user')->field('user.id,user.gender,user.birthday,user.avatar,user.nickname,user.match_audio_price')
  360. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  361. ->where($map)->where($map3)->order('user.logintime desc')->page($this->page,100)->select();
  362. }
  363. if(!empty($lists)){
  364. foreach($lists as $key => &$val){
  365. $val = info_domain_image($val,['avatar']);
  366. $val['age'] = birthtime_to_age($val['birthday']);
  367. unset($val['birthday']);
  368. $val['match_audio_price'] = $this->auth->gender == 0 ? $this->auth->match_audio_price : $val['match_audio_price'];
  369. }
  370. }
  371. $this->success('success',$lists);
  372. }
  373. //视频匹配
  374. public function getvideouser(){
  375. //给出备选用户
  376. $map = [
  377. 'user.status' =>1, //未封禁用户
  378. 'user.gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  379. 'user.is_active' => 1, //在线的
  380. 'user.open_match_video' => 1, //打开语聊开关
  381. ];
  382. if($this->auth->gender == 0){
  383. //或者未首充用户,且还有免费分钟数
  384. $map2['user.is_shouchong'] = 0;
  385. $map2['uw.video_sec'] = ['gt',0];
  386. //男性要有最少一分钟的钱
  387. $map3['uw.gold'] = ['egt',$this->auth->match_video_price];
  388. }else{
  389. $my_gold = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('gold');
  390. $map2['user.match_video_price'] = ['elt',$my_gold];
  391. }
  392. $lists = Db::name('user')->alias('user')->field('user.id,user.gender,user.birthday,user.avatar,user.nickname,user.match_audio_price')
  393. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  394. ->where($map)->where($map2)->order('user.logintime desc')->page($this->page,100)->select();
  395. if(empty($lists) && $this->auth->gender == 0){
  396. $lists = Db::name('user')->alias('user')->field('user.id,user.gender,user.birthday,user.avatar,user.nickname,user.match_audio_price')
  397. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  398. ->where($map)->where($map3)->order('user.logintime desc')->page($this->page,100)->select();
  399. }
  400. if(!empty($lists)){
  401. foreach($lists as $key => &$val){
  402. $val = info_domain_image($val,['avatar']);
  403. $val['age'] = birthtime_to_age($val['birthday']);
  404. unset($val['birthday']);
  405. $val['match_audio_price'] = $this->auth->gender == 0 ? $this->auth->match_audio_price : $val['match_audio_price'];
  406. }
  407. }
  408. $this->success('success',$lists);
  409. }
  410. //聊天匹配
  411. public function gettypinguser(){
  412. //给出备选用户
  413. $map = [
  414. 'user.status' =>1, //未封禁用户
  415. 'user.gender' => $this->auth->gender == 1 ? 0 : 1, //异性
  416. ];
  417. if($this->auth->gender == 0){
  418. //或者未首充用户,且还有免费分钟数
  419. $map2['user.is_shouchong'] = 0;
  420. $map2['uw.typing_times'] = ['gt',0];
  421. //男性要有最少一分钟的钱
  422. $map3['uw.gold'] = ['egt',$this->auth->match_typing_price];
  423. }else{
  424. $my_gold = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('gold');
  425. $map2['user.match_typing_price'] = ['elt',$my_gold];
  426. }
  427. $lists = Db::name('user')->alias('user')->field('user.id')
  428. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  429. ->where($map)->where($map2)->order('user.logintime desc')->page($this->page,100)->select();
  430. if(empty($lists) && $this->auth->gender == 0){
  431. $lists = Db::name('user')->alias('user')->field('user.id')
  432. ->join('user_wallet uw','user.id = uw.user_id','LEFT')
  433. ->where($map)->where($map3)->order('user.logintime desc')->page($this->page,100)->select();
  434. }
  435. $this->success('success',$lists);
  436. }
  437. //过滤规则
  438. private function fliter_user($lists){
  439. if(empty($lists)){
  440. return $lists;
  441. }
  442. //过滤掉通话中的
  443. foreach($lists as $key => $val){
  444. if(redis_matching_get($val['id']) == 1){
  445. unset($lists[$key]);
  446. }
  447. }
  448. return $lists;
  449. }
  450. //亲密度等级信息
  451. public function intimacylevel() {
  452. $user_id = input('user_id', 0, 'intval'); //对方id
  453. if (!$user_id) {
  454. $this->error('参数缺失');
  455. }
  456. if ($this->auth->id > $user_id) { //大的在后
  457. $where['uid'] = $user_id;
  458. $where['other_uid'] = $this->auth->id;
  459. } else { //小的在前
  460. $where['uid'] = $this->auth->id;
  461. $where['other_uid'] = $user_id;
  462. }
  463. $level = 0; //当前等级
  464. $level_name = ''; //当前等级名称
  465. $qinmi_sum = 0; //当前亲密度
  466. $next_level_diff = 0; //距下一等级亲密度差值
  467. $next_level_name = 0; //下一等级名称
  468. $next_level_value = 0;//下一等级亲密度值
  469. //亲密度等级列表
  470. $list = Db::name('intimacy_level')->field('name,level,value')->order('value')->select();
  471. //当前亲密度信息
  472. $user_intimacy_info = Db::name('user_intimacy')->where($where)->find();
  473. if ($user_intimacy_info) {
  474. //当前亲密度
  475. $qinmi_sum = $user_intimacy_info['value'];
  476. if ($list) {
  477. //当前等级信息
  478. $level_info = Db::name('intimacy_level')->where(['value' => ['elt', $user_intimacy_info['value']]])->order('level desc')->find();
  479. if ($level_info) {
  480. $level = $level_info['level'];
  481. $level_name = $level_info['name'];
  482. }
  483. //下一等级信息
  484. $next_level_info = Db::name('intimacy_level')->where(['value' => ['gt', $user_intimacy_info['value']]])->order('value')->find();
  485. if ($next_level_info) {
  486. $next_level_name = $next_level_info['name'];
  487. $next_level_value = $next_level_info['value'];
  488. $next_level_diff = $next_level_info['value'] - $user_intimacy_info['value'];
  489. }
  490. }
  491. } else {
  492. $next_level = Db::name('intimacy_level')->order('value')->find();
  493. $next_level_diff = $next_level['value'];
  494. $next_level_name = $next_level['name'];
  495. $next_level_value = $next_level['value'];
  496. }
  497. if ($list) {
  498. foreach ($list as &$v) {
  499. if ($v['level'] < $level) {
  500. $v['is_unlock'] = 1; //当前等级是否解锁: 1已解锁 2当前等级 3未解锁
  501. } elseif ($v['level'] == $level) {
  502. $v['is_unlock'] = 2;
  503. } else {
  504. $v['is_unlock'] = 3;
  505. }
  506. }
  507. }
  508. $data['level'] = $level; //当前等级
  509. $data['level_name'] = $level_name; //当前等级名称
  510. $data['qinmi_sum'] = $qinmi_sum; //当前亲密度
  511. $data['next_level_diff'] = $next_level_diff; //距下一等级亲密度差值
  512. $data['next_level_name'] = $next_level_name; //下一等级名称
  513. $data['next_level_value'] = $next_level_value; //下一等级亲密度值
  514. $data['level_list'] = $list; //等级列表
  515. $this->success('亲密度等级信息', $data);
  516. }
  517. public function test(){
  518. $this->addintimacy(1,3,20);
  519. }
  520. //增加亲密度,顺带升级
  521. public function addintimacy($uid = 0, $other_uid = 0, $value = 0) {
  522. //增加亲密度
  523. $level_remark = ''; //亲密度等级是否变动: 0未变动 >0是亲密度等级
  524. $user_intimacy_info = Db::name('user_intimacy')->where(['uid' => $uid, 'other_uid' => $other_uid])->find();
  525. if ($user_intimacy_info) {
  526. $user_intimacy_data['value'] = $user_intimacy_info['value'] + $value;
  527. $level = Db::name('intimacy_level')->where(['value' => ['elt', $user_intimacy_data['value']]])->order('level desc')->find();
  528. if ($level) {
  529. $user_intimacy_data['level'] = $level['level'];
  530. if ($level['level'] != $user_intimacy_info['level']) {
  531. $level_remark = "恭喜你们亲密度达到".$level['level']."级,获得称号'".$level['name']."'";
  532. }
  533. }
  534. $user_intimacy_rs = Db::name('user_intimacy')->where(['uid' => $uid, 'other_uid' => $other_uid])->setField($user_intimacy_data);
  535. } else {
  536. $user_intimacy_data['uid'] = $uid;
  537. $user_intimacy_data['other_uid'] = $other_uid;
  538. $user_intimacy_data['value'] = $value;
  539. $level = Db::name('intimacy_level')->where(['value' => ['elt', $value]])->order('level desc')->find();
  540. if ($level) {
  541. $user_intimacy_data['level'] = $level['level'];
  542. $level_remark = "恭喜你们亲密度达到".$level['level']."级,获得称号'".$level['name']."'";
  543. }
  544. $user_intimacy_rs = Db::name('user_intimacy')->insertGetId($user_intimacy_data);
  545. }
  546. return ['status' => $user_intimacy_rs, 'level_remark' => $level_remark];
  547. }
  548. }