ContractServer.php 3.3 KB

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