ExpInquiry.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace app\command;
  3. // +----------------------------------------------------------------------
  4. // | [ WE CAN DO IT MORE SIMPLE ]
  5. // +----------------------------------------------------------------------
  6. // | Copyright (c) 2018-2020 rights reserved.
  7. // +----------------------------------------------------------------------
  8. // | Author: TABLE ME
  9. // +----------------------------------------------------------------------
  10. // | Date: 2020-12-15 16:39
  11. // +----------------------------------------------------------------------
  12. use app\model\api\OrderInfo;
  13. use think\console\Command;
  14. use think\console\Input;
  15. use think\console\Output;
  16. use think\facade\Db;
  17. class ExpInquiry extends Command
  18. {
  19. protected function configure()
  20. {
  21. // 指令配置
  22. $this->setName('ExpInquiry')
  23. ->setDescription('快递追踪系统');
  24. }
  25. protected function execute(Input $input, Output $output)
  26. {
  27. //3天内
  28. $time = strtotime('-3 day');
  29. //今天不查询
  30. $timeLast = strtotime(date('Y-m-d'));
  31. //8小时内查过不查
  32. $time2 = strtotime('-8 hour');
  33. $true = true;
  34. $orderInfo = new OrderInfo;
  35. $p = 1;
  36. while ($true) {
  37. $data = $orderInfo
  38. ->where('status', 2)
  39. ->where('exp_status', 0)
  40. ->where('send_time', '<', $timeLast)
  41. ->where('send_time', '>', $time)
  42. ->where('exp_g_time', '<=', $time2)
  43. ->where('warehouse_id','>',16)
  44. ->page($p, 100)
  45. ->select()
  46. ->toArray();
  47. foreach ($data as $v) {
  48. echo $v['exp_number'] . ' ' . $v['name'] . ' ' . $v['address'] . ' 发货时间:' . date('Y-m-d H:i:s', $v['time']) . PHP_EOL;
  49. $this->setActionData($v);
  50. }
  51. echo "-----------------------------------------页码[" . $p . "]-------------------------------------";
  52. if (empty($data)) {
  53. $true = false;
  54. }
  55. $p++;
  56. }
  57. echo "处理结束" . PHP_EOL;
  58. }
  59. /**
  60. * @param $data
  61. */
  62. private function setActionData($oData)
  63. {
  64. $exp = new \library\lib\expInfo;
  65. $ocode = Db::name("express")->where('id', $oData['exp_id'])->value('ocode');
  66. $data = $exp->showapiExpInfo(trim($oData['exp_number']), empty($ocode) ? 'auto' : $ocode);
  67. if (empty($data['showapi_res_body'])) {
  68. OrderInfo::where('id', $oData['id'])->save(['exp_g_time' => time()]);
  69. return;
  70. }
  71. $expData = empty($data['showapi_res_body']['data']) ? [] : $data['showapi_res_body']['data'];
  72. $signFor = 0;
  73. $signTime = 0;
  74. $inAr = ['揽收', '收件'];
  75. foreach ($expData as $v) {
  76. $bAr = array_filter($inAr, function ($item) use ($v) {
  77. if (strpos($v['context'], $item) !== false) {
  78. return true;
  79. }
  80. return false;
  81. });
  82. if (!empty($bAr)) {
  83. $signFor = 1;
  84. $signTime = strtotime($v['time']);
  85. break;
  86. }
  87. }
  88. //超过2次信息算【揽收】
  89. if (count($expData) > 2) {
  90. $signFor = 1;
  91. $signTime = time();
  92. }
  93. if ($signFor) {
  94. //存储数据
  95. OrderInfo::where('id', $oData['id'])
  96. ->save([
  97. 'exp_status' => $signFor,
  98. 'exp_time' => $signTime,
  99. 'exp_msg' => json_encode($expData),
  100. 'exp_g_time' => time()
  101. ]);
  102. } else {
  103. OrderInfo::where('id', $oData['id'])->save(['exp_g_time' => time()]);
  104. }
  105. echo '[' . $oData['id'] . ']已查询订单,' . ($signFor ? '已揽件' : '未揽件') . PHP_EOL;
  106. }
  107. }