针对软删除查询优化

This commit is contained in:
邓皓元 2019-01-10 11:40:36 +08:00
parent cacfaed7ef
commit 35829b7416
3 changed files with 141 additions and 135 deletions

View File

@ -13,58 +13,60 @@ trait OrderCardConcern
*/
public function withConditions(array $conditions = [])
{
if (isset($conditions['id'])) {
$conditions['id'] = array_wrap($conditions['id']);
$this->model = $this->model->whereIn('id', $conditions['id']);
}
$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['order_id'])) {
$conditions['order_id'] = array_wrap($conditions['order_id']);
$this->model = $this->model->whereIn('order_id', $conditions['order_id']);
}
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']);
$this->model = $this->model->whereIn('sim', $conditions['sim']);
}
if (isset($conditions['sim'])) {
$conditions['sim'] = array_wrap($conditions['sim']);
$query->whereIn('sim', $conditions['sim']);
}
if (isset($conditions['company_id'])) {
$this->model = $this->model->where('company_id', $conditions['company_id']);
}
if (isset($conditions['company_id'])) {
$query->where('company_id', $conditions['company_id']);
}
if (isset($conditions['package_id'])) {
$this->model = $this->model->where('package_id', $conditions['package_id']);
}
if (isset($conditions['package_id'])) {
$query->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['carrier_operator'])) {
$query->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['pay_channel'])) {
$query->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['company_name'])) {
$query->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['package_name'])) {
$query->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['starttime'])) {
$query->where('created_at', '>=', Carbon::parse($conditions['starttime']));
}
if (isset($conditions['endtime'])) {
$this->model = $this->model->where('created_at', '<=', Carbon::parse($conditions['endtime']));
}
if (isset($conditions['endtime'])) {
$query->where('created_at', '<=', Carbon::parse($conditions['endtime']));
}
});
return $this;
}

View File

@ -56,65 +56,67 @@ class OrderRepository extends Repository
*/
public function withConditions(array $conditions = [])
{
if (isset($conditions['id'])) {
$conditions['id'] = array_wrap($conditions['id']);
$this->model = $this->model->whereIn('id', $conditions['id']);
}
$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['source'])) {
$this->model = $this->model->where('source', $conditions['source']);
}
if (isset($conditions['source'])) {
$query->where('source', $conditions['source']);
}
if (isset($conditions['type'])) {
$conditions['type'] = array_wrap($conditions['type']);
$this->model = $this->model->whereIn('type', $conditions['type']);
}
if (isset($conditions['type'])) {
$conditions['type'] = array_wrap($conditions['type']);
$query->whereIn('type', $conditions['type']);
}
if (isset($conditions['company_id'])) {
$this->model = $this->model->where('company_id', $conditions['company_id']);
}
if (isset($conditions['company_id'])) {
$query->where('company_id', $conditions['company_id']);
}
if (isset($conditions['sn'])) {
$this->model = $this->model->where('sn', $conditions['sn']);
}
if (isset($conditions['sn'])) {
$query->where('sn', $conditions['sn']);
}
if (isset($conditions['order_status'])) {
$this->model = $this->model->where('order_status', $conditions['order_status']);
}
if (isset($conditions['order_status'])) {
$query->where('order_status', $conditions['order_status']);
}
if (isset($conditions['transaction_status'])) {
$this->model = $this->model->where('transaction_status', $conditions['transaction_status']);
}
if (isset($conditions['transaction_status'])) {
$query->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['carrier_operator'])) {
$query->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['pay_channel'])) {
$query->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['company_name'])) {
$query->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['package_name'])) {
$query->whereHas('package', function ($relation) use ($conditions) {
$relation->where('name', $conditions['package_name']);
});
}
if (isset($conditions['starttime'])) {
$this->model = $this->model->where('order_at', '>=', Carbon::parse($conditions['starttime']));
}
if (isset($conditions['starttime'])) {
$query->where('order_at', '>=', Carbon::parse($conditions['starttime']));
}
if (isset($conditions['endtime'])) {
$this->model = $this->model->where('order_at', '<=', Carbon::parse($conditions['endtime']));
}
if (isset($conditions['endtime'])) {
$query->where('order_at', '<=', Carbon::parse($conditions['endtime']));
}
});
return $this;
}

View File

@ -53,30 +53,32 @@ class ProductRepository extends Repository
*/
public function withConditions(array $conditions = [])
{
if (isset($conditions['id'])) {
$conditions['id'] = array_wrap($conditions['id']);
$this->model = $this->model->whereIn('id', $conditions['id']);
}
$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'])) {
$this->model = $this->model->where('company_id', $conditions['company_id']);
}
if (isset($conditions['company_id'])) {
$query->where('company_id', $conditions['company_id']);
}
if (isset($conditions['name'])) {
$this->model = $this->model->where('name', 'like', "%{$conditions['name']}%");
}
if (isset($conditions['name'])) {
$query->where('name', 'like', "%{$conditions['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['package_name'])) {
$query->whereHas('package', function ($relation) use ($conditions) {
$relation->where('name', $conditions['package_name']);
});
}
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['carrier_operator'])) {
$query->whereHas('package', function ($relation) use ($conditions) {
$relation->where('carrier_operator', $conditions['carrier_operator']);
});
}
});
return $this;
}