Browse Source

活动商品不显示店铺问题 返回购物车总价 数量

master
Lemon 6 years ago
parent
commit
a1553dbfb6
  1. 13
      app/Controller/v3/GoodsController.php
  2. 8
      app/Model/v3/GoodsActivity.php
  3. 9
      app/Service/v3/Implementations/GoodsActivityService.php
  4. 9
      app/Service/v3/Implementations/GoodsService.php
  5. 6
      app/Service/v3/Implementations/ShopCartService.php
  6. 1
      app/Service/v3/Interfaces/GoodsActivityServiceInterface.php
  7. 2
      app/Service/v3/Interfaces/ShopCartServiceInterface.php

13
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 = '';

8
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
{

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

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

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

1
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);
}

2
app/Service/v3/Interfaces/ShopCartServiceInterface.php

@ -11,4 +11,6 @@ interface ShopCartServiceInterface
public function undo();
public function countGoods();
public function getTotal();
}
Loading…
Cancel
Save