From 459bb3db51f957c46c4d06b34001a3463ddefaeb Mon Sep 17 00:00:00 2001 From: Edward Yang Date: Fri, 13 Jan 2023 14:28:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84mailgun,=20sendmail=20?= =?UTF-8?q?=E9=82=AE=E4=BB=B6=E5=8F=91=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/Repositories/AttributeGroupRepo.php | 2 +- beike/Admin/Repositories/AttributeRepo.php | 2 +- .../AdminForgottenNotification.php | 8 ++++++- beike/Notifications/ForgottenNotification.php | 8 ++++++- beike/Notifications/NewOrderNotification.php | 8 ++++++- .../RegistrationNotification.php | 8 ++++++- .../Notifications/UpdateOrderNotification.php | 8 ++++++- .../Account/ForgottenController.php | 12 +++++----- beike/Shop/Providers/ShopServiceProvider.php | 18 ++++++++++----- resources/lang/en/admin/attribute.php | 22 +++++++++---------- resources/lang/en/admin/attribute_groups.php | 6 ++--- resources/lang/zh_cn/admin/attribute.php | 22 +++++++++---------- .../lang/zh_cn/admin/attribute_groups.php | 6 ++--- 13 files changed, 84 insertions(+), 46 deletions(-) diff --git a/beike/Admin/Repositories/AttributeGroupRepo.php b/beike/Admin/Repositories/AttributeGroupRepo.php index dbd60554..bc604c55 100644 --- a/beike/Admin/Repositories/AttributeGroupRepo.php +++ b/beike/Admin/Repositories/AttributeGroupRepo.php @@ -70,7 +70,7 @@ class AttributeGroupRepo { $group = AttributeGroup::query()->findOrFail($id); if ($group->attributes->count()) { - throw New \Exception(trans('admin/attribute_groups.error_cannot_delete_attribute_used', ['attributes' => implode(', ', $group->attributes->pluck('id')->toArray())])); + throw new \Exception(trans('admin/attribute_groups.error_cannot_delete_attribute_used', ['attributes' => implode(', ', $group->attributes->pluck('id')->toArray())])); } $group->descriptions()->delete(); $group->delete(); diff --git a/beike/Admin/Repositories/AttributeRepo.php b/beike/Admin/Repositories/AttributeRepo.php index 0089eddb..29907c2c 100644 --- a/beike/Admin/Repositories/AttributeRepo.php +++ b/beike/Admin/Repositories/AttributeRepo.php @@ -110,7 +110,7 @@ class AttributeRepo { $productIds = ProductAttribute::query()->where('attribute_id', $id)->pluck('product_id')->toArray(); if ($productIds) { - throw New \Exception(trans('admin/attribute.error_cannot_delete_product_used', ['product_ids' => implode(', ', $productIds)])); + throw new \Exception(trans('admin/attribute.error_cannot_delete_product_used', ['product_ids' => implode(', ', $productIds)])); } $attribute = Attribute::query()->findOrFail($id); $attribute->descriptions()->delete(); diff --git a/beike/Notifications/AdminForgottenNotification.php b/beike/Notifications/AdminForgottenNotification.php index c501052a..cf7a13d5 100644 --- a/beike/Notifications/AdminForgottenNotification.php +++ b/beike/Notifications/AdminForgottenNotification.php @@ -44,7 +44,13 @@ class AdminForgottenNotification extends Notification implements ShouldQueue */ public function via($notifiable) { - return ['mail', 'database']; + $drivers[] = 'database'; + $mailEngine = system_setting('base.mail_engine'); + if ($mailEngine) { + $drivers[] = 'mail'; + } + + return $drivers; } /** diff --git a/beike/Notifications/ForgottenNotification.php b/beike/Notifications/ForgottenNotification.php index 6ca9b376..514d7a5d 100644 --- a/beike/Notifications/ForgottenNotification.php +++ b/beike/Notifications/ForgottenNotification.php @@ -44,7 +44,13 @@ class ForgottenNotification extends Notification implements ShouldQueue */ public function via($notifiable) { - return ['mail', 'database']; + $drivers[] = 'database'; + $mailEngine = system_setting('base.mail_engine'); + if ($mailEngine) { + $drivers[] = 'mail'; + } + + return $drivers; } /** diff --git a/beike/Notifications/NewOrderNotification.php b/beike/Notifications/NewOrderNotification.php index 77389ff5..1c000a49 100644 --- a/beike/Notifications/NewOrderNotification.php +++ b/beike/Notifications/NewOrderNotification.php @@ -41,7 +41,13 @@ class NewOrderNotification extends Notification implements ShouldQueue */ public function via($notifiable) { - return ['mail', 'database']; + $drivers[] = 'database'; + $mailEngine = system_setting('base.mail_engine'); + if ($mailEngine) { + $drivers[] = 'mail'; + } + + return $drivers; } /** diff --git a/beike/Notifications/RegistrationNotification.php b/beike/Notifications/RegistrationNotification.php index 71e55037..5609877f 100644 --- a/beike/Notifications/RegistrationNotification.php +++ b/beike/Notifications/RegistrationNotification.php @@ -41,7 +41,13 @@ class RegistrationNotification extends Notification implements ShouldQueue */ public function via($notifiable) { - return ['mail', 'database']; + $drivers[] = 'database'; + $mailEngine = system_setting('base.mail_engine'); + if ($mailEngine) { + $drivers[] = 'mail'; + } + + return $drivers; } /** diff --git a/beike/Notifications/UpdateOrderNotification.php b/beike/Notifications/UpdateOrderNotification.php index 6e143b36..e6a3aa5b 100644 --- a/beike/Notifications/UpdateOrderNotification.php +++ b/beike/Notifications/UpdateOrderNotification.php @@ -44,7 +44,13 @@ class UpdateOrderNotification extends Notification implements ShouldQueue */ public function via($notifiable) { - return ['mail', 'database']; + $drivers[] = 'database'; + $mailEngine = system_setting('base.mail_engine'); + if ($mailEngine) { + $drivers[] = 'mail'; + } + + return $drivers; } /** diff --git a/beike/Shop/Http/Controllers/Account/ForgottenController.php b/beike/Shop/Http/Controllers/Account/ForgottenController.php index 5cd05e0f..2c55cdcf 100644 --- a/beike/Shop/Http/Controllers/Account/ForgottenController.php +++ b/beike/Shop/Http/Controllers/Account/ForgottenController.php @@ -14,13 +14,12 @@ namespace Beike\Shop\Http\Controllers\Account; use Beike\Shop\Http\Requests\ForgottenRequest; use Beike\Shop\Http\Requests\VerifyCodeRequest; use Beike\Shop\Services\AccountService; -use Illuminate\Http\Request; class ForgottenController { /** * 找回密码页面 - * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View + * @return mixed */ public function index() { @@ -29,10 +28,10 @@ class ForgottenController /** * 接收email地址,生成验证码发送到邮件地址 - * @param Request $request + * @param VerifyCodeRequest $request * @return array */ - public function sendVerifyCode(VerifyCodeRequest $request) + public function sendVerifyCode(VerifyCodeRequest $request): array { AccountService::sendVerifyCodeForForgotten($request->get('email'), 'email'); @@ -41,10 +40,11 @@ class ForgottenController /** * 接收验证码和新密码、确认密码,验证验证码是否正确、密码和确认密码是否相等,然后修改密码 - * @param Request $request + * @param ForgottenRequest $request * @return array + * @throws \Exception */ - public function changePassword(ForgottenRequest $request) + public function changePassword(ForgottenRequest $request): array { AccountService::verifyAndChangePassword($request->get('code'), $request->get('email'), $request->get('password')); diff --git a/beike/Shop/Providers/ShopServiceProvider.php b/beike/Shop/Providers/ShopServiceProvider.php index d4b86278..3c0eb11c 100644 --- a/beike/Shop/Providers/ShopServiceProvider.php +++ b/beike/Shop/Providers/ShopServiceProvider.php @@ -95,17 +95,25 @@ class ShopServiceProvider extends ServiceProvider */ protected function loadMailConfig() { - $mailEngine = system_setting('base.mail_engine', 'smtp'); + $mailEngine = system_setting('base.mail_engine'); $storeMail = system_setting('base.email', ''); + if (empty($mailEngine)) { + return; + } + Config::set('mail.default', $mailEngine); Config::set('mail.from.address', $storeMail); Config::set('mail.from.name', \config('app.name')); - $smtpSetting = system_setting('base.smtp'); - if ($smtpSetting) { - $smtpSetting['transport'] = 'smtp'; - Config::set('mail.mailers.smtp', $smtpSetting); + if ($setting = system_setting('base.smtp')) { + $setting['transport'] = 'smtp'; + Config::set('mail.mailers.smtp', $setting); + } elseif ($setting = system_setting('base.mailgun')) { + Config::set('services.mailgun', $setting); + } elseif ($setting = system_setting('base.sendmail')) { + $setting['transport'] = 'sendmail'; + Config::set('mail.mailers.sendmail', $setting); } } diff --git a/resources/lang/en/admin/attribute.php b/resources/lang/en/admin/attribute.php index c09b5b2d..5b1e83f0 100644 --- a/resources/lang/en/admin/attribute.php +++ b/resources/lang/en/admin/attribute.php @@ -10,15 +10,15 @@ */ return [ - 'index' => 'Attribute', - 'attribute_info' => 'Attribute information', - 'create_at' => 'Create attribute', - 'attribute_value' => 'Cttribute value', - 'set_attribute' => 'Configuration attribute', - 'add_attribute' => 'Add attribute value', - 'before_attribute' => 'Please select the left attribute first', - 'btn_at' => 'Go now', - 'btn_later' => 'Later', - 'to_info_values' => 'Please go to the details page to edit attribute values', - 'error_cannot_delete_product_used' => 'Attribute used by products (ID: :product_ids), can not be deleted!' + 'index' => 'Attribute', + 'attribute_info' => 'Attribute information', + 'create_at' => 'Create attribute', + 'attribute_value' => 'Cttribute value', + 'set_attribute' => 'Configuration attribute', + 'add_attribute' => 'Add attribute value', + 'before_attribute' => 'Please select the left attribute first', + 'btn_at' => 'Go now', + 'btn_later' => 'Later', + 'to_info_values' => 'Please go to the details page to edit attribute values', + 'error_cannot_delete_product_used' => 'Attribute used by products (ID: :product_ids), can not be deleted!', ]; diff --git a/resources/lang/en/admin/attribute_groups.php b/resources/lang/en/admin/attribute_groups.php index 3b7fefaf..0707e24e 100644 --- a/resources/lang/en/admin/attribute_groups.php +++ b/resources/lang/en/admin/attribute_groups.php @@ -10,7 +10,7 @@ */ return [ - 'index' => 'Attribute group', - 'create_at_groups' => 'Create attribute group', - 'error_cannot_delete_attribute_used' => 'Attribute Group used by attribute (ID: :attributes), can not be deleted!' + 'index' => 'Attribute group', + 'create_at_groups' => 'Create attribute group', + 'error_cannot_delete_attribute_used' => 'Attribute Group used by attribute (ID: :attributes), can not be deleted!', ]; diff --git a/resources/lang/zh_cn/admin/attribute.php b/resources/lang/zh_cn/admin/attribute.php index edebfce2..f303f39a 100644 --- a/resources/lang/zh_cn/admin/attribute.php +++ b/resources/lang/zh_cn/admin/attribute.php @@ -10,15 +10,15 @@ */ return [ - 'index' => '属性', - 'attribute_info' => '属性信息', - 'create_at' => '创建属性', - 'attribute_value' => '属性值', - 'set_attribute' => '配置属性', - 'add_attribute' => '添加属性值', - 'before_attribute' => '请先选择左边属性', - 'btn_at' => '立即前往', - 'btn_later' => '稍后再去', - 'to_info_values' => '请前往详情页编辑属性值', - 'error_cannot_delete_product_used' => '属性不能删除,由于该属性被商品(商品ID: :product_ids)使用' + 'index' => '属性', + 'attribute_info' => '属性信息', + 'create_at' => '创建属性', + 'attribute_value' => '属性值', + 'set_attribute' => '配置属性', + 'add_attribute' => '添加属性值', + 'before_attribute' => '请先选择左边属性', + 'btn_at' => '立即前往', + 'btn_later' => '稍后再去', + 'to_info_values' => '请前往详情页编辑属性值', + 'error_cannot_delete_product_used' => '属性不能删除,由于该属性被商品(商品ID: :product_ids)使用', ]; diff --git a/resources/lang/zh_cn/admin/attribute_groups.php b/resources/lang/zh_cn/admin/attribute_groups.php index f6538670..d25cb778 100644 --- a/resources/lang/zh_cn/admin/attribute_groups.php +++ b/resources/lang/zh_cn/admin/attribute_groups.php @@ -10,7 +10,7 @@ */ return [ - 'index' => '属性组', - 'create_at_groups' => '创建属性组', - 'error_cannot_delete_attribute_used' => '属性组不能删除,由于该属性组被属性(属性ID: :attributes)使用' + 'index' => '属性组', + 'create_at_groups' => '创建属性组', + 'error_cannot_delete_attribute_used' => '属性组不能删除,由于该属性组被属性(属性ID: :attributes)使用', ];