/** | /** | ||||
* Affiche le tableau de bord du backend avec les dernières commandes | * Affiche le tableau de bord du backend avec les dernières commandes | ||||
* réalisée, les dernières inscriptions, la liste des clients ayant un crédit | |||||
* réalisées, les dernières inscriptions, la liste des clients ayant un crédit | |||||
* négatif etc. | * négatif etc. | ||||
* | * | ||||
* @return mixed | * @return mixed | ||||
$queryDistributions->andWhere(['>=', 'distribution.date', date('Y-m-d')]); | $queryDistributions->andWhere(['>=', 'distribution.date', date('Y-m-d')]); | ||||
} | } | ||||
$distributionsArray = $queryDistributions->andWhere([ | $distributionsArray = $queryDistributions->andWhere([ | ||||
'distribution.id_producer' => GlobalParam::getCurrentProducerId(), | 'distribution.id_producer' => GlobalParam::getCurrentProducerId(), | ||||
'distribution.active' => 1 | 'distribution.active' => 1 |
$producer = $this->getProducerCurrent(); | $producer = $this->getProducerCurrent(); | ||||
Mailjet::sendMail([ | |||||
'from_email' => $producerManager->getEmailOpendistrib($producer), | |||||
'from_name' => $producer->name, | |||||
'to_email' => $model->email, | |||||
'to_name' => $userManager->getUsername($user), | |||||
'subject' => '[' . $producer->name . '] Nouveau mot de passe', | |||||
'content_view_text' => '@common/mail/newPasswordUserAdmin-text.php', | |||||
'content_view_html' => '@common/mail/newPasswordUserAdmin-html.php', | |||||
'content_params' => [ | |||||
\Yii::$app->mailerService->sendFromProducer( | |||||
'Nouveau mot de passe', | |||||
'newPasswordUserAdmin', | |||||
[ | |||||
'user' => $user, | 'user' => $user, | ||||
'producer' => $producer, | 'producer' => $producer, | ||||
'password' => $password, | 'password' => $password, | ||||
] | |||||
]); | |||||
], | |||||
$model->email, | |||||
$producer | |||||
); | |||||
$this->setFlash('success', 'Nouveau mot de passe envoyé à <strong>'.Html::encode($userManager->getUsername($model)).'</strong>.'); | $this->setFlash('success', 'Nouveau mot de passe envoyé à <strong>'.Html::encode($userManager->getUsername($model)).'</strong>.'); | ||||
$producer = GlobalParam::getCurrentProducer() ; | $producer = GlobalParam::getCurrentProducer() ; | ||||
$userProducer = $userProducerManager->findOneUserProducer($user); | $userProducer = $userProducerManager->findOneUserProducer($user); | ||||
$paramsEmail = [ | |||||
'from_email' => $producerManager->getEmailOpendistrib($producer), | |||||
'from_name' => $producer->name, | |||||
'to_email' => $user->email, | |||||
'to_name' => $userManager->getUsername($user), | |||||
'subject' => '['.$producer->name.'] Mouvement de crédit', | |||||
'content_view_text' => '@common/mail/creditUser-text.php', | |||||
'content_view_html' => '@common/mail/creditUser-html.php', | |||||
'content_params' => [ | |||||
'user' => $user, | |||||
'producer' => $producer, | |||||
'userProducer' => $userProducer, | |||||
'creditForm' => $this | |||||
] | |||||
] ; | |||||
Mailjet::sendMail($paramsEmail); | |||||
\Yii::$app->mailerService->sendFromProducer( | |||||
'Mouvement de crédit', | |||||
'creditUser', | |||||
[ | |||||
'user' => $user, | |||||
'producer' => $producer, | |||||
'userProducer' => $userProducer, | |||||
'creditForm' => $this | |||||
], | |||||
$user->email, | |||||
$producer | |||||
); | |||||
} | } | ||||
} | } | ||||
} | } |
<?php | |||||
namespace common\components; | |||||
use common\logic\Producer\Producer\Model\Producer; | |||||
use yii\mail\MessageInterface; | |||||
class MailerService | |||||
{ | |||||
public function sendFromProducer(string $subject, string $view, array $params, string $toEmail, Producer $producer) | |||||
{ | |||||
$message = $this->composeBase($toEmail, $view, $params); | |||||
$this->initMessageFromProducer($message, $subject, $producer); | |||||
$message->send(); | |||||
} | |||||
public function sendFromSite(string $subject, string $view, array $params, string $toEmail) | |||||
{ | |||||
$message = $this->composeBase($toEmail, $view, $params); | |||||
$this->initMessageFromSite($message, $subject); | |||||
$message->send(); | |||||
} | |||||
public function sendAdmin(string $subject, string $view, array $params = []) | |||||
{ | |||||
$message = $this->composeBase(\Yii::$app->params['adminEmail'], $view, $params); | |||||
$this->initMessageFromSite($message, $subject); | |||||
$message->send(); | |||||
} | |||||
private function composeBase(string $toEmail, string $view, array $params = []) | |||||
{ | |||||
return \Yii::$app->mailer | |||||
->compose([ | |||||
'html' => '@common/mail/'.$view.'-html.php', | |||||
'text' => '@common/mail/'.$view.'-text.php' | |||||
], $params) | |||||
->setTo($toEmail); | |||||
} | |||||
private function initMessageFromSite(MessageInterface $message, string $subject) | |||||
{ | |||||
$message->setFrom([\Yii::$app->params['adminEmail'] => \Yii::$app->params['siteName']]); | |||||
$message->setSubject($this->buildSubject(\Yii::$app->params['siteName'], $subject)); | |||||
return $message; | |||||
} | |||||
private function initMessageFromProducer(MessageInterface $message, string $subject, Producer $producer) | |||||
{ | |||||
$message->setFrom([$this->getEmailOpendistrib($producer) => $producer->name]); | |||||
$message->setSubject($this->buildSubject($producer->name, $subject)); | |||||
return $message; | |||||
} | |||||
private function getEmailOpendistrib(Producer $producer): string | |||||
{ | |||||
return $producer->slug . '@opendistrib.net'; | |||||
} | |||||
private function buildSubject(string $prefix, string $subject) | |||||
{ | |||||
return '['.$prefix.'] '.$subject; | |||||
} | |||||
} |
'class' => 'yii\image\ImageDriver', | 'class' => 'yii\image\ImageDriver', | ||||
'driver' => 'GD', //GD or Imagick | 'driver' => 'GD', //GD or Imagick | ||||
], | ], | ||||
'mailerService' => [ | |||||
'class' => 'common\components\MailerService' | |||||
], | |||||
'urlManagerProducer' => [ | 'urlManagerProducer' => [ | ||||
'class' => 'producer\components\UrlManagerProducer', | 'class' => 'producer\components\UrlManagerProducer', | ||||
'subDomain' => Yii::getAlias('@producerSubdomain'), | 'subDomain' => Yii::getAlias('@producerSubdomain'), |
return [ | return [ | ||||
'version' => '23.8.B', | 'version' => '23.8.B', | ||||
'siteName' => 'Opendistrib', | |||||
'adminEmail' => 'contact@opendistrib.net', | 'adminEmail' => 'contact@opendistrib.net', | ||||
'supportEmail' => 'contact@opendistrib.net', | 'supportEmail' => 'contact@opendistrib.net', | ||||
'user.passwordResetTokenExpire' => 3600, | 'user.passwordResetTokenExpire' => 3600, | ||||
] | ] | ||||
] | ] | ||||
]; | ]; |
return \Yii::$app->urlManagerProducer->getHostInfo() . '/' . \Yii::$app->urlManagerProducer->baseUrl . '/uploads/' . $producer->logo; | return \Yii::$app->urlManagerProducer->getHostInfo() . '/' . \Yii::$app->urlManagerProducer->baseUrl . '/uploads/' . $producer->logo; | ||||
} | } | ||||
/** | |||||
* @deprecated Déplacé dans MailerService | |||||
*/ | |||||
public function getEmailOpendistrib(Producer $producer): string | public function getEmailOpendistrib(Producer $producer): string | ||||
{ | { | ||||
return $producer->slug . '@opendistrib.net'; | return $producer->slug . '@opendistrib.net'; |
public function sendEmailSignup(User $user, Producer $producer) | public function sendEmailSignup(User $user, Producer $producer) | ||||
{ | { | ||||
Mailjet::sendMail([ | |||||
'from_email' => \Yii::$app->params['adminEmail'], | |||||
'from_name' => 'Opendistrib', | |||||
'to_email' => $user->email, | |||||
'to_name' => $this->userSolver->getUsername($user), | |||||
'subject' => '[Opendistrib] Inscription', | |||||
'content_view_text' => '@common/mail/signup-text.php', | |||||
'content_view_html' => '@common/mail/signup-html.php', | |||||
'content_params' => [ | |||||
\Yii::$app->mailerService->sendFromSite( | |||||
'Inscription', | |||||
'signup', | |||||
[ | |||||
'user' => $user, | 'user' => $user, | ||||
'producer' => $producer | 'producer' => $producer | ||||
] | |||||
]); | |||||
], | |||||
$user->email | |||||
); | |||||
} | } | ||||
/** | /** | ||||
{ | { | ||||
if (strlen($user->email)) { | if (strlen($user->email)) { | ||||
$producer = Producer::findOne(GlobalParam::getCurrentProducerId()); | $producer = Producer::findOne(GlobalParam::getCurrentProducerId()); | ||||
\Yii::$app->mailer->compose(); | |||||
$mail = \Yii::$app->mailer->compose( | |||||
['html' => 'createUserAdmin-html', 'text' => 'createUserAdmin-text'], ['user' => $user, 'producer' => $producer, 'password' => $password] | |||||
) | |||||
->setTo($user->email) | |||||
->setFrom(['contact@opendistrib.net' => 'distrib']) | |||||
->setSubject('[Opendistrib] Inscription') | |||||
->send(); | |||||
\Yii::$app->mailerService->sendFromProducer( | |||||
'Inscription', | |||||
'createUserAdmin', | |||||
[ | |||||
'user' => $user, | |||||
'producer' => $producer, | |||||
'password' => $password | |||||
], | |||||
$user->email, | |||||
$producer | |||||
); | |||||
} | } | ||||
} | } | ||||
public function sendMailNewTicketAdmin(Ticket $ticket) | public function sendMailNewTicketAdmin(Ticket $ticket) | ||||
{ | { | ||||
$adminEmail = \Yii::$app->params['adminEmail']; | |||||
Mailjet::sendMail([ | |||||
'from_email' => $adminEmail, | |||||
'from_name' => 'Opendistrib', | |||||
'to_email' => $adminEmail, | |||||
'to_name' => 'Opendistrib', | |||||
'subject' => '[Opendistrib] Nouveau ticket', | |||||
'content_view_text' => '@common/mail/newTicketAdmin-text.php', | |||||
'content_view_html' => '@common/mail/newTicketAdmin-html.php', | |||||
'content_params' => [ | |||||
\Yii::$app->mailerService->sendAdmin( | |||||
'Nouveau ticket', | |||||
'newTicketAdmin', | |||||
[ | |||||
'ticket' => $ticket, | 'ticket' => $ticket, | ||||
] | ] | ||||
]); | |||||
); | |||||
} | } | ||||
} | } |
"stripe/stripe-php": "^7.95", | "stripe/stripe-php": "^7.95", | ||||
"loveorigami/yii2-bootstrap-toggle": "*", | "loveorigami/yii2-bootstrap-toggle": "*", | ||||
"justcoded/yii2-event-listener": "*", | "justcoded/yii2-event-listener": "*", | ||||
"ext-pdo": "*" | |||||
"ext-pdo": "*", | |||||
"weluse/yii2-mailjet": "^0.2.0" | |||||
}, | }, | ||||
"require-dev": { | "require-dev": { | ||||
"yiisoft/yii2-codeception": "*", | "yiisoft/yii2-codeception": "*", |
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", | ||||
"This file is @generated automatically" | "This file is @generated automatically" | ||||
], | ], | ||||
"content-hash": "7da17be4685def1e9635cc5ab5e5a7d9", | |||||
"content-hash": "cf81ea895f037844a4e20f4780fd7e7e", | |||||
"packages": [ | "packages": [ | ||||
{ | { | ||||
"name": "2amigos/yii2-chartjs-widget", | "name": "2amigos/yii2-chartjs-widget", | ||||
], | ], | ||||
"time": "2022-11-03T14:55:06+00:00" | "time": "2022-11-03T14:55:06+00:00" | ||||
}, | }, | ||||
{ | |||||
"name": "weluse/yii2-mailjet", | |||||
"version": "v0.2.0", | |||||
"source": { | |||||
"type": "git", | |||||
"url": "https://github.com/weluse/yii2-mailjet.git", | |||||
"reference": "ec68afa94a5f9cef2b1ed6197b733b7a9fa8f601" | |||||
}, | |||||
"dist": { | |||||
"type": "zip", | |||||
"url": "https://api.github.com/repos/weluse/yii2-mailjet/zipball/ec68afa94a5f9cef2b1ed6197b733b7a9fa8f601", | |||||
"reference": "ec68afa94a5f9cef2b1ed6197b733b7a9fa8f601", | |||||
"shasum": "" | |||||
}, | |||||
"require": { | |||||
"mailjet/mailjet-apiv3-php": "^1.1.5" | |||||
}, | |||||
"type": "library", | |||||
"autoload": { | |||||
"psr-4": { | |||||
"weluse\\mailjet\\": "" | |||||
} | |||||
}, | |||||
"notification-url": "https://packagist.org/downloads/", | |||||
"license": [ | |||||
"MIT" | |||||
], | |||||
"description": "Mailjet client", | |||||
"support": { | |||||
"issues": "https://github.com/weluse/yii2-mailjet/issues", | |||||
"source": "https://github.com/weluse/yii2-mailjet/tree/v0.2.0" | |||||
}, | |||||
"time": "2019-06-19T21:18:00+00:00" | |||||
}, | |||||
{ | { | ||||
"name": "yidas/yii2-bower-asset", | "name": "yidas/yii2-bower-asset", | ||||
"version": "2.0.13.1", | "version": "2.0.13.1", |
$creditHistoryManager->payOrder($order, $user, true); | $creditHistoryManager->payOrder($order, $user, true); | ||||
// client : envoi d'un email de confirmation de paiement | // client : envoi d'un email de confirmation de paiement | ||||
$paramsEmail = [ | |||||
'from_email' => $producerManager->getEmailOpendistrib($producer), | |||||
'from_name' => $producer->name, | |||||
'to_email' => $user->email, | |||||
'to_name' => $userManager->getUsername($user), | |||||
'subject' => '[' . $producer->name . '] Confirmation de paiement', | |||||
'content_view_text' => '@common/mail/paymentOrderConfirm-text.php', | |||||
'content_view_html' => '@common/mail/paymentOrderConfirm-html.php', | |||||
'content_params' => [ | |||||
/*\Yii::$app->mailerService->sendFromProducer( | |||||
'Confirmation de commande', | |||||
'paymentOrderConfirm', | |||||
[ | |||||
'amount' => $amount, | 'amount' => $amount, | ||||
'user' => $user, | 'user' => $user, | ||||
'producer' => $producer, | 'producer' => $producer, | ||||
] | |||||
]; | |||||
//Mailjet::sendMail($paramsEmail); | |||||
], | |||||
$user->email, | |||||
$producer | |||||
);*/ | |||||
// producteur : mail de confirmation | // producteur : mail de confirmation | ||||
Mailjet::sendMail([ | |||||
'from_email' => $producerManager->getEmailOpendistrib($producer), | |||||
'from_name' => $producer->name, | |||||
'to_email' => $contactProducer->email, | |||||
'to_name' => $contactProducer->name, | |||||
'subject' => '[' . $producer->name . '] Confirmation de commande', | |||||
'content_view_text' => '@common/mail/orderConfirmProducer-text.php', | |||||
'content_view_html' => '@common/mail/orderConfirmProducer-html.php', | |||||
'content_params' => [ | |||||
\Yii::$app->mailerService->sendFromSite( | |||||
'Confirmation de commande', | |||||
'orderConfirmProducer', | |||||
[ | |||||
'order' => $order, | 'order' => $order, | ||||
'pointSale' => $pointSale, | 'pointSale' => $pointSale, | ||||
'distribution' => $distribution, | 'distribution' => $distribution, | ||||
'user' => $user, | 'user' => $user, | ||||
'producer' => $producer | 'producer' => $producer | ||||
] | |||||
]); | |||||
], | |||||
$contactProducer->email | |||||
); | |||||
} else { | } else { | ||||
$userProducer = $this->getUserProducerManager()->findOneUserProducer($user); | $userProducer = $this->getUserProducerManager()->findOneUserProducer($user); | ||||
Mailjet::sendMail([ | |||||
'from_email' => $producerManager->getEmailOpendistrib($producer), | |||||
'from_name' => $producer->name, | |||||
'to_email' => $user->email, | |||||
'to_name' => $userManager->getUsername($user), | |||||
'subject' => '[' . $producer->name . '] Alimentation de votre crédit', | |||||
'content_view_text' => '@common/mail/creditConfirm-text.php', | |||||
'content_view_html' => '@common/mail/creditConfirm-html.php', | |||||
'content_params' => [ | |||||
\Yii::$app->mailerService->sendFromProducer( | |||||
'Alimentation de votre crédit', | |||||
'creditConfirm', | |||||
[ | |||||
'user' => $user, | 'user' => $user, | ||||
'userProducer' => $userProducer, | 'userProducer' => $userProducer, | ||||
'producer' => $producer, | 'producer' => $producer, | ||||
'amount' => $amount, | 'amount' => $amount, | ||||
] | |||||
]); | |||||
], | |||||
$user->email, | |||||
$producer | |||||
); | |||||
} | } | ||||
} | } | ||||
case 'charge.failed': | case 'charge.failed': | ||||
// client | // client | ||||
Mailjet::sendMail([ | |||||
'from_email' => $producerManager->getEmailOpendistrib($producer), | |||||
'from_name' => $producer->name, | |||||
'to_email' => $user->email, | |||||
'to_name' => $userManager->getUsername($user), | |||||
'subject' => '[' . $producer->name . '] Erreur de paiement', | |||||
'content_view_text' => '@common/mail/paymentError-text.php', | |||||
'content_view_html' => '@common/mail/paymentError-html.php', | |||||
'content_params' => [ | |||||
\Yii::$app->mailerService->sendFromProducer( | |||||
'Erreur de paiement', | |||||
'paymentError', | |||||
[ | |||||
'amount' => $amount, | 'amount' => $amount, | ||||
'user' => $user, | 'user' => $user, | ||||
'producer' => $producer, | 'producer' => $producer, | ||||
] | |||||
]); | |||||
], | |||||
$user->email, | |||||
$producer | |||||
); | |||||
// producteur | // producteur | ||||
if (isset($order) && $order) { | if (isset($order) && $order) { | ||||
Mailjet::sendMail([ | |||||
'from_email' => $producerManager->getEmailOpendistrib($producer), | |||||
'from_name' => $producer->name, | |||||
'to_email' => $contactProducer->email, | |||||
'to_name' => $contactProducer->name, | |||||
'subject' => '[' . $producer->name . '] Erreur de paiement', | |||||
'content_view_text' => '@common/mail/paymentErrorProducer-text.php', | |||||
'content_view_html' => '@common/mail/paymentErrorProducer-html.php', | |||||
'content_params' => [ | |||||
\Yii::$app->mailerService->sendFromSite( | |||||
'Erreur de paiement', | |||||
'paymentErrorProducer', | |||||
[ | |||||
'amount' => $amount, | 'amount' => $amount, | ||||
'user' => $user, | 'user' => $user, | ||||
'producer' => $producer, | 'producer' => $producer, | ||||
'order' => $order, | 'order' => $order, | ||||
'distribution' => $distribution | 'distribution' => $distribution | ||||
] | |||||
]); | |||||
], | |||||
$contactProducer->email, | |||||
); | |||||
} | } | ||||
break; | break; |
} | } | ||||
} | } | ||||
$paramsEmail = [ | |||||
'from_email' => $producerManager->getEmailOpendistrib($producer), | |||||
'from_name' => $producer->name, | |||||
'to_email' => $user->email, | |||||
'to_name' => $userManager->getUsername($user), | |||||
'subject' => '[' . $producer->name . '] Confirmation de commande', | |||||
'content_view_text' => '@common/mail/orderConfirm-text.php', | |||||
'content_view_html' => '@common/mail/orderConfirm-html.php', | |||||
'content_params' => [ | |||||
/* | |||||
* Envoi email de confirmation | |||||
*/ | |||||
if ($isNewOrder) { | |||||
$emailSubject = 'Confirmation de commande'; | |||||
$emailContentParams = [ | |||||
'order' => $order, | 'order' => $order, | ||||
'pointSale' => $pointSale, | 'pointSale' => $pointSale, | ||||
'distribution' => $distribution, | 'distribution' => $distribution, | ||||
'user' => $user, | 'user' => $user, | ||||
'producer' => $producer | 'producer' => $producer | ||||
] | |||||
]; | |||||
]; | |||||
/* | |||||
* Envoi email de confirmation | |||||
*/ | |||||
if ($isNewOrder) { | |||||
// au client | // au client | ||||
if ($producerManager->getConfig('option_email_confirm')) { | if ($producerManager->getConfig('option_email_confirm')) { | ||||
Mailjet::sendMail($paramsEmail); | |||||
\Yii::$app->mailerService->sendFromProducer( | |||||
$emailSubject, | |||||
'orderConfirm', | |||||
$emailContentParams, | |||||
$user->email, | |||||
$producer | |||||
); | |||||
} | } | ||||
// au producteur | // au producteur | ||||
if ($producerManager->getConfig('option_email_confirm_producer') && $contactProducer && strlen( | if ($producerManager->getConfig('option_email_confirm_producer') && $contactProducer && strlen( | ||||
$contactProducer->email | $contactProducer->email | ||||
)) { | )) { | ||||
$paramsEmail['to_email'] = $contactProducer->email; | |||||
$paramsEmail['to_name'] = $contactProducer->name; | |||||
$paramsEmail['content_view_text'] = '@common/mail/orderConfirmProducer-text.php'; | |||||
$paramsEmail['content_view_html'] = '@common/mail/orderConfirmProducer-html.php'; | |||||
Mailjet::sendMail($paramsEmail); | |||||
\Yii::$app->mailerService->sendFromSite( | |||||
$emailSubject, | |||||
'orderConfirmProducer', | |||||
$emailContentParams, | |||||
$contactProducer->email | |||||
); | |||||
} | } | ||||
} | } | ||||