LwtController.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace console\controllers;
  3. use common\models\LwtCompanyUserRegister;
  4. use common\models\LwtPhoneMessageList;
  5. use common\util\LwtApiDataSave;
  6. use common\util\PhoneMessage;
  7. use yii\console\Controller;
  8. class LwtController extends Controller
  9. {
  10. public function actionAutoRunRegisterData()
  11. {
  12. set_time_limit(0);
  13. $nextDayTime = strtotime(date('Y-m-d', strtotime(' +1 day')));
  14. $range = $nextDayTime - time();
  15. if ($range <= 300) {
  16. echo "每日最后5分钟不跑数据";
  17. return;
  18. }
  19. $continue = true;
  20. /** @var LwtCompanyUserRegister $LwtCompanyUserRegister */
  21. $LwtCompanyUserRegister = LwtCompanyUserRegister::findOne(["state" => 1]);
  22. if ($LwtCompanyUserRegister) {
  23. if (time() - $LwtCompanyUserRegister->refresh_time >= 1200) {
  24. if ($LwtCompanyUserRegister->is_send == 0) {
  25. //查询超过了20分钟,发短信告知
  26. PhoneMessage::saveMsg($LwtCompanyUserRegister->company_name,"查询超过20分钟");
  27. //
  28. $LwtCompanyUserRegister->is_send = 1;
  29. $LwtCompanyUserRegister->msg = "查询超过20分钟";
  30. $LwtCompanyUserRegister->save();
  31. }
  32. } else {
  33. $continue = false;
  34. }
  35. }
  36. if ($continue) {
  37. $exist = false;
  38. $LwtCompanyUserRegister = LwtCompanyUserRegister::findOne(["state" => 0]);
  39. if ($LwtCompanyUserRegister) {
  40. $LwtCompanyUserRegister->state = 1;
  41. $LwtCompanyUserRegister->refresh_time = time();
  42. $LwtCompanyUserRegister->save();
  43. $exist = true;
  44. } else {
  45. $time = time() - 3600 * 4;
  46. $LwtCompanyUserRegister = LwtCompanyUserRegister::find()->where(["<", "refresh_time", $time])->andWhere(["state" => 4])->one();
  47. if ($LwtCompanyUserRegister) {
  48. $exist = true;
  49. } else {
  50. $time = time() - 86400;
  51. $LwtCompanyUserRegister = LwtCompanyUserRegister::find()->where(["<", "update_time", $time])->andWhere(["state" => 2])->one();
  52. if ($LwtCompanyUserRegister) {
  53. $exist = true;
  54. }
  55. }
  56. }
  57. if ($exist) {
  58. $LwtCompanyUserRegister->state = 1;
  59. $LwtCompanyUserRegister->refresh_time = time();
  60. $LwtCompanyUserRegister->is_send = 0;
  61. $LwtCompanyUserRegister->msg = "";
  62. $LwtCompanyUserRegister->save();
  63. try {
  64. LwtApiDataSave::getAllData($LwtCompanyUserRegister->credit_code, $LwtCompanyUserRegister->company_name);
  65. if($LwtCompanyUserRegister->is_first == 0){
  66. //第一次查询成功,发送短信告知
  67. PhoneMessage::saveMsg($LwtCompanyUserRegister->company_name,"数据获取成功");
  68. //更改状态
  69. $LwtCompanyUserRegister->is_first = 1;
  70. }
  71. $LwtCompanyUserRegister->state = 2;
  72. $LwtCompanyUserRegister->update_time = time();
  73. $LwtCompanyUserRegister->save();
  74. } catch (\Exception $e) {
  75. if ($e->getMessage() == "Initializing") {
  76. $LwtCompanyUserRegister->state = 4;
  77. } else {
  78. $LwtCompanyUserRegister->state = 3;
  79. //查询超过了20分钟,发短信告知
  80. PhoneMessage::saveMsg($LwtCompanyUserRegister->company_name,"数据获取失败");
  81. //
  82. $LwtCompanyUserRegister->is_send = 1;
  83. }
  84. $LwtCompanyUserRegister->update_time = time();
  85. $LwtCompanyUserRegister->msg = $e->getMessage();
  86. $LwtCompanyUserRegister->save();
  87. }
  88. }
  89. }
  90. }
  91. public function actionGetData()
  92. {
  93. $msg = [
  94. "creditCode" => "91310000329555773R",
  95. "companyName" => "上海蔚来汽车有限公司",
  96. ];
  97. LwtApiDataSave::getAllData($msg["creditCode"], $msg["companyName"]);
  98. }
  99. protected function LwtApiDataSave()
  100. {
  101. $msg = [
  102. "creditCode" => "91310000329555773R",
  103. "companyName" => "上海蔚来汽车有限公司",
  104. ];
  105. return LwtApiDataSave::AddScanSaveReturnDataAndSave($msg["creditCode"], $msg["companyName"]);
  106. }
  107. protected function GetTopDomainReturnDataAndSave()
  108. {
  109. $msg = [
  110. "scanId" => "15855142931144704",
  111. "assetName" => "",
  112. ];
  113. return LwtApiDataSave::GetTopDomainReturnDataAndSave($msg["scanId"], $msg["assetName"]);
  114. }
  115. protected function GetSecondDomainReturnDataAndSave()
  116. {
  117. $msg = [
  118. "scanId" => "15855142931144704",
  119. "topName" => "niostg.com",
  120. "assetName" => "",
  121. ];
  122. return LwtApiDataSave::GetSecondDomainReturnDataAndSave($msg["scanId"], $msg["topName"], $msg["assetName"]);
  123. }
  124. protected function GetAssetIpReturnDataAndSave()
  125. {
  126. $msg = [
  127. "scanId" => "15855142931144704",
  128. "assetName" => "",
  129. "position" => "",
  130. ];
  131. return LwtApiDataSave::GetAssetIpReturnDataAndSave($msg["scanId"], $msg["assetName"], $msg["position"]);
  132. }
  133. }