sjId ?? 0; $shopId = $shop->id ?? 0; $mainId = $main->id ?? 0; if ($date == null) { $time = date('Ymd'); } else { $time = $date; } $stat = self::getByCondition(['mainId' => $mainId, 'time' => $time], true); if (empty($stat)) { $stat = self::add(['shopId' => $shopId, 'mainId' => $mainId, 'sjId' => $sjId, 'time' => $time, 'num' => 0], true); } $id = $stat->id; $unique = self::getLockById($id); $currentAmount = bcadd($unique->amount, $amount, 2); $unique->amount = $currentAmount; $unique->totalAmount = $main->totalPdSub; $unique->num += 1; $unique->save(); StatPdSubMonthClass::replace($main, $shop, $amount, $time); } }