6 changed files with 139 additions and 1 deletions
-
19app/Controller/v3/GoodsController.php
-
42app/Middleware/Auth/UserMiddleware.php
-
56app/Service/v3/Implementations/GoodsService.php
-
8app/Service/v3/Interfaces/GoodsServiceInterface.php
-
1config/autoload/dependencies.php
-
14config/routes.php
@ -0,0 +1,19 @@ |
|||
<?php |
|||
|
|||
namespace App\Controller\v3; |
|||
|
|||
use App\Controller\BaseController; |
|||
use Hyperf\Di\Annotation\Inject; |
|||
use App\Service\v3\Interfaces\GoodsServiceInterface; |
|||
class GoodsController extends BaseController |
|||
{ |
|||
/** |
|||
* @Inject |
|||
* @var GoodsServiceInterface |
|||
*/ |
|||
protected $goods; |
|||
public function detail(){ |
|||
$res = $this->goods->detail(); |
|||
return $this->success($res); |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
<?php |
|||
|
|||
namespace App\Middleware\Auth; |
|||
|
|||
use Psr\Http\Message\ResponseInterface; |
|||
use Psr\Http\Message\ServerRequestInterface; |
|||
use Psr\Http\Server\MiddlewareInterface; |
|||
use Psr\Http\Server\RequestHandlerInterface; |
|||
|
|||
class UserMiddleware implements MiddlewareInterface |
|||
{ |
|||
|
|||
/** |
|||
* @inheritDoc |
|||
*/ |
|||
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
|||
{ |
|||
if (env('APP_ENV') == 'dev' || env('APP_ENV') == 'local') { |
|||
return $handler->handle($request); |
|||
} |
|||
|
|||
// 校验
|
|||
if (!$this->checkLogin()) { |
|||
|
|||
$content = [ |
|||
"status" => 'ok', |
|||
"code" => 9002, |
|||
"result" => [], |
|||
"message" => '用户登录已失效' |
|||
]; |
|||
|
|||
return $this->response->json($content); |
|||
} |
|||
|
|||
return $handler->handle($request); |
|||
} |
|||
|
|||
private function checkLogin() |
|||
{ |
|||
return true; |
|||
} |
|||
} |
|||
@ -0,0 +1,56 @@ |
|||
<?php |
|||
|
|||
namespace App\Service\v3\Implementations; |
|||
|
|||
use App\Service\v3\Interfaces\GoodsServiceInterface; |
|||
use Hyperf\DbConnection\Db; |
|||
|
|||
class GoodsService implements GoodsServiceInterface |
|||
{ |
|||
public function detail() |
|||
{ |
|||
/* |
|||
* 返回商品 封面图 |
|||
* * 返回商品 轮播图 |
|||
* 返回商品信息 包括名称 规格 tag等 |
|||
* 返回店铺信息 |
|||
* 返回商品规格信息 |
|||
* 猜你喜欢 |
|||
* 限时抢购 |
|||
* 为你推荐 |
|||
* */ |
|||
$goods['detail'] = Db::table('lanzu_goods')->where('id',170)->get(); |
|||
$goods['banner'] = $this->getBanner(); |
|||
$goods['spec'] = $this->getSpec(); |
|||
return $goods; |
|||
} |
|||
|
|||
public function getBanner() |
|||
{ |
|||
$banner = [ |
|||
[ |
|||
'id' => 1, |
|||
'type' => 1, |
|||
'path' => 'https://img.lanzu.vip/static/img/dic_banners/dic_banner_0.jpg' |
|||
], |
|||
[ |
|||
'id' => 2, |
|||
'type' => 1, |
|||
'path' => 'https://img.lanzu.vip/static/img/dic_banners/dic_banner_1.jpg' |
|||
] |
|||
]; |
|||
return $banner; |
|||
} |
|||
|
|||
public function getSpec() |
|||
{ |
|||
$spec = [ |
|||
[ |
|||
'净含量' => '约500G', |
|||
'保存条件' => '常温', |
|||
'保质期' => '10天' |
|||
] |
|||
]; |
|||
return $spec; |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
<?php |
|||
|
|||
namespace App\Service\v3\Interfaces; |
|||
|
|||
interface GoodsServiceInterface |
|||
{ |
|||
public function detail(); |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue