feat : rank
This commit is contained in:
69
app/Service/Admin/Statement/FinancesService.php
Normal file
69
app/Service/Admin/Statement/FinancesService.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\Statement;
|
||||
|
||||
use App\Model\FinancesStatement;
|
||||
use App\Model\Kitchen;
|
||||
use App\Service\Admin\BaseService;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class FinancesService extends BaseService
|
||||
{
|
||||
/**
|
||||
* @var FinancesStatement
|
||||
*/
|
||||
#[Inject]
|
||||
protected FinancesStatement $financesStatementModel;
|
||||
|
||||
/**
|
||||
* @var Kitchen
|
||||
*/
|
||||
#[Inject]
|
||||
protected Kitchen $kitchenModel;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
$searchCityId = $this->request->input('search_city_id');
|
||||
$searchKitchenId = $this->request->input('search_kitchen_id');
|
||||
$limit = (int)$this->request->input('limit',10);
|
||||
|
||||
$list = $this->financesStatementModel
|
||||
->when($searchCityId, function ($query) use ($searchCityId) {
|
||||
$kitchenIds = $this->kitchenModel->where('city_id', $searchCityId)->pluck('id')->toArray();
|
||||
$query->whereIn('kitchen_id', $kitchenIds);
|
||||
})
|
||||
->when($searchKitchenId, function ($query) use ($searchKitchenId) {
|
||||
$query->where('kitchen_id', $searchKitchenId);
|
||||
})
|
||||
->groupBy('cycle_id')
|
||||
->orderByDesc('cycle_id')
|
||||
->select(
|
||||
'date',
|
||||
'cycle_id',
|
||||
// 'kitchen_id',
|
||||
Db::raw('SUM(`gross_sales`) as gross_sales'),
|
||||
Db::raw('SUM(`discounts`) as discounts'),
|
||||
Db::raw('SUM(`net_sales`) as net_sales'),
|
||||
Db::raw('SUM(`option_order_number`) as option_order_number'),
|
||||
Db::raw('SUM(`option_copies`) as option_copies'),
|
||||
Db::raw('SUM(`meal_order_number`) as meal_order_number'),
|
||||
Db::raw('SUM(`meal_copies`) as meal_copies'),
|
||||
)
|
||||
->paginate($limit)
|
||||
->toArray();
|
||||
|
||||
return $this->return->success('success', ['list' => $list]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user