use Yii;
use yii\helpers\Json;
use yii_app\records\ApiCronBuh;
+use yii_app\records\Firms;
class DataBuhController extends BaseController
{
"/var/www/erp24/api2/json_buh";
// "/var/www/www-root/data/www/api.bazacvetov24.ru/data/json";
- public function actionRequest()
+ public function actionRequest($inn)
{
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
- \Yii::$app->response->headers->set('firm', 'IP_Belov');
$request = \Yii::$app->request->getRawBody();
- try {
- $result = Json::decode($request);
- } catch (\Exception $ex) {
- return $this->asJson(['error' => ['code' => 400, 'message' => 'Json body invalid']]);
- }
+ if (array_key_exists($inn, Firms::getInn())) {
+ try {
+ $result = Json::decode($request);
+ } catch (\Exception $ex) {
+ return $this->asJson(['error' => ['code' => 400, 'message' => 'Json body invalid']]);
+ }
- $result['ver'] = $result['ver'] ?? '';
+ $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"]);
- }
+ if (empty($result['ver']) || round($result['ver'], 2) < 1.1) {
+ return $this->asJson(["error_id" => 1, "error" => "minimal version is 1.1"]);
+ }
- $json = '';
+ $json = '';
- try {
- $apiCronTest = ApiCronBuh::find()
- ->where(['status' => 0])
- ->orderBy(['date' => SORT_ASC])
- ->one();
+ try {
+ $apiCronTest = ApiCronBuh::find()
+ ->where(['status' => 0])
+ ->orderBy(['date' => SORT_ASC])
+ ->one();
- if ($apiCronTest) {
- $json = $apiCronTest->json_post;
+ if ($apiCronTest) {
+ $json = $apiCronTest->json_post;
- $apiCronTest->status = 1;
- $apiCronTest->date_up = date("Y-m-d H:i:s");
+ $apiCronTest->status = 1;
+ $apiCronTest->date_up = date("Y-m-d H:i:s");
- $validate = $apiCronTest->validate();
- if ($validate) {
- $apiCronTest->save();
+ $validate = $apiCronTest->validate();
+ if ($validate) {
+ $apiCronTest->save();
+ }
}
+ } catch (Exception $e) {
+ return $e;
}
- } catch (Exception $e) {
- return $e;
- }
- return $this->asJson(json_decode($json, true));
+ return $this->asJson(json_decode($json, true));
+ } else {
+ return 'Такого ИНН нет в списке';
+ }
}
file_put_contents(self::OUT_DIR . '/error_buh_upload.txt', PHP_EOL . 'result empty', FILE_APPEND);
}
- return $this->asJson(['response' => true]);
+ return $this->asJson(['request_id' => $requestId,'response' => true]);
}
}
\ No newline at end of file