企业定价
This commit is contained in:
parent
19158bfe42
commit
2727a5db17
@ -29,7 +29,8 @@ class ProductRepository extends Repository
|
|||||||
'created_at' => 'like',
|
'created_at' => 'like',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function model() {
|
public function model()
|
||||||
|
{
|
||||||
return Model::class;
|
return Model::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,6 +58,10 @@ class ProductRepository extends Repository
|
|||||||
$this->model = $this->model->whereIn('id', $conditions['id']);
|
$this->model = $this->model->whereIn('id', $conditions['id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($conditions['company_id'])) {
|
||||||
|
$this->model = $this->model->where('company_id', $conditions['company_id']);
|
||||||
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,6 +2,9 @@
|
|||||||
namespace App\Domains\Virtual\Services;
|
namespace App\Domains\Virtual\Services;
|
||||||
|
|
||||||
use App\Core\Service;
|
use App\Core\Service;
|
||||||
|
use App\Models\Virtual\Product;
|
||||||
|
use App\Exceptions\NotExistException;
|
||||||
|
use Illuminate\Support\Facades\Validator;
|
||||||
use App\Domains\Virtual\Repositories\ProductRepository;
|
use App\Domains\Virtual\Repositories\ProductRepository;
|
||||||
|
|
||||||
class ProductService extends Service
|
class ProductService extends Service
|
||||||
@ -17,4 +20,63 @@ class ProductService extends Service
|
|||||||
{
|
{
|
||||||
$this->productRepository = $productRepository;
|
$this->productRepository = $productRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取企业定价列表
|
||||||
|
*
|
||||||
|
* @param int $companyId
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getCompanyProducts($companyId)
|
||||||
|
{
|
||||||
|
$list = $this->productRepository->with(['company:id,name', 'package:id,name'])
|
||||||
|
->withConditions(['company_id' => $companyId])->get();
|
||||||
|
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存储企业定价
|
||||||
|
*
|
||||||
|
* @param array $attributes
|
||||||
|
* @return Product
|
||||||
|
*/
|
||||||
|
public function store(array $attributes = [])
|
||||||
|
{
|
||||||
|
$rule = [
|
||||||
|
];
|
||||||
|
|
||||||
|
$message = [
|
||||||
|
];
|
||||||
|
|
||||||
|
Validator::validate($attributes, $rule, $message);
|
||||||
|
|
||||||
|
if (!$attributes['id']) {
|
||||||
|
$node = $this->productRepository->create($attributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($attributes['id']) {
|
||||||
|
if (!$node = $this->productRepository->find($attributes['id'])) {
|
||||||
|
throw new NotExistException('地址不存在或已删除');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->productRepository->setModel($node)->update($attributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $node;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function destroy($ids)
|
||||||
|
{
|
||||||
|
$ids = is_array($ids) ? $ids : [$ids];
|
||||||
|
|
||||||
|
$this->productRepository->destroy($ids);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,6 @@ class Product extends Model
|
|||||||
|
|
||||||
public function package()
|
public function package()
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Package::class, 'company_id', 'id');
|
return $this->belongsTo(Package::class, 'package_id', 'id');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Domains\Virtual\Services\ProductService;
|
||||||
|
|
||||||
require_once realpath(dirname(__FILE__) . '/TestCase.php');
|
require_once realpath(dirname(__FILE__) . '/TestCase.php');
|
||||||
|
|
||||||
$captchaService = app(\App\Domains\Captcha\Services\CaptchaService::class);
|
$res = app(ProductService::class)->getCompanyProducts(1);
|
||||||
|
|
||||||
dd($captchaService->check('mbxgn', '$2y$10$.oCSEw.J9.QxAVRgmE8bv..D0vHHv3y6PNAa07y7Oh3358IWEv1au'));
|
dd($res->toArray());
|
Loading…
x
Reference in New Issue
Block a user