ContractServer.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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\BanRPC;
  14. use App\Servers\Icon\TronRPC;
  15. /**
  16. * Redis数据缓存类
  17. */
  18. class ContractServer
  19. {
  20. static private $server = '';
  21. private $distributionArr=[
  22. 1=>'直推奖',
  23. 2=>'均富池',
  24. 3=>'见点奖',
  25. 4=>'dao池',
  26. 5=>'技术奖',
  27. 6=>'托底池',
  28. 7=>'推荐奖',
  29. ];
  30. private function __construct()
  31. {
  32. }
  33. /**
  34. * 创建对象
  35. * @return ContractServer
  36. */
  37. static function creatServer()
  38. {
  39. if (empty(self::$server)) {
  40. self::$server = new ContractServer();
  41. }
  42. return self::$server;
  43. }
  44. /**
  45. * 报单信息检测
  46. */
  47. function broadcastDetection(){
  48. //检测报单信息
  49. $contractList=Contract::where('status',1)->select(['id','hash','m_id'])->limit(50)->get();
  50. foreach ($contractList as $contract){
  51. $broadcastData=BanRPC::creatServer()->getTransactionReceipt($contract->{'hash'});
  52. if (empty($broadcastData)) {
  53. //交易正在广播中,下次继续查询
  54. continue;
  55. } else {
  56. //交易已完成 返回数据格式数据 ,将数据json保存
  57. $updateInfo['broadcast_data'] = json_encode($broadcastData);
  58. if ($broadcastData['status'] == '0x1') {
  59. $updateInfo['status'] = 2;
  60. } else {
  61. $updateInfo['status'] = 3;
  62. }
  63. dd($updateInfo);
  64. }
  65. }
  66. }
  67. /**
  68. * 合约日志记录
  69. * @param Contract $contract
  70. * @param $msg
  71. * @param array $data
  72. */
  73. function addContractLog(Contract $contract,$msg,$data=[]){
  74. ContractLog::create([
  75. 'contract_id'=> $contract->{'id'},
  76. 'm_id'=> $contract->{'m_id'},
  77. 'msg'=> $msg,
  78. 'contract_data'=> json_encode($contract),
  79. 'data'=> json_encode($data),
  80. ]);
  81. }
  82. }