97 lines
2.0 KiB
PHP
97 lines
2.0 KiB
PHP
<?php
|
|
namespace App\Domains\Virtual\Http\Controllers;
|
|
|
|
use App\Dicts;
|
|
use App\Core\Controller;
|
|
use Illuminate\Http\Request;
|
|
use App\Exceptions\NotExistException;
|
|
use App\Domains\Virtual\Services\ProductService;
|
|
use App\Domains\Virtual\Repositories\ProductRepository;
|
|
|
|
class ProductController extends Controller
|
|
{
|
|
protected $request;
|
|
protected $productService;
|
|
|
|
/**
|
|
* 构造函数,自动注入.
|
|
*/
|
|
public function __construct(Request $request, ProductService $productService)
|
|
{
|
|
$this->request = $request;
|
|
$this->productService = $productService;
|
|
}
|
|
|
|
/**
|
|
* 列表.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index(Dicts $dicts)
|
|
{
|
|
$conditions = $this->request->all();
|
|
|
|
$products = $this->productService->index($conditions);
|
|
|
|
return res($products, '定价列表', 201);
|
|
}
|
|
|
|
/**
|
|
* 历史定价.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function history()
|
|
{
|
|
$conditions = $this->request->all();
|
|
|
|
$products = $this->productService->history($conditions);
|
|
|
|
return res($products, '历史定价', 201);
|
|
}
|
|
|
|
|
|
/**
|
|
* 创建.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
$attributes = $this->request->all();
|
|
|
|
$product = $this->productService->store($attributes);
|
|
|
|
return res($product, '创建成功');
|
|
}
|
|
|
|
/**
|
|
* 编辑.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update($id)
|
|
{
|
|
$attributes = $this->request->all();
|
|
$attributes['id'] = $id;
|
|
|
|
$product = $this->productService->store($attributes);
|
|
|
|
return res($product, '修改成功');
|
|
}
|
|
|
|
/**
|
|
* 删除.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy()
|
|
{
|
|
$ids = $this->request->ids();
|
|
|
|
$this->productService->destroy($ids);
|
|
|
|
return res(true, '删除成功');
|
|
}
|
|
}
|