To send data from local to central for SMS
Showing
1 changed file
with
132 additions
and
0 deletions
| 1 | <?php namespace App\Console\Commands; | ||
| 2 | |||
| 3 | use Illuminate\Console\Command; | ||
| 4 | //use Mail; | ||
| 5 | use DB; | ||
| 6 | use Config; | ||
| 7 | |||
| 8 | use App\Models\User; | ||
| 9 | use App\Models\Accesslog; | ||
| 10 | |||
| 11 | use App\Models\CRMCall; | ||
| 12 | use Schema; | ||
| 13 | use PDO; | ||
| 14 | |||
| 15 | use Illuminate\Database\Schema\Blueprint; | ||
| 16 | |||
| 17 | class Smsreport extends Command { | ||
| 18 | |||
| 19 | /** | ||
| 20 | * The console command name. | ||
| 21 | * | ||
| 22 | * @var string | ||
| 23 | */ | ||
| 24 | protected $signature = 'Smsreport'; | ||
| 25 | |||
| 26 | /** | ||
| 27 | * The console command description. | ||
| 28 | * | ||
| 29 | * @var string | ||
| 30 | */ | ||
| 31 | protected $description = 'App Main Daily Task for Smsreport'; | ||
| 32 | |||
| 33 | /** | ||
| 34 | * Execute the console command. | ||
| 35 | * | ||
| 36 | * @return mixed | ||
| 37 | */ | ||
| 38 | public function handle() | ||
| 39 | { | ||
| 40 | $nowts=time(); | ||
| 41 | $date=date('F_Y'); | ||
| 42 | echo "\n".date('Y-m-d H:i:s')."\n"; | ||
| 43 | |||
| 44 | $logdate=strtotime('0 day'); | ||
| 45 | |||
| 46 | $tcol=0;$fieldsarr=array();$extrahdrarr=array(); | ||
| 47 | $central_ip=env('central_ip'); | ||
| 48 | $server_ip=env('app_ip'); | ||
| 49 | $calllog_report = "calllog_report_".$date; | ||
| 50 | $conn = array( | ||
| 51 | 'driver' => 'mysql', | ||
| 52 | 'host' => $central_ip, | ||
| 53 | 'database' => env('DB_DATABASE', 'kstych_flexydial'), | ||
| 54 | 'username' => env('DB_USERNAME', 'root'), | ||
| 55 | 'password' => env('DB_PASSWORD', ''), | ||
| 56 | 'charset' => 'utf8', | ||
| 57 | 'collation' => 'utf8_unicode_ci', | ||
| 58 | 'prefix' => '', | ||
| 59 | 'options' => array( | ||
| 60 | PDO::ATTR_TIMEOUT => 5, | ||
| 61 | ), | ||
| 62 | ); | ||
| 63 | Config::set("database.connections.conn", $conn); | ||
| 64 | |||
| 65 | DB::connection("conn")->getDatabaseName(); | ||
| 66 | |||
| 67 | $serverclist=DB::connection("conn")->select(DB::raw("select id from server_details where server_ip='$server_ip'")); | ||
| 68 | $server_id=$serverclist[0]->id; | ||
| 69 | if($server_id<10){ | ||
| 70 | $server_id="0".$server_id; | ||
| 71 | } | ||
| 72 | |||
| 73 | |||
| 74 | $maxid=DB::connection("conn")->select(DB::raw("SELECT max(sms_id) as maxid from sms_report where server='$server_id'")); | ||
| 75 | |||
| 76 | $maxids=$maxid[0]->maxid; | ||
| 77 | |||
| 78 | //$alist=DB::select(DB::raw("SELECT * from crmcalls where id>'$maxids' and created_at<'".date("Y-m-d H:i:s",$logdate-(60*60))."'")); | ||
| 79 | $alist=DB::select(DB::raw("SELECT * from sms_log where id>'$maxids'")); | ||
| 80 | $countnumber=count($alist); | ||
| 81 | $finalnumber=$countnumber/50; | ||
| 82 | $finalnumber=floor($finalnumber); | ||
| 83 | $datainser=''; | ||
| 84 | $iii=1; | ||
| 85 | $kkk=1; | ||
| 86 | $shortinsert=""; | ||
| 87 | $userarr=array(); | ||
| 88 | foreach($alist as $aline) | ||
| 89 | { | ||
| 90 | |||
| 91 | $server = $server_id; | ||
| 92 | $sms_id = $aline->id; | ||
| 93 | $created_at = $aline->created_at; | ||
| 94 | $message_time = date("Y-m-d H:i:s",strtotime($aline->created_at)+330*60); | ||
| 95 | $server_ip = $aline->server_ip; | ||
| 96 | $call_id = $aline->call_id; | ||
| 97 | $agent_name = $aline->agent_name; | ||
| 98 | $subdispo = $aline->subdispo; | ||
| 99 | $number = $aline->number; | ||
| 100 | $message = $aline->message; | ||
| 101 | $response = $aline->response; | ||
| 102 | |||
| 103 | $shortinsert.="('$server', '$sms_id','$created_at', '$message_time', '$server_ip', '$call_id', '$agent_name', '$subdispo', '$number', '$message', '$response'),"; | ||
| 104 | |||
| 105 | if($kkk<=$finalnumber){ | ||
| 106 | if($iii%50==0){ | ||
| 107 | |||
| 108 | $shortinsert=substr($shortinsert,0,-1); | ||
| 109 | 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")); | ||
| 110 | $kkk++; | ||
| 111 | } | ||
| 112 | }else{ | ||
| 113 | 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'")); | ||
| 114 | |||
| 115 | } | ||
| 116 | if($iii%50==0){ | ||
| 117 | $shortinsert=""; | ||
| 118 | } | ||
| 119 | $iii++; | ||
| 120 | |||
| 121 | //$update=DB::connection("conn")->select(DB::raw("SELECT crmcall_id as updateid from $calllog_report where server='$server_id' and `state` IN ('DialBegin','DialEnd')")); | ||
| 122 | //echo $update; | ||
| 123 | //DB::update(DB::raw("UPDATE crmcalls set call_flag='C' where id=$crmcall_id")); | ||
| 124 | } | ||
| 125 | echo "\n".date('Y-m-d H:i:s')."\n"; | ||
| 126 | DB::connection("conn")->disconnect(); | ||
| 127 | } | ||
| 128 | |||
| 129 | } | ||
| 130 | |||
| 131 | |||
| 132 |
-
Please register or sign in to post a comment