setName('order_confirm') ->setDescription('系统自动确认收货'); } protected function execute(Input $input, Output $output) { $now = time(); $ableAuto = ConfigService::get('transaction', 'automatically_confirm_receipt'); $confirmTime = ConfigService::get('transaction', 'automatically_confirm_receipt_days') * 24 * 60 * 60; if ($ableAuto == YesNoEnum::NO) { return true; } $orders = Order::with([ 'after_sale_ing' ])->where([ 'order_status' => OrderEnum::STATUS_WAIT_RECEIVE, 'pay_status' => PayEnum::ISPAID ])->whereRaw("express_time+$confirmTime < $now")->select(); try { foreach ($orders as $order) { // 是否售后中 if (isset($order['after_sale_ing']['id'])) { continue; } //更新订单状态 Order::update([ 'order_status' => OrderEnum::STATUS_FINISH, 'confirm_take_time' => time(), 'after_sale_deadline' => OrderLogic::getAfterSaleDeadline(), //售后截止时间 ], ['id' => $order['id']]); //订单日志 (new OrderLog())->record([ 'type' => OrderLogEnum::TYPE_SYSTEM, 'channel' => OrderLogEnum::SYSTEM_CONFIRM_ORDER, 'order_id' => $order['id'] ]); } } catch (\Exception $e) { Log::write('订单自动确认失败,失败原因:' . $e->getMessage()); } } }