]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
правки по загрузке данных
authorAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Thu, 2 May 2024 13:40:32 +0000 (16:40 +0300)
committerAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Thu, 2 May 2024 13:40:32 +0000 (16:40 +0300)
erp24/.gitignore
erp24/api1/views/cron/amo142.php
erp24/api1/views/cron/get-token.php
erp24/config/web.php
erp24/controllers/OrdersController.php
erp24/helpers/File.php
erp24/helpers/ImageResize.php
erp24/inc/amo/amo_inc.php
erp24/modul/orders/delivery.php
erp24/records/Images.php

index edbf380163ef1830552e37d67064b105057468ce..8d07a5db9a77a3a584a61435e32a5c2b42ccf4a5 100644 (file)
@@ -35,3 +35,7 @@ tests/_support/_generated
 #vagrant folder
 /.vagrant
 /cron_last_run.txt
+
+/uploads/*
+/data/*
+/runtime/*
\ No newline at end of file
index 0549e08768380c7bff2de2568ee5c7b3442053fb..307b772478702de71cd19b06780e47a40fcda56d 100644 (file)
@@ -195,8 +195,6 @@ if(!empty($_REQUEST["limit"]))  $limiter=intval($_REQUEST["limit"]);
 
 $date1_=date("Y-m-d",$date1);
 $date2_=date("Y-m-d",$date2);
-$_REQUEST["date1"]=$date1_;
-$_REQUEST["date2"]=$date2_;
 
 if(!empty($_REQUEST["date1"])) {
     $date1=htmlentities($_REQUEST["date1"]);
@@ -228,9 +226,21 @@ if(!empty($_REQUEST["date1"])) {
     $status_amo=intval($_REQUEST["status_id"] ?? 0);
 
 
+} else {
+    $_REQUEST["date1"]=$date1_;
+    $_REQUEST["date2"]=$date2_;
 }
-$unix_delivery_date0=time()-1*3600;
-$unix_delivery_date1=time();
+if(!empty($_REQUEST["date1"])) {
+    $unix_delivery_date0 = strtotime($_REQUEST["date1"]);
+} else {
+    $unix_delivery_date0=time()-1*3600;
+}
+if(!empty($_REQUEST["date2"])) {
+    $unix_delivery_date1=strtotime($_REQUEST["date2"]);
+} else {
+    $unix_delivery_date1=time();
+}
+
 /*
 echo'<form method=post action=""><div class="row"><div class="col-12">
 <input type=date name=date1 value="'.$date1_.'" class="form-control" width=120>
@@ -280,6 +290,10 @@ if(!empty($_REQUEST["date1"])) {
     }
 
     $unset_valiues[]="florist_foto";
+    $unset_valiues[]="florist_peredano";
+    $unset_valiues[]="florist_zabor";
+    $unset_valiues[]="florist_sobrano";
+
 
 //updated_at
     $dt="created_at";
@@ -290,8 +304,8 @@ if(!empty($_REQUEST["date1"])) {
 
     if(isset($_REQUEST["page_amo"])) $page_amo=(int)$_REQUEST["page_amo"];
 
-    $delivery__date='&filter['.$dt.'][from]='.$unix_delivery_date0.'&filter['.$dt.'][to]='.$unix_delivery_date1.'';
-//$delivery__date .='&filter[custom_fields_values][647935][from]='.$unix_delivery_date0.'&filter[custom_fields_values][647935][to]='.$unix_delivery_date1.'&page='.$page_amo.''; //
+//    $delivery__date='&filter['.$dt.'][from]='.$unix_delivery_date0.'&filter['.$dt.'][to]='.$unix_delivery_date1.'';
+$delivery__date .='&filter[custom_fields_values][647935][from]='.$unix_delivery_date0.'&filter[custom_fields_values][647935][to]='.$unix_delivery_date1.'&page='.$page_amo.''; //
 
     echo date("d.m.Y H:i:s" , $unix0);
 
@@ -451,10 +465,11 @@ if(!empty($_REQUEST["date1"])) {
             $sql_query="";
 
             foreach($sql_fields as $pole) {
-                if (array_key_exists($pole, $result)) {
+                if (!array_key_exists($pole, $result)) {
                     unset($result[$pole]);
                 }
             }
+
             $param=array();
             $param_insert=array();
             $i=0; $upper="";
@@ -469,13 +484,20 @@ if(!empty($_REQUEST["date1"])) {
             }
 
 
-            $i=0; $insert="";
+            $i=0; $insert=""; $insert_fields = []; $insert_values = [];
             foreach($result as $row =>$value) {
-                if(!empty($sql_fields[$row])) {   // удаляем поля которых нет в таблице
-                    if($i!=0) { $insert.=",";   }
-                    $insert.=" $row=:$row";
-                    $param_insert[$row]=$value;
-                    $i++;
+                if (!empty($row) and !in_array($row,$unset_valiues)) {
+                    if(in_array($row, $sql_fields)) {   // удаляем поля которых нет в таблице
+                        if($i!=0) {
+                            $insert.=",";
+                        }
+
+                        $insert.=" $row=:$row";
+                        $insert_fields[] = $row;
+                        $insert_values[] = $value;
+                        $param_insert[$row]=$value;
+                        $i++;
+                    }
                 }
             }
 
@@ -491,8 +513,9 @@ if(!empty($_REQUEST["date1"])) {
 
 
 
-                        $z="INSERT INTO  orders_amo SET  ".$insert ." , id='".$result["nomer"]."'";
-                        $db::sql($z,$param_insert);
+                        $z="INSERT INTO  orders_amo (" . implode(", ", $insert_fields) . ", id, update_at) VALUES ('".implode("', '", $insert_values) ."' , '".$result["nomer"]."', NOW())";
+
+                        $db::sql($z);
 //$db::sql($z,$param_insert);
                         mess("Заказ внесен в таблицу $z ");
 
@@ -516,7 +539,9 @@ if(!empty($_REQUEST["date1"])) {
 
                 }
                 catch (Exception $e) {
-                    file_put_contents('modul/content/error.txt', PHP_EOL . $e->getMessage(), FILE_APPEND);
+                    var_dump($e->getFile(). ' ' . $e->getLine() . '  '. $e->getMessage());
+                    die;
+                    file_put_contents('modul/content/error.txt', PHP_EOL . $e->getLine(). '  '. $e->getMessage(), FILE_APPEND);
                 }
 
             } else {
@@ -526,7 +551,8 @@ if(!empty($_REQUEST["date1"])) {
             }
             echo"<h3>Состав</h3>";
             $sum=0;
-            $data=$db::getRows("SELECT item_id, guid, price, name, kol FROM site_order_items_sostav WHERE tip='1' AND lid_id=? ",[(int)$result["nomer"]]);
+//            $data=$db::getRows("SELECT item_id, guid, price, name, kol FROM site_order_items_sostav WHERE tip='1' AND lid_id=? ",[(int)$result["nomer"]]);
+            $date = [];
             foreach($data as $row) {
                 $sum=$sum+$row["kol"]*$row["price"];
                 echo"<br> ". $row["name"] ."  ". $row["kol"] ." ". $row["price"] ."  ". $row["guid"] ." ";
index eee6abd4a794f541e44db8f86b82d9088d3586f0..b69c62dc804d222b656b50ee77f954cb4f52a893 100644 (file)
@@ -40,7 +40,7 @@ if (SECRET_PHRASE != $_GET['secret_phrase']) {
     exit('Incorrect secret phrase');
 }
 
-chmod(__DIR__ . "/../../../inc/amo/" . SECRET_FILE, 0740);
+//chmod(__DIR__ . "/../../../inc/amo/" . SECRET_FILE, 0740);
 
 if (!empty($_GET['grant_type']) && $_GET['grant_type'] == 'refresh_token') {
 
index 5d0ba8fb9abfdf5ef3cf6e91d90f62fa816b4e58..8cea94dff2867e870c461c4f4cb1bb44835328bd 100644 (file)
@@ -10,7 +10,7 @@ $config = [
     'aliases' => [
         '@bower' => '@vendor/bower-asset',
         '@npm'   => '@vendor/npm-asset',
-        '@uploads' => dirname(__DIR__) . "/uploads",
+        '@uploads' => dirname(__DIR__, 1) . "/uploads",
         '@data-path' => dirname(__DIR__, 1) . "/data",
         '@uploads-images-path' => "@uploads/images",
     ],
index 3a0eef92b7fac07c616d8187bb5e3a923edd022f..d7a3c1b4d5a65e4ff6eb6594a58633fae2cb7664 100644 (file)
@@ -4,11 +4,6 @@ namespace app\controllers;
 
 ini_set("memory_limit", "256M");
 
-include_once('../inc/base_new.php');
-include_once('../inc/amo_inc.php');
-error_reporting(E_ALL ^ E_NOTICE);
-ini_set("memory_limit", "256M");
-
 use Exception;
 use Yii;
 use yii\web\Controller;
index aa45c5e020bcc00ec4c06a597bf6ec36d599c043..45ac5d34e9f72b27333bf6d8585b8d232565dd5f 100644 (file)
@@ -363,8 +363,10 @@ class File extends FileHelper
        public static function ResizeImage($file_input, $w_o, $h_o, $quality = 100)
        {
                $file_output = str_replace('uploads/images/', 'uploads/images/resize/' . $w_o . '_' . $h_o . '_' . $quality . '/', $file_input);
-               @mkdir('uploads/images/resize/' . $w_o . '_' . $h_o . '_' . $quality . '/');
-               @mkdir('uploads/images/resize/' . $w_o . '_' . $h_o . '_' . $quality . '/' . substr(basename($file_input), 0, 2));
+               $dirOrigin = 'uploads/images/resize/' . $w_o . '_' . $h_o . '_' . $quality . '/';
+               @mkdir($dirOrigin);
+        $dirResize = $dirOrigin . substr(basename($file_input), 0, 2);
+               @mkdir($dirResize);
                ImageResize::resize($file_input, $file_output, $w_o, $h_o, $quality);
                usleep(10000);
        }
index 1a0d9acc940e67a7ef5b7b45bd0fe037b5a4438a..4ae94545fa1ac19f439bfd8a5e441c24db772213 100644 (file)
@@ -223,7 +223,7 @@ class ImageResize  {
                        $files = (!empty(self::$fileIndex) ? self::$fileIndex : self::getFileIndex());
                        self::$absolutePathArray = \Yii::$app->cache->getOrSet([__FUNCTION__, 'absolute_path_array'], function () use ($files) {
                                $result = [];
-                               $uploadDir = \Yii::getAlias('uploads/images');
+                               $uploadDir = \Yii::getAlias('@uploads/images');
                                if (!empty($files)) {
                                        foreach ($files as $id => $filename) {
                                                $substr = substr($filename, 0, 2);
@@ -231,7 +231,7 @@ class ImageResize  {
                                        }
                                }
                                return $result;
-                       }, 86400, $fileDependency);
+                       }, 0, $fileDependency);
                }
                return self::$absolutePathArray;
        }
@@ -255,7 +255,7 @@ class ImageResize  {
                                        }
                                }
                                return $result;
-                       }, 86400, $fileDependency);
+                       }, 0, $fileDependency);
                }
                return self::$webPathArray;
        }
@@ -273,7 +273,7 @@ class ImageResize  {
                        $files = (!empty(self::$webpIndex) ? self::$webpIndex : self::getWebpIndex());
                        self::$webpAbsolutePathArray = \Yii::$app->cache->getOrSet([__FUNCTION__, 'webp_absolute_path_array'], function () use ($files) {
                                $result = [];
-                               $uploadDir = \Yii::getAlias('uploads/images');
+                               $uploadDir = \Yii::getAlias('@uploads/images');
                                if (!empty($files)) {
                                        foreach ($files as $id => $filename) {
                                                $substr = substr($filename, 0, 2);
@@ -281,7 +281,7 @@ class ImageResize  {
                                        }
                                }
                                return $result;
-                       }, 86400, $fileDependency);
+                       }, 0, $fileDependency);
                }
                return self::$webpAbsolutePathArray;
        }
@@ -321,7 +321,7 @@ class ImageResize  {
        private static function getAbsolutePath($data)
        {
                $frontend = \Yii::getAlias('@frontend');
-               $upload = \Yii::getAlias('uploads/images');
+               $upload = \Yii::getAlias('@uploads/images');
 
                if (is_numeric($data)) {
                        $files = (!empty(self::$absolutePathArray) ? self::$absolutePathArray : self::getAbsolutePathArray());
@@ -374,7 +374,7 @@ class ImageResize  {
         */
        private static function getWebpAbsolutePath($data)
        {
-               $upload = \Yii::getAlias('uploads/images');
+               $upload = \Yii::getAlias('@uploads/images');
 
                if (is_numeric($data)) {
                        $files = (!empty(self::$webpAbsolutePathArray) ? self::$webpAbsolutePathArray : self::getWebpAbsolutePathArray());
@@ -426,7 +426,7 @@ class ImageResize  {
         */
        private static function getResizedAbsolutePath($path, $width, $height, $quality)
        {
-               $upload = \Yii::getAlias('uploads/images');
+               $upload = \Yii::getAlias('@uploads/images');
                $resize = preg_replace('/\/+/', '/', "{$upload}/resize/");
                @mkdir($resize);
 
@@ -498,7 +498,7 @@ class ImageResize  {
                $path = preg_replace('/(.+\/web\/)(.+)/', '/$2', $path);
 
                $frontend = \Yii::getAlias('@frontend');
-               $upload = \Yii::getAlias('uploads/images');
+               $upload = \Yii::getAlias('@uploads/images');
 
                $originalFilename = basename($path);
                $webpFilename = explode('.', $originalFilename)[0] . '.webp';
index d8967045aaf28abe392d612c1f4e5451d863af1e..a1d54989ceb7739b8be8f9ca6d2584034a917261 100755 (executable)
@@ -3,6 +3,7 @@ header('Access-Control-Allow-Origin: *');
 define('SECRET_FILE', __DIR__ . '/token_amo__1234u5u6uvhvhfdjhrrtghhr2022.json');
 define('SUBDOMAIN', 'bazacvetov24');
 $arr_token = json_decode(file_get_contents(SECRET_FILE), true);
+global $ACCESS_TOKEN;
 $ACCESS_TOKEN = $arr_token['access_token'];
 function amo_rest($access_token, $end_point, $method = 'GET', $params) {
 
index a7f127ab1885b27bcfe31fa41e960a852cbbd65a..11ee6bfd4b9c0d462baee1bd019968aeb2c740e7 100644 (file)
@@ -4,6 +4,7 @@ include_once(dirname(__DIR__, 2) . "/inc/db.php");
 include_once(dirname(__DIR__, 2) . "/inc/base_new.php");
 include_once(dirname(__DIR__, 2) . "/inc/design_new.php");
 error_reporting(E_ALL);
+global $ACCESS_TOKEN;
  try {
      
 //include"templates/top.php";
@@ -27,7 +28,7 @@ foreach($statuses as $status) {
 $deal0 = amo_rest($ACCESS_TOKEN, '/api/v4/leads?order[updated_at]=desc&limit=250&filter[statuses][0][pipeline_id]=4021495&filter[statuses][0][status_id]='.$status.''.$delivery__date.'', 'GET', []);
 //echo print_r($deal0);
 
-foreach($deal0["_embedded"]["leads"] as $lid_id3 => $arr0) {
+foreach($deal0["_embedded"]["leads"] ?? [] as $lid_id3 => $arr0) {
 foreach($arr0["custom_fields_values"] as $fid => $arr20) {
  if($arr20["field_id"]==655357) $lid_id5=$arr20["values"][0]["value"];
  if($arr20["field_id"]==647929) $store=$arr20["values"][0]["value"]; // store
index fe07bb90551ea35cc807ee6a5aa02ec6644ceed4..67210757169b38e76e6da91560caa4ecf8684683 100644 (file)
@@ -82,14 +82,19 @@ class Images extends \yii\db\ActiveRecord
         $ext = '.' . end($ar_file_name);
         $file_name = md5($file_obj->name . rand(100000, 999999)) . $ext;
         $dir_name = substr($file_name, 0, 2);
-        if (!is_dir('uploads/images')) {
-            mkdir('uploads/images', 0777, true);
+
+        $uploadDirPath = \Yii::getAlias('@uploads/images');
+
+        if (!is_dir($uploadDirPath)) {
+            mkdir($uploadDirPath, 0777, true);
         }
 
-        if (!is_dir('uploads/images/' . $dir_name)) {
-            mkdir('uploads/images/' . $dir_name);
+        $imageDirPath = $uploadDirPath . '/' . $dir_name;
+        if (!is_dir($imageDirPath)) {
+            mkdir($imageDirPath);
         }
-        if ($file_obj->saveAs(Yii::getAlias('uploads/images/' . $dir_name . '/' . $file_name))) {
+
+        if ($file_obj->saveAs($imageDirPath . '/' . $file_name)) {
             $this->original_name = $file_obj->baseName;
             $this->filename = $file_name;
             $this->size = $file_obj->size;