]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
logging and test request
authorJoySystem_v <fvv2011@gmail.com>
Wed, 21 Aug 2024 12:17:12 +0000 (15:17 +0300)
committerJoySystem_v <fvv2011@gmail.com>
Wed, 21 Aug 2024 12:17:12 +0000 (15:17 +0300)
erp24/api2/controllers/DataController.php

index 7f943c8989895f31fda5bc97226ff097189b2ec9..7cffb24bb77157096ee253b65f657778fd1af5ce 100644 (file)
@@ -365,7 +365,9 @@ class DataController extends BaseController {
         } else {
             $fl = time();
         }
-//        InfoLogService::setInfoLog(__FILE__, __LINE__, 'upload_' . $fl . '.json' , 'info_id_25_1');
+        file_put_contents(self::OUT_DIR . '/error_upload.txt',
+            PHP_EOL . "requestId: " . $requestId, FILE_APPEND);
+        //InfoLogService::setInfoLog(__FILE__, __LINE__, 'upload_' . $fl . '.json' , 'info_id_25_1');
 
         file_put_contents(self::OUT_DIR . '/upload_' . $fl . '.json', PHP_EOL . $request);
 
@@ -378,11 +380,14 @@ class DataController extends BaseController {
             $mess["result"] = true;
             $checks_dell = "";
             $request_id = time();
+            file_put_contents(self::OUT_DIR . '/error_upload.txt',
+                PHP_EOL . "request_id: " . $request_id, FILE_APPEND);
             if (array_key_exists("request_id", $result) && !empty($result["request_id"])) {
                 $request_id = $result["request_id"];
             }
             $type_price = "Розничная цена";
-
+            file_put_contents(self::OUT_DIR . '/error_upload.txt',
+                PHP_EOL . "request_id 2: " . $request_id, FILE_APPEND);
             if (!empty($request_id)) {
                 $apiCron = ApiCron::find()->select(['json_post'])->where(['request_id' => $request_id])->one();
                 if ($apiCron) {
@@ -391,7 +396,8 @@ class DataController extends BaseController {
                     $end_time = $jsn["checks"]["end_time"] ?? date('Y-m-d 00:00:00', time());
                     $checks_dell = $jsn["checks_dell"] ?? "";
                     $type_price = $jsn["prices"]["type_price"] ?? "Розничная цена";
-
+                    file_put_contents(self::OUT_DIR . '/error_upload.txt',
+                        PHP_EOL . "start_time: " . $start_time, FILE_APPEND);
                     ApiCron::updateAll(['status' => 1, 'date_up' => date('Y-m-d H:i:s')],
                         ['and', ['status' => 0], ['request_id' => $request_id]]);
 
@@ -635,6 +641,9 @@ class DataController extends BaseController {
                 }
             }
 
+            file_put_contents(self::OUT_DIR . '/error_upload.txt',
+                PHP_EOL . $update , FILE_APPEND);
+
             if (!empty($result['write_offs'])) {
                 if (!empty($start_time)  and !empty($end_time)) {
                     if ($update) {
@@ -807,8 +816,12 @@ class DataController extends BaseController {
             if (!empty($result['checks'])) {
                 $matrixProductsIds = SalaryHelper::getMatrixProductsIds();
             }
+            file_put_contents(self::OUT_DIR . '/error_upload.txt',
+                PHP_EOL . count($result['checks']) , FILE_APPEND);
+           if (!empty($result['checks']) && count($result['checks']) < 200) {
 
-            if (!empty($result['checks']) && count($result['checks']) < 1000) {
+                file_put_contents(self::OUT_DIR . '/error_upload.txt',
+                    PHP_EOL . "if" , FILE_APPEND);
                 foreach ($result["checks"] as $arr) {
 
                     $check_id = $arr["id"];
@@ -1035,10 +1048,13 @@ class DataController extends BaseController {
                     }
                 }
             } elseif (!empty($result['checks'])) {
+                file_put_contents(self::OUT_DIR . '/error_upload.txt',
+                    PHP_EOL . "elseif" , FILE_APPEND);
                 $dataArrayValues = $this->getSalesDate($result["checks"], $update);
 
                 foreach ($dataArrayValues as $keyMethodName => $rowValue) {
-
+                    file_put_contents(self::OUT_DIR . '/error_upload.txt',
+                        PHP_EOL . $keyMethodName , FILE_APPEND);
                     try {
                         $this->$keyMethodName($rowValue, $update);
                     } catch (Exception $e) {
@@ -1185,7 +1201,7 @@ class DataController extends BaseController {
                                 'guid' => $arr2["id"],
                                 'date_up' => date('Y-m-d H:i:s'),
                                 'name' => $arr2["name"],
-                                'held' => isset($arr2["held"]) ? (bool)$arr2["held"] : false
+                                'held' => isset($arr2["held"]) ? $arr2["held"] : 0
                             ], ['check_id' => $arr2["id"]]);
 //                            $createChecks3 = CreateChecks::find()->where(['check_id' => $arr2["id"]])->orderBy(['id' => SORT_DESC])->one();
 //                            if ($createChecks3) {
@@ -1406,7 +1422,7 @@ class DataController extends BaseController {
                 'terminal_id' => $arr["terminal_id"] ?? '', // terminal_id,
                 'skidka' => $arr["discount"] ?? 0, // skidka
                 'date_up' => $date_up, // date_up
-                'held' => false,
+                'held' => 0,
             ];
 
         }
@@ -1594,20 +1610,22 @@ class DataController extends BaseController {
 
         foreach ($chunkValues as $key => $rows) {
             // Преобразование значений в $rows перед вставкой
-            foreach ($rows as &$row) {
-                if (isset($row['held'])) {
+          //  foreach ($rows as &$row) {
+              //  if (isset($row['held'])) {
                     // Приведение значений к булевому типу
-                    $row['held'] = (bool)$row['held'];
-                }
-            }
+               //     $row['held'] = (bool)$row['held'];
+              //  }
+          //  }
 
             try {
                 $transaction = \Yii::$app->db->beginTransaction();
                 Yii::$app->db->createCommand()->batchInsert($tableName, $columns, $rows)->execute();
                 $transaction->commit();
             } catch (Exception $e) {
-                $transaction->rollBack();
                 $errorString = substr($e->getMessage(), 0, 2000);
+                file_put_contents(self::OUT_DIR . '/error_upload.txt',
+                    PHP_EOL . $errorString, FILE_APPEND);
+                $transaction->rollBack();
                 InfoLogService::setInfoLog(__FILE__, __LINE__, $tableName , 'error_id_25');
                 InfoLogService::setInfoLog(__FILE__, __LINE__, $errorString , 'error_id_25_22');
                 LogService::apiErrorLog(json_encode(["error_id" => 25, "error" => $errorString], JSON_UNESCAPED_UNICODE));