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.
168 lines
6.6 KiB
168 lines
6.6 KiB
<?php
|
|
|
|
namespace App\Controller\v3;
|
|
|
|
use App\Controller\BaseController;
|
|
use App\Model\v3\Category;
|
|
use App\Model\v3\GoodsCategory;
|
|
use App\Request\v3\GoodsEditorRequest;
|
|
use App\Service\v3\Interfaces\CategoryServiceInterface;
|
|
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;
|
|
use App\Request\v3\GoodsRequest;
|
|
class GoodsController extends BaseController
|
|
{
|
|
/**
|
|
* @Inject
|
|
* @var GoodsServiceInterface
|
|
*/
|
|
protected $goodsService;
|
|
|
|
/**
|
|
* @Inject
|
|
* @var GoodsActivityServiceInterface
|
|
*/
|
|
protected $goodsActivityService;
|
|
|
|
/**
|
|
* @Inject
|
|
* @var CollectStoreServiceInterface
|
|
*/
|
|
protected $collectService;
|
|
|
|
/**
|
|
* @Inject
|
|
* @var ShopCartServiceInterface
|
|
*/
|
|
protected $shopCartService;
|
|
|
|
/**
|
|
* @Inject
|
|
* @var CategoryServiceInterface
|
|
*/
|
|
protected $categoryService;
|
|
|
|
public function detail(GoodsRequest $request)
|
|
{
|
|
$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']];
|
|
$res['banner'] = [[
|
|
'banner_url' => $res['detail']['cover_img'],
|
|
'goods_id' => $goodsId,
|
|
'type' => 1,
|
|
'path' => $res['detail']['cover_img'],
|
|
'created_at' => '',
|
|
'updated_at' => '',
|
|
'deleted_at' => '',
|
|
'sort' => '',
|
|
]];
|
|
}
|
|
//如果存在用户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);
|
|
}
|
|
|
|
public function update(GoodsEditorRequest $request)
|
|
{
|
|
$data['id'] = $this->request->input('id',0);
|
|
$data['market_id'] = $this->request->input('market_id',0);
|
|
$data['store_id'] = $this->request->input('store_id',0);
|
|
$data['name'] = $this->request->input('name','');
|
|
$data['category_id'] = $this->request->input('category_id',0);
|
|
$data['goods_category_id'] = $this->request->input('goods_category_id',0);
|
|
$data['goods_unit'] = $this->request->input('goods_unit','');
|
|
$data['price'] = $this->request->input('price',0);
|
|
$data['original_price'] = $this->request->input('original_price',0);
|
|
$data['inventory'] = $this->request->input('inventory',0);
|
|
$data['restrict_num'] = $this->request->input('restrict_num',0);
|
|
$data['start_num'] = $this->request->input('start_num',0);
|
|
$data['spec'] = $this->request->input('spec',[]);
|
|
$data['tags'] = $this->request->input('tags',[]);
|
|
$data['remark'] = $this->request->input('remark','');
|
|
$data['on_sale'] = $this->request->input('on_sale',0);
|
|
$data['is_infinite'] = $this->request->input('is_infinite',0);
|
|
$data['user_id'] = $this->request->input('user_id',0);
|
|
$res = $this->goodsService->update($data);
|
|
return $this->success($res);
|
|
}
|
|
|
|
public function info()
|
|
{
|
|
$goodsId = $this->request->input('goods_id',0);
|
|
$goods = $this->goodsService->info($goodsId);
|
|
$goods['secend'] = Category::find($goods['category_id']);
|
|
$goods['first'] = Category::find($goods['secend']['parent_id']);
|
|
if(!empty($goods['goods_category_id'])){
|
|
$goods['third'] = GoodsCategory::find($goods['goods_category_id']);
|
|
}else{
|
|
$goods['third'] = null;
|
|
}
|
|
$first = $this->categoryService->getByParentId(0);
|
|
$secend = $this->categoryService->getByParentId($goods['first']['id']);
|
|
$third = $this->categoryService->getThird($goods['category_id']);
|
|
$tags = $this->goodsService->getTags();
|
|
return $this->success([
|
|
'goods' => $goods,
|
|
'first' => $first,
|
|
'secend' => $secend,
|
|
'third' => $third,
|
|
'tags' => $tags
|
|
]);
|
|
}
|
|
|
|
public function create(GoodsEditorRequest $request)
|
|
{
|
|
$data['id'] = $this->request->input('id',0);
|
|
$data['market_id'] = $this->request->input('market_id',0);
|
|
$data['store_id'] = $this->request->input('store_id',0);
|
|
$data['name'] = $this->request->input('name','');
|
|
$data['category_id'] = $this->request->input('category_id',0);
|
|
$data['goods_category_id'] = $this->request->input('goods_category_id',0);
|
|
$data['goods_unit'] = $this->request->input('goods_unit','');
|
|
$data['price'] = $this->request->input('price',0);
|
|
$data['original_price'] = $this->request->input('original_price',0);
|
|
$data['inventory'] = $this->request->input('inventory',0);
|
|
$data['restrict_num'] = $this->request->input('restrict_num',0);
|
|
$data['start_num'] = $this->request->input('start_num',0);
|
|
$data['spec'] = $this->request->input('spec',[]);
|
|
$data['tags'] = $this->request->input('tags',[]);
|
|
$data['remark'] = $this->request->input('remark','');
|
|
$data['on_sale'] = $this->request->input('on_sale',0);
|
|
$data['is_infinite'] = $this->request->input('is_infinite',0);
|
|
$data['user_id'] = $this->request->input('user_id',0);
|
|
$res = $this->goodsService->create($data);
|
|
return $this->success($res);
|
|
}
|
|
|
|
public function getTags()
|
|
{
|
|
$tags = $this->goodsService->getTags();
|
|
return $this->success(['tags' => $tags]);
|
|
}
|
|
}
|