From 7d7a9ee9b267dd6f43b825e01f56c4c1d1a02810 Mon Sep 17 00:00:00 2001 From: Aleksey Filippov Date: Thu, 2 May 2024 16:40:32 +0300 Subject: [PATCH] =?utf8?q?=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF?= =?utf8?q?=D0=BE=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B5=20?= =?utf8?q?=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/.gitignore | 4 ++ erp24/api1/views/cron/amo142.php | 60 ++++++++++++++++++-------- erp24/api1/views/cron/get-token.php | 2 +- erp24/config/web.php | 2 +- erp24/controllers/OrdersController.php | 5 --- erp24/helpers/File.php | 6 ++- erp24/helpers/ImageResize.php | 18 ++++---- erp24/inc/amo/amo_inc.php | 1 + erp24/modul/orders/delivery.php | 3 +- erp24/records/Images.php | 15 ++++--- 10 files changed, 75 insertions(+), 41 deletions(-) diff --git a/erp24/.gitignore b/erp24/.gitignore index edbf3801..8d07a5db 100644 --- a/erp24/.gitignore +++ b/erp24/.gitignore @@ -35,3 +35,7 @@ tests/_support/_generated #vagrant folder /.vagrant /cron_last_run.txt + +/uploads/* +/data/* +/runtime/* \ No newline at end of file diff --git a/erp24/api1/views/cron/amo142.php b/erp24/api1/views/cron/amo142.php index 0549e087..307b7724 100644 --- a/erp24/api1/views/cron/amo142.php +++ b/erp24/api1/views/cron/amo142.php @@ -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'
@@ -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"

Состав

"; $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"
". $row["name"] ." ". $row["kol"] ." ". $row["price"] ." ". $row["guid"] ." "; diff --git a/erp24/api1/views/cron/get-token.php b/erp24/api1/views/cron/get-token.php index eee6abd4..b69c62dc 100644 --- a/erp24/api1/views/cron/get-token.php +++ b/erp24/api1/views/cron/get-token.php @@ -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') { diff --git a/erp24/config/web.php b/erp24/config/web.php index 5d0ba8fb..8cea94df 100644 --- a/erp24/config/web.php +++ b/erp24/config/web.php @@ -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", ], diff --git a/erp24/controllers/OrdersController.php b/erp24/controllers/OrdersController.php index 3a0eef92..d7a3c1b4 100644 --- a/erp24/controllers/OrdersController.php +++ b/erp24/controllers/OrdersController.php @@ -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; diff --git a/erp24/helpers/File.php b/erp24/helpers/File.php index aa45c5e0..45ac5d34 100644 --- a/erp24/helpers/File.php +++ b/erp24/helpers/File.php @@ -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); } diff --git a/erp24/helpers/ImageResize.php b/erp24/helpers/ImageResize.php index 1a0d9acc..4ae94545 100644 --- a/erp24/helpers/ImageResize.php +++ b/erp24/helpers/ImageResize.php @@ -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'; diff --git a/erp24/inc/amo/amo_inc.php b/erp24/inc/amo/amo_inc.php index d8967045..a1d54989 100755 --- a/erp24/inc/amo/amo_inc.php +++ b/erp24/inc/amo/amo_inc.php @@ -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) { diff --git a/erp24/modul/orders/delivery.php b/erp24/modul/orders/delivery.php index a7f127ab..11ee6bfd 100644 --- a/erp24/modul/orders/delivery.php +++ b/erp24/modul/orders/delivery.php @@ -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 diff --git a/erp24/records/Images.php b/erp24/records/Images.php index fe07bb90..67210757 100644 --- a/erp24/records/Images.php +++ b/erp24/records/Images.php @@ -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; -- 2.39.5