ImportOrder.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace app\queue\redis\slow;
  3. use app\model\saas\SaasOrder;
  4. use app\model\saas\SaasOrderExpress;
  5. use app\model\system\SystemImport;
  6. use PhpOffice\PhpSpreadsheet\IOFactory;
  7. use Webman\RedisQueue\Consumer;
  8. class ImportOrder implements Consumer
  9. {
  10. /**
  11. * 订单导入发货
  12. * 更新云打印件
  13. * @var string
  14. */
  15. public string $queue = "import-order";
  16. /**
  17. * 连接配置
  18. * @var string
  19. */
  20. public string $connection = "default";
  21. public function consume($data): bool
  22. {
  23. try {
  24. if(empty($data['logId'])) return true;
  25. if(empty($data['poi_id'])) return true;
  26. $path = public_path().$data['path'];
  27. $spreadsheet = IOFactory::load($path);
  28. $worksheet = $spreadsheet->getActiveSheet();
  29. $sheetData = $worksheet->toArray(null, true, true, true);
  30. // 5. 现在 $sheetData 就是一个二维数组,你可以遍历它处理每一行数据
  31. $orderMode = (new SaasOrder);
  32. $excelData= [];
  33. $expressData = [];
  34. foreach ($sheetData as $rowIndex => $row) {
  35. if ($rowIndex > 0 && !empty($row['A'])) {
  36. $excelData[$rowIndex] = $row;
  37. }
  38. }
  39. print_r($excelData);
  40. if (!empty($excelData)) {
  41. foreach (array_values(array_filter($excelData)) as $key=>$val) {
  42. $order = $orderMode->where("order_sn",trim($val['A']))->findOrEmpty();
  43. if ($order->isEmpty()) {
  44. continue;
  45. }
  46. $order->express_status = 2;
  47. $order->save();
  48. $express = (new SaasOrderExpress)->where("express_sn",trim($val['C']))->findOrEmpty();
  49. if ($express->isEmpty()) {
  50. $expressData[$key] = [
  51. "order_sn" => trim($val['A']),
  52. "express_sn" => trim($val['C']),
  53. "mobile" => trim($val['B']),
  54. "last_at" => getDateFull()
  55. ];
  56. }
  57. }
  58. }
  59. if (!empty($expressData)) {
  60. (new SaasOrderExpress)->insertAll(array_values($expressData));
  61. }
  62. (new SystemImport)->where("id",$data['logId'])->update(['status' => 1,"last_at" => getDateFull()]);
  63. return true;
  64. } catch (\Throwable $throwable) {
  65. echo getDateFull()."==导入订单报错===\n";
  66. echo $throwable->getFile()."\n";
  67. echo $throwable->getLine()."\n";
  68. echo $throwable->getMessage()."\n";
  69. }
  70. return true;
  71. }
  72. }