Beispiel #1
0
 /**
  * Add quota for upline.
  *
  * @param model transaction
  * @return boolean
  */
 public function AddQuotaForUpline($transaction)
 {
     $upline = PointLog::userid($transaction->user_id)->referencetype('App\\Models\\User')->first();
     $quota = StoreSetting::type('downline_purchase_quota_bonus')->Ondate('now')->first();
     $whoisupline = 0;
     if ($upline && $upline->reference()->count()) {
         $whoisupline = $upline->reference->referral->value;
     }
     if ($upline && $quota && $whoisupline == 0 && $upline->reference()->count() && $upline->reference->referral()->count()) {
         $quotalog = new QuotaLog();
         $quotalog->fill(['voucher_id' => $upline->reference->referral->id, 'amount' => $quota->value, 'notes' => 'Bonus belanja ' . $transaction->user->name . ' nomor nota #' . $transaction->ref_number]);
         if (!$quotalog->save()) {
             $this->errors = $quotalog->getError();
             return false;
         }
     }
     return true;
 }
Beispiel #2
0
 /**
  * save referral code
  * 
  * @param model of user, referral_code
  * @return boolean
  */
 public function giveReferralCode($user, $referral)
 {
     //save voucher referral
     $newvoucher = new Referral();
     $newvoucher->fill(['user_id' => $user->id, 'code' => $referral, 'type' => 'referral', 'value' => 0, 'started_at' => null, 'expired_at' => null]);
     if (!$newvoucher->save()) {
         $this->errors = $newvoucher->getError();
         return false;
     } else {
         //save quota referral
         $quota = StoreSetting::type('first_quota')->Ondate('now')->first();
         if (!$quota) {
             $this->errors = 'Tidak dapat melakukan registrasi saat ini.';
             return false;
         } else {
             $newquota = new QuotaLog();
             $newquota->fill(['voucher_id' => $newvoucher['id'], 'amount' => $quota->value, 'notes' => 'Hadiah registrasi']);
             if (!$newquota->save()) {
                 $this->errors = $newquota->getError();
                 return false;
             }
         }
     }
     return true;
 }