From 121e325eab3e182079df64bdd95c6474d8abfabc Mon Sep 17 00:00:00 2001 From: marina Date: Tue, 6 Aug 2024 09:53:32 +0300 Subject: [PATCH] =?utf8?q?ERP-85=20=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?utf8?q?=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=20=D0=BE=D0=B1=D0=BC=D0=B5=D0=BD?= =?utf8?q?=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D1=81=201=D0=A1=20?= =?utf8?q?=D0=91=D1=83=D1=85=D0=B3=D0=B0=D0=BB=D1=82=D0=B5=D1=80=D0=B8?= =?utf8?q?=D1=8F=20=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB=D0=BB=D0=B5?= =?utf8?q?=D1=80=20=D0=B8=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../controllers/DataBuhTestController.php | 97 +++++++++++++++++++ erp24/records/ApiCronBuhTest.php | 55 +++++++++++ 2 files changed, 152 insertions(+) create mode 100644 erp24/api2/controllers/DataBuhTestController.php create mode 100644 erp24/records/ApiCronBuhTest.php diff --git a/erp24/api2/controllers/DataBuhTestController.php b/erp24/api2/controllers/DataBuhTestController.php new file mode 100644 index 00000000..d9a77299 --- /dev/null +++ b/erp24/api2/controllers/DataBuhTestController.php @@ -0,0 +1,97 @@ +response->format = \yii\web\Response::FORMAT_JSON; + + $request = \Yii::$app->request->getRawBody(); + + try { + $result = Json::decode($request); + } catch (\Exception $ex) { + return $this->asJson(['error' => ['code' => 400, 'message' => 'Json body invalid']]); + } + + $result['ver'] = $result['ver'] ?? ''; + + + if (empty($result['ver']) || round($result['ver'], 2) < 1.1) { + return $this->asJson(["error_id" => 1, "error" => "minimal version is 1.1"]); + } + + $json = ''; + + try { + $apiCronTest = ApiCronBuhTest::find() + ->where(['status' => 0]) + ->andWhere(['direct_id' => 1]) + ->orderBy(['date' => SORT_ASC]) + ->one(); + if ($apiCronTest) { + $json = $apiCronTest->json_post; + + $apiCronTest->status = 1; + $apiCronTest->date_up = date("Y-m-d H:i:s"); + + $validate = $apiCronTest->validate(); + if ($validate) { + $apiCronTest->save(); + } + } + } catch (Exception $e) { + + } + + return $this->asJson(json_decode($json, true)); + } + + + public function actionUpload() { + set_time_limit(600); + Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; + + $request = Yii::$app->request->getRawBody(); + + try { + $result = Json::decode($request); + } catch (Exception $ex) { + return $this->asJson(['error' => ['code' => 400, 'message' => 'Json body invalid']]); + } + + $requestId = ''; + if (!empty($result["request_id"])) { + $requestId = $result["request_id"]; + } + + try { + + + $apiCronTest = new ApiCronBuhTest(); + $apiCronTest->date = date("Y-m-d H:i:s"); + $apiCronTest->date_up = date("Y-m-d H:i:s"); + $apiCronTest->status = 2; + $apiCronTest->json_post = $request; + $apiCronTest->request_id = $requestId; + $apiCronTest->direct_id = 2; + $validate = $apiCronTest->validate(); + if ($validate) { + $apiCronTest->save(); + } + + } catch (Exception $e) { + + } + + return $this->asJson(['response' => true]); + } + +} \ No newline at end of file diff --git a/erp24/records/ApiCronBuhTest.php b/erp24/records/ApiCronBuhTest.php new file mode 100644 index 00000000..48eb2504 --- /dev/null +++ b/erp24/records/ApiCronBuhTest.php @@ -0,0 +1,55 @@ + 36], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'date' => 'Date', + 'date_up' => 'Date Up', + 'status' => 'Status', + 'json_post' => 'Json Post', + 'request_id' => 'Request ID', + ]; + } +} -- 2.39.5