v.2.15
Discounts block update
This commit is contained in:
43
commands/GETOnlineDiscount.php
Normal file
43
commands/GETOnlineDiscount.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\ShiftOnlineItems;
|
||||
use App\Component\Models\ShiftOnlineOrders;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class GETOnlineDiscount extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'getonlinediscount';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
$count = $totalSum = $discountSum = 0;
|
||||
$count = ShiftOnlineOrders::where('is_deleted', 0)
|
||||
->where('is_returned', 0)
|
||||
->where('sale_sum', '>', 0)
|
||||
->count();
|
||||
if ($count > 0) {
|
||||
$totalSum = ShiftOnlineOrders::where('is_deleted', 0)
|
||||
->where('is_returned', 0)
|
||||
->where('sale_sum', '>', 0)
|
||||
->sum('order_sum');
|
||||
$orders = ShiftOnlineOrders::where('is_deleted', 0)
|
||||
->where('is_returned', 0)->get();
|
||||
foreach ($orders as $key => $order) {
|
||||
$items = ShiftOnlineItems::where('order_code', $order['code'])->get();
|
||||
foreach ($items as $key => $item) {
|
||||
$realPrice = $item['real_price'] * $item['count'] * $item['cof'];
|
||||
$salePrice = $item['sale_price'] * $item['count'];
|
||||
$discountSum = round(($discountSum + abs($salePrice - $realPrice)), 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => 'success',
|
||||
'count' => $count,
|
||||
'sum' => $discountSum,
|
||||
'total_sum' => $totalSum,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user