@@ -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