97 lines
2.8 KiB
PHP
97 lines
2.8 KiB
PHP
<?php
|
|
/**
|
|
* This service file is part of item.
|
|
*
|
|
* @author ctexthuang
|
|
* @contact ctexthuang@qq.com
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Service\Admin\System;
|
|
|
|
use App\Constants\Admin\UserCode;
|
|
use App\Constants\Common\RoleCode;
|
|
use App\Exception\ErrException;
|
|
use App\Model\AdminUser;
|
|
use App\Model\Caterer;
|
|
use App\Model\Kitchen;
|
|
use App\Service\Admin\BaseService;
|
|
use Hyperf\Di\Annotation\Inject;
|
|
|
|
class CatererService extends BaseService
|
|
{
|
|
/**
|
|
* @var AdminUser
|
|
*/
|
|
#[Inject]
|
|
protected AdminUser $adminUserModel;
|
|
|
|
/**
|
|
* @var Kitchen
|
|
*/
|
|
#[Inject]
|
|
protected Kitchen $kitchenModel;
|
|
|
|
/**
|
|
* @var Caterer
|
|
*/
|
|
#[Inject]
|
|
protected Caterer $catererModel;
|
|
|
|
public function handle(): array
|
|
{
|
|
$cityId = (int)$this->request->input('city_id',0);
|
|
$limit = (int)$this->request->input('limit',10);
|
|
if (empty($cityId)) return $this->return->success('success',['list' => []]);
|
|
|
|
$list = $this
|
|
->catererModel
|
|
->leftJoin('admin_user', 'admin_user.id', '=', 'caterer.user_id')
|
|
->where('admin_user.is_del',UserCode::IS_NO_DEL)
|
|
->where('admin_user.status',UserCode::ENABLE)
|
|
->whereIn('admin_user.role_id',[RoleCode::MEAL_CATERING,RoleCode::OPTION_CATERING])
|
|
->where('admin_user.city_id', $cityId)
|
|
->paginate($limit,['admin_user.id','admin_user.chinese_name','caterer.kitchen_id','caterer.type','admin_user.role_id','admin_user.status'])
|
|
->toArray();
|
|
|
|
if (empty($list['data'])) return $this->return->success('success',['list' => []]);
|
|
$kitchenIds = array_unique(array_column($list['data'],'kitchen_id'));
|
|
$kitchenList = $this->kitchenModel->getDataByIds($kitchenIds);
|
|
$kitchenList = array_column($kitchenList,null,'id');
|
|
|
|
foreach ($list['data'] as &$item){
|
|
$item['kitchen_name'] = $kitchenList[$item['kitchen_id']]['name'] ?? '';
|
|
}
|
|
|
|
return $this->return->success('success',['list' => $list]);
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function catererList()
|
|
{
|
|
return $this->return->success('success',['list' => []]);
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function edit(): array
|
|
{
|
|
$userId = (int)$this->request->input('user_id');
|
|
$kitchenId = $this->request->input('kitchen_id');
|
|
|
|
$kitchenInfo = $this->kitchenModel->getInfoById($kitchenId);
|
|
if (empty($kitchenInfo)) throw new ErrException('该厨房信息为空');
|
|
|
|
$info = $this->catererModel->where('user_id',$userId)->first();
|
|
if (empty($info)) throw new ErrException('该用户信息为空');
|
|
|
|
$info->kitchen_id = $kitchenId;
|
|
if (!$info->save()) throw new ErrException('设置配餐信息失败');
|
|
|
|
return $this->return->success();
|
|
}
|
|
} |