PrintState.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace app\queue\redis\slow;
  3. use app\extra\tools\PrintExtend;
  4. use app\model\saas\SaasPrint;
  5. use Webman\RedisQueue\Consumer;
  6. class PrintState implements Consumer
  7. {
  8. /**
  9. * 消费队列名
  10. * 更新云打印件
  11. * @var string
  12. */
  13. public string $queue = "print-state";
  14. /**
  15. * 连接配置
  16. * @var string
  17. */
  18. public string $connection = "default";
  19. public function consume($data): bool
  20. {
  21. echo getDateFull()."===批量查询打印件状态\n";
  22. $print = (new SaasPrint)->select();
  23. $sn = [];
  24. if ($print->isEmpty()) return true;
  25. foreach ($print as $key => $value) {
  26. $sn[$key] = $value['sn'];
  27. }
  28. $resp = (new PrintExtend)->config(['appid' => sConf('wechat.ex_appid'),'secret' => sConf('wechat.ex_secret')])->deviceState($sn);
  29. if (!$resp['status']) return true;
  30. if (empty($resp['data'])) return true;
  31. foreach ($resp['data'] as $key => $val) {
  32. echo getDateFull()."===更新序列号=={$val['sn']}=={$val['status']}=={$val['deviceStatus']}\n";
  33. $state = (new SaasPrint)->where("sn",$val['sn'])->update(["online" => $val['status'],"device_state" => $val['deviceStatus']]);
  34. echo "更新状态==={$state}\n";
  35. }
  36. return true;
  37. }
  38. }