ef60cd4d
Administrator
first commit
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
<?php
class EventMailTask extends \Phalcon\CLI\Task
{
private $projects;
private $event_info;
private $post;
function mainAction(){
$projects = \projects::find();
$eventsData = $this->getEventData($projects);
foreach($eventsData as $project_id => $events){
foreach($events as $event){
echo "call function \n";
$this->eventMailerAction($project_id, $event);
}
}
}
|
ef60cd4d
Administrator
first commit
|
31
32
33
|
public function startEventsAction(){
$this->actionEventAction();
$this->orderTimeAfterAction();
|
e91b656d
Administrator
change request to...
|
34
|
$this->seriesOfLettersAction();
|
ef60cd4d
Administrator
first commit
|
35
36
|
}
|
853d882a
Administrator
change request to...
|
37
|
public function seriesOfLettersAction(){
|
7882b398
Administrator
change request to...
|
38
|
|
853d882a
Administrator
change request to...
|
39
40
41
42
|
$projects = $this->getActiveProjects();
foreach($projects as $project){
|
62ff66e4
Administrator
change request to...
|
43
44
|
$events = \eventInfo::getEventsByTrigger($this->modelsManager, $project->id, 'series_of_letter');
|
853d882a
Administrator
change request to...
|
45
46
|
foreach($events as $event){
|
62ff66e4
Administrator
change request to...
|
47
|
if($event instanceof \eventInfo){
|
853d882a
Administrator
change request to...
|
48
|
|
62ff66e4
Administrator
change request to...
|
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
$customers = (new customersEmailList())->findFirst("id={$event->customer_id}");
if($customers instanceof customersEmailList){
$eventEmail = ( new \eventEmail())->findFirst("id={$event->event_id}");
if($eventEmail instanceof eventEmail){
$eventEmail = $eventEmail->toArray();
print_r($eventEmail);
}else {
continue;
}
$template = \emailTemplates::findFirst("event_id = {$event->event_id} AND project_id = {$project->id}")->toArray();
$this->post['name']=$customers->name;
$this->post['email']=$customers->email;
$this->post['phone']=$customers->phone;
$this->post['address']=$customers->address;
$this->sendMailData($template,$customers->toArray(),$eventEmail,$project);
$event->last_delivery = date("Y-m-d H:i:s");
$event->delete();
|
853d882a
Administrator
change request to...
|
71
|
}
|
853d882a
Administrator
change request to...
|
72
|
|
853d882a
Administrator
change request to...
|
73
|
|
62ff66e4
Administrator
change request to...
|
74
75
76
|
}
|
853d882a
Administrator
change request to...
|
77
|
}
|
62ff66e4
Administrator
change request to...
|
78
|
|
853d882a
Administrator
change request to...
|
79
80
81
|
}
}
|
ef60cd4d
Administrator
first commit
|
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
public function actionEventAction(){
$projects = $this->getActiveProjects();
foreach($projects as $project){
$events = $this->eventByTrigger($project,'action');
foreach($events as $event){
if(!$event->isNew() ){
if(!$event->isRecurring()){
continue;
}
}
print_r($event->toArray());
switch ($event->event_action) {
case 'birthday':
|
2dfdc329
Administrator
change request to...
|
99
100
101
102
103
104
105
106
107
|
$customers = $project->findUsersByBirthday();
foreach($customers as $customer){
$this->post['name']=$customer->name;
$this->post['email']=$customer->email;
$this->post['phone']=$customer->phone;
$this->post['address']=$customer->address;
$this->sendMail($customer->toArray(),$project,$event,$event->eventEmail->toArray());
}
|
ef60cd4d
Administrator
first commit
|
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
break;
}
}
}
}
public function orderTimeAfterAction(){
$projects = $this->getActiveProjects();
$model = new \spyEvent();
$customers_model = new customersEmailList();
foreach($projects as $project){
$events = $this->eventByTrigger($project,'order_time_after');
foreach($events as $event){
if(!$event->isNew() ){
if(!$event->isRecurring()){
continue;
}
}
|
62ff66e4
Administrator
change request to...
|
134
|
$users = $model->getSpyUsers( $this->modelsManager, $project);
|
ef60cd4d
Administrator
first commit
|
135
136
137
138
139
|
foreach( $users as $user){
$event_data = $model->spyTimeAfter($project, $user['id'])->toArray();
$customers = $customers_model->findFirst("id={$user['id']}");
|
62ff66e4
Administrator
change request to...
|
140
|
if($customers instanceof customersEmailList && $customers->checkEventForUser($event->id, $project->id)){
|
ef60cd4d
Administrator
first commit
|
141
142
143
144
145
146
147
148
149
150
151
|
$sum = 0;
foreach($event_data as $item_one){
$sum += (integer)$item_one['price']*$item_one['quantity'];
}
$this->post['name']=$customers->name;
$this->post['email']=$customers->email;
$this->post['phone']=$customers->phone;
$this->post['address']=$customers->address;
$this->post['sum']=$sum;
|
2dfdc329
Administrator
change request to...
|
152
|
$this->sendMail($customers->toArray(),$project,$event,$event->eventEmail->toArray(),$event_data);
|
ef60cd4d
Administrator
first commit
|
153
154
155
156
157
158
159
160
161
162
163
|
}
}
//$customers = $project->findUsersTimeAfter()->toArray();
}
}
}
|
62ff66e4
Administrator
change request to...
|
164
165
166
167
168
169
|
/**
*TODO: $this->post array with dynamic data for static letters, need to change in some variable
*
*
*
**/
|
ef60cd4d
Administrator
first commit
|
170
171
172
|
private function prepareEventData($item_data, $template){
if($template['text_type']=='static' ){
|
e91b656d
Administrator
change request to...
|
173
|
|
2dfdc329
Administrator
change request to...
|
174
|
|
ef60cd4d
Administrator
first commit
|
175
176
177
|
if( $item_data ){
$template['text'] = $this->MyMailer->OnlineEvent->itemSet( $template, $item_data );
}
|
2dfdc329
Administrator
change request to...
|
178
179
180
181
|
$template['text'] = $this->MyMailer->OnlineEvent->dataSet( $template['text'], $this->post );
|
ef60cd4d
Administrator
first commit
|
182
183
184
|
} else {
|
62ff66e4
Administrator
change request to...
|
185
186
187
|
if( $item_data ) {
$template['text'] = $this->MyMailer->OfflineEvent->itemDynamicSet($template, $item_data);
}
|
ef60cd4d
Administrator
first commit
|
188
|
$template['text'] = $this->MyMailer->OnlineEvent->dataSet( $template['text'], $this->post );
|
2dfdc329
Administrator
change request to...
|
189
|
|
ef60cd4d
Administrator
first commit
|
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
|
}
return $template['text'];
}
private function eventByTrigger($project, $trigger){
$result = array();
foreach($project->offlineEvents() as $eventOffline){
$offlineData = $eventOffline->selectByTrigger($trigger);
foreach($offlineData as $data){
$result[] = $data;
}
}
return $result;
}
private function getActiveProjects(){
return \projects::find("status = 'active'");
}
|
ef60cd4d
Administrator
first commit
|
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
|
private function getEventInfo($event, $customers,$project){
$info = \eventInfo::findFirst("event_id = {$event->id} AND customer_id = {$customers['id']}");
if($info instanceof \eventInfo){
return $info;
} else {
$info = new \eventInfo();
$info->customer_id = $customers['id'];
$info->event_id = $event->id;
$info->project_id = $project->id;
$info->event_trigger = $event->event_trigger;
$info->save();
return $info;
}
}
|
62ff66e4
Administrator
change request to...
|
236
237
238
239
240
241
242
243
|
/**
* send Email
* @params array $customers
* @params object $project
* @params object $offline_data_model
* @params array $event
* @params array $event_data
**/
|
ef60cd4d
Administrator
first commit
|
244
245
246
247
|
public function sendMail($customers,$project,$offline_data_model, $event, $event_data = [] ){
if($customers){
|
2dfdc329
Administrator
change request to...
|
248
|
$event_info = $this->getEventInfo($offline_data_model,$customers,$project);
|
ef60cd4d
Administrator
first commit
|
249
250
251
252
253
|
$template = \emailTemplates::findFirst("event_id = {$event['id']} AND project_id = {$project->id}")->toArray();
|
62ff66e4
Administrator
change request to...
|
254
255
256
257
258
259
|
// if(isset($get['item_data']) && !empty($get['item_data'])){
// $item_data = json_decode($get['item_data']);
//
// $template->text = $this->UTMParser->itemSet( $template->toArray(), $item_data );
//
// }
|
ef60cd4d
Administrator
first commit
|
260
|
|
62ff66e4
Administrator
change request to...
|
261
|
$this->sendMailData($template,$customers,$event,$project,$event_data);
|
ef60cd4d
Administrator
first commit
|
262
263
|
$event_info->last_delivery = date("Y-m-d H:i:s");
|
ef60cd4d
Administrator
first commit
|
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
$event_info->save();
// $model = \delivery::find();
// foreach($model->toArray() as $data){
// $result = $this->MyMailer->getCampaignDeliveryStats( $data['campaign_id']);
//
// $result['status'] = $this->MyMailer->getDeliveryStatus( $data['campaign_id']);
// print_r($result);
// }
// $model->status = $this->MyMailer->getCampaignDeliveryStats( $id);
}
}
|
62ff66e4
Administrator
change request to...
|
278
279
280
281
282
283
284
285
|
/**
* send Email
* @params array $customers
* @params object $project
* @params array $event
* @params array $event_data
* @params array $template
**/
|
ef60cd4d
Administrator
first commit
|
286
|
|
62ff66e4
Administrator
change request to...
|
287
288
289
|
private function sendMailData($template,$customers,$event,$project,$event_data=[])
{
$template['text'] = $this->prepareEventData($event_data, $template);
|
ef60cd4d
Administrator
first commit
|
290
|
|
62ff66e4
Administrator
change request to...
|
291
|
$template['text'] = $this->UTMParser->parse($event, $template);
|
ef60cd4d
Administrator
first commit
|
292
|
|
62ff66e4
Administrator
change request to...
|
293
294
295
296
297
|
$this->MyMailer->OfflineEvent->setFromName($project->name);
$this->MyMailer->OfflineEvent->SendDelivery(new \delivery(),$template,$event,[$customers]);
}
|
ef60cd4d
Administrator
first commit
|
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
|
public function getEventData($projects){
$eventsData = array();
$date = date('d.m.Y');
foreach($projects as $project){
$events = \eventEmail::find("email_type='event_offline' AND project_id=$project->id")->toArray();
if( $events ){
foreach($events as $k => $v){
$conditions = \eventOfflineData::find("event_id = {$v['id']}")->toArray();
if(!empty($conditions)){
$events[$k]['conditions'] = $conditions[0];
} else {
$events[$k]['conditions'] = array();
}
if(!empty($events[$k]['conditions']['event_trigger']) ) {
if($events[$k]['conditions']['event_trigger'] == 'birthday'){
$events[$k]['users'] = \customersEmailList::find("project_id=$project->id AND birthday = '$date'")->toArray();
}
continue;
}
if(!empty($events[$k]['conditions']['event_date']) && $events[$k]['conditions']['event_date'] == $date ) {
$events[$k]['users'] = \customersEmailList::find("project_id=$project->id")->toArray();
echo "will send today";
}
if(!empty($events[$k]['conditions']['equal_fields_one'])){
$events[$k]['users'] = \customersEmailList::find("project_id=$project->id AND {$events[$k]['conditions']['equal_fields_one']} = '{$events[$k]['conditions']['equal_fields_two']}'")->toArray();
}
}
$eventsData[$project->id] = $events;
}
}
return $eventsData;
}
}
|