php - 队列完成后触发事件
问题描述
我想在队列完成后触发一个事件并使用 Pusher 发送 $ids 变量我已经看到大多数建议都使用 Queue:: 之后我不知道如何使用我坚持了 3 天,我已经安装了推送器,我只需要在作业完成后发送 $ids 变量。这是我的代码:
class ShipWithAramex implements ShouldQueue
{ use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
@return void
public $data;
public $type;
public $auth_id;
public $validatedOrders;
public function __construct($data,$type,$validatedOrders,$auth_id)
{
$this->data=$data;
$this->type=$type;
$this->auth_id=$auth_id;
$this->validatedOrders=$validatedOrders;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
try {
//code...
$ids=[];
$armx = new Aramex();
foreach ($this->data as $key => $order)
{
array_push($ids,$order->id);
$address = $order->address;
$city = $order->city;
$zip_code = $order->zip_code;
$country = "MA";
if($order->country=="Morocco")
$order->country = 'MA';
if($city != "nc"){
$nt = Note::where('note', 'like', 'Order added auto from woocommerce %')
->where('order_id', $order->id)->first();
if (@$nt !== null)
{
$note = trim($nt->note);
$order_id = explode(' ', $note) [5];
$website = new WPApi();
}
if ($order->store_id != null)
{
$wh = Webhook::find($order->store_id);
}
else
{
$wh = Webhook::where('user_id', $this->auth_id)
->orderByDesc("id")
->first();
}
$cnx=null;
if ($wh!=null) {
$cnx = $website->connect($wh->url, $wh->ck, $wh->cs);
$tst = (object)$cnx->get('orders/' . $order_id);
$bill = (object)($tst->billing);
$address = $bill->address_1.' '.$bill->address_2;
$city = $bill->city;
$zip_code = $bill->postcode;
$country = $bill->country;
}
if ($this->validatedOrders)
{
foreach ($this->validatedOrders as $key => $line)
{
$tofix = json_decode($line);
if ($order->id == $tofix->order)
{
$order->city = $tofix->city;
$order->address = $tofix->address;
$order->country = $tofix->country;
$order->zip_code = $tofix->zip;
}
}
}
$toUpdate['Billing']=array('postcode'=>$order->zip_code,
'address'=>$order->address,
'address_1'=>$order->address,
'city'=>$order->city);
if ($cnx) {
$respo=$cnx->put('orders/'.$order_id,$toUpdate);
}
}
$result = $armx->create($order, $this->type);
$url = $result['doc'];
$file_name = basename($url);
if (file_put_contents(storage_path("app/public/aramex/" . $order->id . ".pdf") , file_get_contents($url)))
{
$payment = 'P';
if ($this->type == 'CODS')
{
$payment = $this->type;
}
$PDFParser = new Parser();
$pdf = $PDFParser->parseFile(storage_path('app/public/aramex/' . $order['id'] . '.pdf'));
$text = $pdf->getText();
$destination = explode(' ', explode(PHP_EOL, $text) [3]) [0];
EndOfday::updateOrCreate(['order_id' => $order->id],
['date' => date('Y-m-d') ,
'type' => $payment,
'country' => $order->country,
'city' => $order->city,
'postcode' => (isset($order->zip_code)) ? $order->zip_code : "00",
'destination' => $destination,
'user_id' => $this->auth_id ]);
$br_code = BrCode::create(['br_code' => $result['track'], 'status' => 0]);
Note::create(['note' => 'This Order is Shipped By Aramex. Tracking: ' . $result['track'],
'order_id' => $order->id,
'user_id' => $this->auth_id ]);
$ordBr = Order::find($order->id)->update(['br_code_id' => $br_code->id]);
}
}
}
catch (\Throwable $th) {
$this->failed($th);
}
}
public function failed($exception)
{
dd($exception->getMessage());
}
}
解决方案
推荐阅读
- reactjs - 如何使用 REST API(React) 从 SharePoint 列表将图像上传到图像列
- powershell - PowerShell - 仅导入和拆分 csv 文件中的一列
- postgresql - 如果语句在 Postgresql 中使用提取日期
- html - Excel VBA 宏获取 HTML SPAN ID 值
- vue.js - 默认选中所有复选框
- java - Apache POI 仅在 Number 为十进制时才应用浮点格式
- delphi - 如何获取驱动器的 SHSTOCKICONID?
- android - Kotlin 替换字符串中的所有匹配表达式
- function - Julia 在调用之前覆盖函数
- android - Android - 在回收站视图 ListAdapter 上调用 notifyDataSetChanged()