PrintState.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. namespace app\queue\redis;
  3. use app\extra\tools\PrintService;
  4. use app\model\saas\SaasPrint;
  5. use Webman\RedisQueue\Consumer;
  6. class PrintState implements Consumer
  7. {
  8. public $queue = "print-state";
  9. public $connection = "default";
  10. public function consume($data): bool
  11. {
  12. echo getDateFull()."===批量查询打印件状态\n";
  13. $print = (new SaasPrint)->select();
  14. $sn = [];
  15. if ($print->isEmpty()) return true;
  16. foreach ($print as $key => $value) {
  17. $sn[$key] = $value['sn'];
  18. }
  19. $resp = (new PrintService)->config(['appid' => sConf('dy.ex_appid'),'secret' => sConf('dy.ex_secret')])->deviceState($sn);
  20. if (!$resp['status']) return true;
  21. if (empty($resp['data'])) return true;
  22. foreach ($resp['data'] as $key => $val) {
  23. echo getDateFull()."===更新序列号=={$val['sn']}=={$val['status']}=={$val['deviceStatus']}\n";
  24. $state = (new SaasPrint)->where("sn",$val['sn'])->update(["online" => $val['status'],"device_state" => $val['deviceStatus']]);
  25. echo "更新状态==={$state}\n";
  26. }
  27. return true;
  28. }
  29. }