2025-08-07 20:21:47 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace app\api\model;
|
|
|
|
|
|
|
2025-11-14 14:49:38 +08:00
|
|
|
|
use think\Db;
|
2025-08-07 20:21:47 +08:00
|
|
|
|
use think\Model;
|
|
|
|
|
|
|
|
|
|
|
|
class UserCp extends Model
|
|
|
|
|
|
{
|
2025-11-14 14:49:38 +08:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 检测是否赠送的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)
|
2025-08-07 20:21:47 +08:00
|
|
|
|
{
|
2025-11-14 14:49:38 +08:00
|
|
|
|
$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');
|
2025-08-07 20:21:47 +08:00
|
|
|
|
|
2025-11-14 14:49:38 +08:00
|
|
|
|
//添加一个记录
|
|
|
|
|
|
$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;
|
2025-08-07 20:21:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|