ContractServer.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace App\Servers;
  3. use App\Jobs\BusinessFileJob;
  4. use App\Jobs\MsgFileJob;
  5. use App\Models\BlockItems;
  6. use App\Models\Contract;
  7. use App\Models\ContractDistribution;
  8. use App\Models\ContractLog;
  9. use App\Models\ErrorRecord;
  10. use App\Models\Invest;
  11. use App\Models\Member;
  12. use App\Models\MemberBoth;
  13. use App\Servers\Icon\TronRPC;
  14. /**
  15. * Redis数据缓存类
  16. */
  17. class ContractServer
  18. {
  19. static private $server = '';
  20. private $distributionArr=[
  21. 1=>'直推奖',
  22. 2=>'均富池',
  23. 3=>'见点奖',
  24. 4=>'dao池',
  25. 5=>'技术奖',
  26. 6=>'托底池',
  27. 7=>'推荐奖',
  28. ];
  29. private function __construct()
  30. {
  31. }
  32. /**
  33. * 创建对象
  34. * @return ContractServer
  35. */
  36. static function creatServer()
  37. {
  38. if (empty(self::$server)) {
  39. self::$server = new ContractServer();
  40. }
  41. return self::$server;
  42. }
  43. /**
  44. * 报单信息检测
  45. * @param BlockItems $blockItem
  46. */
  47. function broadcastDetection(BlockItems $blockItem){
  48. //检测报单信息
  49. $contract=Contract::where('hash',$blockItem->{'hash'})->first();
  50. if($contract){
  51. if($contract->{'status'}!=1){
  52. ErrorRecord::create([
  53. 'm_id' => 0,
  54. 'msg' => '合约状态从异常',
  55. 'data' => json_encode($contract)
  56. ]);
  57. $this->addContractLog($contract,'合约状态异常,程序终止清分,记录扫快信息',$blockItem);
  58. }else{
  59. $ret = TronRPC::CreationTron()->getTransaction($contract->{'hash'});
  60. if (!empty($ret['ret'][0]['contractRet']) && $ret['ret'][0]['contractRet'] == 'SUCCESS') {
  61. //检测交易信息
  62. if($contract->{'type'}==1){
  63. //初始合约
  64. //生成双轨关系
  65. $member=Member::where('id',$contract->{'m_id'})->select(['id','recom_id'])->first();
  66. JobServer::creatServer()->creatBothJob($member->{'id'},$member->{'recom_id'});
  67. //报单拆分
  68. $this->oneSettle($contract);
  69. }else{
  70. //复投合约
  71. $this->twoSettle($contract);
  72. }
  73. } else {
  74. ErrorRecord::create([
  75. 'm_id' => $contract->{'m_id'},
  76. 'msg' => '交易失败',
  77. 'data' => json_encode($contract)
  78. ]);
  79. }
  80. }
  81. }else{
  82. ErrorRecord::create([
  83. 'm_id' => 0,
  84. 'msg' => '合约信息不存在,扫快信息:',
  85. 'data' => json_encode($blockItem)
  86. ]);
  87. }
  88. }
  89. /**
  90. * 合约日志记录
  91. * @param Contract $contract
  92. * @param $msg
  93. * @param array $data
  94. */
  95. function addContractLog(Contract $contract,$msg,$data=[]){
  96. ContractLog::create([
  97. 'contract_id'=> $contract->{'id'},
  98. 'm_id'=> $contract->{'m_id'},
  99. 'msg'=> $msg,
  100. 'contract_data'=> json_encode($contract),
  101. 'data'=> json_encode($data),
  102. ]);
  103. }
  104. }