You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
2.3 KiB
69 lines
2.3 KiB
<?php
|
|
|
|
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;
|
|
use App\Service\v3\Interfaces\GoodsServiceInterface;
|
|
use App\Service\v3\Interfaces\GoodsActivityServiceInterface;
|
|
use App\Constants\v3\Goods;
|
|
class GoodsController extends BaseController
|
|
{
|
|
/**
|
|
* @Inject
|
|
* @var GoodsServiceInterface
|
|
*/
|
|
protected $goodsService;
|
|
|
|
/**
|
|
* @Inject
|
|
* @var GoodsActivityServiceInterface
|
|
*/
|
|
protected $goodsActivityService;
|
|
|
|
/**
|
|
* @Inject
|
|
* @var CollectStoreServiceInterface
|
|
*/
|
|
protected $collectService;
|
|
|
|
/**
|
|
* @Inject
|
|
* @var ShopCartServiceInterface
|
|
*/
|
|
protected $shopCartService;
|
|
|
|
public function detail()
|
|
{
|
|
$params = $this->request->all();
|
|
$activity = $this->request->input('activity',1);
|
|
$goodsId = $this->request->input('goods_id',0);
|
|
$marketId = $this->request->input('market_id',0);
|
|
//判断是普通商品还是特价商品
|
|
if($activity == Goods::IS_ACTIVITY){
|
|
$res['detail'] = $this->goodsActivityService->detail($goodsId);
|
|
$res['banner'] = $this->goodsActivityService->getBanner($goodsId);
|
|
}else{
|
|
$res['detail'] = $this->goodsService->detail($goodsId);
|
|
$res['banner'] = $this->goodsService->getBanner($goodsId);
|
|
}
|
|
|
|
//如果没有banner数据,使用商品cover图
|
|
if(count($res['banner']) == 0){
|
|
$res['banner'] = [$res['detail']['cover_img']];
|
|
}
|
|
//如果存在用户ID则请求 购物车和收藏店铺信息
|
|
if(isset($params['user_id'])) {
|
|
$res['shopcart']['count'] = $this->shopCartService->countGoods($params['user_id'],$marketId);
|
|
$res['shopcart']['total'] = $this->shopCartService->getTotal($params['user_id'],$marketId);
|
|
$res['detail']->store->is_collected = (bool)$this->collectService->check($params['user_id'], $res['detail']->store->id);
|
|
}else{
|
|
$res['shopcart'] = '';
|
|
$res['detail']->store->is_collected = '';
|
|
}
|
|
return $this->success($res);
|
|
}
|
|
}
|