Browse Source

Merge pull request 'nima' (#4) from nima into master

Reviewed-on: #4
masoud
dizox 4 years ago
parent
commit
deb78d4fab
  1. 1
      app/Listeners/BusinessUpdateListener.php
  2. 5
      app/Models/Business.php
  3. 5
      database/migrations/2020_08_18_085018_create_businesses_table.php
  4. 26
      routes/console.php

1
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));
=======

5
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',
];

5
database/migrations/2020_08_18_085018_create_businesses_table.php

@ -1,8 +1,8 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateBusinessesTable extends Migration
{
@ -26,6 +26,7 @@ class CreateBusinessesTable extends Migration
$table->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();
});

26
routes/console.php

@ -1,19 +1,15 @@
<?php
use Illuminate\Foundation\Inspiring;
use App\Models\Business;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Artisan;
/*
|--------------------------------------------------------------------------
| Console Routes
|--------------------------------------------------------------------------
|
| This file is where you may define all of your Closure based console
| commands. Each Closure is bound to a command instance allowing a
| simple approach to interacting with each command's IO methods.
|
*/
Artisan::command('inspire', function () {
$this->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');
Loading…
Cancel
Save