redis->executeCommand('LLEN', [$copyKey])) { $current = Yii::$app->redis->executeCommand('RPOP', [$copyKey]); $copyList[] = $current; } if (empty($copyList)) { return false; } foreach ($copyList as $copy) { $arr = json_decode($copy, true); $oldMainId = $arr['oldMainId'] ?? 0; $newMainId = $arr['newMainId'] ?? 0; $main = MainClass::getById($newMainId, true); if (empty($main)) { continue; } $has = CpClassClass::getByCondition(['mainId' => $newMainId], true); if (!empty($has)) { continue; } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { CpClass::copyCp($oldMainId, $newMainId); $transaction->commit(); noticeUtil::push("success 旧mainId:{$oldMainId}复制产品到新mainId:{$newMainId} 成功", '15280215347'); } catch (\Exception $e) { $transaction->rollBack(); $msg = $e->getMessage(); noticeUtil::push("error 旧mainId:{$oldMainId}复制产品到新mainId:{$newMainId} 报错:{$msg}", '15280215347'); } } } //商家的产品初始化 ssh 20240215 public function actionInitMainCp() { ini_set('memory_limit', '2045M'); set_time_limit(0); $shopList = ShopClass::getAllByCondition(['ptStyle' => 2], null, '*', null, true); //$shopList = ShopClass::getAllByCondition(['id' => 36523], null, '*', null, true); if (empty($shopList)) { util::stop('没有找到门店84'); } foreach ($shopList as $shop) { $mainId = $shop->mainId; $hasClass = CpClass::getByCondition(['mainId' => $mainId], true); if (!empty($hasClass)) { continue; } $main = MainClass::getById($mainId, true); if (empty($main)) { noticeUtil::push("mainId:{$mainId} 初始化产品没有找到main信息", '15280215347'); continue; } $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { PtCpService::initMainCp($main); $transaction->commit(); echo "mainId:{$mainId} 初始化产品 success \n"; } catch (\Exception $e) { $transaction->rollBack(); $msg = $e->getMessage(); noticeUtil::push("mainId:{$mainId} 初始化产品报错:{$msg}", '15280215347'); } } } }