1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Console\Commands; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Carbon\Carbon; |
7
|
|
|
use App\Sms_event; |
8
|
|
|
use App\Member; |
9
|
|
|
use App\Enquiry; |
10
|
|
|
|
11
|
|
|
class SmsEvent extends Command |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* The name and signature of the console command. |
15
|
|
|
* |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $signature = 'sms:event'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* The console command description. |
22
|
|
|
* |
23
|
|
|
* @var string |
24
|
|
|
*/ |
25
|
|
|
protected $description = 'Triggers sms for events scheduled for the day'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Create a new command instance. |
29
|
|
|
* |
30
|
|
|
* @return void |
31
|
|
|
*/ |
32
|
|
|
public function __construct() |
33
|
|
|
{ |
34
|
|
|
parent::__construct(); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Execute the console command. |
39
|
|
|
* |
40
|
|
|
* @return mixed |
41
|
|
|
*/ |
42
|
|
|
public function handle() |
43
|
|
|
{ |
44
|
|
|
$smsevents = Sms_event::where('date','=',Carbon::today())->get(); |
45
|
|
|
$sender_id = \Utilities::getSetting('sms_sender_id'); |
46
|
|
|
|
47
|
|
|
foreach($smsevents as $smsevent) |
48
|
|
|
{ |
49
|
|
|
$sms_text = $smsevent->message; |
50
|
|
|
$sms_status = $smsevent->status; |
51
|
|
|
|
52
|
|
|
foreach(explode(",", $smsevent->send_to) as $sendTo) |
53
|
|
|
{ |
54
|
|
|
switch ($sendTo) |
55
|
|
|
{ |
56
|
|
|
case 0: |
57
|
|
|
$recievers = Member::where('status',1)->get(); |
58
|
|
|
foreach ($recievers as $reciever) |
59
|
|
|
{ |
60
|
|
|
\Utilities::Sms($sender_id,$reciever->contact,$sms_text,$sms_status); |
61
|
|
|
} |
62
|
|
|
break; |
63
|
|
|
|
64
|
|
|
case 1: |
65
|
|
|
$recievers = Member::where('status',0)->get(); |
66
|
|
|
foreach ($recievers as $reciever) |
67
|
|
|
{ |
68
|
|
|
\Utilities::Sms($sender_id,$reciever->contact,$sms_text,$sms_status); |
69
|
|
|
} |
70
|
|
|
break; |
71
|
|
|
|
72
|
|
|
case 2: |
73
|
|
|
$recievers = Enquiry::where('status',1)->get(); |
74
|
|
|
foreach ($recievers as $reciever) |
75
|
|
|
{ |
76
|
|
|
\Utilities::Sms($sender_id,$reciever->contact,$sms_text,$sms_status); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
break; |
80
|
|
|
|
81
|
|
|
case 3: |
82
|
|
|
$recievers = Enquiry::where('status',0)->get(); |
83
|
|
|
foreach ($recievers as $reciever) |
84
|
|
|
{ |
85
|
|
|
\Utilities::Sms($sender_id,$reciever->contact,$sms_text,$sms_status); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
break; |
89
|
|
|
|
90
|
|
|
default: |
91
|
|
|
# code... |
92
|
|
|
break; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
} |
98
|
|
|
|