예제 #1
0
 private function setIncentive($userId, $dateSold)
 {
     $saleCount = $this->saleRepo->countByAgentAndDate($userId, $dateSold);
     $incentive = Incentive::where('date', $dateSold)->where('user_id', $userId)->first();
     if ($saleCount > 0) {
         $data = $this->getIncentiveData($saleCount);
         if ($incentive) {
             $incentive->sale_count = $saleCount;
             $incentive->multiplier = $data['multiplier'];
             $incentive->amount = $data['amount'];
             $incentive->save();
             return true;
         } else {
             $data = ['user_id' => $userId, 'date' => $dateSold, 'sale_count' => $saleCount, 'multiplier' => $data['multiplier'], 'amount' => $data['amount']];
             $incentive = Incentive::create($data);
             if ($incentive) {
                 return true;
             } else {
                 return false;
             }
         }
     } else {
         if ($incentive) {
             $incentive->delete();
             return true;
         }
     }
     return false;
 }