39 lines
1.3 KiB
PHP
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::getName($item['menu_code']);
|
|
$items[] = array('name' => $dish, '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,
|
|
];
|
|
}
|
|
} |