db->createCommand($sql); $data = $command->queryAll(); if (empty($data)) { return false; } foreach ($data as $item) { $id = $item['id'] ?? 0; $ptItemId = $item['itemId'] ?? 0; $preCover = $item['cover'] ?? ''; $ptItem = PtItemClass::getById($ptItemId, true); $cover = $ptItem->cover ?? ''; if (!empty($cover)) { ProductClass::updateById($id, ['cover' => $cover]); echo "productId:" . $id . "原图:{$preCover}, 恢复图片:" . $cover . "\n"; } else { echo "productId:" . $id . " 恢复图片没有成功-----------------\n"; } } } // ./yii product/sk-price public function actionSkPrice() { ini_set('memory_limit', '2045M'); set_time_limit(0); $list = ProductClass::getAllByCondition([], null, '*', null, true); if (empty($list)) { return false; } foreach ($list as $key => $item) { $price = $item->price ?? 0; $skAddPrice = $item->skAddPrice ?? 0; $addPrice = $item->addPrice ?? 0; $diff = bcsub($skAddPrice, $addPrice, 2); $currentPrice = $price; if ($diff > 0) { $currentPrice = bcadd($price, $diff, 2); } $item->skPrice = $currentPrice; $item->save(); } } }