From bbeacc452fe93e079d65ea2f489d32d98e0cc450 Mon Sep 17 00:00:00 2001 From: marina Date: Wed, 28 Aug 2024 15:36:13 +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?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/api2/controllers/DataBuhController.php | 1 + erp24/services/MotivationServiceBuh.php | 22 ++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/erp24/api2/controllers/DataBuhController.php b/erp24/api2/controllers/DataBuhController.php index 7f6f21c3..31559597 100644 --- a/erp24/api2/controllers/DataBuhController.php +++ b/erp24/api2/controllers/DataBuhController.php @@ -97,6 +97,7 @@ class DataBuhController extends BaseController file_put_contents(self::OUT_DIR . '/upload_' . $fl . '.json', PHP_EOL . $request); try { + $apiCron = ApiCronBuh::findOne(['request_id' => $requestId]); if ($apiCron) { $apiCron->date_up = date("Y-m-d H:i:s"); diff --git a/erp24/services/MotivationServiceBuh.php b/erp24/services/MotivationServiceBuh.php index b61108c2..583d9aae 100644 --- a/erp24/services/MotivationServiceBuh.php +++ b/erp24/services/MotivationServiceBuh.php @@ -2,6 +2,7 @@ namespace yii_app\services; +use yii\helpers\ArrayHelper; use yii_app\records\Motivation; use yii_app\records\MotivationBuh; use yii_app\records\MotivationBuhValue; @@ -40,25 +41,28 @@ class MotivationServiceBuh $alias = $validate === 'month' ? 'month' : 'week' . $week; $motivationValueGroup = MotivationValueGroup::findOne(['alias' => $alias]); + + $storeBuhIds = ArrayHelper::map(StoreGuidBuh::find()->select(['store_guid', 'store_id'])->asArray()->all(), 'store_guid', 'store_id'); + $motivationCostsItems = ArrayHelper::map(MotivationCostsItem::find()->select(['name', 'code'])->asArray()->all(), 'name', 'code'); + if (!empty($data['cost_items'])) { foreach ($data['cost_items'] as $stores) { foreach ($stores as $storeData) { - $storeBuh = StoreGuidBuh::find() - ->andWhere(['store_guid' => $storeData['store_guid']]) - ->one(); + $storeBuh = array_key_exists($storeData['store_guid'], $storeBuhIds); if (!$storeBuh) { LogService::apiErrorLog(json_encode(["error_id" => 45, "error" => 'Несуществующий магазин! Название: ' . $storeData['store_name'] . ' , guid: ' . $storeData['store_guid']], JSON_UNESCAPED_UNICODE)); return; } - $store = CityStore::getCityStoreById($storeBuh->store_id, true); + $storeId = $storeBuhIds[$storeData['store_guid']]; foreach ($storeData['items'] as $items) { foreach ($items as $item) { - $value = MotivationCostsItem::findOne(['name' => $item['name']]); + $value = array_key_exists($item['name'], $motivationCostsItems); if (!$value) { LogService::apiErrorLog(json_encode(["error_id" => 46, "error" => $item['name']], JSON_UNESCAPED_UNICODE)); + return; } $motivationBuh = MotivationBuh::findOne([ @@ -79,9 +83,9 @@ class MotivationServiceBuh $motivationBuhValue = MotivationBuhValue::findOne([ 'motivation_buh_id' => $motivationBuh->id, - 'store_id' => $store['id'], + 'store_id' => $storeId, 'motivation_group_id' => $motivationValueGroup->id, - 'value_id' => $value->id, + 'value_id' => $motivationCostsItems[$storeData['items']], 'value_type' => MotivationCostsItem::DATA_TYPE_FLOAT, ]); @@ -91,9 +95,9 @@ class MotivationServiceBuh $motivationBuhValue = new MotivationBuhValue(); $motivationBuhValue->setAttributes([ 'motivation_buh_id' => $motivationBuh->id, - 'store_id' => $store['id'], + 'store_id' => $storeId, 'motivation_group_id' => $motivationValueGroup->id, - 'value_id' => $value->id, + 'value_id' => $motivationCostsItems[$storeData['items']], 'value_type' => MotivationCostsItem::DATA_TYPE_FLOAT, 'value_float' => $item['summ'] ]); -- 2.39.5