From: Alexander Smirnov Date: Wed, 27 Dec 2023 13:55:39 +0000 (+0300) Subject: add cron/domru-cams during moving api1 to yii X-Git-Tag: 1.1~195^2~8 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=72888fc843011440b94355bc4ff50a6e546b4d89;p=erp24_rep%2Fyii-erp24%2F.git add cron/domru-cams during moving api1 to yii --- diff --git a/.gitignore b/.gitignore index 7e1be957..0a01b811 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ erp24/runtime erp24/web/dist .idea erp24/api1/runtime +erp24/api1/views/cron/txt/ +erp24/api1/views/cron/xml/ diff --git a/erp24/api1/actions/cron/DomRuCamsAction.php b/erp24/api1/actions/cron/DomRuCamsAction.php new file mode 100644 index 00000000..b3191970 --- /dev/null +++ b/erp24/api1/actions/cron/DomRuCamsAction.php @@ -0,0 +1,13 @@ +controller->renderPartial('domru-cams'); + } +} \ No newline at end of file diff --git a/erp24/api1/controllers/CronController.php b/erp24/api1/controllers/CronController.php index d2baaac6..e60d8f4f 100644 --- a/erp24/api1/controllers/CronController.php +++ b/erp24/api1/controllers/CronController.php @@ -12,6 +12,7 @@ class CronController extends BaseController '1c' => \app\actions\cron\OneCAction::class, 'amo142' => \app\actions\cron\Amo142Action::class, 'cloudpayments' => \app\actions\cron\CloudPaymentsAction::class, + 'domru-cams' => \app\actions\cron\DomRuCamsAction::class, ]; } } diff --git a/erp24/api1/views/cron/domru-cams.php b/erp24/api1/views/cron/domru-cams.php new file mode 100644 index 00000000..9b945273 --- /dev/null +++ b/erp24/api1/views/cron/domru-cams.php @@ -0,0 +1,181 @@ +db->createCommand("SELECT entity_id, export_val FROM `export_import_table` WHERE export_id='3' AND entity='city_store'")->queryAll(); + +// $data=$db::getRows("SELECT entity_id, export_val FROM `export_import_table` WHERE export_id='3' AND entity='city_store'"); +foreach ($data as $row) $revers[$row["export_val"]]=$row["entity_id"]; + + +$tip=0; + +echo"

Названия камер в личном кабинете Дом ру должны = названию магазина export_import_table

"; +foreach($revers as $cam_id => $name) { + + echo"
$cam_id => $name"; + +} + + +$tip=rand(0,4); +$daysCnt=2; +if(isset($_GET["tip"])) $tip=(int)$_GET["tip"]; +if(!empty($_GET["daysCnt"])) $daysCnt=(int)$_GET["daysCnt"]; + + + +if($tip==0) $array = array( 'Login' => 'mochage-8r-136', 'Password' => 'fjtq8z3u'); +if($tip==1) $array = array( 'Login' => 'kuznzx-am-136', 'Password' => '8e4ma237'); +if($tip==2) $array = array( 'Login' => 'lazava-d8-136', 'Password' => '5gp3znn0'); +if($tip==3) $array = array( 'Login' => 'alieah-4d-136', 'Password' => 'qh7bxq5p'); +if($tip==4) $array = array( 'Login' => 'ipbelo-n2-ci', 'Password' => '8h09h42q38'); + +echo"
ТИП $tip ".$array[$tip]["Login"]." "; + + +$acc=1; + +$ch = curl_init('https://vs.domru.ru/api/Login'); +curl_setopt($ch, CURLOPT_POST, 1); +curl_setopt($ch, CURLOPT_POSTFIELDS, $array); + +// Или предать массив строкой: +// curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($array, '', '&')); + +curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); +curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); +curl_setopt($ch, CURLOPT_HEADER, false); +$html = curl_exec($ch); +curl_close($ch); + +$json=json_decode($html,true); + + +//echo " ".$json["SessionID"]." "; +$sid=$json["SessionID"]; + +$array = array( + 'SessionID' => $sid +); + + +$ch = curl_init('https://vs.domru.ru/api/GetCameras'); +curl_setopt($ch, CURLOPT_POST, 1); +curl_setopt($ch, CURLOPT_POSTFIELDS, $array); +curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); +curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); +curl_setopt($ch, CURLOPT_HEADER, false); +$html = curl_exec($ch); +curl_close($ch); +$json=json_decode($html,true, 512, JSON_UNESCAPED_UNICODE); + +echo"
Названия камер"; +foreach($json as $id => $arrs) { + echo"
$id - name=".$arrs["Name"]." ".$arrs["AccountObjectName"]." CameraID=".$arrs["CameraID"]." "; +} + + +//exit(); +//echo'
';print_r($json);echo'
'; + + + +echo"За дней $daysCnt"; + +for($Offset=0;$Offset<=$daysCnt;$Offset++) { + $array = array( + 'SessionID' => $sid, + 'Analytics' => 'CrossingLine', + 'From' =>date("Y-m-d H:i:s",time()-86400*($Offset)), + 'To' => date("Y-m-d H:i:s",time()-86400*($Offset-1)), + 'Direction' =>'Out', + 'GroupBy' => 'hour', + 'Limit' =>1000 + + ); + + $ch = curl_init('https://vs.domru.ru/api/ExportReport'); + curl_setopt($ch, CURLOPT_POST, 1); + curl_setopt($ch, CURLOPT_POSTFIELDS, $array); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_HEADER, false); + $html = curl_exec($ch); + curl_close($ch); + + +//echo $html; + + $file_put = __DIR__ . "/xml/ExportReport".$acc."_".$Offset.".xml"; + + file_put_contents($file_put,$html); +//echo""; + $json=json_decode($html,true, 512, JSON_UNESCAPED_UNICODE); + +//echo" ".$json["Error"].""; + $xml = simplexml_load_file($file_put); + $maas=json_decode(json_encode($xml), true); + asort($maas); + foreach($maas["count"] ?? [] as $id =>$arr) { +//echo"
DateTime=".$arr["DateTime"]." $id =>".$arr["CameraName"]." CameraID=".$arr["CameraID"]." value=".$arr["Value"]." " ; + + + if(isset($revers[$arr["CameraName"]])) { + $store_id=$revers[$arr["CameraName"]]; + $date_ar=explode(" ",$arr["DateTime"]); + $date=$date_ar[0]; + $hour=explode(":",$date_ar[1]); + $hour=$hour[0]; + $counter=(int)$arr["Value"]; +//echo"
$store_id,$date,$hour,$counter"; + + $counterArr[$store_id][$date][$hour] +=$counter; + $all[$arr["CameraName"]]=$all[$arr["CameraName"]]+$arr["Value"]; + $allcnt[$arr["CameraName"]]++; + $count_date[$arr["CameraName"]][$date]=$count_date[$arr["CameraName"]][$date]+$arr["Value"]; + + } else echo"
у камеры нет сопоставления ".$arr["CameraName"]." = ".$revers[$arr["CameraName"]]." "; + } + + + // вносим в массив + foreach($maas["count"] ?? [] as $id =>$arr) { + if(isset($revers[$arr["CameraName"]])) { + $store_id=$revers[$arr["CameraName"]]; + $date_ar=explode(" ",$arr["DateTime"]); + $date=$date_ar[0]; + $hour=explode(":",$date_ar[1]); + $hour=$hour[0]; + $counter=$counterArr[$store_id][$date][$hour] ; +// $z="insert IGNORE into store_visitors (store_id, date, date_hour, counter) values (?,?,?,?) ON DUPLICATE KEY UPDATE counter=?"; +// $db::sql($z,[$store_id,$date,$hour,$counter,$counter]); + Yii::$app->db->createCommand("insert IGNORE into store_visitors (store_id, date, date_hour, counter) values (:store_id,:date,:date_hour,:counter) ON DUPLICATE KEY UPDATE counter=:counter") + ->bindValues([ + ':store_id' => $store_id, + ':date' => $date, + ':date_hour' => $hour, + ':counter' => $counter, + ])->execute(); + echo"
$date h=$hour store_id=$store_id value=$counter"; + + + } + + + } + + + $filename ='file_cnt.txt'; + file_put_contents(__DIR__ . '/txt/' . $filename, $Offset."".date("Y-m-d H:i:s").""); + if ($all) { + arsort($all); + foreach ($all as $cid => $val) echo "
$cid = > $val "; ///".$allcnt[$cid]." + } +} + diff --git a/erp24/api1/views/cron/txt/placeholder b/erp24/api1/views/cron/txt/placeholder new file mode 100644 index 00000000..e69de29b diff --git a/erp24/api1/views/cron/xml/placeholder b/erp24/api1/views/cron/xml/placeholder new file mode 100644 index 00000000..e69de29b