sjId; $mainId = $main->id ?? 0; $stat = self::getByCondition(['sjId' => $sjId, 'mainId' => $mainId, 'time' => $time], true); if (empty($stat)) { $stat = self::add(['mainId' => $mainId, 'sjId' => $sjId, 'time' => $time, 'year' => $year, 'month' => $month], true); } $id = $stat->id; $unique = self::getLockById($id); if (empty($unique)) { util::fail('没有记录'); } $currentAmount = bcadd($unique->amount, $amount, 2); $unique->amount = $currentAmount; $unique->totalAmount = $main->totalStockIn; $unique->save(); } }