public function change_balanceAction()
 {
     $this->_setReadNode(0);
     // Убеждаемся, что читать будем из мастера
     Zend_Registry::get('logger')->log("Start change balance " . __CLASS__ . '::' . __FUNCTION__ . ', line ' . __LINE__, Zend_Log::INFO);
     $this->find_doubleAction(false);
     $pp = new project_partner();
     $this->_partners = $pp->select($count);
     $not_notify_ids = explode(',', Zend_Registry::get('config')->balance->p_ids);
     $is_partner_switch_off = false;
     foreach ($this->_partners as $partner) {
         $flow = $partner->get_current_flow();
         if ($flow > 0) {
             $partner->change_balance(array('reason' => 'Billing by schedule: ' . $partner->get('name'), 'sum' => -$flow));
         }
         // Вот тут списываем за заказ звонка
         if ($partner->get('status') == '1' && $partner->get('zero_deactivate') == 1 && $partner->get('payment_type') == 'cpc') {
             $payment_link = '';
             $user = new user($partner->get('user_id'));
             if ($partner->get('contract_type') == 'fl') {
                 $url_1000 = $this->_generateBillingUrl($user, 'Пополнение баланса магазина ' . $user->get('name'), 1000);
                 $url_500 = $this->_generateBillingUrl($user, 'Пополнение баланса магазина ' . $user->get('name'), 500);
                 $url_3000 = $this->_generateBillingUrl($user, 'Пополнение баланса магазина ' . $user->get('name'), 3000);
                 $url_5000 = $this->_generateBillingUrl($user, 'Пополнение баланса магазина ' . $user->get('name'), 5000);
                 $payment_link = "<br><br>Быстрое пополнение баланса на <a href=\"{$url_500}\">500</a>, <a href=\"{$url_1000}\">1000</a>, <a href=\"{$url_3000}\">3000</a> или <a href=\"{$url_5000}\">5000</a> рублей";
             }
             if ($partner->get_balance() < 0) {
                 $partner->switch_off();
                 $et = new email_template('partner_switch_off');
                 $et->assign('PARTNER_NAME', $user->get('name'))->assign('PAYMENT_LINK', $payment_link)->send(Zend_Registry::get('config')->balance->email);
                 if (Zend_Registry::get('config')->balance->notify_partners) {
                     $et->send($user->get('email'))->send('*****@*****.**');
                 }
                 // Очищаем кеш
                 $is_partner_switch_off = true;
             } elseif ($partner->get_balance() < $partner->get('balance_notif') && !$partner->get('last_chinese_warning')) {
                 $et = new email_template('balance_limit');
                 $balance_bill = '';
                 if ($partner->get('contract_type') == 'dogovor' && $partner->get('is_balance_notif_bill')) {
                     $mpdf = new mPDF();
                     $mpdf->WriteHTML(file_get_contents("http://{$_SERVER['SERVER_NAME']}/report/bill/?partner_id=" . $partner->get('id') . "&sum=" . $partner->get('balance_notif_bill') . "&clear_template"));
                     $bill = new bill();
                     $bill = $bill->latest_bill($partner->get('id'));
                     $pdf = $mpdf->Output('', 'S');
                     $et->attachFile('Schet_N' . $bill->get('id') . '_ideipodarkov.pdf', $pdf);
                     $balance_bill = '<br><br>К письму прикреплен счет на ' . $bill->get('sum') . ' руб.';
                 }
                 $et->assign('PARTNER_NAME', $user->get('name'))->assign('PAYMENT_LINK', $payment_link)->assign('LIMIT', $partner->get('balance_notif'))->assign('BILL_SEND', $balance_bill);
                 if (!empty($balance_bill)) {
                     $et->send(Zend_Registry::get('config')->balance->email);
                 }
                 if (Zend_Registry::get('config')->balance->notify_partners) {
                     $partner->update(array('last_chinese_warning' => '1'));
                     $et->send($user->get('email'))->send('*****@*****.**');
                 }
             }
         }
         sleep(30);
     }
     if ($is_partner_switch_off) {
         $gift = new gift();
         $gift->cache_commit('gifts2partners');
         sleep(15);
         $this->compile_idea_dayAction(false);
     }
     Zend_Registry::get('logger')->log("Stop change balance " . __CLASS__ . '::' . __FUNCTION__ . ', line ' . __LINE__, Zend_Log::INFO);
     die('ok');
 }