feat : caterer
This commit is contained in:
97
app/Service/Admin/System/CatererService.php
Normal file
97
app/Service/Admin/System/CatererService.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?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']);
|
||||
|
||||
if ($list->isEmpty()) return $this->return->success('success',['list' => []]);
|
||||
$list = $list->toArray();
|
||||
$kitchenIds = array_unique(array_column($list,'kitchen_id'));
|
||||
$kitchenList = $this->kitchenModel->getDataByIds($kitchenIds);
|
||||
$kitchenList = array_column($kitchenList,null,'id');
|
||||
|
||||
foreach ($list 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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user