from(Clear::tableName()); //$query->where(['id'=>828832]); $query->orderBy('id desc'); foreach ($query->batch(500) as $clearList) { foreach ($clearList as $clear) { $status = $clear['status'] ?? 1; $clearId = $clear['id'] ?? 0; $clearPrice = $clear['actPrice'] ?? 0; $addTime = $clear['addTime'] ?? ''; $clearPrice = floatval($clearPrice); if ($status == 2) { $relateList = OrderCgClearClass::getAllByCondition(['clearId' => $clearId], null, '*'); $count = count($relateList); if ($count == 1) { foreach ($relateList as $relate) { $cgId = $relate['cgId'] ?? 0; $cgInfo = GhsClass::getById($cgId, true); $remainDebtPrice = $cgInfo->remainDebtPrice ?? 0; $remainDebtPrice = floatval($remainDebtPrice); if ($remainDebtPrice > 0 && $clearPrice == $remainDebtPrice) { echo "clearId {$clearId} cgId {$cgId} remainDebtPrice {$remainDebtPrice} {$addTime} 需要清除 \n"; } } } } } } } public function actionGhsGhs() { ini_set('memory_limit', '2045M'); set_time_limit(0); $query = new \yii\db\Query(); $query->from(Ghs::tableName()); $query->where(['ownPtStyle' => 2]); foreach ($query->batch(500) as $ghsList) { $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { foreach ($ghsList as $ghs) { $ghsId = $ghs['id'] ?? 0; $balance = PurchaseOrderClass::sum(['ghsId' => $ghsId, 'debt' => 1], 'actPrice'); $debtNum = PurchaseOrderClass::getCount(['ghsId' => $ghsId, 'debt' => 1]); GhsClass::updateById($ghsId, ['balance' => -$balance, 'debtNum' => $debtNum]); $customId = $ghs['customId'] ?? 0; CustomClass::updateById($customId, ['balance' => -$balance, 'debtNum' => $debtNum]); } $transaction->commit(); } catch (\Exception $e) { $transaction->rollBack(); $msg = $e->getMessage(); echo "报错了:" . $msg . "\n"; } } } }