105 lines
2.7 KiB
PHP
105 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Virtual\Repositories;
|
|
|
|
use App\Core\Repository;
|
|
use App\Models\Virtual\Order as Model;
|
|
use App\Domains\Virtual\Services\CommonService;
|
|
|
|
class OrderRepository 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;
|
|
}
|
|
|
|
/**
|
|
* 查询条件
|
|
*
|
|
* @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['company_id'])) {
|
|
$this->model = $this->model->where('company_id', $conditions['company_id']);
|
|
}
|
|
|
|
if (isset($conditions['sn'])) {
|
|
$this->model = $this->model->where('sn', $conditions['sn']);
|
|
}
|
|
|
|
if (isset($conditions['order_status'])) {
|
|
$this->model = $this->model->where('order_status', $conditions['order_status']);
|
|
}
|
|
|
|
if (isset($conditions['transaction_status'])) {
|
|
$this->model = $this->model->where('transaction_status', $conditions['transaction_status']);
|
|
}
|
|
|
|
if (isset($conditions['carrier_operator'])) {
|
|
$this->model = $this->model->whereHas('package', function ($relation) use ($conditions) {
|
|
$relation->where('carrier_operator', $conditions['carrier_operator']);
|
|
});
|
|
}
|
|
|
|
if (isset($conditions['pay_channel'])) {
|
|
$this->model = $this->model->where('pay_channel', $conditions['pay_channel']);
|
|
}
|
|
|
|
if (isset($conditions['package_name'])) {
|
|
$this->model = $this->model->whereHas('package', function ($relation) use ($conditions) {
|
|
$relation->where('name', $conditions['package_name']);
|
|
});
|
|
}
|
|
|
|
if (isset($conditions['starttime'])) {
|
|
$this->model = $this->model->where('order_at', '>=', $conditions['starttime']);
|
|
}
|
|
|
|
if (isset($conditions['endtime'])) {
|
|
$this->model = $this->model->where('order_at', '<=', $conditions['endtime']);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
}
|