96 lines
3.1 KiB
PHP
96 lines
3.1 KiB
PHP
<?php
|
||
|
||
namespace App\Commands;
|
||
|
||
use App\Component\Models\Dishes;
|
||
use App\Component\Models\ShiftOnlineItems;
|
||
use App\Component\Models\ShiftOnlineOrders;
|
||
use App\Component\Models\Staff;
|
||
use App\Console\Commands\HRCCommand;
|
||
use App\Console\Commands\HRCCommandInterface;
|
||
|
||
class GETOnlineStaff extends HRCCommand implements HRCCommandInterface {
|
||
protected $signature = 'getonlinestaff';
|
||
|
||
public function command($input, $output = null) {
|
||
function staffName($data) {
|
||
$staff_name = Staff::where('code', $data)->where('is_history', 0)->first();
|
||
if ($staff_name) {
|
||
$staff_name = $staff_name['name'];
|
||
} else {
|
||
$staff_name = Staff::where('code', $data)->where('is_history', 1)->first();
|
||
if ($staff_name) {
|
||
$staff_name = $staff_name['name'];
|
||
} else {
|
||
$staff_name = 'Связанный персонал не найден';
|
||
}
|
||
}
|
||
return $staff_name;
|
||
}
|
||
if ($input['method'] == 'dashboard') {
|
||
$staff_data = [];
|
||
$staffs = ShiftOnlineOrders::select('who_open')
|
||
->where('is_deleted', 0)
|
||
->where('is_returned', 0)
|
||
->where('order_sum', '>', 0)
|
||
->groupBy('who_open')
|
||
->get();
|
||
foreach ($staffs as $key => $staff) {
|
||
$count = ShiftOnlineOrders::where('who_open', $staff['who_open'])
|
||
->where('is_deleted', 0)
|
||
->where('is_returned', 0)
|
||
->where('order_sum', '>', 0)
|
||
->count();
|
||
$name = staffName($staff['who_open']);
|
||
$code = $staff['who_open'];
|
||
$sum = ShiftOnlineOrders::where('who_open', $staff['who_open'])
|
||
->where('is_deleted', 0)
|
||
->where('is_returned', 0)
|
||
->where('order_sum', '>', 0)
|
||
->sum('order_sum');
|
||
$staff_data[] = array('name' => $name, 'code' => $code + 0, 'orders_count' => $count + 0, 'orders_sum' => $sum + 0);
|
||
}
|
||
|
||
return [
|
||
'status' => 'success',
|
||
'staff' => $staff_data,
|
||
];
|
||
}
|
||
if ($input['method'] == 'items') {
|
||
if (isset($input['order'])) {
|
||
$orderId = $input['order'] + 0;
|
||
$items = [];
|
||
$order = ShiftOnlineOrders::where('code', $orderId)->first();
|
||
$who_open = staffName($order['who_open']);
|
||
$who_close = staffName($order['who_close']);
|
||
$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));
|
||
}
|
||
} else {
|
||
return [
|
||
'status' => 'success',
|
||
'message' => 'Проверьте введенные данные',
|
||
];
|
||
}
|
||
return [
|
||
'status' => 'success',
|
||
'who_open' => $who_open,
|
||
'who_close' => $who_close,
|
||
'title' => 'Подробнее о заказе №' . $order['code'],
|
||
'total' => $order['order_sum'],
|
||
'items' => $items,
|
||
];
|
||
}
|
||
|
||
}
|
||
} |