Browse Source

商品详情初始化

master
Lemon 6 years ago
parent
commit
2454a4f99f
  1. 19
      app/Controller/v3/GoodsController.php
  2. 42
      app/Middleware/Auth/UserMiddleware.php
  3. 56
      app/Service/v3/Implementations/GoodsService.php
  4. 8
      app/Service/v3/Interfaces/GoodsServiceInterface.php
  5. 1
      config/autoload/dependencies.php
  6. 14
      config/routes.php

19
app/Controller/v3/GoodsController.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);
}
}

42
app/Middleware/Auth/UserMiddleware.php

@ -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;
}
}

56
app/Service/v3/Implementations/GoodsService.php

@ -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;
}
}

8
app/Service/v3/Interfaces/GoodsServiceInterface.php

@ -0,0 +1,8 @@
<?php
namespace App\Service\v3\Interfaces;
interface GoodsServiceInterface
{
public function detail();
}

1
config/autoload/dependencies.php

@ -35,4 +35,5 @@ return [
\App\Service\WxRefundServiceInterface::class => \App\Service\WxRefundService::class,
\App\Service\SmsServiceInterface::class => \App\Service\SmsAliService::class,
\App\Service\OrderListServiceInterface::class => \App\Service\OrderListService::class,
\App\Service\v3\Interfaces\GoodsServiceInterface::class => \App\Service\v3\Implementations\GoodsService::class,
];

14
config/routes.php

@ -73,4 +73,16 @@ Router::addGroup('/wechat/',function () {
Router::post('notify/wxminionline', 'App\Controller\NotifyController@wxminiOnline');
Router::post('notify/wxminioffline', 'App\Controller\NotifyController@wxminiOffline');
Router::post('notify/wxpayrefund', 'App\Controller\NotifyPayRefundController@wxPayRefund');
});
});
// 不需要登录的路由
Router::addGroup('/v3/', function () {
Router::post('location/getNearestMarket', 'App\Controller\v3\LocationController@getNearestMarket');
Router::post('home/appletIndex', 'App\Controller\v3\HomeController@appletIndex');
Router::post('Goods/detail', 'App\Controller\v3\GoodsController@detail');
},['middleware' => [\App\Middleware\Auth\ApiMiddleware::class]]);
// 需要登录的路由
Router::addGroup('/v3/', function () {
},['middleware' => [\App\Middleware\Auth\ApiMiddleware::class, \App\Middleware\Auth\UserMiddleware::class]]);
Loading…
Cancel
Save