From: marina Date: Tue, 6 Aug 2024 06:53:32 +0000 (+0300) Subject: ERP-85 Реализовать обмен данных с 1С Бухгалтерия X-Git-Tag: 1.4~22^2~42 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=121e325eab3e182079df64bdd95c6474d8abfabc;p=erp24_rep%2Fyii-erp24%2F.git ERP-85 Реализовать обмен данных с 1С Бухгалтерия контроллер и модель --- 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', + ]; + } +}