Merge branch 'local' into dev

This commit is contained in:
邓皓元 2019-05-10 17:02:39 +08:00
commit 368f210c03
3 changed files with 48 additions and 66 deletions

View File

@ -19,6 +19,7 @@ class CardExport extends AbstractExport implements FromQuery, WithHeadings, With
public function __construct(array $conditions = [])
{
$conditions['type'] = isset($conditions['card_status']) ? [0, 1, 2] : 0;
$this->conditions = $conditions;
parent::__construct();
}

View File

@ -124,6 +124,50 @@ trait OrderCardConcern
$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;

View File

@ -39,80 +39,17 @@ class CardService extends Service
public function index(array $conditions = [])
{
$limit = $conditions['limit'] ?? 20;
$conditions['type'] = 0;
$conditions['type'] = isset($conditions['card_status']) ? [0, 1, 2] : 0;
if (isset($conditions['card_status'])) {
$res = $this->listByCardStatus($conditions);
$total = $res->total();
$conditions['sim'] = $res->pluck('sim')->toArray();
} else {
$total = $this->orderCardPartitionRepository->withConditions($conditions)->applyConditions()->count();
}
$total = $this->orderCardPartitionRepository->withConditions($conditions)->count();
$page = Request::get('page');
$cards = $this->orderCardPartitionRepository->withConditions($conditions)->applyConditions()->forPage($page, $limit)->get();
$cards = $this->orderCardPartitionRepository->selectRaw('sim')->withConditions($conditions)->forPage($page, $limit)->get();
$cards = static::transformer($cards);
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);
}
/**
* 格式转化
*