Files
admin-php-module/commands/GETDiscountItems.php
miroman-afk 2d148e3eb5 v.2.15
Discounts block update
2022-04-28 23:55:53 +03:00

39 lines
1.3 KiB
PHP

<?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,
];
}
}