From a1553dbfb6bc932c5bf798a27efbd86fc0ed8b0d Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Sat, 5 Sep 2020 11:18:46 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E5=95=86=E5=93=81=E4=B8=8D?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E5=BA=97=E9=93=BA=E9=97=AE=E9=A2=98=20?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E8=B4=AD=E7=89=A9=E8=BD=A6=E6=80=BB=E4=BB=B7?= =?UTF-8?q?=20=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/v3/GoodsController.php | 13 +++++++++++-- app/Model/v3/GoodsActivity.php | 8 ++++---- .../v3/Implementations/GoodsActivityService.php | 9 +++++++-- app/Service/v3/Implementations/GoodsService.php | 9 +++++++-- app/Service/v3/Implementations/ShopCartService.php | 6 ++++++ .../v3/Interfaces/GoodsActivityServiceInterface.php | 1 + .../v3/Interfaces/ShopCartServiceInterface.php | 2 ++ 7 files changed, 38 insertions(+), 10 deletions(-) diff --git a/app/Controller/v3/GoodsController.php b/app/Controller/v3/GoodsController.php index 7e647e7..4f620f8 100644 --- a/app/Controller/v3/GoodsController.php +++ b/app/Controller/v3/GoodsController.php @@ -3,6 +3,7 @@ namespace App\Controller\v3; use App\Controller\BaseController; +use App\Service\v3\Interfaces\ShopCartServiceInterface; use App\Service\v3\Implementations\GoodsActivityService; use App\Service\v3\Interfaces\CollectStoreServiceInterface; use Hyperf\Di\Annotation\Inject; @@ -29,18 +30,26 @@ class GoodsController extends BaseController */ protected $collectService; + /** + * @Inject + * @var ShopCartServiceInterface + */ + protected $shopCartService; + public function detail() { $params = $this->request->all(); //判断是普通商品还是特价商品 if(isset($params['activity']) && $params['activity'] == Goods::IS_ACTIVITY){ - $res['detail'] = $this->goodsActivityService->do($params['goods_id']); + $res['detail'] = $this->goodsActivityService->detail($params['goods_id']); $res['banner'] = $this->goodsActivityService->getBanner(); }else{ - $res['detail'] = $this->goodsService->do($params['goods_id']); + $res['detail'] = $this->goodsService->detail($params['goods_id']); $res['banner'] = $this->goodsService->getBanner(); } if(isset($params['user_id'])) { + $res['shopcart']['check'] = $this->shopCartService->check(111); + $res['shopcart']['total'] = $this->shopCartService->getTotal(); $res['detail']->store->is_collected = (bool)$this->collectService->check($params['user_id'], $params['store_id']); }else{ $res['detail']->store->is_collected = ''; diff --git a/app/Model/v3/GoodsActivity.php b/app/Model/v3/GoodsActivity.php index b7b3bf9..ccff8c3 100644 --- a/app/Model/v3/GoodsActivity.php +++ b/app/Model/v3/GoodsActivity.php @@ -39,10 +39,10 @@ class GoodsActivity extends Model 'total_seconds', ]; - protected $visible = [ - 'id', 'cover_img', 'name', 'original_price', 'price', 'inventory', 'store_id', 'spec', 'tags', 'sales', - 'month_sales', 'cart_num', 'is_effective', 'noneffective_note', 'total_seconds', - ]; + // protected $visible = [ + // 'id', 'cover_img', 'name', 'original_price', 'price', 'inventory', 'store_id', 'spec', 'tags', 'sales', + // 'month_sales', 'cart_num', 'is_effective', 'noneffective_note', 'total_seconds','store_id' + // ]; protected function boot(): void { diff --git a/app/Service/v3/Implementations/GoodsActivityService.php b/app/Service/v3/Implementations/GoodsActivityService.php index 8938dd7..c83dfc1 100644 --- a/app/Service/v3/Implementations/GoodsActivityService.php +++ b/app/Service/v3/Implementations/GoodsActivityService.php @@ -12,8 +12,7 @@ class GoodsActivityService implements GoodsActivityServiceInterface { public function do($goodsId) { - $res = GoodsActivity::query()->with('store')->where('id',$goodsId)->first(); - return $res; + } @@ -50,4 +49,10 @@ class GoodsActivityService implements GoodsActivityServiceInterface $banner = GoodsActivityBanner::query()->where('goods_id',1572)->get(); return $banner; } + + public function detail($goodsId) + { + $res = GoodsActivity::query()->with('store')->where('id',$goodsId)->first(); + return $res; + } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/GoodsService.php b/app/Service/v3/Implementations/GoodsService.php index 082359c..64bdd99 100644 --- a/app/Service/v3/Implementations/GoodsService.php +++ b/app/Service/v3/Implementations/GoodsService.php @@ -12,8 +12,7 @@ class GoodsService implements GoodsServiceInterface { public function do($goodsId) { - $res = Goods::query()->with('store')->where('id',$goodsId)->first(); - return $res; + } @@ -45,4 +44,10 @@ class GoodsService implements GoodsServiceInterface $banner = GoodsBanner::query()->where('goods_id',1572)->get(); return $banner; } + + public function detail($goodsId) + { + $res = Goods::query()->with('store')->where('id',$goodsId)->first(); + return $res; + } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/ShopCartService.php b/app/Service/v3/Implementations/ShopCartService.php index 9b1380e..83c426b 100644 --- a/app/Service/v3/Implementations/ShopCartService.php +++ b/app/Service/v3/Implementations/ShopCartService.php @@ -44,4 +44,10 @@ class ShopCartService implements ShopCartServiceInterface { return mt_rand(1,100); } + + public function getTotal() + { + $randomFloat = rand(100,999)/100; + return $randomFloat; + } } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/GoodsActivityServiceInterface.php b/app/Service/v3/Interfaces/GoodsActivityServiceInterface.php index 3ed8c71..7084c83 100644 --- a/app/Service/v3/Interfaces/GoodsActivityServiceInterface.php +++ b/app/Service/v3/Interfaces/GoodsActivityServiceInterface.php @@ -8,4 +8,5 @@ interface GoodsActivityServiceInterface public function check($goodsId,$num = 1); public function undo(); public function getBanner(); + public function detail($goodsId); } \ No newline at end of file diff --git a/app/Service/v3/Interfaces/ShopCartServiceInterface.php b/app/Service/v3/Interfaces/ShopCartServiceInterface.php index 30c8975..eb9c0cc 100644 --- a/app/Service/v3/Interfaces/ShopCartServiceInterface.php +++ b/app/Service/v3/Interfaces/ShopCartServiceInterface.php @@ -11,4 +11,6 @@ interface ShopCartServiceInterface public function undo(); public function countGoods(); + + public function getTotal(); } \ No newline at end of file