from(Purchase::tableName()); $date = date("Y-m-d H:i:s"); $query->where(['status' => PurchaseClass::STATUS_UN_PAY])->andWhere(['<=', 'deadline', $date]); $query->orderBy('deadline ASC'); Yii::$app->params['ptStyle'] = dict::getDict('ptStyle', 'hd'); //如果有报错,抛出异常 Yii::$app->params['errorReport'] = 1; $arr = []; foreach ($query->batch() as $purchases) { foreach ($purchases as $purchase) { $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); $id = $purchase['id'] ?? 0; $orderSn = $purchase['orderSn'] ?? ''; try { $current = PurchaseClass::getById($id, true); $cgStyle = $current->cgStyle ?? dict::getDict('cgStyle', 'hd'); $orderSn = $current->orderSn ?? ''; if ($cgStyle == dict::getDict('cgStyle', 'hd')) { //花店采购的取消 PurchaseService::expire($current); $transaction->commit(); noticeUtil::push("【测试】采购单已经取消!订单号:{$orderSn}", '15280215347'); } elseif ($cgStyle == dict::getDict('cgStyle', 'ghs')) { //供应商发起的记欠款 PurchaseService::debt($current); $transaction->commit(); noticeUtil::push("【测试】采购单已经记欠款!订单号:{$orderSn}", '15280215347'); } else { noticeUtil::push("采购单类型没有找到 orderSn:" + $orderSn, '15280215347'); } } catch (\Exception $e) { $transaction->rollBack(); $msg = $e->getMessage(); noticeUtil::push("【测试】采购单过期处理报错了!订单号:{$orderSn},错误信息:{$msg}", '15280215347'); } $log = "过期的采购单:{$id} json:" . json_encode($purchase); $arr[] = $log; } } if (!empty($arr)) { foreach ($arr as $item) { Yii::info($item); } } } }