| Server IP : 103.82.32.14 / Your IP : 216.73.217.55 Web Server : Apache/2.2.32 (Unix) mod_ssl/2.2.32 OpenSSL/1.0.1e-fips mod_fcgid/2.3.9 System : Linux cloud.lonmanhoabinh.com 2.6.32-754.35.1.el6.x86_64 #1 SMP Sat Nov 7 12:42:14 UTC 2020 x86_64 User : lonmakmf ( 524) PHP Version : 5.6.30 Disable Function : NONE MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /home/rubymnik/public_html/ |
Upload File : |
<?php
include 'configchannelupdate.php';
header('Access-Control-Allow-Origin: *');
header("Content-Type: application/json");
$data = json_decode(file_get_contents("php://input"));
$datachannel = explode("\n", $data->channel);
$idChannel = "";
$nameChannel = "";
$idChannelInsert = "";
$soThangTru = 1;
$mothCurrent = date("m");
$daTruNgayUpdate = false;
$dataUpdateChannel = false;
$ngayUpdateCu = 0;
$ngayUpdateCuVew = 0;
foreach($datachannel as $key => $channel)
{
if(strlen($channel) < 5) continue;
$str = explode('::', $channel);
if (strpos($str[2], 'thg') == false) {
continue;
}
$idChannel = $str[0];
$nameChannel = $str[1];
// ngày tháng update
$dateEx = explode(' ', $str[2]);
$ngayUpdate = $dateEx[0] . '/' . str_replace(",", "", $dateEx[2]) . '/' . $dateEx[3];
$ngayUpdateCu = $ngayUpdateCuVew;
$view = str_replace(".", "", $str[3]);
$view = str_replace(" ", "", $view);
$re = '/[0-9,]+/m';
$strview = $view;
$view = "";
preg_match_all($re, $strview, $matches, PREG_SET_ORDER, 0);
foreach($matches as $key => $mat)
{
$view .= $mat[0];
}
$gioXem = str_replace(".", "", $str[4]);
$gioXem = str_replace(" ", "", $gioXem);
$re = '/[0-9,]+/m';
$strGioXem = $gioXem;
$gioXem = "";
preg_match_all($re, $strGioXem, $matches, PREG_SET_ORDER, 0);
foreach($matches as $key => $mat)
{
$gioXem .= $mat[0];
}
$thoiGianXemTrungBinh = $str[5];
$doanhThu = $str[6];
$pos = strpos($doanhThu, "—");
if($pos === false)
{
$re = '/[0-9,]+/m';
$strDoanhThu = $doanhThu;
$soTien = "";
preg_match_all($re, $strDoanhThu, $matches, PREG_SET_ORDER, 0);
foreach($matches as $key => $mat)
{
$soTien .= $mat[0];
}
$pos = strpos($doanhThu, "$");
if($pos != false)
{
$doanhThu = $soTien;
}
$pos = strpos($doanhThu, "₫");
if($pos != false)
{
$doanhThu = $soTien / 23000;
}
$pos = strpos($doanhThu, "€");
if($pos != false)
{
$doanhThu = $soTien * 1.1846;
}
}
else
{
$doanhThu = 0;
}
$doanhThu = str_replace(",", ".", $doanhThu);
//file_put_contents("list.txt", $doanhThu);
if($idChannelInsert == "")
{
$result = mysqli_fetch_assoc(Select('QuanLyChannel', false, '`IdChannel` LIKE "'.$idChannel.'"'));
if(!isset($result['IdChannel']))
{
$infoAccessToken = array(
'IdChannel' => mysql_real_escape_string($idChannel),
'NameChannel' => mysql_real_escape_string($idChannel)
);
Insert('QuanLyChannel', $infoAccessToken);
$result = mysqli_fetch_assoc(Select('QuanLyChannel', false, '`IdChannel` LIKE "'.$idChannel.'"'));
}
$idChannelInsert = $result['id'];
}
else if(!$dataUpdateChannel)
{
$dataUpdateChannel = true;
//Update('QuanLyChannel', array('NameChannel' => mysql_real_escape_string($nameChannel)), '`IdChannel` LIKE "'.$idChannel.'"');
}
$date = explode('/', $ngayUpdate);
$time = mktime(0,0,0,$date[1],$date[0],$date[2]);
$mysqldate = date( 'Y-m-d H:i:s', $time);
$listInsert[] = array(
'IdChannel' => $idChannelInsert,
'NgayUpdate' => $mysqldate,
'SoLuotXem' => $view,
'GioXem' => $gioXem,
'ThoiGianXemTrungBinh' => mysql_real_escape_string($thoiGianXemTrungBinh),
'DoanhThu' => $doanhThu,
);
}
if($idChannelInsert > 0)
{
foreach($listInsert as $key => $item)
{
if($key == 0)
{
if($item['DoanhThu'] == 0 && $listInsert[1]['DoanhThu'] > 0)
{
continue;
}
}
$result = Select('SoLieuChannel', true, '`NgayUpdate` = "'.$item['NgayUpdate'].'" AND `IdChannel` = "'.$idChannelInsert.'"');
if($result == 0)
{
Insert('SoLieuChannel', $item);
}
else
{
if($item['DoanhThu'] == 0)
{
Update('SoLieuChannel', array('SoLuotXem' => $item['SoLuotXem'], 'GioXem' => $item['GioXem']), '`NgayUpdate` = "'.$item['NgayUpdate'].'" AND `IdChannel` = "'.$idChannelInsert.'"');
}
else
{
Update('SoLieuChannel', array('DoanhThu' => $item['DoanhThu'], 'SoLuotXem' => $item['SoLuotXem'], 'GioXem' => $item['GioXem']), '`NgayUpdate` = "'.$item['NgayUpdate'].'" AND `IdChannel` = "'.$idChannelInsert.'"');
}
}
}
}
?>