id ?? 0; $stat = self::getByCondition(['mainId' => $mainId, 'time' => $time], true); if (empty($stat)) { $stat = self::add(['mainId' => $mainId, 'time' => $time, 'year' => $year, 'month' => $month, 'num' => 1], true); } $id = $stat->id; $unique = self::getLockById($id); $currentAmount = bcadd($unique->amount, $amount, 2); $unique->amount = $currentAmount; $unique->totalAmount = $main->totalWast; $unique->num += 1; $unique->save(); } }