card_status
This commit is contained in:
parent
6a441bca74
commit
f3442e0559
@ -19,6 +19,7 @@ class CardExport extends AbstractExport implements FromQuery, WithHeadings, With
|
|||||||
|
|
||||||
public function __construct(array $conditions = [])
|
public function __construct(array $conditions = [])
|
||||||
{
|
{
|
||||||
|
$conditions['type'] = isset($conditions['card_status']) ? [0, 1, 2] : 0;
|
||||||
$this->conditions = $conditions;
|
$this->conditions = $conditions;
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
@ -124,6 +124,50 @@ trait OrderCardConcern
|
|||||||
$relation->where('transaction_no', 'like', "%{$conditions['transaction_no']}%");
|
$relation->where('transaction_no', 'like', "%{$conditions['transaction_no']}%");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch ($conditions['card_status']) {
|
||||||
|
case 0:
|
||||||
|
$query->whereNull('service_start_at')->whereHas('card', function ($relation) {
|
||||||
|
$relation->whereNull('cancelled_at');
|
||||||
|
})->where('created_at', '<', Carbon::now()->subMonths(6));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
$query->whereNull('service_start_at')->whereHas('card', function ($relation) {
|
||||||
|
$relation->whereNull('cancelled_at');
|
||||||
|
})->where('created_at', '>=', Carbon::now()->subMonths(6));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
$havingRaw = sprintf("MAX(service_end_at) >= '%s'", date('Y-m-d H:i:s'));
|
||||||
|
|
||||||
|
$query->whereNotNull('service_start_at')
|
||||||
|
->groupBy('sim')->havingRaw($havingRaw)
|
||||||
|
->whereHas('card', function ($relation) {
|
||||||
|
$relation->whereNull('cancelled_at');
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
$havingRaw = sprintf("MAX(service_end_at) < '%s'", date('Y-m-d H:i:s'));
|
||||||
|
|
||||||
|
$query->whereNotNull('service_start_at')
|
||||||
|
->groupBy('sim')->havingRaw($havingRaw)
|
||||||
|
->whereHas('card', function ($relation) {
|
||||||
|
$relation->whereNull('cancelled_at');
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
$query->whereHas('card', function ($relation) {
|
||||||
|
$relation->whereNotNull('cancelled_at');
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
# code...
|
||||||
|
break;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -39,80 +39,17 @@ class CardService extends Service
|
|||||||
public function index(array $conditions = [])
|
public function index(array $conditions = [])
|
||||||
{
|
{
|
||||||
$limit = $conditions['limit'] ?? 20;
|
$limit = $conditions['limit'] ?? 20;
|
||||||
$conditions['type'] = 0;
|
$conditions['type'] = isset($conditions['card_status']) ? [0, 1, 2] : 0;
|
||||||
|
|
||||||
if (isset($conditions['card_status'])) {
|
$total = $this->orderCardPartitionRepository->withConditions($conditions)->count();
|
||||||
$res = $this->listByCardStatus($conditions);
|
|
||||||
$total = $res->total();
|
|
||||||
$conditions['sim'] = $res->pluck('sim')->toArray();
|
|
||||||
} else {
|
|
||||||
$total = $this->orderCardPartitionRepository->withConditions($conditions)->applyConditions()->count();
|
|
||||||
}
|
|
||||||
|
|
||||||
$page = Request::get('page');
|
$cards = $this->orderCardPartitionRepository->selectRaw('sim')->withConditions($conditions)->forPage($page, $limit)->get();
|
||||||
|
|
||||||
$cards = $this->orderCardPartitionRepository->withConditions($conditions)->applyConditions()->forPage($page, $limit)->get();
|
|
||||||
|
|
||||||
$cards = static::transformer($cards);
|
$cards = static::transformer($cards);
|
||||||
|
|
||||||
return new LengthAwarePaginator($cards, $total, $limit);
|
return new LengthAwarePaginator($cards, $total, $limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function listByCardStatus(array $conditions = [])
|
|
||||||
{
|
|
||||||
$limit = $conditions['limit'] ?? 20;
|
|
||||||
$conditions['type'] = [0, 1, 2];
|
|
||||||
|
|
||||||
$query = $this->orderCardPartitionRepository->selectRaw('sim')->withConditions($conditions);
|
|
||||||
|
|
||||||
switch ($conditions['card_status']) {
|
|
||||||
|
|
||||||
case 0:
|
|
||||||
$query = $query->whereNull('service_start_at')->whereHas('card', function ($relation) {
|
|
||||||
$relation->whereNull('cancelled_at');
|
|
||||||
})->where('created_at', '<', Carbon::now()->subMonths(6));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 1:
|
|
||||||
$query = $query->whereNull('service_start_at')->whereHas('card', function ($relation) {
|
|
||||||
$relation->whereNull('cancelled_at');
|
|
||||||
})->where('created_at', '>=', Carbon::now()->subMonths(6));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
$havingRaw = sprintf("MAX(service_end_at) >= '%s'", date('Y-m-d H:i:s'));
|
|
||||||
|
|
||||||
$query = $query->whereNotNull('service_start_at')
|
|
||||||
->groupBy('sim')->havingRaw($havingRaw)
|
|
||||||
->whereHas('card', function ($relation) {
|
|
||||||
$relation->whereNull('cancelled_at');
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 3:
|
|
||||||
$havingRaw = sprintf("MAX(service_end_at) < '%s'", date('Y-m-d H:i:s'));
|
|
||||||
|
|
||||||
$query = $query->whereNotNull('service_start_at')
|
|
||||||
->groupBy('sim')->havingRaw($havingRaw)
|
|
||||||
->whereHas('card', function ($relation) {
|
|
||||||
$relation->whereNull('cancelled_at');
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 4:
|
|
||||||
$query = $query->whereHas('card', function ($relation) {
|
|
||||||
$relation->whereNotNull('cancelled_at');
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
# code...
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $query->paginate($limit);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 格式转化
|
* 格式转化
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user