| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace app\queue\redis\slow;
- use app\model\saas\SaasOrder;
- use app\model\saas\SaasOrderExpress;
- use app\model\system\SystemImport;
- use PhpOffice\PhpSpreadsheet\IOFactory;
- use Webman\RedisQueue\Consumer;
- class ImportOrder implements Consumer
- {
- /**
- * 订单导入发货
- * 更新云打印件
- * @var string
- */
- public string $queue = "import-order";
- /**
- * 连接配置
- * @var string
- */
- public string $connection = "default";
- public function consume($data): bool
- {
- try {
- if(empty($data['logId'])) return true;
- if(empty($data['poi_id'])) return true;
- $path = public_path().$data['path'];
- $spreadsheet = IOFactory::load($path);
- $worksheet = $spreadsheet->getActiveSheet();
- $sheetData = $worksheet->toArray(null, true, true, true);
- // 5. 现在 $sheetData 就是一个二维数组,你可以遍历它处理每一行数据
- $orderMode = (new SaasOrder);
- $excelData= [];
- $expressData = [];
- foreach ($sheetData as $rowIndex => $row) {
- if ($rowIndex > 0 && !empty($row['A'])) {
- $excelData[$rowIndex] = $row;
- }
- }
- print_r($excelData);
- if (!empty($excelData)) {
- foreach (array_values(array_filter($excelData)) as $key=>$val) {
- $order = $orderMode->where("order_sn",trim($val['A']))->findOrEmpty();
- if ($order->isEmpty()) {
- continue;
- }
- $order->express_status = 2;
- $order->save();
- $express = (new SaasOrderExpress)->where("express_sn",trim($val['C']))->findOrEmpty();
- if ($express->isEmpty()) {
- $expressData[$key] = [
- "order_sn" => trim($val['A']),
- "express_sn" => trim($val['C']),
- "mobile" => trim($val['B']),
- "last_at" => getDateFull()
- ];
- }
- }
- }
- if (!empty($expressData)) {
- (new SaasOrderExpress)->insertAll(array_values($expressData));
- }
- (new SystemImport)->where("id",$data['logId'])->update(['status' => 1,"last_at" => getDateFull()]);
- return true;
- } catch (\Throwable $throwable) {
- echo getDateFull()."==导入订单报错===\n";
- echo $throwable->getFile()."\n";
- echo $throwable->getLine()."\n";
- echo $throwable->getMessage()."\n";
- }
- return true;
- }
- }
|