Smsreport.php
3.71 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
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
<?php namespace App\Console\Commands;
use Illuminate\Console\Command;
//use Mail;
use DB;
use Config;
use App\Models\User;
use App\Models\Accesslog;
use App\Models\CRMCall;
use Schema;
use PDO;
use Illuminate\Database\Schema\Blueprint;
class Smsreport extends Command {
/**
* The console command name.
*
* @var string
*/
protected $signature = 'Smsreport';
/**
* The console command description.
*
* @var string
*/
protected $description = 'App Main Daily Task for Smsreport';
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$nowts=time();
$date=date('F_Y');
echo "\n".date('Y-m-d H:i:s')."\n";
$logdate=strtotime('0 day');
$tcol=0;$fieldsarr=array();$extrahdrarr=array();
$central_ip=env('central_ip');
$server_ip=env('app_ip');
$calllog_report = "calllog_report_".$date;
$conn = array(
'driver' => 'mysql',
'host' => $central_ip,
'database' => env('DB_DATABASE', 'kstych_flexydial'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'options' => array(
PDO::ATTR_TIMEOUT => 5,
),
);
Config::set("database.connections.conn", $conn);
DB::connection("conn")->getDatabaseName();
$serverclist=DB::connection("conn")->select(DB::raw("select id from server_details where server_ip='$server_ip'"));
$server_id=$serverclist[0]->id;
if($server_id<10){
$server_id="0".$server_id;
}
$maxid=DB::connection("conn")->select(DB::raw("SELECT max(sms_id) as maxid from sms_report where server='$server_id'"));
$maxids=$maxid[0]->maxid;
//$alist=DB::select(DB::raw("SELECT * from crmcalls where id>'$maxids' and created_at<'".date("Y-m-d H:i:s",$logdate-(60*60))."'"));
$alist=DB::select(DB::raw("SELECT * from sms_log where id>'$maxids'"));
$countnumber=count($alist);
$finalnumber=$countnumber/50;
$finalnumber=floor($finalnumber);
$datainser='';
$iii=1;
$kkk=1;
$shortinsert="";
$userarr=array();
foreach($alist as $aline)
{
$server = $server_id;
$sms_id = $aline->id;
$created_at = $aline->created_at;
$message_time = date("Y-m-d H:i:s",strtotime($aline->created_at)+330*60);
$server_ip = $aline->server_ip;
$call_id = $aline->call_id;
$agent_name = $aline->agent_name;
$subdispo = $aline->subdispo;
$number = $aline->number;
$message = $aline->message;
$response = $aline->response;
$shortinsert.="('$server', '$sms_id','$created_at', '$message_time', '$server_ip', '$call_id', '$agent_name', '$subdispo', '$number', '$message', '$response'),";
if($kkk<=$finalnumber){
if($iii%50==0){
$shortinsert=substr($shortinsert,0,-1);
DB::connection("conn")->insert(DB::raw("INSERT INTO sms_report (`server`, `sms_id`, `created_at`, `message_time`, `server_ip`, `call_id`, `agent_name`, `subdispo`, `number`, `message`, `response`) VALUES $shortinsert"));
$kkk++;
}
}else{
DB::connection("conn")->insert(DB::raw("INSERT INTO sms_report set server='$server', sms_id='$sms_id', created_at='$created_at', message_time='$message_time', server_ip='$server_ip', call_id='$call_id', agent_name='$agent_name', subdispo='$subdispo', number='$number', message='$message', response='$response'"));
}
if($iii%50==0){
$shortinsert="";
}
$iii++;
//$update=DB::connection("conn")->select(DB::raw("SELECT crmcall_id as updateid from $calllog_report where server='$server_id' and `state` IN ('DialBegin','DialEnd')"));
//echo $update;
//DB::update(DB::raw("UPDATE crmcalls set call_flag='C' where id=$crmcall_id"));
}
echo "\n".date('Y-m-d H:i:s')."\n";
DB::connection("conn")->disconnect();
}
}