createIfNotExist($DateID, $type); return DB::table('QPRecordDB.dbo.RecordPaidRewardDailyStatistics') ->where(['DateID' => $DateID, 'StatType' => $type]) ->increment('TotalAmount', $amount); } private function createIfNotExist($DateID, $type) { $exist = DB::table('QPRecordDB.dbo.RecordPaidRewardDailyStatistics') ->where(['DateID' => $DateID, 'StatType' => $type])->first(); if (!$exist) { try { DB::table('QPRecordDB.dbo.RecordPaidRewardDailyStatistics')->insert([ 'DateID' => $DateID, 'StatType' => $type, ]); } catch (QueryException $e) { if (stripos($e->getMessage(), 'duplicate key') === false) { throw $e; } } } return true; } }