企业定价

This commit is contained in:
邓皓元 2018-12-12 09:09:24 +08:00
parent 19158bfe42
commit 2727a5db17
4 changed files with 75 additions and 6 deletions

View File

@ -16,7 +16,7 @@ class ProductRepository extends Repository
/**
* 是否开启数据转化
*
*
* @var bool
*/
protected $needTransform = false;
@ -29,7 +29,8 @@ class ProductRepository extends Repository
'created_at' => 'like',
];
public function model() {
public function model()
{
return Model::class;
}
@ -57,6 +58,10 @@ class ProductRepository extends Repository
$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;
}
}
}

View File

@ -2,6 +2,9 @@
namespace App\Domains\Virtual\Services;
use App\Core\Service;
use App\Models\Virtual\Product;
use App\Exceptions\NotExistException;
use Illuminate\Support\Facades\Validator;
use App\Domains\Virtual\Repositories\ProductRepository;
class ProductService extends Service
@ -17,4 +20,63 @@ class ProductService extends Service
{
$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;
}
}

View File

@ -15,6 +15,6 @@ class Product extends Model
public function package()
{
return $this->belongsTo(Package::class, 'company_id', 'id');
return $this->belongsTo(Package::class, 'package_id', 'id');
}
}

View File

@ -1,7 +1,9 @@
<?php
use App\Domains\Virtual\Services\ProductService;
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());