feat : caterer
This commit is contained in:
53
app/Controller/Admin/CatererController.php
Normal file
53
app/Controller/Admin/CatererController.php
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Controller\Admin;
|
||||||
|
|
||||||
|
use App\Middleware\Admin\JwtAuthMiddleware;
|
||||||
|
use App\Service\Admin\System\CatererService;
|
||||||
|
use Hyperf\HttpServer\Annotation\Controller;
|
||||||
|
use Hyperf\HttpServer\Annotation\Middlewares;
|
||||||
|
use Hyperf\HttpServer\Annotation\RequestMapping;
|
||||||
|
use Hyperf\Validation\Annotation\Scene;
|
||||||
|
|
||||||
|
#[Controller(prefix: "admin/caterer")]
|
||||||
|
#[Middlewares([
|
||||||
|
JwtAuthMiddleware::class,
|
||||||
|
])]
|
||||||
|
class CatererController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 配餐列表
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
#[RequestMapping(path: "caterer_list", methods: "GET")]
|
||||||
|
#[Scene(scene: "caterer_list")]
|
||||||
|
public function catererList()
|
||||||
|
{
|
||||||
|
//todo
|
||||||
|
return (new CatererService)->catererList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配餐详细列表
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
#[RequestMapping(path: "caterer_detail_list", methods: "GET")]
|
||||||
|
#[Scene(scene: "caterer_detail_list")]
|
||||||
|
public function catererDetailList()
|
||||||
|
{
|
||||||
|
return (new CatererService)->handle();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置配餐数据
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
#[RequestMapping(path: "setting_caterer", methods: "POST")]
|
||||||
|
#[Scene(scene: "setting_caterer")]
|
||||||
|
public function settingCaterer()
|
||||||
|
{
|
||||||
|
return (new CatererService)->edit();
|
||||||
|
}
|
||||||
|
}
|
||||||
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