From cf4a1e1c314df00c811382b230789a00e8cbcfd6 Mon Sep 17 00:00:00 2001 From: Lemon <15040771@qq.com> Date: Fri, 4 Sep 2020 14:40:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E5=8C=BA=E5=88=86=E6=99=AE?= =?UTF-8?q?=E9=80=9A=E7=89=B9=E4=BB=B7=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 | 5 -- app/Model/v3/User.php | 1 + .../Implementations/GoodsActivityService.php | 63 +++++++++++++++++++ .../v3/Implementations/GoodsService.php | 15 +---- .../GoodsActivityServiceInterface.php | 11 ++++ .../v3/Interfaces/GoodsServiceInterface.php | 2 +- 6 files changed, 78 insertions(+), 19 deletions(-) create mode 100644 app/Service/v3/Implementations/GoodsActivityService.php create mode 100644 app/Service/v3/Interfaces/GoodsActivityServiceInterface.php diff --git a/app/Constants/v3/Goods.php b/app/Constants/v3/Goods.php index 79c0568..04bf235 100644 --- a/app/Constants/v3/Goods.php +++ b/app/Constants/v3/Goods.php @@ -25,9 +25,4 @@ class Goods extends AbstractConstants * @Message("无限库存") */ const IS_INVENTORY = 1; - - /** - * @Message("活动商品") - */ - const IS_ACTIVITY = 2; } \ No newline at end of file diff --git a/app/Model/v3/User.php b/app/Model/v3/User.php index 8df0971..9e7d670 100644 --- a/app/Model/v3/User.php +++ b/app/Model/v3/User.php @@ -23,6 +23,7 @@ class User extends Model 'language', ]; protected $visible = [ + 'id', 'nick_name', 'avatar', 'openid', diff --git a/app/Service/v3/Implementations/GoodsActivityService.php b/app/Service/v3/Implementations/GoodsActivityService.php new file mode 100644 index 0000000..d392a1a --- /dev/null +++ b/app/Service/v3/Implementations/GoodsActivityService.php @@ -0,0 +1,63 @@ +with('store')->where('id',$goodsId)->first(); + return $res; + } + + + public function check($goodsId,$num = 1) + { + $data = GoodsActivity::query()->with('store')->where('id', $goodsId)->first(); + //活动商品 校验 + if($data->expire_time < time()){ + return '活动已结束'; + } + + if($data->store->is_rest != Store::IS_OPEN_YES){ + return '店铺已休息'; + } + + if($data->on_sale == 0 || !is_null($data->deleted_at)){ + return '商品已下架'; + } + + if($data->is_infinite != 1 && $data->inventory < $num){ + return '库存不足'; + } + + return ''; + } + + public function undo() + { + // TODO: Implement undo() method. + } + + 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; + } +} \ No newline at end of file diff --git a/app/Service/v3/Implementations/GoodsService.php b/app/Service/v3/Implementations/GoodsService.php index d8cc5f4..de0e14c 100644 --- a/app/Service/v3/Implementations/GoodsService.php +++ b/app/Service/v3/Implementations/GoodsService.php @@ -17,20 +17,9 @@ class GoodsService implements GoodsServiceInterface } - public function check($goodsId,$num = 1,$activity_type = 1) + public function check($goodsId,$num = 1) { - if($activity_type == goodsConstants::IS_ACTIVITY) { - $builder = GoodsActivity::query(); - }else{ - $builder = Goods::query(); - } - $data = $builder->with('store')->where('id', $goodsId)->first(); - //活动商品 校验 - if($activity_type == goodsConstants::IS_ACTIVITY) { - if($data->expire_time < time()){ - return '活动已结束'; - } - } + $data = Goods::query()->with('store')->where('id', $goodsId)->first(); if($data->store->is_rest != Store::IS_OPEN_YES){ return '店铺已休息'; } diff --git a/app/Service/v3/Interfaces/GoodsActivityServiceInterface.php b/app/Service/v3/Interfaces/GoodsActivityServiceInterface.php new file mode 100644 index 0000000..3ed8c71 --- /dev/null +++ b/app/Service/v3/Interfaces/GoodsActivityServiceInterface.php @@ -0,0 +1,11 @@ +