| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- <?php
- namespace App\Servers;
- use App\Jobs\BusinessFileJob;
- use App\Jobs\MsgFileJob;
- use App\Models\BlockItems;
- use App\Models\Contract;
- use App\Models\ContractDistribution;
- use App\Models\ContractLog;
- use App\Models\ErrorRecord;
- use App\Models\Invest;
- use App\Models\Member;
- use App\Models\MemberBoth;
- use App\Servers\Icon\TronRPC;
- /**
- * Redis数据缓存类
- */
- class ContractServer
- {
- static private $server = '';
- private $distributionArr=[
- 1=>'直推奖',
- 2=>'均富池',
- 3=>'见点奖',
- 4=>'dao池',
- 5=>'技术奖',
- 6=>'托底池',
- 7=>'推荐奖',
- ];
- private function __construct()
- {
- }
- /**
- * 创建对象
- * @return ContractServer
- */
- static function creatServer()
- {
- if (empty(self::$server)) {
- self::$server = new ContractServer();
- }
- return self::$server;
- }
- /**
- * 报单信息检测
- * @param BlockItems $blockItem
- */
- function broadcastDetection(BlockItems $blockItem){
- //检测报单信息
- $contract=Contract::where('hash',$blockItem->{'hash'})->first();
- if($contract){
- if($contract->{'status'}!=1){
- ErrorRecord::create([
- 'm_id' => 0,
- 'msg' => '合约状态从异常',
- 'data' => json_encode($contract)
- ]);
- $this->addContractLog($contract,'合约状态异常,程序终止清分,记录扫快信息',$blockItem);
- }else{
- $ret = TronRPC::CreationTron()->getTransaction($contract->{'hash'});
- if (!empty($ret['ret'][0]['contractRet']) && $ret['ret'][0]['contractRet'] == 'SUCCESS') {
- //检测交易信息
- if($contract->{'type'}==1){
- //初始合约
- //生成双轨关系
- $member=Member::where('id',$contract->{'m_id'})->select(['id','recom_id'])->first();
- JobServer::creatServer()->creatBothJob($member->{'id'},$member->{'recom_id'});
- //报单拆分
- $this->oneSettle($contract);
- }else{
- //复投合约
- $this->twoSettle($contract);
- }
- } else {
- ErrorRecord::create([
- 'm_id' => $contract->{'m_id'},
- 'msg' => '交易失败',
- 'data' => json_encode($contract)
- ]);
- }
- }
- }else{
- ErrorRecord::create([
- 'm_id' => 0,
- 'msg' => '合约信息不存在,扫快信息:',
- 'data' => json_encode($blockItem)
- ]);
- }
- }
- /**
- * 首单清分
- * @param Contract $contract
- */
- function oneSettle(Contract $contract){
- if($contract->{'direct_proportion'}>0){
- //直推金额分化
- $directId=Member::where('id',$contract->{'m_id'})->value('recom_id');
- if($directId){
- $this->addDistribution($contract,$directId,1,$contract->{'direct_proportion'},0);
- }else{
- $this->addContractLog($contract,'直推人信息异常,跳出首单直推奖');
- }
- }
- if($contract->{'grant_proportion'}>0){
- //均富池清分
- $distribution= $this->addDistribution($contract,0,2,$contract->{'grant_proportion'},1);
- if($distribution){
- GrantPondServer::creatServer()->grandPond($distribution);
- }
- }
- if($contract->{'point_proportion'}>0){
- //见点清分
- $distribution= $this->addDistribution($contract,0,3,$contract->{'point_proportion'},1);
- if($distribution){
- }
- }
- if($contract->{'dao_proportion'}>0){
- //dao池
- $distribution= $this->addDistribution($contract,0,4,$contract->{'dao_proportion'},1);
- if($distribution){
- }
- }
- if($contract->{'technology_proportion'}>0){
- //技术奖
- $distribution= $this->addDistribution($contract,0,5,$contract->{'technology_proportion'},0);
- if($distribution){
- }
- }
- if($contract->{'reveal_proportion'}>0){
- //托底池
- $distribution= $this->addDistribution($contract,0,6,$contract->{'reveal_proportion'},1);
- if($distribution){
- }
- }
- }
- /**
- * 复投清分
- * @param Contract $contract
- */
- function twoSettle(Contract $contract){
- if($contract->{'dao_proportion'}>0){
- //dao池
- $distribution= $this->addDistribution($contract,0,4,$contract->{'dao_proportion'},1);
- if($distribution){
- }
- }
- if($contract->{'reveal_proportion'}>0){
- //托底池
- $distribution= $this->addDistribution($contract,0,6,$contract->{'reveal_proportion'},1);
- if($distribution){
- }
- }
- if($contract->{'parent_proportion'}>0){
- //dao池
- $parentProportion=$contract->{'parent_proportion'};
- $myBothData=MemberBoth::where('m_id',$contract->{'m_id'})->first();
- $distribution= $this->addDistribution($contract,0,7,$contract->{'parent_proportion'},1);
- if($distribution){
- }
- }
- }
- /**
- * 添加清分信息
- * @param Contract $contract
- * @param $toMid
- * @param $type
- * @param $money
- * @param int $isTransition
- * @return ContractDistribution|\Illuminate\Database\Eloquent\Model
- */
- function addDistribution(Contract $contract,$toMid,$type,$money,$isTransition=1){
- $lkMoney=CommonServer::creatServer()->getConfigValue('lk_money');
- $lkNum=$lkMoney*$money;
- return ContractDistribution::create([
- 'contract_id'=>$contract->{'id'},
- 'm_id'=>$contract->{'m_id'},
- 'broadcast_id'=>0,
- 'is_transition'=>$isTransition,
- 'usdt_num'=>$money,
- 'lk_num'=>$lkNum,
- 'lk_money'=>$lkMoney,
- 'type'=>$type,
- 'to_m_id'=>$toMid,
- ]);
- }
- /**
- * 合约日志记录
- * @param Contract $contract
- * @param $msg
- * @param array $data
- */
- function addContractLog(Contract $contract,$msg,$data=[]){
- ContractLog::create([
- 'contract_id'=> $contract->{'id'},
- 'm_id'=> $contract->{'m_id'},
- 'msg'=> $msg,
- 'contract_data'=> json_encode($contract),
- 'data'=> json_encode($data),
- ]);
- }
- }
|