From cb9c901b35bbaf80efcdf84b14a1013e48a0448f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E5=8D=8E=E6=B8=85?= <18691022700@163.com> Date: Fri, 14 Nov 2025 14:49:38 +0800 Subject: [PATCH] =?UTF-8?q?CP=20=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/controller/UserCp.php | 16 +++ application/api/model/GiveGift.php | 4 + application/api/model/SingerSong.php | 7 +- application/api/model/UserCp.php | 137 +++++++++++++++++++++++++- 4 files changed, 160 insertions(+), 4 deletions(-) create mode 100644 application/api/controller/UserCp.php diff --git a/application/api/controller/UserCp.php b/application/api/controller/UserCp.php new file mode 100644 index 0000000..f82e153 --- /dev/null +++ b/application/api/controller/UserCp.php @@ -0,0 +1,16 @@ +tasks_complete($uid,3); } + //cp检测 + model('api/UserCp')->checkGift($uid, $give_gift, $to_id, $from_id); } //增加房间火热值hot_value @@ -859,6 +861,8 @@ class GiveGift extends Model //直播间送礼物 每日任务 model('DailyTasks')->tasks_complete($uid,3); } + //cp检测 + model('api/UserCp')->checkGift($uid, $give_gift, $to_id, $from_id); } //增加房间火热值hot_value diff --git a/application/api/model/SingerSong.php b/application/api/model/SingerSong.php index 3ff2ba1..0977386 100644 --- a/application/api/model/SingerSong.php +++ b/application/api/model/SingerSong.php @@ -69,6 +69,11 @@ class SingerSong extends Model */ public function singerAddSong($user_id, $song_name, $gift_id, $gift_num) { + //查询是否是认证歌手 + $res = db::name('vs_singer')->where(['user_id' => $user_id])->find(); + if (!$res || $res['status'] != 1) { + return ['code' => 0, 'msg' => '请先认证歌手', 'data' => null]; + } //查询是否提交过歌曲 $res = db::name('vs_singer_song')->where(['user_id' => $user_id, 'song_name' => $song_name])->find(); if ($res) { @@ -233,7 +238,7 @@ class SingerSong extends Model $exp_coin = round($coin / get_system_config_value('singer_coin_exp'), 2); $exps = $exp + $exp_coin; //查询等级 - $level = db::name('vs_singer_level')->where(['exp' => ['<=', $exps]])->order('exp desc')->find(); + $level = db::name('vs_singer_level')->where(['change_value' => ['<=', $exps]])->order('exp desc')->find(); if ($level) { db::name('vs_singer')->where(['id' => $is_singer['id']])->update(['exp' => $exps,'level' => $level['level']]); } diff --git a/application/api/model/UserCp.php b/application/api/model/UserCp.php index 8c17bf7..cf189f3 100644 --- a/application/api/model/UserCp.php +++ b/application/api/model/UserCp.php @@ -2,13 +2,144 @@ namespace app\api\model; +use think\Db; use think\Model; class UserCp extends Model { - //用户关系卡(亲密拍)、关系位(真爱拍 ->有电影房) - public function user_cp_list($uid,$user_id) - { + /* + * 检测是否赠送的Cp礼物 + * @param $from_user_id 送礼用户ID + * @param $gift_id 礼物ID + * @param $to_user_id 接收用户ID + * @param $room_id 房间ID + */ + public function checkGift($from_user_id, $gift_id, $to_user_id, $room_id) + { + $cp_gift_id = explode(',', get_system_config_value('cp_gift_id')); + if(!in_array($gift_id, $cp_gift_id)){ + return false; + } + + $rees = Db::name('user_cp_zone')->where(['user_id1' => $from_user_id,'user_id2' => $to_user_id,'status' => 1])->find(); + if(!$rees){ + $rees = Db::name('user_cp_zone')->where(['user_id1' => $to_user_id,'user_id2' => $from_user_id,'status' => 1])->find(); + } + if($rees){ + $this->addCpLevel($from_user_id, $to_user_id, $room_id, $gift_id, $rees['id']); + return true; + } + + //查询收礼人有没有给送礼人送过cp礼物 + $res = Db::name('user_cp_find')->where(['from_user_id' => $to_user_id, 'to_user_id' => $from_user_id,'status' => 0])->find(); + if($res){ + //创建推送信息1:回应送礼 并创建Cp空间, + $data = [ + 'from_user_id' => $from_user_id, + 'to_user_id' => $to_user_id, + 'gift_id' => $gift_id, + 'createtime' => time(), + 'status' => 1 + ]; + Db::name('user_cp_find')->insert($data); + //修改状态 + Db::name('user_cp_find')->where(['id' => $res['id']])->update(['status' => 1]); + //创建Cp空间 + + $data = [ + 'user_id1' => $from_user_id, + 'user_id2' => $to_user_id, + 'createtime' => time(), + 'status' => 1,//1-已建立Cp空间,2-已取消 + 'level' => 1, + //经验值 + 'exp' => 0, + ]; + Db::name('user_cp_zone')->insert($data); + + //给前端推送 + $text = [ + 'text' => '组建Cp' + ]; + //聊天室推送系统消息 + model('Chat')->sendMsg(1081,$room_id,$text); + }else{//创建推送信息2:表达心动信号 + //查询是否有相应的Cp空间 + $ress = Db::name('user_cp_find') + ->where(['status' => ['in',[0,1]]]) + ->whereOr(['from_user_id' => $from_user_id]) + ->whereOr(['to_user_id' => $from_user_id]) + ->select(); + if($ress){ + //把状态改为2 status:0-待回应,1-建交成功,2-已取消, + foreach ($ress as $v){ + Db::name('user_cp_find')->where(['id' => $v['id']])->update(['status' => 2]); + } + } + $rees = Db::name('user_cp_zone')->where(['user_id1' => $from_user_id,'user_id2' => $to_user_id,'status' => 1])->find(); + if(!$rees){ + $rees = Db::name('user_cp_zone')->where(['user_id1' => $to_user_id,'user_id2' => $from_user_id,'status' => 1])->find(); + } + if($rees){ + //修改状态 + Db::name('user_cp_zone')->where(['id' => $rees['id']])->update(['status' => 2]); + } + + $data = [ + 'from_user_id' => $from_user_id, + 'to_user_id' => $to_user_id, + 'gift_id' => $gift_id, + 'createtime' => time(), + ]; + Db::name('user_cp_find')->insert($data); + //给前端推送 + $text = [ + 'text' => '有心动信号' + ]; + //聊天室推送系统消息 + model('Chat')->sendMsg(1080,$room_id,$text); + } + return true; + } + + + /* + * 送Cp礼物 增加Cp 经验 判断是否升级 + * @param $from_user_id 送礼用户ID + * @param $to_user_id 接收用户ID + * @param $gift_id 礼物ID + * @param $room_id 房间ID + * @param $cp_zone_id Cp空间ID + */ + public function addCpLevel($from_user_id, $to_user_id, $room_id, $gift_id, $cp_zone_id) + { + $jinbi_arr = explode(',', get_system_config_value('cp_exp_rate')); + $jinbi = $jinbi_arr[0]; + $jinyan = $jinbi_arr[1]; + $exp = round(db::name('vs_gift')->where(['gid' => $gift_id])->value('gift_price') / $jinbi * $jinyan, 2); + $yuan_exp = Db::name('user_cp_zone')->where(['id' => $cp_zone_id])->value('exp'); + + //添加一个记录 + $datas = [ + 'room_id' => $room_id, + 'from_user_id' => $from_user_id, + 'to_user_id' => $to_user_id, + 'gift_id' => $gift_id, + 'cp_zone_id' => $cp_zone_id, + 'exp' => $exp, + 'exp_total' => $yuan_exp + $exp, + 'createtime' => time(), + ]; + Db::name('user_cp_gift_log')->insert($datas); + //判断是否升级 + $level = Db::name('user_cp_level')->where(['exp' => ['<=', $yuan_exp + $exp]])->order('exp desc')->value('level'); + if($level){ + //修改Cp空间等级 + $data['level'] = $level; + } + $data['exp'] = $yuan_exp + $exp; + Db::name('user_cp_zone')->where(['id' => $cp_zone_id])->update($data); + return true; } } \ No newline at end of file