86 lines
2.0 KiB
PHP
86 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Virtual\Repositories;
|
|
|
|
use App\Core\Repository;
|
|
use App\Models\Virtual\Product as Model;
|
|
|
|
class ProductRepository extends Repository
|
|
{
|
|
/**
|
|
* 是否关闭缓存
|
|
*
|
|
* @var boolean
|
|
*/
|
|
protected $cacheSkip = false;
|
|
|
|
/**
|
|
* 是否开启数据转化
|
|
*
|
|
* @var bool
|
|
*/
|
|
protected $needTransform = false;
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
protected $fieldSearchable = [
|
|
'id' => '=',
|
|
'created_at' => 'like',
|
|
];
|
|
|
|
public function model()
|
|
{
|
|
return Model::class;
|
|
}
|
|
|
|
/**
|
|
* 数据格式化
|
|
*
|
|
* @param mixed $result
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function transform($model)
|
|
{
|
|
return $model->toArray();
|
|
}
|
|
|
|
/**
|
|
* 查询条件
|
|
*
|
|
* @return void
|
|
*/
|
|
public function withConditions(array $conditions = [])
|
|
{
|
|
$this->model = $this->model->where(function ($query) use ($conditions) {
|
|
if (isset($conditions['id'])) {
|
|
$conditions['id'] = array_wrap($conditions['id']);
|
|
$query->whereIn('id', $conditions['id']);
|
|
}
|
|
|
|
if (isset($conditions['company_id'])) {
|
|
$query->where('company_id', $conditions['company_id']);
|
|
}
|
|
|
|
if (isset($conditions['name'])) {
|
|
$query->where('name', 'like', "%{$conditions['name']}%");
|
|
}
|
|
|
|
if (isset($conditions['package_name'])) {
|
|
$query->whereHas('package', function ($relation) use ($conditions) {
|
|
$relation->withTrashed()->where('name', $conditions['package_name']);
|
|
});
|
|
}
|
|
|
|
if (isset($conditions['carrier_operator'])) {
|
|
$query->whereHas('package', function ($relation) use ($conditions) {
|
|
$relation->withTrashed()->where('carrier_operator', $conditions['carrier_operator']);
|
|
});
|
|
}
|
|
});
|
|
|
|
return $this;
|
|
}
|
|
}
|