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