Order.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /*
  3. * FecShop file.
  4. *
  5. * @link http://www.fecshop.com/
  6. * @copyright Copyright (c) 2016 FecShop Software LLC
  7. * @license http://www.fecshop.com/license/
  8. */
  9. namespace fecshop\services\email;
  10. use Yii;
  11. use fecshop\services\Service;
  12. /**
  13. * @author Terry Zhao <2358269014@qq.com>
  14. * @since 1.0
  15. */
  16. class Order extends Service
  17. {
  18. /**
  19. * 邮件模板部分配置.
  20. */
  21. public $emailTheme;
  22. /**
  23. * @param $emailInfo | Array ,数组格式格式如下:
  24. * [ 'emcustomer_emailail' => 'xx@xx.com' , [...] ] 其中customer_email是必须有的数组key,对于其他的,
  25. * 可以根据功能添加,添加后,可以在邮件模板的$params中调用,譬如调用customer_email为 $params['customer_email']
  26. * @return boolean , 如果发送成功,则返回true。
  27. * 新订单邮件
  28. */
  29. public function sendCreateEmail($orderInfo)
  30. {
  31. $toEmail = $orderInfo['customer_email'];
  32. if (Yii::$app->user->isGuest) {
  33. $emailThemeInfo = $this->emailTheme['guestCreate'];
  34. } else {
  35. $emailThemeInfo = $this->emailTheme['loginedCreate'];
  36. }
  37. if (isset($emailThemeInfo['enable']) && $emailThemeInfo['enable']) {
  38. $mailerConfigParam = '';
  39. if (isset($emailThemeInfo['mailerConfig']) && $emailThemeInfo['mailerConfig']) {
  40. $mailerConfigParam = $emailThemeInfo['mailerConfig'];
  41. }
  42. if (isset($emailThemeInfo['widget']) && $emailThemeInfo['widget']) {
  43. $widget = $emailThemeInfo['widget'];
  44. }
  45. if (isset($emailThemeInfo['viewPath']) && $emailThemeInfo['viewPath']) {
  46. $viewPath = $emailThemeInfo['viewPath'];
  47. }
  48. if ($widget && $viewPath) {
  49. list($subject, $htmlBody) = Yii::$service->email->getSubjectAndBody($widget, $viewPath, '', $orderInfo);
  50. $sendInfo = [
  51. 'to' => $toEmail,
  52. 'subject' => $subject,
  53. 'htmlBody' => $htmlBody,
  54. 'senderName'=> Yii::$service->store->currentStore,
  55. ];
  56. Yii::$service->email->send($sendInfo, $mailerConfigParam);
  57. return true;
  58. }
  59. }
  60. }
  61. }