feat : chef
This commit is contained in:
29
app/Controller/Api/ChefController.php
Normal file
29
app/Controller/Api/ChefController.php
Normal 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();
|
||||
}
|
||||
}
|
||||
66
app/Service/Api/Chef/IndexService.php
Normal file
66
app/Service/Api/Chef/IndexService.php
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user