Browse Source

merge haj mohammad

pull/6/head
mahdihty 4 years ago
parent
commit
804a96f77f
  1. 33
      app/Listeners/BusinessUpdateListener.php

33
app/Listeners/BusinessUpdateListener.php

@ -2,26 +2,10 @@
namespace App\Listeners; namespace App\Listeners;
use App\Models\User;
use App\Models\Business;
use Illuminate\Support\Arr;
<<<<<<< Updated upstream
use App\Channels\FcmChannel;
use App\Events\BusinessUpdate;
use App\Events\BusinessUserCreate;
use App\Notifications\DBNotification;
use App\Notifications\FcmNotification;
use App\Notifications\MailNotification;
use Illuminate\Queue\InteractsWithQueue;
=======
use App\Events\BusinessUpdate; use App\Events\BusinessUpdate;
use App\Events\BusinessUserCreate;
use App\Models\Business;
use App\Notifications\DBNotification; use App\Notifications\DBNotification;
use App\Notifications\MailNotification; use App\Notifications\MailNotification;
use Illuminate\Queue\InteractsWithQueue;
>>>>>>> Stashed changes
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Notification;
class BusinessUpdateListener class BusinessUpdateListener
@ -29,7 +13,6 @@ class BusinessUpdateListener
public function handle(BusinessUpdate $event) public function handle(BusinessUpdate $event)
{ {
$payload = $event->message; $payload = $event->message;
<<<<<<< Updated upstream
$business = Business::findOrFail($payload->business)->load('owners'); $business = Business::findOrFail($payload->business)->load('owners');
$this->checkWalletIsRunningLow($business); $this->checkWalletIsRunningLow($business);
@ -44,7 +27,7 @@ class BusinessUpdateListener
$hours = $moving_average_days * 24; $hours = $moving_average_days * 24;
$business->load([ $business->load([
'cost' => fn ($query) => $query->where('created_at', '>=', now('Asia/Tehran')->subHours($hours)),
'cost' => fn($query) => $query->where('created_at', '>=', now('Asia/Tehran')->subHours($hours)),
]); ]);
// The wallet is running out // The wallet is running out
@ -78,7 +61,7 @@ class BusinessUpdateListener
$recent_payments_number = 10; $recent_payments_number = 10;
$negativity_threshold = 20; $negativity_threshold = 20;
$business->load([ $business->load([
'transactions' => fn ($query) => $query->where('succeeded', '=', true)
'transactions' => fn($query) => $query->where('succeeded', '=', true)
->orderBy('created_at') ->orderBy('created_at')
->take($recent_payments_number), ->take($recent_payments_number),
]); ]);
@ -93,16 +76,6 @@ class BusinessUpdateListener
$business->update(['suspended_at' => now(),]); $business->update(['suspended_at' => now(),]);
Notification::send($business->owners, new MailNotification($message)); Notification::send($business->owners, new MailNotification($message));
Notification::send($business->owners, new DBNotification($message)); Notification::send($business->owners, new DBNotification($message));
=======
$wallet = $payload?->data?->diff?->wallet;
$owners = Business::findOrFail($payload->business)->owners;
$message = ['body' => 'Test'];
if ($wallet < 0) {
Notification::send($owners, new MailNotification($message));
Notification::send($owners, new DBNotification($message));
>>>>>>> Stashed changes
} }
} }
} }
Loading…
Cancel
Save