diff --git a/app/Listeners/BusinessUpdateListener.php b/app/Listeners/BusinessUpdateListener.php index f292847..6378197 100644 --- a/app/Listeners/BusinessUpdateListener.php +++ b/app/Listeners/BusinessUpdateListener.php @@ -90,6 +90,7 @@ class BusinessUpdateListener $threshold = $average_payment / 100 * $negativity_threshold; $message = ['body' => __('notification.business.suspended')]; if ($business->wallet < $threshold) { + $business->update(['suspended_at' => now(),]); Notification::send($business->owners, new MailNotification($message)); Notification::send($business->owners, new DBNotification($message)); ======= diff --git a/app/Models/Business.php b/app/Models/Business.php index ad38198..80e869f 100644 --- a/app/Models/Business.php +++ b/app/Models/Business.php @@ -5,10 +5,10 @@ namespace App\Models; use App\Models\File; use App\Models\Model; use App\Models\SoftDeletes; -use App\Models\ReportableRelation; use Illuminate\Validation\Rule; use Illuminate\Http\UploadedFile; use Spatie\MediaLibrary\HasMedia; +use App\Models\ReportableRelation; use Illuminate\Support\Facades\Cache; use Spatie\MediaLibrary\InteractsWithMedia; use Spatie\MediaLibrary\MediaCollections\Models\Media; @@ -27,7 +27,7 @@ class Business extends Model implements HasMedia protected $table = 'businesses'; - protected $fillable = ['name', 'slug', 'wallet','files_volume','cache', 'color', 'description', 'has_avatar', 'calculated_at', 'users']; + protected $fillable = ['name', 'slug', 'wallet','files_volume','cache', 'color', 'description', 'has_avatar', 'calculated_at', 'suspended_at', 'users']; protected $fillable_relations = [ 'users' @@ -43,6 +43,7 @@ class Business extends Model implements HasMedia protected $casts = [ 'has_avatar' => 'boolean', 'calculated_at' => 'datetime', + 'suspended_at' => 'datetime', 'wallet' => 'integer', ]; diff --git a/database/migrations/2020_08_18_085018_create_businesses_table.php b/database/migrations/2020_08_18_085018_create_businesses_table.php index b0d168f..3c4dda5 100644 --- a/database/migrations/2020_08_18_085018_create_businesses_table.php +++ b/database/migrations/2020_08_18_085018_create_businesses_table.php @@ -1,8 +1,8 @@ timestamp('calculated_at')->nullable()->index(); $table->timestamp('created_at')->nullable(); $table->timestamp('updated_at')->nullable(); + $table->timestamp('suspended_at')->nullable(); $table->timestamp('deleted_at')->nullable(); }); diff --git a/routes/console.php b/routes/console.php index e05f4c9..d548d65 100644 --- a/routes/console.php +++ b/routes/console.php @@ -1,19 +1,15 @@ comment(Inspiring::quote()); -})->purpose('Display an inspiring quote'); +Artisan::command('business:reset', function () { + Business::first()->update([ + 'wallet' => 10000, + 'calculated_at' => now()->subMonth(2), + ]); + $this->call('cache:clear'); + DB::statement('TRUNCATE TABLE `costs` '); + DB::statement('TRUNCATE TABLE `notifications`'); +})->purpose('Reset the businesses after test cost:work');