| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- namespace App\Servers;
- use App\Jobs\BusinessFileJob;
- use App\Jobs\MsgFileJob;
- use App\Models\BlockItems;
- use App\Models\Contract;
- use App\Models\ContractLog;
- use App\Models\ErrorRecord;
- use App\Models\Invest;
- use App\Models\Member;
- use App\Servers\Icon\TronRPC;
- /**
- * Redis数据缓存类
- */
- class ContractServer
- {
- static private $server = '';
- 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){
- //直推金额分化
- }
- }
- /**
- * 复投清分
- * @param Contract $contract
- */
- function twoSettle(Contract $contract){
- }
- /**
- * 合约日志记录
- * @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),
- ]);
- }
- }
|