90 lines
2.1 KiB
PHP
90 lines
2.1 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 getCompanyProducts(Dicts $dicts)
|
|
{
|
|
$companyId = $this->request->get('company_id');
|
|
$carrierOperator = $this->request->get('carrier_operator');
|
|
|
|
$products = $this->productService->getCompanyProducts($companyId, $carrierOperator);
|
|
|
|
$carrierOperators = $dicts->get('carrier_operator');
|
|
|
|
$products->map(function ($item) use ($carrierOperators) {
|
|
$item->carrier_operator = $carrierOperators[$item['package']['carrier_operator']] ?? '未知';
|
|
});
|
|
|
|
return res($products, '定价列表', 201);
|
|
}
|
|
|
|
|
|
/**
|
|
* 创建.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
$attributes = $this->request->all();
|
|
|
|
$account = $this->productService->store($attributes);
|
|
|
|
return res($account, '创建成功');
|
|
}
|
|
|
|
/**
|
|
* 编辑.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update($id)
|
|
{
|
|
$attributes = $this->request->all();
|
|
$attributes['id'] = $id;
|
|
|
|
$account = $this->productService->store($attributes);
|
|
|
|
return res($account, '修改成功');
|
|
}
|
|
|
|
/**
|
|
* 删除.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy()
|
|
{
|
|
$ids = $this->request->ids();
|
|
|
|
$this->productService->destroy($ids);
|
|
|
|
return res(true, '删除成功');
|
|
}
|
|
}
|