2], null, '*', null, true); if (!empty($list)) { foreach ($list as $clear) { $payTime = $clear->payTime ?? ''; $saleIds = $clear->saleIds ?? ''; $ids = explode(',', trim($saleIds)); print_r($ids); if (!empty($ids)) { OrderClass::updateByIds($ids, ['clearTime' => $payTime]); } $purchaseIds = $clear->purchaseIds ?? ''; $purchaseIds = explode(',', $purchaseIds); print_r($purchaseIds); if (!empty($purchaseIds)) { PurchaseClass::updateByIds($purchaseIds, ['clearTime' => $payTime]); } echo "-----------------\n"; } } } /** * 历史 xhClear 回填 xhOrderCgClear * * 用法: * php yii clear/backfill-order-cg-clear * php yii clear/backfill-order-cg-clear --dryRun=1 * php yii clear/backfill-order-cg-clear --clearId=123 */ public function actionBackfillOrderCgClear() { ini_set('memory_limit', '2045M'); set_time_limit(0); if ($this->batchSize < 1) { $this->stderr("batchSize 必须大于 0\n"); return ExitCode::UNSPECIFIED_ERROR; } $hd2Gys = dict::getDict('clearStyle', 'hd2Gys'); $gys2Hd = dict::getDict('clearStyle', 'gys2Hd'); $where = [ 'clearStyle' => ['in', [intval($hd2Gys), intval($gys2Hd)]], ]; if ($this->clearId > 0) { $where['id'] = intval($this->clearId); } $lastId = 0; $total = 0; $inserted = 0; $skipped = 0; $this->stdout(sprintf( "开始回填 xhOrderCgClear,dryRun=%d,batchSize=%d,clearId=%d\n", (int)$this->dryRun, $this->batchSize, (int)$this->clearId )); while (true) { $batchWhere = $where; if ($lastId > 0) { $batchWhere['id>'] = $lastId; } $list = PurchaseClearClass::getLimitList('*', $batchWhere, $this->batchSize, 'id asc'); if (empty($list)) { break; } foreach ($list as $clear) { $total++; $lastId = intval($clear['id'] ?? 0); $saleIds = trim($clear['saleIds'] ?? ''); $purchaseIds = trim($clear['purchaseIds'] ?? ''); if ($saleIds === '' && $purchaseIds === '') { $skipped++; continue; } if ($this->dryRun) { $this->stdout("dryRun clearId={$lastId} saleIds={$saleIds} purchaseIds={$purchaseIds}\n"); continue; } $count = OrderCgClearClass::backfillFromClear($clear); if ($count > 0) { $inserted += $count; $this->stdout("clearId={$lastId} 写入 {$count} 行\n"); } else { $skipped++; } } if (count($list) < $this->batchSize) { break; } } $this->stdout("完成:扫描 {$total} 条,写入 {$inserted} 行关系,跳过 {$skipped} 条\n"); return ExitCode::OK; } }