feat : rank
This commit is contained in:
77
app/Service/Admin/Statement/DriverService.php
Normal file
77
app/Service/Admin/Statement/DriverService.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?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\Site;
|
||||
use App\Model\SiteDriverStatement;
|
||||
use App\Service\Admin\BaseService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class DriverService extends BaseService
|
||||
{
|
||||
/**
|
||||
* @var SiteDriverStatement
|
||||
*/
|
||||
#[Inject]
|
||||
protected SiteDriverStatement $siteDriverStatementModel;
|
||||
|
||||
/**
|
||||
* @var Site
|
||||
*/
|
||||
#[Inject]
|
||||
protected Site $siteModel;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
$searchCityId = $this->request->input('search_city_id');
|
||||
$searchCycleId = $this->request->input('search_cycle_id');
|
||||
$searchDriverId = $this->request->input('search_driver_id');
|
||||
$limit = (int)$this->request->input('limit',10);
|
||||
|
||||
$list = $this->siteDriverStatementModel
|
||||
->when($searchCityId, function ($query) use ($searchCityId) {
|
||||
$query->whereIn('city_id', $searchCityId);
|
||||
})
|
||||
->when($searchDriverId, function ($query) use ($searchDriverId) {
|
||||
$query->where('driver_id', $searchDriverId);
|
||||
})
|
||||
->when($searchCycleId, function ($query) use ($searchCycleId) {
|
||||
$query->where('cycle_id', $searchCycleId);
|
||||
})
|
||||
->orderByDesc('cycle_id')
|
||||
->select(
|
||||
'date',
|
||||
'cycle_id',
|
||||
'site_id',
|
||||
'option_order_number',
|
||||
'option_copies',
|
||||
'option_add_staple_food_num',
|
||||
'meal_order_number',
|
||||
'meal_copies',
|
||||
'meal_add_staple_food_num'
|
||||
)
|
||||
->paginate($limit)
|
||||
->toArray();
|
||||
|
||||
if (empty($list['data'])) return $this->return->success('success', ['list' => []]);
|
||||
|
||||
$siteIds = array_column($list['data'], 'site_id');
|
||||
$siteList = $this->siteModel->whereIn('id', $siteIds)->pluck('name', 'id')->toArray();
|
||||
foreach ($list['data'] as &$v) {
|
||||
$v['site_name'] = $siteList[$v['site_id']] ?? '';
|
||||
}
|
||||
|
||||
return $this->return->success('success', ['list' => $list]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user