コード例 #1
0
 public function validateData()
 {
     //Verify the keyfob, device key and action
     //Validate the action
     if (!in_array($this->action, $this->deviceActions)) {
         throw new ValidationException('Invalid Device Action');
     }
     //Validate the device
     try {
         $this->device = $this->equipmentRepository->findBySlug($this->deviceKey);
     } catch (ModelNotFoundException $e) {
         throw new ValidationException('Invalid Device Key');
     }
     //Confirm the device is working
     if (!$this->device->working) {
         throw new ValidationException('Device Not Working');
     }
     //Validate the key fob
     $this->keyFob = $this->lookupKeyFob($this->keyFobId);
     //Make sure the user is active
     $this->user = $this->keyFob->user()->first();
     if (!$this->user || !$this->user->active) {
         throw new ValidationException('User Invalid');
     }
     //Make sure the user is allowed to use the device
     if ($this->device->requires_induction) {
         //Verify the user has training
         if (!$this->inductionRepository->isUserTrained($this->user->id, $this->deviceKey)) {
             throw new ValidationException('User Not Trained');
         }
     }
     //Make sure the member has enough money on their account
     $minimumBalance = $this->bbCredit->acceptableNegativeBalance('equipment-fee');
     if ($this->user->cash_balance + $minimumBalance * 100 <= 0) {
         throw new ValidationException('User doesn\'t have enough credit');
     }
 }