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' ); } }