' => 0], 'id asc', '*', null, true); if (!empty($list)) { foreach ($list as $item) { $orderSn = $item->orderSn ?? ''; $addTime = $item->addTime ?? ''; $connection = Yii::$app->db;//事务处理 $transaction = $connection->beginTransaction(); try { $totalNum = 0; $productList = StockWastageOrderItemClass::getAllByCondition(['orderSn' => $orderSn], null, '*', null, true); if (!empty($productList)) { foreach ($productList as $product) { $itemInfo = $product->itemInfo ?? ''; if (empty($itemInfo)) { $transaction->rollBack(); continue; } $arr = json_decode($itemInfo, true); if (is_array($arr) == false) { $transaction->rollBack(); continue; } $name = $arr['itemName'] ?? ''; $cover = $arr['itemCover'] ?? ''; $product->name = $name; $product->cover = $cover; $product->addTime = $addTime; $product->save(); $totalNum = bcadd($totalNum, $product->itemNum, 2); } } $item->num = $totalNum; $item->save(); $transaction->commit(); } catch (\Exception $e) { $transaction->rollBack(); $msg = $e->getMessage(); echo "报错了:" . $msg . "\n"; } } } } }