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