|
|
@@ -18,28 +18,27 @@ class CpController extends Controller
|
|
|
//创建分店时,复制产品,重要脚本,不能删除
|
|
|
public function actionCopyCp()
|
|
|
{
|
|
|
-// $copyKey = 'copy_old_cp_to_new_cp';
|
|
|
-// $copyList = [];
|
|
|
-// while ($count = Yii::$app->redis->executeCommand('LLEN', [$copyKey])) {
|
|
|
-// $current = Yii::$app->redis->executeCommand('RPOP', [$copyKey]);
|
|
|
-// $copyList[] = $current;
|
|
|
-// }
|
|
|
-// if (empty($copyList)) {
|
|
|
-// return false;
|
|
|
-// }
|
|
|
- $copyList = [json_encode(['oldMainId' => 854, 'newMainId' => 858])];
|
|
|
+ $copyKey = 'copy_old_cp_to_new_cp';
|
|
|
+ $copyList = [];
|
|
|
+ while ($count = Yii::$app->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;
|
|
|
-// }
|
|
|
+ if (empty($main)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $has = CpClassClass::getByCondition(['mainId' => $newMainId], true);
|
|
|
+ if (!empty($has)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
$connection = Yii::$app->db;
|
|
|
$transaction = $connection->beginTransaction();
|
|
|
try {
|