You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.5 KiB
74 lines
2.5 KiB
<?php
|
|
|
|
namespace App\Listeners;
|
|
|
|
use App\Common\OrderStatus;
|
|
use App\Events\OrderUpdated;
|
|
use App\Models\Agent;
|
|
use App\Models\OrderProductItem;
|
|
use App\Models\Supplier;
|
|
use App\Service\SmsService;
|
|
use App\Traits\SmsTraits;
|
|
|
|
class OrderEventSubscriber
|
|
{
|
|
public function onOrderUpdated($event)
|
|
{
|
|
if (env('SMS_SWITCH', '') == true) {
|
|
$order = $event->order;
|
|
$sms = new SmsService();
|
|
//退款通知
|
|
if ($order->isDirty('status') && $order->status == OrderStatus::REFUNDING) {
|
|
$mobile = Agent::query()->where('id',$order->agent_id)->value('contact_mobile');
|
|
$sms->send('refund', [$order->order_no, SmsTraits::$systeaNameText['agent']], [$mobile]);
|
|
}
|
|
|
|
//付款通知
|
|
if ($order->isDirty('status') && ($order->status == OrderStatus::PAY_EARNEST || $order->status == OrderStatus::PAID)) {
|
|
//通知代理商
|
|
$mobile = Agent::query()->where('id',$order->agent_id)->value('contact_mobile');
|
|
if (!empty($mobile)) {
|
|
$sms->send('order', [$order->order_no, SmsTraits::$systeaNameText['agent']], [$mobile]);
|
|
}
|
|
//通知供应商
|
|
$supplierIds = OrderProductItem::query()->with('supplier')->where('order_id', $order->id)->distinct()->pluck('supplier_id');
|
|
$phone = Supplier::query()->whereIn('id', $supplierIds)->pluck('contact_mobile')->toArray();
|
|
if (!empty($phone)) {
|
|
$sms->send('order', [$order->order_no, SmsTraits::$systeaNameText['supplier']], $phone);//供应商
|
|
}
|
|
}
|
|
|
|
//核销
|
|
if ($order->isDirty('status') && $order->status == OrderStatus::SUCCESS) {
|
|
//通知用户
|
|
if (!empty($order->mobile)) {
|
|
$sms->send('verify', [$order->order_no, SmsTraits::$systeaNameText['user']], [$order->mobile]);//用户
|
|
}
|
|
//通知供应商
|
|
$supplierIds = OrderProductItem::query()->with('supplier')->where('order_id', $order->id)->distinct()->pluck('supplier_id');
|
|
$phone = Supplier::query()->whereIn('id', $supplierIds)->pluck('contact_mobile')->toArray();
|
|
if(!empty($phone)) {
|
|
$sms->send('verify', [$order->order_no, SmsTraits::$systeaNameText['supplier']], $phone);//供应商
|
|
}
|
|
//通知代理商
|
|
$mobile = Agent::query()->where('id',$order->agent_id)->value('contact_mobile');
|
|
if (!empty($mobile)) {
|
|
$sms->send('verify', [$order->order_no, SmsTraits::$systeaNameText['agent']], [$mobile]);//代理商
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 为订阅者注册监听器
|
|
*
|
|
* @param Illuminate\Events\Dispatcher $events
|
|
*/
|
|
public function subscribe($events)
|
|
{
|
|
$events->listen(
|
|
OrderUpdated::class,
|
|
OrderEventSubscriber::class . '@onOrderUpdated'
|
|
);
|
|
}
|
|
}
|