v.2.15
Discounts block update
This commit is contained in:
39
commands/GETDiscountItems.php
Normal file
39
commands/GETDiscountItems.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\Dishes;
|
||||
use App\Component\Models\ShiftOnlineItems;
|
||||
use App\Component\Models\ShiftOnlineOrders;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class GETDiscountItems extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'getdiscountitems';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
$orderId = $input['order'] + 0;
|
||||
$items = [];
|
||||
$order = ShiftOnlineOrders::where('code', $orderId)->first();
|
||||
$onlineItems = ShiftOnlineItems::where('order_code', $order['code'])->where('modificator_code', 0)->get();
|
||||
foreach ($onlineItems as $key => $item) {
|
||||
$realPrice = $item['real_price'] * $item['count'] * $item['cof'];
|
||||
$salePrice = $item['sale_price'] * $item['count'];
|
||||
if ($realPrice > 0) {
|
||||
$discount = $salePrice / $realPrice;
|
||||
$discount = (1 - $discount) * 100;
|
||||
} else {
|
||||
$discount = 0;
|
||||
}
|
||||
$dish = Dishes::where('code', $item['dish_code'])->where('is_history', 0)->first();
|
||||
$items[] = array('name' => $dish['name'], 'discount' => round($discount, 0), 'count' => $item['count'], 'sale_price' => $salePrice, 'sum' => round($realPrice, 2));
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => 'success',
|
||||
'title' => $order['code'],
|
||||
'total' => $order['order_sum'],
|
||||
'items' => $items,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user