/**
  * Do Interest Payout
  * @since 1.5.2
  * @version 1.0
  */
 public function do_interest_payout()
 {
     $work_marker = 'MYCRED_BANK_COMPPAY_' . $this->mycred_type;
     define($work_marker, time());
     $option_id = 'mycred_bank_interest_pay' . $this->mycred_type;
     $current_work = mycred_get_option($option_id, false);
     if ($current_work === false) {
         $this->update_run_count('payout');
         $this->save_last_run('payout');
         return;
     }
     $now = date_i18n('U');
     $work = $current_work;
     foreach ($current_work as $row => $user_id) {
         // Get past interest to add up to
         $accumulated_interest = mycred_get_user_meta($user_id, $this->mycred_type . '_comp', '', true);
         if ($accumulated_interest != '') {
             // Add a unique Payout ID
             $data = array('payout_id' => $now . $user_id);
             // Prevent duplicates
             if (!$this->core->has_entry('interest', 0, $user_id, $data, $this->mycred_type)) {
                 $this->core->add_creds('interest', $user_id, $accumulated_interest, $this->prefs['log'], 0, $data, $this->mycred_type);
             }
         }
         // Remove from workload
         unset($work[$row]);
         if (!empty($work)) {
             mycred_update_option($option_id, $work);
         } else {
             mycred_delete_option($option_id);
             $this->update_run_count('payout');
             $this->save_last_run('payout');
         }
     }
 }
 /**
  * Update users balance
  * Returns the updated balance of the given user.
  *
  * @param $user_id (int), required user id
  * @param $amount (int|float), amount to add/deduct from users balance. This value must be pre-formated.
  * @returns the new balance.
  * @since 0.1
  * @version 1.4.1
  */
 public function update_users_balance($user_id = NULL, $amount = NULL, $type = 'mycred_default')
 {
     // Minimum Requirements: User id and amount can not be null
     if ($user_id === NULL || $amount === NULL) {
         return $amount;
     }
     if (empty($type)) {
         $type = $this->get_cred_id();
     }
     // Enforce max
     if ($this->max() > $this->zero() && $amount > $this->max()) {
         $amount = $this->number($this->max());
         do_action('mycred_max_enforced', $user_id, $_amount, $this->max());
     }
     // Adjust creds
     $current_balance = $this->get_users_balance($user_id, $type);
     $new_balance = $current_balance + $amount;
     // Update creds
     mycred_update_user_meta($user_id, $type, '', $new_balance);
     // Update total creds
     $total = mycred_query_users_total($user_id, $type);
     mycred_update_user_meta($user_id, $type, '_total', $total);
     // Clear caches
     mycred_delete_option('mycred-cache-total-' . $type);
     // Let others play
     do_action('mycred_update_user_balance', $user_id, $current_balance, $amount, $type);
     // Return the new balance
     return $this->number($new_balance);
 }
 /**
  * Do Payout
  * @since 1.5.2
  * @version 1.0
  */
 public function do_masspayout()
 {
     $work_marker = 'MYCRED_BANK_RECPAY_' . $this->mycred_type;
     if (!defined($work_marker)) {
         define($work_marker, time());
     }
     $option_id = 'mycred_bank_recurring_pay' . $this->mycred_type;
     $current_work = mycred_get_option($option_id, false);
     if ($current_work === false) {
         $this->update_run_count('masspayout');
         $this->save_last_run('masspayout');
         $this->update_cycles();
         return;
     }
     $now = date_i18n('U');
     $work = $current_work;
     foreach ($current_work as $row => $user_id) {
         // Add a unique Payout ID
         $data = array('payout_id' => $now . $user_id);
         // Prevent duplicates
         if (!$this->core->has_entry('interest', 0, $user_id, $data, $this->mycred_type)) {
             $this->core->add_creds('recurring_payout', $user_id, $this->prefs['amount'], $this->prefs['log'], 0, $data, $this->mycred_type);
         }
         // Remove from workload
         unset($work[$row]);
         if (!empty($work)) {
             mycred_update_option($option_id, $work);
         } else {
             mycred_delete_option($option_id);
             $this->update_run_count('masspayout');
             $this->save_last_run('masspayout');
             $this->update_cycles();
         }
     }
 }