id ?? 0; $where = ['mainId' => $mainId, 'catId' => $catId, 'time' => $time]; $model = self::getByCondition($where, true); if (empty($model)) { $data = ['mainId' => $mainId, 'time' => $time, 'catId' => $catId, 'catName' => $catName]; $model = self::add($data, true); } $id = $model->id; $stat = self::getLockById($id); $stat->workNum = bcadd($workNum, $stat->workNum); $stat->num = bcadd($num, $stat->num); $stat->save(); StatWorkCatMonthClass::replace($main, $catId, $catName, $workNum, $num); } }