1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Common; |
4
|
|
|
|
5
|
|
|
use App\Model\Common\Template; |
6
|
|
|
use App\Model\Mailjob\ExpiryMailDay; |
7
|
|
|
use App\Model\Order\Invoice; |
8
|
|
|
use App\Model\Order\Order; |
9
|
|
|
use App\Model\Product\Subscription; |
10
|
|
|
use App\User; |
11
|
|
|
use Carbon\Carbon; |
12
|
|
|
|
13
|
|
|
class CronController extends BaseCronController |
14
|
|
|
{ |
15
|
|
|
protected $subscription; |
16
|
|
|
protected $order; |
17
|
|
|
protected $user; |
18
|
|
|
protected $template; |
19
|
|
|
protected $invoice; |
20
|
|
|
|
21
|
|
|
public function __construct() |
22
|
|
|
{ |
23
|
|
|
$subscription = new Subscription(); |
24
|
|
|
$this->sub = $subscription; |
25
|
|
|
|
26
|
|
|
$order = new Order(); |
27
|
|
|
$this->order = $order; |
28
|
|
|
|
29
|
|
|
$user = new User(); |
30
|
|
|
$this->user = $user; |
31
|
|
|
|
32
|
|
|
$template = new Template(); |
33
|
|
|
$this->template = $template; |
34
|
|
|
|
35
|
|
|
$invoice = new Invoice(); |
36
|
|
|
$this->invoice = $invoice; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function getExpiredInfoByOrderId($orderid) |
40
|
|
|
{ |
41
|
|
|
$yesterday = new Carbon('today'); |
42
|
|
|
$sub = $this->sub |
43
|
|
|
->where('order_id', $orderid) |
44
|
|
|
->where('update_ends_at', '!=', '0000-00-00 00:00:00') |
45
|
|
|
->whereNotNull('update_ends_at') |
46
|
|
|
->where('update_ends_at', '<', $yesterday) |
47
|
|
|
->first(); |
48
|
|
|
|
49
|
|
|
return $sub; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function getAllDaysExpiryUsers($day) |
53
|
|
|
{ |
54
|
|
|
$sub = $this->getAllDaysExpiryInfo($day); |
55
|
|
|
//dd($sub->get()); |
56
|
|
|
$users = []; |
57
|
|
|
if ($sub->get()->count() > 0) { |
58
|
|
|
foreach ($sub->get() as $key => $value) { |
59
|
|
|
$users[$key]['users'] = $this->sub->find($value->id)->user()->get(); |
60
|
|
|
$users[$key]['orders'] = $this->sub->find($value->id)->order()->get(); |
61
|
|
|
$users[$key]['subscription'] = $value; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $users; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function get15DaysExpiryUsers() |
69
|
|
|
{ |
70
|
|
|
$sub = $this->get15DaysExpiryInfo(); |
71
|
|
|
$users = []; |
72
|
|
|
if ($sub->get()->count() > 0) { |
73
|
|
|
foreach ($sub->get() as $key => $value) { |
74
|
|
|
$users[$key]['users'] = $this->sub->find($value->id)->user()->get(); |
75
|
|
|
$users[$key]['orders'] = $this->sub->find($value->id)->order()->get(); |
76
|
|
|
$users[$key]['subscription'] = $value; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return $users; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function getOneDayExpiryUsers() |
84
|
|
|
{ |
85
|
|
|
$sub = $this->getOneDayExpiryInfo(); |
86
|
|
|
$users = []; |
87
|
|
|
if ($sub->get()->count() > 0) { |
88
|
|
|
foreach ($sub->get() as $key => $value) { |
89
|
|
|
$users[$key]['users'] = $this->sub->find($value->id)->user()->get(); |
90
|
|
|
$users[$key]['orders'] = $this->sub->find($value->id)->order()->get(); |
91
|
|
|
$users[$key]['subscription'] = $value; |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return $users; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function getOnDayExpiryUsers() |
99
|
|
|
{ |
100
|
|
|
$sub = $this->getOnDayExpiryInfo(); |
101
|
|
|
$users = []; |
102
|
|
|
if ($sub->get()->count() > 0) { |
103
|
|
|
foreach ($sub->get() as $key => $value) { |
104
|
|
|
$users[$key]['users'] = $this->sub->find($value->id)->user()->get(); |
105
|
|
|
$users[$key]['orders'] = $this->sub->find($value->id)->order()->get(); |
106
|
|
|
$users[$key]['subscription'] = $value; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
return $users; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
public function getExpiredUsers() |
114
|
|
|
{ |
115
|
|
|
$sub = $this->getExpiredInfo(); |
116
|
|
|
$users = []; |
117
|
|
|
if ($sub->get()->count() > 0) { |
118
|
|
|
foreach ($sub->get() as $key => $value) { |
119
|
|
|
$users[$key]['users'] = $this->sub->find($value->id)->user()->get(); |
120
|
|
|
$users[$key]['orders'] = $this->sub->find($value->id)->order()->get(); |
121
|
|
|
$users[$key]['subscription'] = $value; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
return $users; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function get30DaysOrders() |
129
|
|
|
{ |
130
|
|
|
$users = []; |
131
|
|
|
$users = $this->get30DaysExpiryUsers(); |
132
|
|
|
if (count($users) > 0) { |
133
|
|
|
return $users[0]['orders']; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
return $users; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
public function get15DaysOrders() |
140
|
|
|
{ |
141
|
|
|
$users = []; |
142
|
|
|
$users = $this->get15DaysExpiryUsers(); |
143
|
|
|
if (count($users) > 0) { |
144
|
|
|
return $users[0]['orders']; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
return $users; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
public function get1DaysOrders() |
151
|
|
|
{ |
152
|
|
|
$users = []; |
153
|
|
|
$users = $this->getOneDayExpiryUsers(); |
154
|
|
|
if (count($users) > 0) { |
155
|
|
|
return $users[0]['orders']; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
return $users; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public function get0DaysOrders() |
162
|
|
|
{ |
163
|
|
|
$users = []; |
164
|
|
|
$users = $this->getOnDayExpiryUsers(); |
165
|
|
|
if (count($users) > 0) { |
166
|
|
|
return $users[0]['orders']; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
return $users; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function getPlus1Orders() |
173
|
|
|
{ |
174
|
|
|
$users = []; |
175
|
|
|
$users = $this->getExpiredUsers(); |
176
|
|
|
if (count($users) > 0) { |
177
|
|
|
return $users[0]['orders']; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
return $users; |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
public function get15DaysSubscription() |
184
|
|
|
{ |
185
|
|
|
$users = []; |
186
|
|
|
$users = $this->get15DaysExpiryUsers(); |
187
|
|
|
if (count($users) > 0) { |
188
|
|
|
return $users[0]['subscription']; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
return $users; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
public function get1DaysSubscription() |
195
|
|
|
{ |
196
|
|
|
$users = []; |
197
|
|
|
$users = $this->getOneDayExpiryUsers(); |
198
|
|
|
if (count($users) > 0) { |
199
|
|
|
return $users[0]['subscription']; |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
return $users; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
public function get0DaysSubscription() |
206
|
|
|
{ |
207
|
|
|
$users = []; |
208
|
|
|
$users = $this->getOnDayExpiryUsers(); |
209
|
|
|
if (count($users) > 0) { |
210
|
|
|
return $users[0]['subscription']; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
return $users; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
public function getPlus1Subscription() |
217
|
|
|
{ |
218
|
|
|
$users = []; |
219
|
|
|
$users = $this->getExpiredUsers(); |
220
|
|
|
if (count($users) > 0) { |
221
|
|
|
return $users[0]['subscription']; |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
return $users; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
public function getUsers() |
228
|
|
|
{ |
229
|
|
|
$users = []; |
230
|
|
|
if (count($this->get30DaysUsers())) { |
231
|
|
|
array_push($users, $this->get30DaysUsers()); |
232
|
|
|
} |
233
|
|
|
if (count($this->get15DaysUsers())) { |
234
|
|
|
array_push($users, $this->get15DaysUsers()); |
235
|
|
|
} |
236
|
|
|
if (count($this->get1DaysUsers())) { |
237
|
|
|
array_push($users, $this->get1DaysUsers()); |
238
|
|
|
} |
239
|
|
|
if (count($this->get0DaysUsers())) { |
240
|
|
|
array_push($users, $this->get0DaysUsers()); |
241
|
|
|
} |
242
|
|
|
if (count($this->getPlus1Users())) { |
243
|
|
|
array_push($users, $this->getPlus1Users()); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
return $users; |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
public function eachSubscription() |
250
|
|
|
{ |
251
|
|
|
$allDays = ExpiryMailDay::pluck('days')->toArray(); |
252
|
|
|
$sub = $this->getSubscriptions($allDays); |
253
|
|
|
foreach ($sub as $value) { |
254
|
|
|
$userid = $value->user_id; |
255
|
|
|
$user = $this->getUserById($userid); |
256
|
|
|
$end = $value->update_ends_at; |
257
|
|
|
$order = $this->getOrderById($value->order_id); |
258
|
|
|
$invoice = $this->getInvoiceByOrderId($value->order_id); |
259
|
|
|
$item = $this->getInvoiceItemByInvoiceId($invoice->id); |
260
|
|
|
$product = $item->product_name; |
261
|
|
|
if (emailSendingStatus()) { |
262
|
|
|
$this->mail($user, $end, $product, $order, $value->id); |
263
|
|
|
} |
264
|
|
|
} |
265
|
|
|
} |
266
|
|
|
} |
267
|
|
|
|