vd/app/Domains/Virtual/Repositories/Concerns/OrderCardConcern.php

72 lines
2.4 KiB
PHP

<?php
namespace App\Domains\Virtual\Repositories\Concerns;
use Illuminate\Support\Carbon;
trait OrderCardConcern
{
/**
* 查询条件
*
* @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['order_id'])) {
$conditions['order_id'] = array_wrap($conditions['order_id']);
$this->model = $this->model->whereIn('order_id', $conditions['order_id']);
}
if (isset($conditions['sim'])) {
$conditions['sim'] = array_wrap($conditions['sim']);
$this->model = $this->model->whereIn('sim', $conditions['sim']);
}
if (isset($conditions['company_id'])) {
$this->model = $this->model->where('company_id', $conditions['company_id']);
}
if (isset($conditions['package_id'])) {
$this->model = $this->model->where('package_id', $conditions['package_id']);
}
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['company_name'])) {
$this->model = $this->model->whereHas('company', function ($relation) use ($conditions) {
$relation->where('name', $conditions['company_name']);
});
}
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('created_at', '>=', Carbon::parse($conditions['starttime']));
}
if (isset($conditions['endtime'])) {
$this->model = $this->model->where('created_at', '<=', Carbon::parse($conditions['endtime']));
}
return $this;
}
}