delStatus; //已经下架的商品 if ($delStatus == 1) { $product->status = 2; $product->delStatus = 0; $product->save(); echo $product->name . " {$product->id} 已经下架 status 变成 2 delStatus 变成 0\n"; } } } //更新封面 ./yii product/update-cover public function actionUpdateCover() { $list = ProductClass::getAllByCondition([], null, '*', null, true); if (empty($list)) { return false; } foreach ($list as $product) { $itemId = $product->itemId ?? 0; $ptItem = PtItemClass::getById($itemId, true); $ptCover = $ptItem->cover ?? ''; if (!empty($ptCover)) { $product->cover = $ptCover; $product->save(); echo "{$product->id} 已更新为{$ptCover} \n"; } } } //更新重量 ./yii product/update-weight public function actionUpdateWeight() { $list = ProductClass::getAllByCondition(['shopId' => 10], null, '*', null, true); if (empty($list)) { return false; } foreach ($list as $product) { $itemId = $product->itemId ?? 0; $ptItem = PtItemClass::getById($itemId, true); $weight = $product->weight ?? 0; if (!empty($weight)) { $preWeight = $ptItem->weight ?? 0; $ptItem->weight = $weight; $ptItem->save(); echo "平台花材{$ptItem->id} 重量由{$preWeight}更新为{$weight} \n"; } } } }