我正在使用laravel-excel软件包,并且DB
中有30,000多种产品,我需要对数据进行排队,然后将最终文件发送到电子邮件中,以通知用户该文件已准备好下载通过电子邮件!
记录到this:
(new ExportProducts(merchant()->id))->queue('products.xlsx')->chain([
// how to send the file to job ?
//new NotifyMerchantFileExport(request()->user()),
]);
排队完成后,有什么方法可以将文件发送到电子邮件吗?
答案 0 :(得分:0)
遵循以下结构:
在您的_globalHook = Hook.GlobalEvents();
_globalHook.KeyPress += GlobalHookKeyPress; //Subscribe
_globalHook.KeyPress -= GlobalHookKeyPress; //Unsubscribe
类中,请确保using System;
using System.Windows.Forms;
using System.Diagnostics;
using System.Reactive.Linq;
using Gma.System.MouseKeyHook;
using MouseKeyHook.Rx;
namespace HotkeyPlay
{
public partial class Form1 : Form
{
private IDisposable _keysObservable;
public Form1()
{
InitializeComponent();
var triggers = new Trigger[]
{
Trigger.On(Keys.H).Alt().Shift()
};
_keysObservable =
Hook
.GlobalEvents()
.KeyDownObservable()
.Matching(triggers)
.Subscribe((trigger) =>
{
Debug.WriteLine(trigger.ToString());
});
}
private void button1_Click(object sender, EventArgs e)
{
_keysObservable.Dispose();
var triggers = new Trigger[]
{
Trigger.On(Keys.B).Alt().Shift()
};
_keysObservable =
Hook
.GlobalEvents()
.KeyDownObservable()
.Matching(triggers)
.Subscribe((trigger) =>
{
Debug.WriteLine(trigger.ToString());
});
}
}
}
。
Install-Package System.Reactive.Linq
Install-Package MouseKeyHook.Rx
中的可能是这样的:
ExportProducts
创建新工作,我将其称为implements ShouldQueue
:
FooController
创建一个新的电子邮件文件<?php
namespace App\Http\Controllers;
use App\Exports\ExportProducts;
use App\Http\Controllers\Controller;
use App\Jobs\Export\NotifyMerchantOfCompleteFileExport;
class FooController extends Controller
{
public function index()
{
$fileName = 'uploads/excel-files/'.Str::random(3).'.xlsx';
$filePath = asset($fileName);
(new ExportProducts)->store($fileName,'public')->chain([
new NotifyUserOfCompleteFileExport(auth()->user(),$filePath),
]);;
return back()->withSuccess('export started'));
}
}
:
NotifyUserOfCompleteFileExport
说明步骤2
只需将您需要下载的最终文件存储在内部
队列完成后,公共<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Support\Facades\Mail;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use App\Mail\Merchant\CompleteExportedFile;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
class NotifyUserOfCompleteFileExport implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $user;
public $filePath;
public function __construct($user,$filePath)
{
$this->user = $user;
$this->filePath = $filePath;
}
public function handle()
{
Mail::to($this->user)->send(new CompleteExportedFile($this->filePath));
}
}
将此文件的目录传递到作业文件CompleteExportedFile
,然后再次向用户发送电子邮件以及该文件的路径,最后,您可以为该文件创建一个新刀片您的电子邮件,然后将文件路径放入html标签:
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class CompleteExportedFile extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels;
public $filePath;
public function __construct($filePath)
{
$this->filePath = $filePath;
}
public function build()
{
return $this->subject('File has been exported')
->markdown('emails.send-export-file');
}
}
希望它有用:)