Skip to content

Commit baeac22

Browse files
committed
[feature] v1
1 parent ba45e05 commit baeac22

34 files changed

+1159
-205
lines changed

app/Http/Controllers/Api/DealingController.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,32 @@ public function fetch(
2828
);
2929
}
3030

31+
/**
32+
* @param \App\Services\Application\DealingFetchBillingTransactionService $dealingFetchBillingTransactionService
33+
* @return \Illuminate\Http\Response|\Illuminate\Contracts\Routing\ResponseFactory
34+
*/
35+
public function fetchBillingTransaction(
36+
\App\Services\Application\DealingFetchBillingTransactionService $dealingFetchBillingTransactionService
37+
) {
38+
return response()->json(
39+
$dealingFetchBillingTransactionService->getResponseData(),
40+
Response::HTTP_OK
41+
);
42+
}
43+
44+
/**
45+
* @param \App\Services\Application\DealingFetchBillingSortBillingDateService $dealingFetchBillingSortBillingDateService
46+
* @return \Illuminate\Http\Response|\Illuminate\Contracts\Routing\ResponseFactory
47+
*/
48+
public function fetchBillingSortBillingDate(
49+
\App\Services\Application\DealingFetchBillingSortBillingDateService $dealingFetchBillingSortBillingDateService
50+
) {
51+
return response()->json(
52+
$dealingFetchBillingSortBillingDateService->getResponseData(),
53+
Response::HTTP_OK
54+
);
55+
}
56+
3157
/**
3258
* @param \App\Http\Requests\Api\Dealing\UpdateRequest $request
3359
* @param \App\Infrastructures\Models\DomainDealing $domainDealing

app/Http/Controllers/Api/DomainController.php

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ public function __construct()
1212
{
1313
parent::__construct();
1414

15-
$this->middleware('can:owner,domain')->except(['fetch', 'store']);
15+
$this->middleware('can:owner,domain')->except([
16+
'fetch',
17+
'fetchTotalSeller',
18+
'fetchTransition',
19+
'fetchSortExpired',
20+
'store'
21+
]);
1622
}
1723

1824
/**
@@ -28,6 +34,45 @@ public function fetch(
2834
);
2935
}
3036

37+
/**
38+
* @param \App\Services\Application\DomainFetchTotalSellerService $domainFetchTotalSellerService
39+
* @return \Illuminate\Http\Response|\Illuminate\Contracts\Routing\ResponseFactory
40+
*/
41+
public function fetchTotalSeller(
42+
\App\Services\Application\DomainFetchTotalSellerService $domainFetchTotalSellerService
43+
) {
44+
return response()->json(
45+
$domainFetchTotalSellerService->getResponseData(),
46+
Response::HTTP_OK
47+
);
48+
}
49+
50+
/**
51+
* @param \App\Services\Application\DomainFetchTransactionService $domainFetchTransactionService
52+
* @return \Illuminate\Http\Response|\Illuminate\Contracts\Routing\ResponseFactory
53+
*/
54+
public function fetchTransition(
55+
\App\Services\Application\DomainFetchTransactionService $domainFetchTransactionService
56+
) {
57+
return response()->json(
58+
$domainFetchTransactionService->getResponseData(),
59+
Response::HTTP_OK
60+
);
61+
}
62+
63+
/**
64+
* @param \App\Services\Application\DomainFetchSortExpiredService $domainFetchSortExpiredService
65+
* @return \Illuminate\Http\Response|\Illuminate\Contracts\Routing\ResponseFactory
66+
*/
67+
public function fetchSortExpired(
68+
\App\Services\Application\DomainFetchSortExpiredService $domainFetchSortExpiredService
69+
) {
70+
return response()->json(
71+
$domainFetchSortExpiredService->getResponseData(),
72+
Response::HTTP_OK
73+
);
74+
}
75+
3176
/**
3277
* @param \App\Http\Requests\Api\Domain\UpdateRequest $request
3378
* @param \App\Infrastructures\Models\Domain $domain

app/Http/Resources/BillingResource.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public function toArray($request): array
2020
'billing_date' => $this->billing_date,
2121
'is_fixed' => $this->is_fixed,
2222
'changed_at' => $this->changed_at,
23+
'domain_name' => $this->getDomainName(),
2324
'updated_at' => $this->updated_at,
2425
'created_at' => $this->created_at,
2526
];

app/Infrastructures/Models/Domain.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,18 @@ public function isOwned(): bool
9292
{
9393
return $this->is_active && ! $this->is_transferred;
9494
}
95+
96+
/**
97+
* @return integer
98+
*/
99+
public function getTotalSeller(): int
100+
{
101+
$totalPrice = 0;
102+
103+
foreach ($this->domainDealings as $domainDealing) {
104+
$totalPrice += $domainDealing->getTotalPrice();
105+
}
106+
107+
return $totalPrice;
108+
}
95109
}

app/Infrastructures/Models/DomainBilling.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ final class DomainBilling extends BaseModel
1414
'changed_at',
1515
];
1616

17+
protected $casts = [
18+
'total' => 'integer',
19+
'is_fixed' => 'boolean',
20+
];
21+
1722
protected $dates = [
1823
'billing_date',
1924
'changed_at',
@@ -36,4 +41,20 @@ public function getUserId(): int
3641
{
3742
return $this->domainDealing->getUserId();
3843
}
44+
45+
/**
46+
* @return string
47+
*/
48+
public function getDomainName(): string
49+
{
50+
return $this->domainDealing->getDomainName();
51+
}
52+
53+
/**
54+
* @return boolean
55+
*/
56+
public function isFixed(): bool
57+
{
58+
return $this->is_fixed;
59+
}
3960
}

app/Infrastructures/Models/DomainDealing.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,28 @@ public function getNextBillingDate(): \Carbon\Carbon
131131
{
132132
return $this->getNextBillingDateByTargetDate($this->billing_date);
133133
}
134+
135+
/**
136+
* @return integer
137+
*/
138+
public function getTotalPrice(): int
139+
{
140+
$totalPrice = 0;
141+
142+
foreach ($this->domainBillings as $domainBilling) {
143+
if ($domainBilling->isFixed()) {
144+
$totalPrice += $domainBilling->total;
145+
}
146+
}
147+
148+
return $totalPrice;
149+
}
150+
151+
/**
152+
* @return string
153+
*/
154+
public function getDomainName(): string
155+
{
156+
return $this->domain->name;
157+
}
134158
}

app/Infrastructures/Models/Subdomain.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,6 @@ public function dnsRecordType(): \Illuminate\Database\Eloquent\Relations\Belongs
4545
return $this->belongsTo('App\Infrastructures\Models\DnsRecordType', 'type_id');
4646
}
4747

48-
/**
49-
* @return string
50-
*/
51-
public function getFullDomainNameAttribute(): string
52-
{
53-
if ($this->prefix !== '') {
54-
return $this->prefix . '.' . $this->domain->name;
55-
}
56-
57-
return $this->domain->name;
58-
}
59-
6048
/**
6149
* @return string
6250
*/
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Infrastructures\Queries\Domain\Billing;
6+
7+
use App\Infrastructures\Models\DomainBilling;
8+
9+
final class EloquentBillingQueryService implements EloquentBillingQueryServiceInterface
10+
{
11+
/**
12+
* @param array $userIds
13+
* @param \Carbon\Carbon $startDatetime
14+
* @param \Carbon\Carbon $endDatetime
15+
* @return \Illuminate\Database\Eloquent\Collection
16+
*/
17+
public function getBillingByUserIdsBillingDateBetweenStartDatetimeEndDatetime(
18+
array $userIds,
19+
\Carbon\Carbon $startDatetime,
20+
\Carbon\Carbon $endDatetime
21+
): \Illuminate\Database\Eloquent\Collection {
22+
return DomainBilling::join('domain_dealings', 'domain_dealings.id', '=', 'domain_billings.dealing_id')
23+
->join('domains', 'domains.id', '=', 'domain_dealings.domain_id')
24+
->select('domain_billings.*')
25+
->whereIn('domains.user_id', $userIds)
26+
->whereBetween('domain_billings.billing_date', [$startDatetime, $endDatetime])
27+
->get();
28+
}
29+
30+
/**
31+
* @param array $userIds
32+
* @param \Carbon\Carbon $targetDatetime
33+
* @param integer $take
34+
* @return \Illuminate\Database\Eloquent\Collection
35+
*/
36+
public function getSortBillingDateBillingsByUserIdsBillingDateGreaterThanTargetDatetimeTake(
37+
array $userIds,
38+
\Carbon\Carbon $targetDatetime,
39+
int $take
40+
): \Illuminate\Database\Eloquent\Collection {
41+
return DomainBilling::join('domain_dealings', 'domain_dealings.id', '=', 'domain_billings.dealing_id')
42+
->join('domains', 'domains.id', '=', 'domain_dealings.domain_id')
43+
->select('domain_billings.*')
44+
->whereIn('domains.user_id', $userIds)
45+
->where('domain_billings.is_fixed', false)
46+
->where('domain_billings.billing_date', '>=', $targetDatetime)
47+
->orderBy('domain_billings.billing_date')
48+
->take($take)
49+
->get();
50+
}
51+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Infrastructures\Queries\Domain\Billing;
6+
7+
interface EloquentBillingQueryServiceInterface
8+
{
9+
/**
10+
* @param array $userIds
11+
* @param \Carbon\Carbon $startDatetime
12+
* @param \Carbon\Carbon $endDatetime
13+
* @return \Illuminate\Database\Eloquent\Collection
14+
*/
15+
public function getBillingByUserIdsBillingDateBetweenStartDatetimeEndDatetime(
16+
array $userIds,
17+
\Carbon\Carbon $startDatetime,
18+
\Carbon\Carbon $endDatetime
19+
): \Illuminate\Database\Eloquent\Collection;
20+
21+
/**
22+
* @param array $userIds
23+
* @param \Carbon\Carbon $targetDatetime
24+
* @param integer $take
25+
* @return \Illuminate\Database\Eloquent\Collection
26+
*/
27+
public function getSortBillingDateBillingsByUserIdsBillingDateGreaterThanTargetDatetimeTake(
28+
array $userIds,
29+
\Carbon\Carbon $targetDatetime,
30+
int $take
31+
): \Illuminate\Database\Eloquent\Collection;
32+
}

app/Infrastructures/Queries/Domain/EloquentDomainQueryService.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,83 @@ public function getByUserIds(array $userIds): \Illuminate\Database\Eloquent\Coll
3838
{
3939
return Domain::whereIn('user_id', $userIds)->get();
4040
}
41+
42+
/**
43+
* @param array $userIds
44+
* @param \Carbon\Carbon $targetDatetime
45+
* @return \Illuminate\Database\Eloquent\Collection
46+
*/
47+
public function getActiveByUserIdsPurchasedAtLessThanTargetDatetime(
48+
array $userIds,
49+
\Carbon\Carbon $targetDatetime
50+
): \Illuminate\Database\Eloquent\Collection {
51+
return Domain::whereIn('user_id', $userIds)
52+
->where('is_active', true)
53+
->where('is_transferred', false)
54+
->whereNull('canceled_at')
55+
->where('purchased_at', '<=', $targetDatetime)
56+
->get();
57+
}
58+
59+
/**
60+
* @param array $userIds
61+
* @param \Carbon\Carbon $startDatetime
62+
* @param \Carbon\Carbon $endDatetime
63+
* @return \Illuminate\Database\Eloquent\Collection
64+
*/
65+
public function getBillingByUserIdsBillingDateBetweenStartDatetimeEndDatetime(
66+
array $userIds,
67+
\Carbon\Carbon $startDatetime,
68+
\Carbon\Carbon $endDatetime
69+
): \Illuminate\Database\Eloquent\Collection {
70+
return Domain::join('domain_dealings', 'domains.id', '=', 'domain_dealings.domain_id')
71+
->join('domain_billings', 'domain_dealings.id', '=', 'domain_billings.dealing_id')
72+
->select('domain_billings.*')
73+
->whereIn('domains.user_id', $userIds)
74+
->whereBetween('domain_billings.billing_date', [$startDatetime, $endDatetime])
75+
->get();
76+
}
77+
78+
/**
79+
* @param array $userIds
80+
* @param \Carbon\Carbon $targetDatetime
81+
* @param integer $take
82+
* @return \Illuminate\Database\Eloquent\Collection
83+
*/
84+
public function getSortExpiredByUserIdsExpiredGreaterThanTargetDatetimeTake(
85+
array $userIds,
86+
\Carbon\Carbon $targetDatetime,
87+
int $take
88+
): \Illuminate\Database\Eloquent\Collection {
89+
return Domain::whereIn('user_id', $userIds)
90+
->where('is_active', true)
91+
->where('is_transferred', false)
92+
->whereNull('canceled_at')
93+
->where('expired_at', '>=', $targetDatetime)
94+
->orderBy('expired_at')
95+
->take($take)
96+
->get();
97+
}
98+
99+
/**
100+
* @param array $userIds
101+
* @param \Carbon\Carbon $targetDatetime
102+
* @param integer $take
103+
* @return \Illuminate\Database\Eloquent\Collection
104+
*/
105+
public function getSortBillingDateBillingsByUserIdsBillingDateGreaterThanTargetDatetimeTake(
106+
array $userIds,
107+
\Carbon\Carbon $targetDatetime,
108+
int $take
109+
): \Illuminate\Database\Eloquent\Collection {
110+
return Domain::join('domain_dealings', 'domains.id', '=', 'domain_dealings.domain_id')
111+
->join('domain_billings', 'domain_dealings.id', '=', 'domain_billings.dealing_id')
112+
->select('domain_billings.*')
113+
->whereIn('domains.user_id', $userIds)
114+
->where('domain_billings.is_fixed', false)
115+
->where('domain_billings.billing_date', '>=', $targetDatetime)
116+
->orderBy('domain_billings.billing_date')
117+
->take($take)
118+
->get();
119+
}
41120
}

0 commit comments

Comments
 (0)