众筹商品信息更新失败
这是 队列
[2018-12-10 11:50:06] Processing: App\Listeners\SendOrderPaidMail
[2018-12-10 11:50:06] Processing: App\Listeners\UpdateProductSoldCount
[2018-12-10 11:50:06] Processed: App\Listeners\UpdateProductSoldCount
[2018-12-10 11:50:07] Processed: App\Listeners\SendOrderPaidMail
这是EventServiceProvider.php
.
.
.
use App\Listeners\UpdateCrowdfundingProductProgress;
.
.
.
OrderPaid::class => [
UpdateProductSoldCount::class,
SendOrderPaidMail::class,
UpdateCrowdfundingProductProgress::class,
],
.
.
.
这是UpdateCrowdfundingProductProgress.php
<?php
namespace App\Listeners;
use App\Events\OrderPaid;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Models\Order;
class UpdateCrowdfundingProductProgress
{
public function handle(OrderPaid $event)
{
$order = $event->getOrder();
// 如果订单类型不是众筹商品订单,无需处理
if ($order->type !== Order::TYPE_CROWDFUNDING) {
return;
}
$crowdfunding = $order->items[0]->product->crowdfunding;
$data = Order::query()
// 查出订单类型为众筹订单
->where('type', Order::TYPE_CROWDFUNDING)
// 并且是已支付的
->whereNotNull('paid_at')
->whereHas('items', function ($query) use ($crowdfunding) {
// 并且包含了本商品
$query->where('product_id', $crowdfunding->product_id);
})
->first([
// 取出订单总金额
\DB::raw('sum(total_amount) as total_amount'),
// 取出去重的支持用户数
\DB::raw('count(distinct(user_id)) as user_count'),
]);
$crowdfunding->update([
'total_amount' => $data->total_amount,
'user_count' => $data->user_count,
]);
}
}
我的邮件设置的是MAIL_DRIVER=log
,测试回调前使用了php artisan config:clear
,同时重启了队列php artisan horizon
问题是 UpdateCrowdfundingProductProgress
这个监听并没有加入到队列中,订单的信息和支付邮件都发送成功了。不知道是为啥
推荐文章: