vd/app/Domains/Virtual/Repositories/PackageRepository.php
2018-12-20 16:22:10 +08:00

83 lines
1.8 KiB
PHP

<?php
namespace App\Domains\Virtual\Repositories;
use App\Core\Repository;
use App\Models\Virtual\Package as Model;
class PackageRepository extends Repository
{
/**
* 是否关闭缓存
*
* @var boolean
*/
protected $cacheSkip = false;
/**
* 是否开启数据转化
*
* @var bool
*/
protected $needTransform = false;
/**
* @var array
*/
protected $fieldSearchable = [
'id' => '=',
'type' => '=',
'sn' => 'like',
'name' => 'like',
'carrier_operator' => '=',
];
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 = [])
{
if (isset($conditions['id'])) {
$conditions['id'] = array_wrap($conditions['id']);
$this->model = $this->model->whereIn('id', $conditions['id']);
}
if (isset($conditions['type'])) {
$this->model = $this->model->where('type', $conditions['type']);
}
if (isset($conditions['sn'])) {
$this->model = $this->model->where('sn', "%{$conditions['sn']}%");
}
if (isset($conditions['name'])) {
$this->model = $this->model->where('name', "%{$conditions['name']}%");
}
if (isset($conditions['carrier_operator'])) {
$this->model = $this->model->where('carrier_operator', $conditions['carrier_operator']);
}
return $this;
}
}