333152, 'xhUnitType' => 1], 'id DESC', '*', null, true); if (!empty($list)) { foreach ($list as $key => $item) { $cost = $item->cost ?? 0; $xhPrice = $item->xhPrice ?? 0; $ratio = $item->ratio ?? 21; $productId = $item->productId ?? 0; $name = $item->name ?? ''; $smallCost = bcdiv($cost, $ratio, 2); if ($ratio > 1) { if ($cost > 10 && $cost > $xhPrice) { // echo $productId . ' ' . $name . ' 成本:' . $cost . ' 价格:' . $xhPrice . ' 比例:' . $ratio . ' 小单位成本:' . $smallCost . "\n"; // $item->cost = $smallCost; // $item->save(); } if ($cost < 10 && $cost > $xhPrice) { echo $productId . ' ' . $name . ' 成本:' . $cost . ' 价格:' . $xhPrice . ' 比例:' . $ratio . "\n"; $item->cost = $xhPrice; $item->save(); } } } } } }