From 92543163353f2f48314d6cdd35b272d48c180976 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 4 Sep 2020 16:43:58 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6=E4=BC=98=E5=8C=96?= =?UTF-8?q?=20=E5=95=86=E5=93=81=E5=8C=BA=E5=88=86=E6=99=AE=E9=80=9A?= =?UTF-8?q?=E5=95=86=E5=93=81=E5=92=8C=E6=B4=BB=E5=8A=A8=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Constants/v3/Goods.php | 7 +- app/Controller/v3/GoodsController.php | 32 +++++- app/Model/v3/GoodsActivityBanner.php | 14 +++ app/Model/v3/GoodsBanner.php | 13 +++ app/Model/v3/ShoppingCart.php | 12 +++ app/Model/v3/Store.php | 5 + .../Implementations/GoodsActivityService.php | 20 +--- .../v3/Implementations/GoodsService.php | 15 +-- .../v3/Implementations/ShopCartService.php | 97 ++----------------- config/autoload/dependencies.php | 1 + 10 files changed, 97 insertions(+), 119 deletions(-) create mode 100644 app/Model/v3/GoodsActivityBanner.php create mode 100644 app/Model/v3/GoodsBanner.php create mode 100644 app/Model/v3/ShoppingCart.php diff --git a/app/Constants/v3/Goods.php b/app/Constants/v3/Goods.php index 04bf235..65a233c 100644 --- a/app/Constants/v3/Goods.php +++ b/app/Constants/v3/Goods.php @@ -19,10 +19,15 @@ class Goods extends AbstractConstants /** * @Message("已下架") */ - const ON_SALE_NO = 2; + const ON_SALE_NO = 0; /** * @Message("无限库存") */ const IS_INVENTORY = 1; + + /** + * @Message("活动商品") + */ + const IS_ACTIVITY = 2; } \ No newline at end of file diff --git a/app/Controller/v3/GoodsController.php b/app/Controller/v3/GoodsController.php index 924f978..7e647e7 100644 --- a/app/Controller/v3/GoodsController.php +++ b/app/Controller/v3/GoodsController.php @@ -3,8 +3,12 @@ namespace App\Controller\v3; use App\Controller\BaseController; +use App\Service\v3\Implementations\GoodsActivityService; +use App\Service\v3\Interfaces\CollectStoreServiceInterface; use Hyperf\Di\Annotation\Inject; use App\Service\v3\Interfaces\GoodsServiceInterface; +use App\Service\v3\Interfaces\GoodsActivityServiceInterface; +use App\Constants\v3\Goods; class GoodsController extends BaseController { /** @@ -12,11 +16,35 @@ class GoodsController extends BaseController * @var GoodsServiceInterface */ protected $goodsService; + + /** + * @Inject + * @var GoodsActivityServiceInterface + */ + protected $goodsActivityService; + + /** + * @Inject + * @var CollectStoreServiceInterface + */ + protected $collectService; + public function detail() { $params = $this->request->all(); - $res['detail'] = $this->goodsService->do(35); - $res['banner'] = $this->goodsService->getBanner(); + //判断是普通商品还是特价商品 + if(isset($params['activity']) && $params['activity'] == Goods::IS_ACTIVITY){ + $res['detail'] = $this->goodsActivityService->do($params['goods_id']); + $res['banner'] = $this->goodsActivityService->getBanner(); + }else{ + $res['detail'] = $this->goodsService->do($params['goods_id']); + $res['banner'] = $this->goodsService->getBanner(); + } + if(isset($params['user_id'])) { + $res['detail']->store->is_collected = (bool)$this->collectService->check($params['user_id'], $params['store_id']); + }else{ + $res['detail']->store->is_collected = ''; + } return $this->success($res); } } \ No newline at end of file diff --git a/app/Model/v3/GoodsActivityBanner.php b/app/Model/v3/GoodsActivityBanner.php new file mode 100644 index 0000000..14d9c38 --- /dev/null +++ b/app/Model/v3/GoodsActivityBanner.php @@ -0,0 +1,14 @@ +hasMany(Goods::class, 'store_id', 'id'); } + + public function shoppingCart() + { + return $this->hasMany(ShoppingCart::class, 'store_id', 'id'); + } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/GoodsActivityService.php b/app/Service/v3/Implementations/GoodsActivityService.php index d392a1a..8938dd7 100644 --- a/app/Service/v3/Implementations/GoodsActivityService.php +++ b/app/Service/v3/Implementations/GoodsActivityService.php @@ -5,8 +5,9 @@ namespace App\Service\v3\Implementations; use App\Service\v3\Interfaces\GoodsActivityServiceInterface; use Hyperf\DbConnection\Db; use App\Constants\v3\Store; -use App\Constants\v3\goods as goodsConstants; +use App\Constants\v3\Goods; use App\Model\v3\GoodsActivity; +use App\Model\v3\GoodsActivityBanner; class GoodsActivityService implements GoodsActivityServiceInterface { public function do($goodsId) @@ -28,11 +29,11 @@ class GoodsActivityService implements GoodsActivityServiceInterface return '店铺已休息'; } - if($data->on_sale == 0 || !is_null($data->deleted_at)){ + if($data->on_sale == Goods::ON_SALE_NO || !is_null($data->deleted_at)){ return '商品已下架'; } - if($data->is_infinite != 1 && $data->inventory < $num){ + if($data->is_infinite != Goods::IS_INVENTORY && $data->inventory < $num){ return '库存不足'; } @@ -46,18 +47,7 @@ class GoodsActivityService implements GoodsActivityServiceInterface 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' - ] - ]; + $banner = GoodsActivityBanner::query()->where('goods_id',1572)->get(); return $banner; } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/GoodsService.php b/app/Service/v3/Implementations/GoodsService.php index de0e14c..082359c 100644 --- a/app/Service/v3/Implementations/GoodsService.php +++ b/app/Service/v3/Implementations/GoodsService.php @@ -5,9 +5,9 @@ namespace App\Service\v3\Implementations; use App\Service\v3\Interfaces\GoodsServiceInterface; use Hyperf\DbConnection\Db; use App\Model\v3\Goods; +use App\Model\v3\GoodsBanner; use App\Constants\v3\Store; use App\Constants\v3\goods as goodsConstants; -use App\Model\v3\GoodsActivity; class GoodsService implements GoodsServiceInterface { public function do($goodsId) @@ -42,18 +42,7 @@ class GoodsService implements GoodsServiceInterface 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' - ] - ]; + $banner = GoodsBanner::query()->where('goods_id',1572)->get(); return $banner; } } \ No newline at end of file diff --git a/app/Service/v3/Implementations/ShopCartService.php b/app/Service/v3/Implementations/ShopCartService.php index 1cda6e3..759e496 100644 --- a/app/Service/v3/Implementations/ShopCartService.php +++ b/app/Service/v3/Implementations/ShopCartService.php @@ -2,56 +2,18 @@ namespace App\Service\v3\Implementations; +use App\Model\v3\ShoppingCart; +use App\Model\v3\Store; use App\Service\v3\Interfaces\ShopCartServiceInterface; +use Hyperf\DbConnection\Db; class ShopCartService implements ShopCartServiceInterface { public function do() { - $res = [ - [ - 'store_nmae' => '五金杂货铺', - 'price' => '100.00', - 'note' => '多放辣椒', - 'store_id' => 66, - 'goods_list' => - [ - [ - 'id' => 3971, - 'goods_id' => 1301, - 'name' => '半边手撕鸡', - 'num' => 4, - 'price' => '90.00', - 'total' => '360.00' - ] - ] - ], - [ - 'store_nmae' => '回味手撕鸡J009', - 'note' => '手撕鸡加辣', - 'store_price' => '720.00', - 'store_id' => 123, - 'goods_list' => - [ - [ - 'id' => 3971, - 'goods_id' => 1301, - 'name' => '半边手撕鸡', - 'num' => 4, - 'price' => '90.00', - 'total' => '360.00' - ], - [ - 'id' => 3971, - 'goods_id' => 1301, - 'name' => '半边手撕鸡', - 'num' => 4, - 'price' => '90.00', - 'total' => '360.00' - ] - ] - ], - ]; + $storeIds = Db::table('lanzu_shopping_cart')->where('user_id',15)->pluck('store_id')->toArray(); + $res = Store::query()->with('shoppingCart')->whereIn('id',$storeIds) + ->get(); return $res; } @@ -62,50 +24,9 @@ class ShopCartService implements ShopCartServiceInterface public function undo() { - $res = [ - [ - 'store_nmae' => '五金杂货铺', - 'price' => '100.00', - 'note' => '多放辣椒', - 'store_id' => 66, - 'goods_list' => - [ - [ - 'id' => 3971, - 'goods_id' => 1301, - 'name' => '半边手撕鸡', - 'num' => 4, - 'price' => '90.00', - 'total' => '360.00' - ] - ] - ], - [ - 'store_nmae' => '回味手撕鸡J009', - 'note' => '手撕鸡加辣', - 'store_price' => '720.00', - 'store_id' => 123, - 'goods_list' => - [ - [ - 'id' => 3971, - 'goods_id' => 1301, - 'name' => '半边手撕鸡', - 'num' => 4, - 'price' => '90.00', - 'total' => '360.00' - ], - [ - 'id' => 3971, - 'goods_id' => 1301, - 'name' => '半边手撕鸡', - 'num' => 4, - 'price' => '90.00', - 'total' => '360.00' - ] - ] - ], - ]; + $storeIds = Db::table('lanzu_shopping_cart')->where('user_id',198)->pluck('store_id')->toArray(); + $res = Store::query()->with('shoppingCart')->whereIn('id',$storeIds) + ->get(); return $res; } diff --git a/config/autoload/dependencies.php b/config/autoload/dependencies.php index 3cceb2a..f9ce1c5 100644 --- a/config/autoload/dependencies.php +++ b/config/autoload/dependencies.php @@ -59,4 +59,5 @@ return [ \App\Service\v3\Interfaces\BannerServiceInterface::class => \App\Service\v3\Implementations\BannerService::class, \App\Service\v3\Interfaces\ActivityServiceInterface::class => \App\Service\v3\Implementations\ActivityService::class, \App\Service\v3\Interfaces\LocationServiceInterface::class => \App\Service\v3\Implementations\LocationService::class, + \App\Service\v3\Interfaces\GoodsActivityServiceInterface::class => \App\Service\v3\Implementations\GoodsActivityService::class, ];