105 lines
3.1 KiB
PHP
105 lines
3.1 KiB
PHP
<?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\AdminUser;
|
|
use App\Model\ChefStatement;
|
|
use App\Model\Kitchen;
|
|
use App\Model\Sku;
|
|
use App\Service\Admin\BaseService;
|
|
use Hyperf\DbConnection\Db;
|
|
use Hyperf\Di\Annotation\Inject;
|
|
|
|
class ChefService extends BaseService
|
|
{
|
|
/**
|
|
* @var ChefStatement
|
|
*/
|
|
#[Inject]
|
|
protected ChefStatement $chefStatementModel;
|
|
|
|
/**
|
|
* @var Kitchen
|
|
*/
|
|
#[Inject]
|
|
protected Kitchen $kitchenModel;
|
|
|
|
/**
|
|
* @var AdminUser
|
|
*/
|
|
#[Inject]
|
|
protected AdminUser $adminUserModel;
|
|
|
|
/**
|
|
* @var Sku
|
|
*/
|
|
#[Inject]
|
|
protected Sku $skuModel;
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function handle(): array
|
|
{
|
|
$searchCityId = $this->request->input('search_city_id');
|
|
$searchKitchenId = $this->request->input('search_kitchen_id');
|
|
$searchCycleId = $this->request->input('search_cycle_id');
|
|
$searchChefId = $this->request->input('search_chef_id');
|
|
$limit = (int)$this->request->input('limit',10);
|
|
|
|
$list = $this->chefStatementModel
|
|
->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);
|
|
})
|
|
->when($searchChefId, function ($query) use ($searchChefId) {
|
|
$query->where('chef_id', $searchChefId);
|
|
})
|
|
->when($searchCycleId, function ($query) use ($searchCycleId) {
|
|
$query->where('cycle_id', $searchCycleId);
|
|
})
|
|
->orderByDesc('cycle_id')
|
|
->select(
|
|
'date',
|
|
'cycle_id',
|
|
'kitchen_id',
|
|
'chef_id',
|
|
'sku_id',
|
|
'sale',
|
|
'refund',
|
|
'cancel'
|
|
)
|
|
->paginate($limit)
|
|
->toArray();
|
|
|
|
if (empty($list['data'])) return $this->return->success('success', ['list' => []]);
|
|
|
|
$skuIds = array_column($list['data'], 'sku_id');
|
|
$chefIds = array_column($list['data'], 'chef_id');
|
|
$skuList = $this->skuModel->whereIn('id', $skuIds)->select('price','title','id')->get();
|
|
if ($skuList->isNotEmpty()) {
|
|
$skuList = array_column($skuList->toArray(), null,'id');
|
|
}
|
|
|
|
$chefList = $this->adminUserModel->getChefNameByIds($chefIds);
|
|
foreach ($list['data'] as &$v) {
|
|
$v['sku_title'] = $skuList[$v['sku_id']]['title'] ?? '';
|
|
$v['sku_price'] = $skuList[$v['sku_id']]['price'] ?? '0.00';
|
|
$v['total_price'] = bcmul($skuList[$v['sku_id']]['price'],(string)$v['sale'],2);
|
|
$v['chef_name'] = $chefList[$v['chef_id']] ?? '';
|
|
}
|
|
|
|
return $this->return->success('success', ['list' => $list]);
|
|
}
|
|
} |