"im20210118173813522", // 1 => "云南运营主体", // 2 => "熊振宇", // 3 => "13708872753", // 4 => "文菊焱", // 5 => "", // 6 => "云南省昆明市昆明市盘龙区联盟街道金康园社区卫生服务站", // 7 => "妇保科", // 8 => "否", // 9 => "进行中", // 10 => "", // 11 => "否", // 12 => "1.99", // 13 => "0.00", // 14 => "1.99", // 15 => "1.99", // 16 => "微信支付", // 17 => "单次图文咨询", // 18 => "已付款", // 19 => "2021-01-18 17:38:13", // ]; //检查是否有该订单 $isHave = $this->getValue(new Order(), ['order_sn' => $row[0]], 'id'); if ($isHave) return null; $user_id = $this->getValue(new User(), ['phone' => $row[3]], 'id'); if (empty($user_id)) { echo $row[3] . '用户缺失' . PHP_EOL; return null; } //患者信息 $patientInfo = Patient::where(['name' => $row[4]])->first(); if (empty($patientInfo)) { echo $row[4] . '患者缺失' . PHP_EOL; continue; } $org_id = $this->getValue(new Organization(), ['name' => $row[6]], 'id'); if (empty($org_id)) { echo $row[6] . '机构缺失' . PHP_EOL; continue; } //如果没有用户不导入该订单 if (empty($user_id)) { Log::info('订单没有用户信息,订单编号: ' . $row[0] . PHP_EOL); continue; } // 1 => "未支付" // 2 => "待支付" // 3 => "进行中" // 4 => "已完成" // 5 => "已取消" // 6 => "已超时" // 7 => "已预约" //订单状态 $status = Order::getStatus(); //订单状态 $paystatus = Order::getPayStatus(); $pay_status = array_search($row[18], $paystatus); $order_status = array_search($row[9], $status); $docter_id = $this->getValue(new Docter(), ['name' => $row[4]], 'id'); $org_id = $this->getValue(new Organization(), ['name' => $row[6]], 'id'); $evaluate = $row[10] == '已评价' ? 1 : 0; $pay_types = [1 => '微信支付', 2 => '余额支付', 3 => '服务包支付']; //支付方式 $payType = array_search($row[16], $pay_types) + 1; if ($payType == 1) $payType = 2; $orderInfo = [ 'order_sn' => $row[0], 'patient_id' => $patientInfo->id, 'user_id' => $user_id, 'docter_id' => $docter_id, 'order_status' => $order_status, 'organization_id' => $org_id, 'is_evaluate' => $evaluate, 'is_discount' => $row[11], 'total_amount' => $row[12] * 100, 'discount_amount' => $row[13] * 100, 'payment_amount' => $row[15] * 100, 'payment_type' => $payType, 'payment_status' => $pay_status, 'product_type' => 2, 'created_at' => $row[19], ]; $order = Order::create($orderInfo); $orderId = $order['id']; $orderPatient = [ 'patient_id' => $patientInfo->id, 'name' => $row[0], 'order_id' => $orderId, 'patient_id' => $patientInfo->id, 'address' => $patientInfo->address, 'sex' => $patientInfo->sex, 'organization_id' => $org_id, ]; OrderPatient::insert($orderPatient); } return null; } public function startRow(): int { return 2; } public function batchSize(): int { return 1000; } public function chunkSize(): int { return 1000; } public function getValue($model,$where,$field) { return $model->where($where)->value($field); } }