write me a warner
This commit is contained in:
@@ -18,6 +18,9 @@ class Kernel extends ConsoleKernel
|
||||
|
||||
// Remove non saved attachments...
|
||||
$schedule->call(new PruneStaleAttachments)->daily();
|
||||
|
||||
// IF any warnings unresolved warnings exists, send notify me
|
||||
$schedule->call(new WarnDev)->dailyAt('16:00');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
25
app/Console/WarnDev.php
Normal file
25
app/Console/WarnDev.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use App\Models\System\Warning;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class WarnDev extends Command
|
||||
{
|
||||
/**
|
||||
* Notify me if any unresolved warnings exists
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __invoke()
|
||||
{
|
||||
$warnings = Warning::whereNull('resolved_at')->get();
|
||||
|
||||
if ($warnings->isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
sendSMS('61929248', 'Warnings: '.$warnings->count());
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
use App\Models\Auth\Verification;
|
||||
use App\Models\Ecommerce\Channel\Channel;
|
||||
use App\Models\Ecommerce\Product\Inventory\Inventory;
|
||||
use App\Models\System\Warning;
|
||||
use App\Repositories\Ecommerce\Product\Barcode\BarcodeRepository;
|
||||
use Illuminate\Http\Client\PendingRequest;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -388,3 +389,16 @@ function createHalkbankOrder($price = 123): array
|
||||
'url' => $paymentResponse['formUrl'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Warn brother
|
||||
*/
|
||||
function warn(string $message, string $content = '', string $where = '', string $notes = ''): void
|
||||
{
|
||||
Warning::forceCreate([
|
||||
'name' => $message,
|
||||
'content' => $content,
|
||||
'where' => $where,
|
||||
'notes' => $notes,
|
||||
]);
|
||||
}
|
||||
@@ -41,10 +41,24 @@ class CreateOrderService
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
// Update Stock
|
||||
// Update Stock directly in products table, also relationship
|
||||
$stock = $cart->product->stock - $cart->product_quantity;
|
||||
$cart->product->update([
|
||||
'stock' => $cart->product->stock - $cart->product_quantity,
|
||||
'stock' => $stock,
|
||||
]);
|
||||
|
||||
$data = DB::table('inventory_product')->where('product_id', $cart->product_id)->first();
|
||||
if ($data) {
|
||||
DB::table('inventory_product')->where('id', $data->id)->update([
|
||||
'stock' => $stock,
|
||||
]);
|
||||
} else {
|
||||
warn('Product has no inventory record', json_encode([
|
||||
'product_id' => $cart->product_id,
|
||||
'order_id' => $order->id,
|
||||
]));
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// 3. Clear User Cart
|
||||
|
||||
@@ -13,6 +13,7 @@ use Database\Seeders\New\ProductPricesSeeder;
|
||||
use Database\Seeders\New\ProductPropertiesSeeder;
|
||||
use Database\Seeders\New\ProductPropertyValuesSeeder;
|
||||
use Database\Seeders\New\ProductsTableSeeder;
|
||||
use Database\Seeders\New\ProductStocksSeeder;
|
||||
use Database\Seeders\New\PropertiesTableSeeder;
|
||||
use Database\Seeders\New\SectionsSeeder;
|
||||
use Database\Seeders\New\SellersTableSeeder;
|
||||
@@ -44,6 +45,7 @@ class DatabaseSeeder extends Seeder
|
||||
// ProductBarcodesSeeder::class,
|
||||
// ProductPropertiesSeeder::class,
|
||||
// ProductPropertyValuesSeeder::class,
|
||||
ProductStocksSeeder::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
34
database/seeders/new/ProductStocksSeeder.php
Normal file
34
database/seeders/new/ProductStocksSeeder.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders\New;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use JsonMachine\Items;
|
||||
use JsonMachine\JsonDecoder\ExtJsonDecoder;
|
||||
|
||||
class ProductStocksSeeder extends Seeder
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
//
|
||||
// DB::transaction(function () {
|
||||
// $table = 'products';
|
||||
|
||||
// DB::table($table)->truncate();
|
||||
|
||||
// $items = Items::fromFile(
|
||||
// database_path('data/items.json'),
|
||||
// ['decoder' => new ExtJsonDecoder(true)]
|
||||
// );
|
||||
|
||||
// foreach ($items as $data) {
|
||||
// DB::table($table)->insert([]);
|
||||
// }
|
||||
|
||||
// DB::statement("
|
||||
// SELECT setval('{$table}_id_seq', (SELECT MAX(id) from {$table}))
|
||||
// ");
|
||||
// });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user