feat : chef

This commit is contained in:
2025-03-24 17:52:08 +08:00
parent 86248751bd
commit 6d66843c38
2 changed files with 95 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace App\Controller\Api;
use App\Middleware\Api\JwtAuthMiddleware;
use App\Service\Api\Chef\IndexService;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\Validation\Annotation\Scene;
#[Controller(prefix: 'api/chef')]
#[Middlewares([
JwtAuthMiddleware::class,
])]
class ChefController
{
/**
* @return array
*/
#[RequestMapping(path: "index", methods: "GET")]
#[Scene(scene: "index")]
public function index(): array
{
return (new IndexService)->handle();
}
}

View File

@@ -0,0 +1,66 @@
<?php
/**
* This service file is part of item.
*
* @author ctexthuang
* @contact ctexthuang@qq.com
*/
declare(strict_types=1);
namespace App\Service\Api\Chef;
use App\Exception\ErrException;
use App\Model\AdminUser;
use App\Model\Chef;
use App\Service\Api\BaseService;
use App\Service\ServiceTrait\Common\OssTrait;
use Hyperf\Di\Annotation\Inject;
class IndexService extends BaseService
{
use OssTrait;
/**
* @var AdminUser
*/
#[Inject]
protected AdminUser $adminUserModel;
/**
* @var Chef
*/
#[Inject]
protected Chef $chefModel;
/**
* @return array
*/
public function handle(): array
{
$chefId = $this->request->input('chef_id');
$chef = $this->chefModel
->leftJoin('admin_user', 'admin_user.id', '=', 'chef.user_id')
->where('chef.user_id', $chefId)
->select([
'admin_user.id',
'admin_user.username',
'admin_user.avatar',
'admin_user.chinese_name',
'chef.profile',
'chef.specialties',
])
->first();
if (empty($chef)) throw new ErrException('厨师不存在');
$avatarUrl = $this->getOssObjectById($chef->avatar);
$res = $chef->toArray();
$res['avatar_url'] = $avatarUrl;
// todo 评价补全
return $this->return->success('success', $res);
}
}