Update api requests
This commit is contained in:
70
commands/TopDishes.php
Normal file
70
commands/TopDishes.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use App\Component\Models\Dishes;
|
||||
use App\Component\Models\OnlineItems;
|
||||
use App\Console\Commands\HRCCommand;
|
||||
use App\Console\Commands\HRCCommandInterface;
|
||||
|
||||
class TopDishes extends HRCCommand implements HRCCommandInterface {
|
||||
protected $signature = 'gettopdishes';
|
||||
|
||||
public function command($input, $output = null) {
|
||||
|
||||
$info = OnlineItems::where('menu_code', '>', 0)->get()->unique('menu_code');
|
||||
$count = OnlineItems::where('menu_code', '>', 0)->count();
|
||||
if ($count > 0) {
|
||||
foreach ($info as $key => $value) {
|
||||
$out[] = $value;
|
||||
}
|
||||
foreach ($out as $key => $item) {
|
||||
$dishInfo = Dishes::select('name')
|
||||
->where('code', '=', $item['menu_code'])
|
||||
->where('legacy_code', '=', $item['dish_code'])
|
||||
->where('is_history', '=', 0)
|
||||
->get();
|
||||
$onlineDishInfo = OnlineItems::select('real_price', 'sale_price', 'special_price')
|
||||
->where('menu_code', '=', $item['menu_code'])
|
||||
->where('dish_code', '=', $item['dish_code'])
|
||||
->get();
|
||||
$dishName = $dishInfo[0]->name;
|
||||
$dishCount = OnlineItems::where('menu_code', '=', $item['menu_code'])->sum('count');
|
||||
$dishSum = $onlineDishInfo[0]->real_price * $dishCount;
|
||||
if ($dishSum > 0) {
|
||||
$dishTotalCost = round(($onlineDishInfo[0]->special_price * $dishCount), 2);
|
||||
$dishPercent = round((100 - ((($dishSum - $dishTotalCost) * 100) / $dishSum)), 2);
|
||||
$dishProfit = $dishSum - $dishTotalCost;
|
||||
} else {
|
||||
$dishTotalCost = 0;
|
||||
$dishPercent = 0;
|
||||
$dishProfit = 0;
|
||||
}
|
||||
$dishes[] = array('name' => $dishName, 'count' => $dishCount, 'sum' => $dishSum, 'totalCost' => $dishTotalCost, 'percentProffit' => $dishPercent, 'proffit' => $dishProfit);
|
||||
}
|
||||
for ($i = 0; $i < count($dishes); $i++) {
|
||||
$sortkey[$i] = $dishes[$i]['count'];
|
||||
}
|
||||
arsort($sortkey);
|
||||
foreach ($sortkey as $key => $key) {
|
||||
$sorted[] = $dishes[$key];
|
||||
}
|
||||
$sorted = array_slice($sorted, 0, 10);
|
||||
return [
|
||||
'status' => 'success',
|
||||
'dishes' => $sorted,
|
||||
// 'info' => $info,
|
||||
// 'test' => $dishes,
|
||||
// 'count' => $dishCount,
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
'status' => 'success',
|
||||
'dishes' => [],
|
||||
// 'info' => $info,
|
||||
// 'test' => $dishes,
|
||||
// 'count' => $dishCount,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user