From: marina Date: Tue, 6 Aug 2024 09:21:15 +0000 (+0300) Subject: ERP-85 Реализовать обмен данных с 1С Бухгалтерия X-Git-Tag: 1.4~22^2~41 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=707b0aae6d1647a640374a3e4b0bdfaef378aa60;p=erp24_rep%2Fyii-erp24%2F.git ERP-85 Реализовать обмен данных с 1С Бухгалтерия --- diff --git a/erp24/api2/controllers/DataBuhController.php b/erp24/api2/controllers/DataBuhController.php new file mode 100644 index 00000000..b37dbd7e --- /dev/null +++ b/erp24/api2/controllers/DataBuhController.php @@ -0,0 +1,95 @@ +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 = ApiCronBuh::find() + ->where(['status' => 0]) + ->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 ApiCronBuh(); + $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; + $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/api2/controllers/DataBuhTestController.php b/erp24/api2/controllers/DataBuhTestController.php deleted file mode 100644 index d9a77299..00000000 --- a/erp24/api2/controllers/DataBuhTestController.php +++ /dev/null @@ -1,97 +0,0 @@ -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/migrations/m240805_071431_create_api_cron_buh_table.php b/erp24/migrations/m240805_071431_create_api_cron_buh_table.php new file mode 100644 index 00000000..d531b5d7 --- /dev/null +++ b/erp24/migrations/m240805_071431_create_api_cron_buh_table.php @@ -0,0 +1,32 @@ +createTable('{{%erp24.api_cron_buh}}', [ + 'id' => $this->primaryKey(), + 'date' => $this->dateTime()->notNull(), + 'date_up' => $this->dateTime()->notNull(), + 'status' => $this->integer()->notNull()->defaultValue(0)->comment('Статус'), + 'json_post' => $this->text()->null()->comment('Тело запроса'), + 'request_id' => $this->string(36)->notNull()->comment('id запроса'), + ]); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropTable('{{%erp24.api_cron_buh}}'); + } +} diff --git a/erp24/migrations/m240805_071431_create_api_cron_buh_test_table.php b/erp24/migrations/m240805_071431_create_api_cron_buh_test_table.php deleted file mode 100644 index 6d56733d..00000000 --- a/erp24/migrations/m240805_071431_create_api_cron_buh_test_table.php +++ /dev/null @@ -1,32 +0,0 @@ -createTable('{{%api_cron_buh_test}}', [ - 'id' => $this->primaryKey(), - 'date' => $this->dateTime()->notNull(), - 'date_up' => $this->dateTime()->notNull(), - 'status' => $this->integer()->notNull()->defaultValue(0)->comment('Статус'), - 'json_post' => $this->text()->null()->comment('Тело запроса'), - 'request_id' => $this->string(36)->notNull()->comment('id запроса'), - ]); - } - - /** - * {@inheritdoc} - */ - public function safeDown() - { - $this->dropTable('{{%api_cron_buh_test}}'); - } -} diff --git a/erp24/records/ApiCronBuh.php b/erp24/records/ApiCronBuh.php new file mode 100644 index 00000000..cc77bec6 --- /dev/null +++ b/erp24/records/ApiCronBuh.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', + ]; + } +} diff --git a/erp24/records/ApiCronBuhTest.php b/erp24/records/ApiCronBuhTest.php deleted file mode 100644 index 48eb2504..00000000 --- a/erp24/records/ApiCronBuhTest.php +++ /dev/null @@ -1,55 +0,0 @@ - 36], - ]; - } - - /** - * {@inheritdoc} - */ - public function attributeLabels() - { - return [ - 'id' => 'ID', - 'date' => 'Date', - 'date_up' => 'Date Up', - 'status' => 'Status', - 'json_post' => 'Json Post', - 'request_id' => 'Request ID', - ]; - } -}