where('task_status',0)->limit(20)->lock(true)->select(); if(empty($tasklist)){ Db::rollback(); echo 'empty'; exit; } try { $money_to_jewel = config('site.money_to_jewel') ?: 10; //余额兑换金币 // $getempirical_conf = config("site.getempirical"); foreach($tasklist as $key => $giftuserparty){ echo $giftuserparty['id'].'
'; $giftValue = $giftuserparty['value']; $hotValue = $giftValue; //用户信息 $authuser_info = Db::name('user')->field('nickname')->where('id',$giftuserparty['user_id'])->find(); $touserInfo = Db::name('user')->field('nickname')->where('id',$giftuserparty['user_to_id'])->find(); $party_id = $giftuserparty['party_id']; //添加获赠用户余额 $user_id = $giftuserparty['user_to_id']; if($giftuserparty['getvalue'] > 0){ $getMoney = bcdiv($giftuserparty['getvalue'],$money_to_jewel,2); if($getMoney > 0){ $rs_wallet = model('wallet')->lockChangeAccountRemain($user_id,$getMoney,'+',0,"{$authuser_info['nickname']}送你{$giftuserparty['gift_name']}x{$giftuserparty['number']}",101,'money'); if($rs_wallet['status'] == false){ Db::rollback(); $this->error($rs_wallet['msg']); } } } $partyInfo = \app\common\model\Party::field("id,room_type,party_name,party_hot,user_id,platRate,guilderRate")->where(["id"=>$giftuserparty['party_id']])->find(); //增加房主抽成 if ($partyInfo && $giftuserparty['guildervalue'] > 0) { $guilderMoney = bcdiv($giftuserparty['guildervalue'],$money_to_jewel,2); if($guilderMoney > 0){ $rs_wallet = model('wallet')->lockChangeAccountRemain($partyInfo->user_id,$guilderMoney,'+',0,"{$authuser_info['nickname']}送礼物{$giftuserparty['gift_name']}x{$giftuserparty['number']}给{$touserInfo['nickname']},房间礼物抽成",102,'money'); if($rs_wallet['status'] == false){ Db::rollback(); $this->error($rs_wallet['msg']); } } } // 如果是主播,则添加魅力值记录做榜单统计,这个表和送礼物日志表重复了,无意义 /*if($partyInfo) { $data = []; $data["user_id"] = $giftuserparty['user_to_id']; $data["party_id"] = $party_id; $data["charm"] = $hotValue; $data["createtime"] = time(); \app\common\model\UserCharmRank::insert($data); }*/ //用户经验升级 //$getempirical = $getempirical_conf * $hotValue; // 获取用户贵族信息 /*$noble = \app\common\model\User::getUserNoble($giftuserparty['user_id']); if(isset($noble["noble_on"]) && $noble["noble_on"] == 1) { $getempirical = $getempirical + $getempirical * ($noble["explain"]/100); }*/ // 增加用户经验值 //$res = \app\common\model\User::addEmpirical($giftuserparty['user_id'],$getempirical); /*if ($res){ $this->auth->level = $res->level; }*/ //增加被送礼物用户的魅力等级 $res_charm = \app\common\model\User::add_charm_level($giftuserparty['user_to_id'],$giftValue); // +exp // \app\common\model\TaskLog::tofinish($giftuserparty['user_id'],"OBHqCX4g",$giftuserparty['number']); // +message \app\common\model\Message::addMessage($giftuserparty['user_to_id'],"礼物通知","收到 ".$authuser_info['nickname']." 赠送的".$giftuserparty['gift_name']." x".$giftuserparty['number']." 价值 ".$giftValue ." 金币"); //增加送礼用户的财富等级 $res_wealth = \app\common\model\User::add_wealth_level($giftuserparty['user_id'],$giftValue); $rs_up = Db::name('gift_user_party')->where('id',$giftuserparty['id'])->update(['task_status'=>1]); if($rs_up === false){ Db::rollback(); echo '更新错误'.$giftuserparty['id']; exit; } } Db::commit(); } 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()); } } /////////////////////////////////////////下面都是工具方法//////////////////////////////////////////////// }