84 lines
2.9 KiB
PHP
84 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Domains\Virtual\Repositories\Concerns;
|
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
trait OrderCardConcern
|
|
{
|
|
/**
|
|
* 查询条件
|
|
*
|
|
* @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['type'])) {
|
|
$conditions['type'] = array_wrap($conditions['type']);
|
|
$query->whereIn('type', $conditions['type']);
|
|
}
|
|
|
|
if (isset($conditions['order_id'])) {
|
|
$conditions['order_id'] = array_wrap($conditions['order_id']);
|
|
$query->whereIn('order_id', $conditions['order_id']);
|
|
}
|
|
|
|
if (isset($conditions['sim'])) {
|
|
$conditions['sim'] = array_wrap($conditions['sim']);
|
|
$query->whereIn('sim', $conditions['sim']);
|
|
}
|
|
|
|
if (isset($conditions['company_id'])) {
|
|
$query->where('company_id', $conditions['company_id']);
|
|
}
|
|
|
|
if (isset($conditions['package_id'])) {
|
|
$query->where('package_id', $conditions['package_id']);
|
|
}
|
|
|
|
if (isset($conditions['carrier_operator'])) {
|
|
$query->whereHas('package', function ($relation) use ($conditions) {
|
|
$relation->withTrashed()->where('carrier_operator', $conditions['carrier_operator']);
|
|
});
|
|
}
|
|
|
|
if (isset($conditions['pay_channel'])) {
|
|
$query->where('pay_channel', $conditions['pay_channel']);
|
|
}
|
|
|
|
if (isset($conditions['company_name'])) {
|
|
$query->whereHas('company', function ($relation) use ($conditions) {
|
|
$relation->withTrashed()->where('name', $conditions['company_name']);
|
|
});
|
|
}
|
|
|
|
if (isset($conditions['package_name'])) {
|
|
$query->whereHas('package', function ($relation) use ($conditions) {
|
|
$relation->withTrashed()->where('name', $conditions['package_name']);
|
|
});
|
|
}
|
|
|
|
if (isset($conditions['starttime'])) {
|
|
$query->where('created_at', '>=', Carbon::parse($conditions['starttime']));
|
|
}
|
|
|
|
if (isset($conditions['endtime'])) {
|
|
$query->where('created_at', '<=', Carbon::parse($conditions['endtime']));
|
|
}
|
|
|
|
if (isset($conditions['month'])) {
|
|
$conditions['month'] = (int)Carbon::parse($conditions['month'])->format('Ym');
|
|
$query->whereRaw("timelines_array(sim) @> '{{$conditions['month']}}'");
|
|
}
|
|
});
|
|
|
|
return $this;
|
|
}
|
|
}
|