完善mailgun, sendmail 邮件发送

This commit is contained in:
Edward Yang 2023-01-13 14:28:24 +08:00
parent 50ca3e4aff
commit 459bb3db51
13 changed files with 84 additions and 46 deletions

View File

@ -70,7 +70,7 @@ class AttributeGroupRepo
{ {
$group = AttributeGroup::query()->findOrFail($id); $group = AttributeGroup::query()->findOrFail($id);
if ($group->attributes->count()) { 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->descriptions()->delete();
$group->delete(); $group->delete();

View File

@ -110,7 +110,7 @@ class AttributeRepo
{ {
$productIds = ProductAttribute::query()->where('attribute_id', $id)->pluck('product_id')->toArray(); $productIds = ProductAttribute::query()->where('attribute_id', $id)->pluck('product_id')->toArray();
if ($productIds) { 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 = Attribute::query()->findOrFail($id);
$attribute->descriptions()->delete(); $attribute->descriptions()->delete();

View File

@ -44,7 +44,13 @@ class AdminForgottenNotification extends Notification implements ShouldQueue
*/ */
public function via($notifiable) public function via($notifiable)
{ {
return ['mail', 'database']; $drivers[] = 'database';
$mailEngine = system_setting('base.mail_engine');
if ($mailEngine) {
$drivers[] = 'mail';
}
return $drivers;
} }
/** /**

View File

@ -44,7 +44,13 @@ class ForgottenNotification extends Notification implements ShouldQueue
*/ */
public function via($notifiable) public function via($notifiable)
{ {
return ['mail', 'database']; $drivers[] = 'database';
$mailEngine = system_setting('base.mail_engine');
if ($mailEngine) {
$drivers[] = 'mail';
}
return $drivers;
} }
/** /**

View File

@ -41,7 +41,13 @@ class NewOrderNotification extends Notification implements ShouldQueue
*/ */
public function via($notifiable) public function via($notifiable)
{ {
return ['mail', 'database']; $drivers[] = 'database';
$mailEngine = system_setting('base.mail_engine');
if ($mailEngine) {
$drivers[] = 'mail';
}
return $drivers;
} }
/** /**

View File

@ -41,7 +41,13 @@ class RegistrationNotification extends Notification implements ShouldQueue
*/ */
public function via($notifiable) public function via($notifiable)
{ {
return ['mail', 'database']; $drivers[] = 'database';
$mailEngine = system_setting('base.mail_engine');
if ($mailEngine) {
$drivers[] = 'mail';
}
return $drivers;
} }
/** /**

View File

@ -44,7 +44,13 @@ class UpdateOrderNotification extends Notification implements ShouldQueue
*/ */
public function via($notifiable) public function via($notifiable)
{ {
return ['mail', 'database']; $drivers[] = 'database';
$mailEngine = system_setting('base.mail_engine');
if ($mailEngine) {
$drivers[] = 'mail';
}
return $drivers;
} }
/** /**

View File

@ -14,13 +14,12 @@ namespace Beike\Shop\Http\Controllers\Account;
use Beike\Shop\Http\Requests\ForgottenRequest; use Beike\Shop\Http\Requests\ForgottenRequest;
use Beike\Shop\Http\Requests\VerifyCodeRequest; use Beike\Shop\Http\Requests\VerifyCodeRequest;
use Beike\Shop\Services\AccountService; use Beike\Shop\Services\AccountService;
use Illuminate\Http\Request;
class ForgottenController class ForgottenController
{ {
/** /**
* 找回密码页面 * 找回密码页面
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View * @return mixed
*/ */
public function index() public function index()
{ {
@ -29,10 +28,10 @@ class ForgottenController
/** /**
* 接收email地址生成验证码发送到邮件地址 * 接收email地址生成验证码发送到邮件地址
* @param Request $request * @param VerifyCodeRequest $request
* @return array * @return array
*/ */
public function sendVerifyCode(VerifyCodeRequest $request) public function sendVerifyCode(VerifyCodeRequest $request): array
{ {
AccountService::sendVerifyCodeForForgotten($request->get('email'), 'email'); AccountService::sendVerifyCodeForForgotten($request->get('email'), 'email');
@ -41,10 +40,11 @@ class ForgottenController
/** /**
* 接收验证码和新密码、确认密码,验证验证码是否正确、密码和确认密码是否相等,然后修改密码 * 接收验证码和新密码、确认密码,验证验证码是否正确、密码和确认密码是否相等,然后修改密码
* @param Request $request * @param ForgottenRequest $request
* @return array * @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')); AccountService::verifyAndChangePassword($request->get('code'), $request->get('email'), $request->get('password'));

View File

@ -95,17 +95,25 @@ class ShopServiceProvider extends ServiceProvider
*/ */
protected function loadMailConfig() protected function loadMailConfig()
{ {
$mailEngine = system_setting('base.mail_engine', 'smtp'); $mailEngine = system_setting('base.mail_engine');
$storeMail = system_setting('base.email', ''); $storeMail = system_setting('base.email', '');
if (empty($mailEngine)) {
return;
}
Config::set('mail.default', $mailEngine); Config::set('mail.default', $mailEngine);
Config::set('mail.from.address', $storeMail); Config::set('mail.from.address', $storeMail);
Config::set('mail.from.name', \config('app.name')); Config::set('mail.from.name', \config('app.name'));
$smtpSetting = system_setting('base.smtp'); if ($setting = system_setting('base.smtp')) {
if ($smtpSetting) { $setting['transport'] = 'smtp';
$smtpSetting['transport'] = 'smtp'; Config::set('mail.mailers.smtp', $setting);
Config::set('mail.mailers.smtp', $smtpSetting); } 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);
} }
} }

View File

@ -10,15 +10,15 @@
*/ */
return [ return [
'index' => 'Attribute', 'index' => 'Attribute',
'attribute_info' => 'Attribute information', 'attribute_info' => 'Attribute information',
'create_at' => 'Create attribute', 'create_at' => 'Create attribute',
'attribute_value' => 'Cttribute value', 'attribute_value' => 'Cttribute value',
'set_attribute' => 'Configuration attribute', 'set_attribute' => 'Configuration attribute',
'add_attribute' => 'Add attribute value', 'add_attribute' => 'Add attribute value',
'before_attribute' => 'Please select the left attribute first', 'before_attribute' => 'Please select the left attribute first',
'btn_at' => 'Go now', 'btn_at' => 'Go now',
'btn_later' => 'Later', 'btn_later' => 'Later',
'to_info_values' => 'Please go to the details page to edit attribute values', '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!' 'error_cannot_delete_product_used' => 'Attribute used by products (ID: :product_ids), can not be deleted!',
]; ];

View File

@ -10,7 +10,7 @@
*/ */
return [ return [
'index' => 'Attribute group', 'index' => 'Attribute group',
'create_at_groups' => 'Create attribute group', 'create_at_groups' => 'Create attribute group',
'error_cannot_delete_attribute_used' => 'Attribute Group used by attribute (ID: :attributes), can not be deleted!' 'error_cannot_delete_attribute_used' => 'Attribute Group used by attribute (ID: :attributes), can not be deleted!',
]; ];

View File

@ -10,15 +10,15 @@
*/ */
return [ return [
'index' => '属性', 'index' => '属性',
'attribute_info' => '属性信息', 'attribute_info' => '属性信息',
'create_at' => '创建属性', 'create_at' => '创建属性',
'attribute_value' => '属性值', 'attribute_value' => '属性值',
'set_attribute' => '配置属性', 'set_attribute' => '配置属性',
'add_attribute' => '添加属性值', 'add_attribute' => '添加属性值',
'before_attribute' => '请先选择左边属性', 'before_attribute' => '请先选择左边属性',
'btn_at' => '立即前往', 'btn_at' => '立即前往',
'btn_later' => '稍后再去', 'btn_later' => '稍后再去',
'to_info_values' => '请前往详情页编辑属性值', 'to_info_values' => '请前往详情页编辑属性值',
'error_cannot_delete_product_used' => '属性不能删除由于该属性被商品商品ID: :product_ids使用' 'error_cannot_delete_product_used' => '属性不能删除由于该属性被商品商品ID: :product_ids使用',
]; ];

View File

@ -10,7 +10,7 @@
*/ */
return [ return [
'index' => '属性组', 'index' => '属性组',
'create_at_groups' => '创建属性组', 'create_at_groups' => '创建属性组',
'error_cannot_delete_attribute_used' => '属性组不能删除由于该属性组被属性属性ID: :attributes使用' 'error_cannot_delete_attribute_used' => '属性组不能删除由于该属性组被属性属性ID: :attributes使用',
]; ];