|
@@ -1359,83 +1359,36 @@ class Party extends Common
|
|
|
if (!$this->apiLimit(1, 1000)) {
|
|
|
$this->error(__('Operation frequently'));
|
|
|
}
|
|
|
+
|
|
|
+ //
|
|
|
$user_ids = $this->request->request("user_id");// 赠送对象
|
|
|
$gift_id = $this->request->request("gift_id");// 礼物ID
|
|
|
$party_id = $this->request->request("party_id",0);// 派对ID
|
|
|
- $room_type = 1; // 房间类型
|
|
|
$number = $this->request->request("number");// 赠送数量
|
|
|
+ $room_type = 1; // 房间类型
|
|
|
$is_back = 0;// 是否背包赠送: 1=是,0=否
|
|
|
- if (!$user_ids || !in_array($is_back,[0,1]) || !$gift_id || !$number || !in_array($room_type,[1,2])) $this->error(__('Invalid parameters'));
|
|
|
- $user_id_arr = explode(",",$user_ids);
|
|
|
+ if (!$user_ids || !$gift_id || !$number)
|
|
|
+ {
|
|
|
+ $this->error(__('Invalid parameters'));
|
|
|
+ }
|
|
|
+
|
|
|
+ //
|
|
|
+ $user_id_arr = explode(',',$user_ids);
|
|
|
$userCount = count($user_id_arr);
|
|
|
$userauthid = $this->auth->id;
|
|
|
- $soundCoinRate = config("site.gift_plat_scale"); // 声币兑换比例
|
|
|
- $userModel = new \app\common\model\User();
|
|
|
-
|
|
|
- $backGiftId = 0;
|
|
|
- $boxgiftInfo = [];
|
|
|
- if($is_back == 1) {
|
|
|
- // 获取背包礼物信息
|
|
|
- $giftInfo = \app\common\model\GiftBack::get($gift_id);
|
|
|
- if(!$giftInfo) $this->error("背包礼物获取失败");
|
|
|
- $backGiftId = $giftInfo->gift_id;
|
|
|
- // 随机获取一个礼物
|
|
|
- $allCount = $number*$userCount;
|
|
|
- $giftbackList = \app\common\model\GiftBack::where(["name"=>$giftInfo->name,"user_id"=>$userauthid,'is_use'=>0])->limit($allCount)->select();
|
|
|
- $giftInfo = isset($giftbackList[0])?$giftbackList[0]:[];
|
|
|
- $giftcount = 0;
|
|
|
- $giftList = [];
|
|
|
- if($giftbackList) foreach($giftbackList as $k => $v) {
|
|
|
- $giftcount = $giftcount + $v["number"];
|
|
|
- $giftList[$k] = $v;
|
|
|
- if($giftcount >= $allCount) {
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if($giftcount < $allCount) $this->error("背包数量不足");
|
|
|
- $giftValue = $giftInfo["value"] * $number;
|
|
|
- $getValue = $giftInfo["value"] * $number;
|
|
|
- } else {
|
|
|
-// // 不可以赠送给自己
|
|
|
-// if(in_array($userauthid,$user_id_arr)) $this->error("不可以赠送给自己!");
|
|
|
-
|
|
|
- // 获取礼物信息
|
|
|
- $giftModel = new \app\common\model\Gift();
|
|
|
- $where = [];
|
|
|
- $where["id"] = $gift_id;
|
|
|
- $giftInfo = $giftModel->where($where)->find();
|
|
|
- if (!$giftInfo) $this->error("请选择礼物!");
|
|
|
- $giftValue = $giftInfo["value"] * $number;
|
|
|
- $giftCountValue = $giftInfo["value"] * $number * $userCount;
|
|
|
- $getValue = $giftValue;
|
|
|
- // 判断如果是礼物盒则随机开礼物盒礼物
|
|
|
- /*if($giftInfo->box_type > 0) {
|
|
|
- $boxgiftInfo = $this->getBoxGift($giftInfo->box_type);
|
|
|
- $getValue = $boxgiftInfo["price"];
|
|
|
- }*/
|
|
|
|
|
|
- // 判断当前用户余额
|
|
|
- $user_gold = model('wallet')->getWallet($userauthid,'gold');
|
|
|
|
|
|
- if($user_gold < $giftCountValue) $this->error("您的金币余额不足!");
|
|
|
- }
|
|
|
+ // 获取礼物信息
|
|
|
+ $giftInfo = Db::name('gift')->where('id',$gift_id)->find();
|
|
|
+ if (!$giftInfo) {$this->error("请选择礼物!");}
|
|
|
+ $giftValue = $giftInfo["value"] * $number;
|
|
|
+ $giftCountValue = $giftInfo["value"] * $number * $userCount;
|
|
|
|
|
|
- $hotValue = $getValue;
|
|
|
|
|
|
- /*$getValue = round($getValue * (100 - $soundCoinRate) / 100);
|
|
|
+ // 判断当前用户余额
|
|
|
+ $user_gold = model('wallet')->getWallet($userauthid,'gold');
|
|
|
+ if($user_gold < $giftCountValue) {$this->error("您的金币余额不足!");}
|
|
|
|
|
|
- // 转换统计
|
|
|
- $progetValue = $hotValue - $getValue;
|
|
|
- if($progetValue >0) {
|
|
|
- $data = [];
|
|
|
- $data["user_id"] = $user_ids;
|
|
|
- $data["party_id"] = $party_id?$party_id:0;
|
|
|
- $data["gift_value"] = $hotValue;
|
|
|
- $data["plat_value"] = $hotValue - $getValue;
|
|
|
- $data["createtime"] = time();
|
|
|
- \app\common\model\UserChangeLog::insert($data);
|
|
|
- }*/
|
|
|
|
|
|
if($party_id){
|
|
|
$partyInfo = \app\common\model\Party::field("user_id,platRate,guilderRate")->where(["id"=>$party_id])->find();
|
|
@@ -1443,34 +1396,13 @@ class Party extends Common
|
|
|
$this->error('不存在的语聊间');
|
|
|
}
|
|
|
}
|
|
|
- /*
|
|
|
- // 转换声币后 再进行抽点设置
|
|
|
- $partyInfo = null;
|
|
|
- if(!$party_id) {
|
|
|
- $platRate = 10;
|
|
|
- $guilderRate = 30;
|
|
|
- } else {
|
|
|
- $partyInfo = \app\common\model\Party::field("user_id,platRate,guilderRate")->where(["id"=>$party_id])->find();
|
|
|
- // 获取系统配置信息
|
|
|
- $platRate = $partyInfo->platRate; // 平台抽成百分比
|
|
|
- $guilderRate = $partyInfo->guilderRate; // 工会长抽成百分比
|
|
|
- }
|
|
|
-
|
|
|
- $platValue = bcmul($platRate/100,$getValue);
|
|
|
- $guilderValue = bcmul($guilderRate/100,$getValue);
|
|
|
- $getValue = bcsub(bcsub($getValue,$platValue),$guilderValue);
|
|
|
- */
|
|
|
|
|
|
-// $gif_image = $is_back==1?$giftInfo["gif_image"]:$giftInfo["special"];
|
|
|
$returnData = [];
|
|
|
Db::startTrans();
|
|
|
try {
|
|
|
$redis = new Redis();
|
|
|
$redisconfig = config("redis");
|
|
|
$redis->connect($redisconfig["host"], $redisconfig["port"], 86400 * 31);
|
|
|
- // 事务处理余额与记录信息
|
|
|
- $userjewellogModel = new \app\common\model\UserJewelLog();
|
|
|
- $usersoundcoinlogModel = new \app\common\model\UserSoundcoinLog();
|
|
|
|
|
|
// 获取当天零点
|
|
|
$day = date("Ymd");
|
|
@@ -1482,115 +1414,61 @@ class Party extends Common
|
|
|
$allVal = 0;
|
|
|
$i = 0;
|
|
|
foreach($user_id_arr as $user_id) {
|
|
|
- // 获取赠送用户信息
|
|
|
- $where = [];
|
|
|
- $where["id"] = $user_id;
|
|
|
- $touserInfo = $userModel->where($where)->find();
|
|
|
-
|
|
|
- if($is_back == 1) {
|
|
|
- $b=0;
|
|
|
- foreach($giftList as $k => $v) {
|
|
|
- for($a=1;$a<=$v["number"];$a++) {
|
|
|
- $b++;
|
|
|
- $num = $v["number"] - $a;
|
|
|
- if($num > 0) {
|
|
|
- $res1 = \app\common\model\GiftBack::where(["id"=>$v["id"]])->setDec("number");
|
|
|
- } else {
|
|
|
- $res1 = \app\common\model\GiftBack::update(["is_use"=>1,"use_time"=>time()],["id"=>$v["id"]]);
|
|
|
- }
|
|
|
- if($b == $number) break;
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- $res2 = true;
|
|
|
- } else {
|
|
|
- // 扣除当前用户钻石余额
|
|
|
- $wallet_rs = model('wallet')->lockChangeAccountRemain($userauthid,'gold',-$giftValue,51,'赠送礼物:'.$giftInfo["name"]);
|
|
|
- if($wallet_rs['status'] === false){
|
|
|
- Db::rollback();
|
|
|
- $this->error($wallet_rs['msg']);
|
|
|
- }
|
|
|
|
|
|
- /*$where = [];
|
|
|
- $where["id"] = $userauthid;
|
|
|
- $res1 = $userModel->where($where)->setDec("jewel", $giftValue);
|
|
|
- // 添加当前用户钻石流水记录
|
|
|
- $res2 = $userjewellogModel->addUserJewelLog($userauthid, $giftValue, "-", $userInfo["jewel"], "赠送礼物:'" . $giftInfo["name"] . "',扣除" . $giftValue . "钻石!", 3);*/
|
|
|
- }
|
|
|
-
|
|
|
- $giftuserpartyModel = new \app\common\model\GiftUserParty();
|
|
|
// 添加礼物赠送记录表
|
|
|
$data = [];
|
|
|
$data["user_id"] = $userauthid;
|
|
|
$data["user_to_id"] = $user_id;
|
|
|
$data["party_id"] = $party_id;
|
|
|
-
|
|
|
- if($boxgiftInfo){
|
|
|
- $data["gift_id"] = $boxgiftInfo['gift_id'];
|
|
|
- $data["gift_give_type"] = 2;
|
|
|
- $data["gift_name"] = $boxgiftInfo["gift_name"];
|
|
|
- $data["gift_gif_image"] = $boxgiftInfo["image"];
|
|
|
- $data["number"] = $number;
|
|
|
- $data["price"] = $boxgiftInfo["price"];
|
|
|
- $data["value"] = $boxgiftInfo["price"] * $number;
|
|
|
- }else{
|
|
|
- $data["gift_id"] = $backGiftId > 0 ? $backGiftId : $gift_id;
|
|
|
- $data["gift_give_type"] = $is_back ? 1 : 2;
|
|
|
- $data["gift_name"] = $giftInfo["name"];
|
|
|
- $data["gift_gif_image"] = $giftInfo["image"];
|
|
|
- $data["number"] = $number;
|
|
|
- $data["price"] = $giftInfo["value"];
|
|
|
- $data["value"] = $giftValue;
|
|
|
- }
|
|
|
+ $data["gift_id"] = $gift_id;
|
|
|
+ $data["gift_give_type"] = 2;
|
|
|
+ $data["gift_name"] = $giftInfo["name"];
|
|
|
+ $data["gift_gif_image"] = $giftInfo["image"];
|
|
|
+ $data["number"] = $number;
|
|
|
+ $data["price"] = $giftInfo["value"];
|
|
|
+ $data["value"] = $giftValue;
|
|
|
|
|
|
$data["createtime"] = time();
|
|
|
- $res5 = $giftuserpartyModel->allowField(true)->save($data);
|
|
|
- if(!$res5){
|
|
|
+ $log_id = Db::name('gift_user_party')->insertGetId($data);
|
|
|
+ if(!$log_id){
|
|
|
Db::rollback();
|
|
|
$this->error('赠送失败');
|
|
|
}
|
|
|
|
|
|
- // 添加赠送用户声币余额
|
|
|
- if($getValue > 0){
|
|
|
- $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,'money',$getValue,52,'获得礼物:'.$giftInfo["name"]);
|
|
|
+ if($giftValue > 0){
|
|
|
+ // 扣除当前用户钻石余额
|
|
|
+ $wallet_rs = model('wallet')->lockChangeAccountRemain($userauthid,'gold',-$giftValue,51,'赠送礼物:'.$giftInfo["name"],'gift_user_party',$log_id);
|
|
|
+ if($wallet_rs['status'] === false){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($wallet_rs['msg']);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 添加赠送用户余额
|
|
|
+ $money_to_gold = config('site.money_to_gold');
|
|
|
+ $gift_plat_scale = config('site.gift_plat_scale');
|
|
|
+ $giftmoney = bcdiv($giftValue,$money_to_gold,2);
|
|
|
+ $money = bcdiv(bcmul($giftmoney,100 - $gift_plat_scale,2),100,2);
|
|
|
+
|
|
|
+ $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,'money',$money,52,'获得礼物:'.$giftInfo["name"],'gift_user_party',$log_id);
|
|
|
if($wallet_rs['status'] === false){
|
|
|
Db::rollback();
|
|
|
$this->error($wallet_rs['msg']);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /*$where = [];
|
|
|
- $where["id"] = $user_id;
|
|
|
- $res3 = $userModel->where($where)->setInc("sound_coin", $getValue);
|
|
|
- $getValue == 0 && $res3 = true;
|
|
|
- // 添加赠送用户声币流水记录soundCoin
|
|
|
- // xxx送你
|
|
|
- $res4 = $usersoundcoinlogModel->addUserSoundcoinLog($user_id, $getValue, "+", $touserInfo["sound_coin"], "{$this->auth->nickname}送你{$giftInfo['name']}x{$number}", 1, $giftuserpartyModel->id);*/
|
|
|
-
|
|
|
- // 增加房主抽成
|
|
|
- /*if ($partyInfo && $guilderValue > 0) {
|
|
|
-
|
|
|
- $where = [];
|
|
|
- $where["id"] = $partyInfo->user_id;
|
|
|
- $userModel->where($where)->setInc("sound_coin", $guilderValue);
|
|
|
- // 添加赠送用户声币流水记录soundCoin
|
|
|
- // xxx送礼物给xxx,房间礼物抽成
|
|
|
- $usersoundcoinlogModel->addUserSoundcoinLog($partyInfo->user_id, $guilderValue, "+", $touserInfo["sound_coin"], "{$this->auth->nickname}送礼物{$giftInfo['name']}x{$number}给{$touserInfo['nickname']},房间礼物抽成", 4, $giftuserpartyModel->id);
|
|
|
- }*/
|
|
|
-
|
|
|
- //总消费增加
|
|
|
-// $res6 = Db::name('user')->where('id',$user_id)->setInc("renewcount", $giftCountValue);
|
|
|
+
|
|
|
$res6 = true;
|
|
|
|
|
|
if ($res6) {
|
|
|
$i++;
|
|
|
if($party_id > 0) {
|
|
|
// 添加redis记录做财富排行榜日榜用
|
|
|
- $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_get_" . $party_id . ":" . $day . "d", $hotValue, $user_id);
|
|
|
+ $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_get_" . $party_id . ":" . $day . "d", $giftValue, $user_id);
|
|
|
// 添加redis记录做财富排行榜周榜用
|
|
|
- $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_get_" . $party_id . ":" . $weekday . "w", $hotValue, $user_id);
|
|
|
+ $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_get_" . $party_id . ":" . $weekday . "w", $giftValue, $user_id);
|
|
|
// 添加redis记录做财富排行榜月榜用
|
|
|
- $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_get_" . $party_id . ":" . $monthday . "m", $hotValue, $user_id);
|
|
|
+ $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_get_" . $party_id . ":" . $monthday . "m", $giftValue, $user_id);
|
|
|
// 添加redis记录做贡献排行榜日榜用
|
|
|
$redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_to_" . $party_id . ":" . $day . "d", $giftValue, $userauthid);
|
|
|
// 添加redis记录做贡献排行榜周榜用
|
|
@@ -1599,49 +1477,12 @@ class Party extends Common
|
|
|
$redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_to_" . $party_id . ":" . $monthday . "m", $giftValue, $userauthid);
|
|
|
|
|
|
// tcp 更新用户魅力值
|
|
|
- $this->updateUserCharm($party_id, $user_id, $hotValue);
|
|
|
-
|
|
|
- // 如果是主播,则添加魅力值记录做榜单统计
|
|
|
- /*if($room_type == 2) {
|
|
|
- $data = [];
|
|
|
- $data["user_id"] = $user_id;
|
|
|
- $data["party_id"] = $party_id;
|
|
|
- $data["charm"] = $hotValue;
|
|
|
- $data["createtime"] = time();
|
|
|
- \app\common\model\UserCharmRank::insert($data);
|
|
|
+ $this->updateUserCharm($party_id, $user_id, $giftValue);
|
|
|
|
|
|
- }*/
|
|
|
|
|
|
}
|
|
|
- /*$getempirical = config("site.getempirical");
|
|
|
- $getempirical = $getempirical * $hotValue;
|
|
|
- // 获取用户贵族信息
|
|
|
- $noble = \app\common\model\User::getUserNoble($this->auth->id);
|
|
|
- if(isset($noble["noble_on"]) && $noble["noble_on"] == 1) {
|
|
|
- $getempirical = $getempirical + $getempirical * ($noble["explain"]/100);
|
|
|
- }
|
|
|
-
|
|
|
- // 增加用户经验值
|
|
|
- $res = \app\common\model\User::addEmpirical($this->auth->id,$getempirical);
|
|
|
- if ($res){
|
|
|
- $this->auth->level = $res->level;
|
|
|
- }*/
|
|
|
-
|
|
|
- // +exp
|
|
|
-// \app\common\model\TaskLog::tofinish($this->auth->id,"OBHqCX4g",$number);
|
|
|
|
|
|
- //贵族升级处理
|
|
|
-// $this->checkBeNoble($redis,$this->auth->id,$giftCountValue);
|
|
|
-
|
|
|
- // +message
|
|
|
-// \app\common\model\Message::addMessage($user_id,"礼物通知","收到 ".$this->auth->nickname." 赠送的".$giftInfo["name"]." x".$number);
|
|
|
-
|
|
|
- $allVal = $allVal + $hotValue;
|
|
|
-
|
|
|
-// // 剪掉背包礼物
|
|
|
-// if($is_back == 1) {
|
|
|
-// \app\common\model\GiftBack::update(["is_use"=>1],["id"=>$gift_id]);
|
|
|
-// }
|
|
|
+ $allVal = $allVal + $giftValue;
|
|
|
|
|
|
}
|
|
|
}
|
|
@@ -1676,33 +1517,9 @@ class Party extends Common
|
|
|
$returnData["userCharm"] = $userCharm;
|
|
|
$returnData["partyHot"] = $this->changeW($partyHot);
|
|
|
$returnData["partyUserTop"] = $partyUserTop;
|
|
|
- if($is_back != 1) {
|
|
|
- if($giftInfo->box_type > 0) { // 不是背包,宝箱中赠送
|
|
|
- $returnData["box_type"] = $giftInfo->box_type;
|
|
|
- $returnData["box_image"] = $giftInfo->image;
|
|
|
- $returnData["image"] = $boxgiftInfo["image"];
|
|
|
- $returnData["name"] = $boxgiftInfo["gift_name"];
|
|
|
- $returnData["gif_image"] = $boxgiftInfo["special"];
|
|
|
- } else {
|
|
|
- $returnData["image"] = $giftInfo["image"];
|
|
|
- $returnData["gif_image"] = $giftInfo["special"];
|
|
|
- }
|
|
|
- } else {
|
|
|
- $returnData["image"] = $giftInfo["image"];
|
|
|
- $returnData["gif_image"] = $giftInfo["gif_image"];
|
|
|
- }
|
|
|
+ $returnData["image"] = $giftInfo["image"];
|
|
|
+ $returnData["gif_image"] = $giftInfo["special"];
|
|
|
|
|
|
- /*
|
|
|
- // 增加抽点记录
|
|
|
- $data = [];
|
|
|
- $data["user_id"] = $user_ids;
|
|
|
- $data["party_id"] = $party_id?$party_id:0;
|
|
|
- $data["gift_value"] = $getValue;
|
|
|
- $data["plat_value"] = $platValue;
|
|
|
- $data["guilder_value"] = $guilderValue;
|
|
|
- $data["createtime"] = time();
|
|
|
- \app\common\model\UserProfitLog::insert($data);
|
|
|
- */
|
|
|
Db::commit();
|
|
|
$this->success("赠送成功!",$returnData);
|
|
|
} else {
|
|
@@ -1817,308 +1634,7 @@ class Party extends Common
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 全麦/单独赠送宝箱
|
|
|
- */
|
|
|
- public function giveBoxToYou() {
|
|
|
- // 接口防并发
|
|
|
- if (!$this->apiLimit(1, 1000)) {
|
|
|
- $this->error(__('Operation frequently'));
|
|
|
- }
|
|
|
- $user_ids = $this->request->request("user_id");// 赠送对象
|
|
|
- $gift_id = $this->request->request("gift_id");// 礼物ID
|
|
|
- $party_id = $this->request->request("party_id",0);// 派对ID
|
|
|
- $room_type = $this->request->request('room_type',1); // 房间类型
|
|
|
- $number = $this->request->request("number");// 赠送数量
|
|
|
- if (!$user_ids || !$gift_id || !$number || !in_array($room_type,[1,2])) $this->error(__('Invalid parameters'));
|
|
|
-
|
|
|
- $user_id_arr = explode(",",$user_ids);
|
|
|
- $userCount = count($user_id_arr);
|
|
|
- $userauthid = $this->auth->id;
|
|
|
- $soundCoinRate = config("site.giftCoin"); // 声币兑换比例
|
|
|
- $userModel = new \app\common\model\User();
|
|
|
-
|
|
|
- // 获取礼物信息
|
|
|
- $giftModel = new \app\common\model\Gift();
|
|
|
- $where = [];
|
|
|
- $where["id"] = $gift_id;
|
|
|
- $giftInfo = $giftModel->where($where)->find();
|
|
|
- if (!$giftInfo) $this->error("请选择礼物!");
|
|
|
- //宝箱价值
|
|
|
- $giftCountValue = $giftInfo["value"] * $number * $userCount;
|
|
|
- //随机开礼物盒礼物
|
|
|
- $boxgiftInfo = $this->getBoxesGift($giftInfo->box_type,$userCount,$number);
|
|
|
- // 判断当前用户余额
|
|
|
- $where = [];
|
|
|
- $where["id"] = $userauthid;
|
|
|
- $userInfo = $userModel->where($where)->lock(true)->find();
|
|
|
- if (!$userInfo) $this->error("用户信息查询失败!");
|
|
|
- if($userInfo["jewel"] < $giftCountValue) $this->error("您的钻石余额不足!");
|
|
|
-
|
|
|
- // 转换声币后 再进行抽点设置
|
|
|
- if(!$party_id) {
|
|
|
- $platRate = 10;
|
|
|
- $guilderRate = 30;
|
|
|
- } else {
|
|
|
- $partyInfo = \app\common\model\Party::field("user_id,platRate,guilderRate")->where(["id"=>$party_id])->find();
|
|
|
- // 获取系统配置信息
|
|
|
- $platRate = $partyInfo->platRate; // 平台抽成百分比
|
|
|
- $guilderRate = $partyInfo->guilderRate; // 工会长抽成百分比
|
|
|
- }
|
|
|
-
|
|
|
- $returnData = [];
|
|
|
- // 获取当天零点
|
|
|
- $day = date("Ymd");
|
|
|
- // 获取本周第一天
|
|
|
- $weekday = $this->firstOfWeek(date("Y-m-d H:i:s"));
|
|
|
- // 获取本月第一天
|
|
|
- $monthday = date("Ym01");
|
|
|
- $allVal = 0;
|
|
|
- $i = 0;
|
|
|
- $allUserBoxGiftInfo = [];//每个玩家获得的礼物
|
|
|
-
|
|
|
- $redis = new Redis();
|
|
|
- $redisconfig = config("redis");
|
|
|
- $redis->connect($redisconfig["host"], $redisconfig["port"], 86400 * 31);
|
|
|
- Db::startTrans();
|
|
|
- try {
|
|
|
- // 事务处理余额与记录信息
|
|
|
- $userjewellogModel = new \app\common\model\UserJewelLog();
|
|
|
- $usersoundcoinlogModel = new \app\common\model\UserSoundcoinLog();
|
|
|
- $giftuserpartyModel = new \app\common\model\GiftUserParty();
|
|
|
-
|
|
|
- // 扣除当前用户钻石余额
|
|
|
- $where = [];
|
|
|
- $where["id"] = $userauthid;
|
|
|
- $res1 = $userModel->where($where)->setDec("jewel", $giftCountValue);
|
|
|
-
|
|
|
- // 添加当前用户钻石流水记录
|
|
|
- $res2 = $userjewellogModel->addUserJewelLog($userauthid, $giftCountValue, "-", $userInfo["jewel"], "赠送礼物:'" . $giftInfo["name"] . "',扣除" . $giftCountValue . "钻石!", 3);
|
|
|
- $UserProfitLogList = [];
|
|
|
- foreach($user_id_arr as $user_id) {
|
|
|
-
|
|
|
- // 添加礼物赠送记录表
|
|
|
- $data = [];
|
|
|
- for ($k=0;$k<$number;$k++){
|
|
|
- $data[$k]["user_id"] = $userauthid;
|
|
|
- $data[$k]["user_to_id"] = $user_id;
|
|
|
- $data[$k]["party_id"] = $party_id;
|
|
|
- $data[$k]["createtime"] = time();
|
|
|
- $oneBoxGiftInfo = array_pop($boxgiftInfo);
|
|
|
- $giftId = $oneBoxGiftInfo['gift_id'];
|
|
|
- $oneBoxGiftInfoNew['id'] = $oneBoxGiftInfo['gift_id'];
|
|
|
- $oneBoxGiftInfoNew['name'] = $oneBoxGiftInfo['gift_name'];
|
|
|
- $oneBoxGiftInfoNew['image'] = $oneBoxGiftInfo['image'];
|
|
|
- $oneBoxGiftInfoNew['gif_image'] = $oneBoxGiftInfo['special'];
|
|
|
- $oneBoxGiftInfoNew['price'] = $oneBoxGiftInfo["price"];
|
|
|
- $oneBoxGiftInfoNew['only_gif_image'] = $oneBoxGiftInfo["only_special"];
|
|
|
- $oneBoxGiftInfoNew['number'] = 1;
|
|
|
-
|
|
|
-// 合并重复的礼物数量
|
|
|
- if (isset($allUserBoxGiftInfo[$user_id][$giftId])){
|
|
|
- $allUserBoxGiftInfo[$user_id][$giftId]['number'] += 1;
|
|
|
- }else{
|
|
|
- $allUserBoxGiftInfo[$user_id][$giftId] = $oneBoxGiftInfoNew;
|
|
|
- }
|
|
|
-
|
|
|
- if($oneBoxGiftInfo){
|
|
|
- $data[$k]["gift_id"] = $oneBoxGiftInfo['gift_id'];
|
|
|
- $data[$k]["gift_give_type"] = 2;
|
|
|
- $data[$k]["gift_name"] = $oneBoxGiftInfo["gift_name"];
|
|
|
- $data[$k]["gift_gif_image"] = $oneBoxGiftInfo["image"];
|
|
|
- $data[$k]["number"] = 1;
|
|
|
- $data[$k]["price"] = $oneBoxGiftInfo["price"];
|
|
|
- $data[$k]["value"] = $oneBoxGiftInfo["price"];
|
|
|
- }
|
|
|
- }
|
|
|
- $res5 = $giftuserpartyModel->allowField(true)->saveAll($data);
|
|
|
-
|
|
|
- // 获取赠送用户信息
|
|
|
- $where = [];
|
|
|
- $where["id"] = $user_id;
|
|
|
- $toUserInfo = $userModel->where($where)->find();
|
|
|
-
|
|
|
- $UserChangeLogList = [];
|
|
|
- $res4 = [];
|
|
|
- $res6 = [];
|
|
|
- $getValueForUser = 0;
|
|
|
- $platValueForUser = 0;
|
|
|
- $guilderValueForUser = 0;
|
|
|
- $userSound_coin = $toUserInfo["sound_coin"];
|
|
|
- //礼物总价值
|
|
|
- $hotValueCount = 0;
|
|
|
- foreach ($res5 as $oneBoxGiftInfo){
|
|
|
- $getValue = $oneBoxGiftInfo['price'];
|
|
|
-
|
|
|
- $hotValueCount += $getValue;
|
|
|
- $hotValue = $getValue;
|
|
|
- $getValue = round($getValue * ($soundCoinRate/100));
|
|
|
- $progetValue = $hotValue - $getValue;
|
|
|
-
|
|
|
- // 转换统计
|
|
|
- if($progetValue >0) {
|
|
|
- $UserChangeLogData["user_id"] = $oneBoxGiftInfo['user_to_id'];
|
|
|
- $UserChangeLogData["party_id"] = $party_id?$party_id:0;
|
|
|
- $UserChangeLogData["gift_value"] = $hotValue;
|
|
|
- $UserChangeLogData["plat_value"] = $hotValue - $getValue;
|
|
|
- $UserChangeLogData["createtime"] = time();
|
|
|
- $UserChangeLogList[]=$UserChangeLogData;
|
|
|
- }
|
|
|
-
|
|
|
- $platValue = bcmul($platRate/100,$getValue);
|
|
|
- $guilderValue = bcmul($guilderRate/100,$getValue);
|
|
|
- $getValue = bcsub(bcsub($getValue,$platValue),$guilderValue);
|
|
|
-
|
|
|
- $getValueForUser = bcadd($getValue,$getValueForUser);
|
|
|
- $platValueForUser = bcadd($platValue,$platValueForUser);
|
|
|
- $guilderValueForUser = bcadd($guilderValue,$guilderValueForUser);
|
|
|
-
|
|
|
- // 添加赠送用户声币流水记录soundCoin
|
|
|
- // xxx送你
|
|
|
- $res4[] = $this->boxAddUserSoundcoinLog($user_id, $getValue, "+", $userSound_coin, "{$this->auth->nickname}送你{$giftInfo['name']}x1,开出{$oneBoxGiftInfo->gift_name}x1", 1, $oneBoxGiftInfo->id);
|
|
|
- // 增加房主抽成
|
|
|
- if (isset($partyInfo) && $guilderValue > 0){
|
|
|
- $res6[] = $this->boxAddUserSoundcoinLog($partyInfo->user_id, $guilderValue, "+", $userSound_coin, "{$this->auth->nickname}送礼物{$giftInfo['name']}x1,开出{$oneBoxGiftInfo->gift_name}x1给{$toUserInfo['nickname']},房间礼物抽成", 4, $oneBoxGiftInfo->id);
|
|
|
- }
|
|
|
-
|
|
|
- $userSound_coin = bcadd($getValue,$userSound_coin);
|
|
|
- }
|
|
|
- $res4 = array_merge($res4,$res6);//同表合并插入
|
|
|
- $res4 = $usersoundcoinlogModel->insertAll($res4);
|
|
|
-
|
|
|
- //增加抽点记录
|
|
|
- $UserProfitLogList[] = $this->addUserProfitLogList($user_id,$party_id,$getValueForUser,$platValueForUser,$guilderValueForUser);
|
|
|
-
|
|
|
- // 转换统计
|
|
|
- if (!empty($UserChangeLogData)) \app\common\model\UserChangeLog::insertAll($UserChangeLogList);
|
|
|
-
|
|
|
- // 添加赠送用户声币余额
|
|
|
- $where = [];
|
|
|
- $where["id"] = $user_id;
|
|
|
- $res3 = $userModel->where($where)->setInc("sound_coin", $getValueForUser);
|
|
|
- $getValueForUser == 0 && $res3 = true;
|
|
|
-
|
|
|
- //总消费增加
|
|
|
- $res6 = Db::name('user')->where('id',$user_id)->setInc("renewcount", $giftCountValue);
|
|
|
-
|
|
|
- if ($res1 && $res2 && $res3 && $res4 && $res5 && $res6) {
|
|
|
- $i++;
|
|
|
- if($party_id > 0) {
|
|
|
- // 添加redis记录做财富排行榜日榜用
|
|
|
- $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_get_" . $party_id . ":" . $day . "d", $hotValueCount, $user_id);
|
|
|
- // 添加redis记录做财富排行榜周榜用
|
|
|
- $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_get_" . $party_id . ":" . $weekday . "w", $hotValueCount, $user_id);
|
|
|
- // 添加redis记录做财富排行榜月榜用
|
|
|
- $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_get_" . $party_id . ":" . $monthday . "m", $hotValueCount, $user_id);
|
|
|
- // 添加redis记录做贡献排行榜日榜用
|
|
|
- $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_to_" . $party_id . ":" . $day . "d", $hotValueCount, $userauthid);
|
|
|
- // 添加redis记录做贡献排行榜周榜用
|
|
|
- $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_to_" . $party_id . ":" . $weekday . "w", $hotValueCount, $userauthid);
|
|
|
- // 添加redis记录做贡献排行榜月榜用
|
|
|
- $redis->zIncrBy($this->roomTypeArr[$room_type] . "_jewel_to_" . $party_id . ":" . $monthday . "m", $hotValueCount, $userauthid);
|
|
|
-
|
|
|
- // tcp 更新用户魅力值
|
|
|
- $this->updateUserCharm($party_id, $user_id, $hotValueCount);
|
|
|
-
|
|
|
- // 如果是主播,则添加魅力值记录做榜单统计
|
|
|
- if($room_type == 2) {
|
|
|
- $data = [];
|
|
|
- $data["user_id"] = $user_id;
|
|
|
- $data["party_id"] = $party_id;
|
|
|
- $data["charm"] = $hotValueCount;
|
|
|
- $data["createtime"] = time();
|
|
|
- \app\common\model\UserCharmRank::insert($data);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- $getempirical = config("site.getempirical");
|
|
|
- $getempirical = $getempirical * $hotValueCount;
|
|
|
- // 获取用户贵族信息
|
|
|
- $noble = \app\common\model\User::getUserNoble($this->auth->id);
|
|
|
- if(isset($noble["noble_on"]) && $noble["noble_on"] == 1) {
|
|
|
- $getempirical = $getempirical + $getempirical * ($noble["explain"]/100);
|
|
|
- }
|
|
|
-
|
|
|
- // 增加用户经验值
|
|
|
- $res = \app\common\model\User::addEmpirical($this->auth->id,$getempirical);
|
|
|
- if ($res){
|
|
|
- $this->auth->level = $res->level;
|
|
|
- }
|
|
|
-
|
|
|
- //贵族升级处理
|
|
|
- $this->checkBeNoble($redis,$this->auth->id,$giftCountValue);
|
|
|
-
|
|
|
- // +exp
|
|
|
- \app\common\model\TaskLog::tofinish($this->auth->id,"OBHqCX4g",$number);
|
|
|
-
|
|
|
- // +message
|
|
|
- \app\common\model\Message::addMessage($user_id,"礼物通知","收到 ".$this->auth->nickname." 赠送的".$giftInfo["name"]." x".$number);
|
|
|
-
|
|
|
- $allVal = $allVal + $hotValueCount;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $this->checkAllUserBoxGiftInfo($allUserBoxGiftInfo);
|
|
|
-
|
|
|
- // 获取用户魅力值
|
|
|
- $users = $redis->zRange("hourCharm_".$party_id,0,-1,true);
|
|
|
- $u = [];
|
|
|
- if($users) {
|
|
|
- foreach($users as $k => $v) {
|
|
|
- if (empty($allUserBoxGiftInfo[$k])) continue;
|
|
|
- $u[] = [
|
|
|
- "user_id" => $k,
|
|
|
- "charm" => $this->changeW($v),
|
|
|
- 'gifList'=> $allUserBoxGiftInfo[$k] ?? [],
|
|
|
- ];
|
|
|
- }
|
|
|
- }
|
|
|
- $userCharm = $u;
|
|
|
- unset($u);
|
|
|
-
|
|
|
- // tcp 更新房间热度
|
|
|
- $partyHot = $this->updatePartyHot($party_id, $allVal, $room_type);
|
|
|
-
|
|
|
- // 如果是派对,则添加派对热度值记录做榜单统计
|
|
|
- if($room_type == 1) {
|
|
|
- $data = [];
|
|
|
- $data["party_id"] = $party_id;
|
|
|
- $data["hot"] = $allVal;
|
|
|
- $data["createtime"] = time();
|
|
|
- \app\common\model\PartyHot::insert($data);
|
|
|
- }
|
|
|
-
|
|
|
- // tcp 获取房间用户周前三名
|
|
|
- $partyUserTop = $this->getPartyUserTop($party_id, $room_type);
|
|
|
-
|
|
|
- if($i == $userCount) {
|
|
|
- $returnData["userCharm"] = $userCharm;
|
|
|
- $returnData["partyHot"] = $this->changeW($partyHot);
|
|
|
- $returnData["partyUserTop"] = $partyUserTop;
|
|
|
-
|
|
|
- $returnData["box_type"] = $giftInfo->box_type;
|
|
|
- $returnData["box_image"] = $giftInfo->image;
|
|
|
- $returnData["box_num"] = $number;
|
|
|
- if(!empty($UserProfitLogList)) \app\common\model\UserProfitLog::insertAll($UserProfitLogList);
|
|
|
|
|
|
- Db::commit();
|
|
|
- $this->success("赠送成功!",$returnData);
|
|
|
- } else {
|
|
|
- Db::rollback();
|
|
|
- $this->success("赠送失败!");
|
|
|
- }
|
|
|
- } catch (ValidateException $e) {
|
|
|
- Db::rollback();
|
|
|
- $this->error($e->getMessage());
|
|
|
- } catch (PDOException $e) {
|
|
|
- Db::rollback();
|
|
|
- $this->error($e->getMessage());
|
|
|
- } catch (Exception $e) {
|
|
|
- Db::rollback();
|
|
|
- $this->error($e->getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 消费开通贵族
|