]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
add cron/domru-cams during moving api1 to yii
authorAlexander Smirnov <fredeom@mail.ru>
Wed, 27 Dec 2023 13:55:39 +0000 (16:55 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Wed, 27 Dec 2023 13:55:39 +0000 (16:55 +0300)
.gitignore
erp24/api1/actions/cron/DomRuCamsAction.php [new file with mode: 0644]
erp24/api1/controllers/CronController.php
erp24/api1/views/cron/domru-cams.php [new file with mode: 0644]
erp24/api1/views/cron/txt/placeholder [new file with mode: 0644]
erp24/api1/views/cron/xml/placeholder [new file with mode: 0644]

index 7e1be95710b953c4b95908bc4ae72a63e900f7a0..0a01b8111b7d1f50e9e05522d5fd48517bd3b13e 100644 (file)
@@ -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 (file)
index 0000000..b319197
--- /dev/null
@@ -0,0 +1,13 @@
+<?php
+
+namespace app\actions\cron;
+
+use Yii;
+use yii\base\Action;
+
+class DomRuCamsAction extends Action
+{
+    public function run() {
+        return $this->controller->renderPartial('domru-cams');
+    }
+}
\ No newline at end of file
index d2baaac654086c3fc8801a3ae90d6c847a9e80e7..e60d8f4f515c1f92ff95651f2b6a801c8519fd95 100644 (file)
@@ -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 (file)
index 0000000..9b94527
--- /dev/null
@@ -0,0 +1,181 @@
+<?php
+
+include_once(dirname(__DIR__, 3) . "/startup.php");
+include_once(dirname(__DIR__, 3) . "/inc/db.php");
+
+error_reporting(E_ALL ^ E_NOTICE);
+
+// https://api.bazacvetov24.ru/cron/domru_cams.php?tip=0&token=1CjgpXfgkh1pXV3KR2H57G3VtHCffrp154up1t36&daysCnt=12
+
+$data = Yii::$app->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"<h2>Названия камер в личном кабинете Дом ру должны = названию магазина export_import_table</h2>";
+foreach($revers as $cam_id => $name) {
+
+    echo"<br>$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"<br> ТИП $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"<br>Названия камер";
+foreach($json as $id => $arrs) {
+    echo"<br> $id - name=".$arrs["Name"]."  ".$arrs["AccountObjectName"]."  CameraID=".$arrs["CameraID"]."  ";
+}
+
+
+//exit();
+//echo'<pre>';print_r($json);echo'</pre>';
+
+
+
+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"<textarea class=\"form-control\">$html</textarea>";
+    $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"<br>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"<br>$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"<br><font color=red>у камеры нет сопоставления ".$arr["CameraName"]." = ".$revers[$arr["CameraName"]]." </font>";
+    }
+
+
+    // вносим в массив
+    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"<br> $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 "<br> $cid = > $val  "; ///".$allcnt[$cid]."
+    }
+}
+
diff --git a/erp24/api1/views/cron/txt/placeholder b/erp24/api1/views/cron/txt/placeholder
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/erp24/api1/views/cron/xml/placeholder b/erp24/api1/views/cron/xml/placeholder
new file mode 100644 (file)
index 0000000..e69de29