From: Vladimir Fomichev Date: Mon, 8 Sep 2025 14:59:37 +0000 (+0300) Subject: Загрузка букетов X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=d4a2260e30d464b5803ef87b5dce91bf1aca8409;p=erp24_rep%2Fyii-erp24%2F.git Загрузка букетов --- diff --git a/erp24/api2/controllers/DataController.php b/erp24/api2/controllers/DataController.php index 5a33815b..c23fc2b5 100644 --- a/erp24/api2/controllers/DataController.php +++ b/erp24/api2/controllers/DataController.php @@ -16,6 +16,9 @@ use yii_app\records\AnalystsBusinessOperationsTypes; use yii_app\records\ApiCron; use yii_app\records\Assemblies; use yii_app\records\Balances; +use yii_app\records\BouquetComposition; +use yii_app\records\BouquetCompositionMatrixTypeHistory; +use yii_app\records\BouquetCompositionProducts; use yii_app\records\Cashes; use yii_app\records\CityStore; use yii_app\records\CreateChecks; @@ -1189,6 +1192,7 @@ class DataController extends BaseController } if (!empty($result["nomenclature"]["elements"])) { // Products1c::deleteAll(['and', ['tip' => 'products'], ['view' => 0]]); + $bouquets = BouquetComposition::find()->select('guid')->column(); foreach ($result["nomenclature"]["elements"] as $gi => $arr) { // if (!empty($arr["name"]) && in_array($arr["name"][0], ['ь', 'Ь', 'ъ', 'Ъ'])) { // Не вносим номенклатуру, помеченную на удаление // continue; @@ -1212,6 +1216,45 @@ class DataController extends BaseController LogService::apiErrorLog(json_encode(["error_id" => 8, "error" => $products1c6->getErrors()], JSON_UNESCAPED_UNICODE)); } + if(!empty($arr["components"])) { + if(!in_array($arr["id"], $bouquets)) { + $newBouquetComp = new BouquetComposition(); + $newBouquetComp->guid = $arr["id"]; + $newBouquetComp->name = $arr["name"]; + $newBouquetComp->created_by = Admin::getAdminAgentId() ?: null; + if(!$newBouquetComp->save()) { + LogService::apiErrorLog(json_encode(["error_id" => 8.1, "error" => $newBouquetComp->getErrors()], JSON_UNESCAPED_UNICODE)); + } else { + foreach ($arr["components"] as $guid => $quantity) { + $newBouquetCompProd = new BouquetCompositionProducts(); + $newBouquetCompProd->bouquet_id = $newBouquetComp->id; + $newBouquetCompProd->product_guid = $guid; + $newBouquetCompProd->count = $quantity; + $newBouquetCompProd->created_by = Admin::getAdminAgentId() ?: null; + if(!$newBouquetCompProd->save()) { + LogService::apiErrorLog(json_encode(["error_id" => 8.2, "error" => $newBouquetCompProd->getErrors()], JSON_UNESCAPED_UNICODE)); + } + } + $costModels = []; + foreach (BouquetComposition::getRegions() as $region_id) { + $costModels[$region_id] = $newBouquetComp->getCostModel($region_id, array_keys($arr["components"]), true); + } + if(empty($costModels)) { + LogService::apiErrorLog(json_encode(["error_id" => 8.3, "error" => "Стоимость и цена не подсчитаны"], JSON_UNESCAPED_UNICODE)); + } + $bouquetTypeHistory = new BouquetCompositionMatrixTypeHistory(); + $bouquetTypeHistory->bouquet_id = $newBouquetComp->id; + $bouquetTypeHistory->matrix_type_id = 1; + $bouquetTypeHistory->created_by = Admin::getAdminAgentId() ?: null; + $bouquetTypeHistory->is_active = 1; + $bouquetTypeHistory->date_from = date('Y-m-d H:i:s'); + if(!$bouquetTypeHistory->save()) { + LogService::apiErrorLog(json_encode(["error_id" => 8.4, "error" => $bouquetTypeHistory->getErrors()], JSON_UNESCAPED_UNICODE)); + } + } + } + } + foreach ($arr as $key => $property) { if (!in_array($key, Products1c::PRODUCT1C_FIELDS)) { if (empty($property)) continue; diff --git a/erp24/records/Admin.php b/erp24/records/Admin.php index a81b3322..449b9287 100755 --- a/erp24/records/Admin.php +++ b/erp24/records/Admin.php @@ -89,6 +89,8 @@ class Admin extends ActiveRecord implements IdentityInterface 72, // ]; + const ADMIN_AGENT_FOR_EXCHANGE_NAME = 'agent'; + public $imageFile; private $store_arrArr; @@ -732,6 +734,12 @@ class Admin extends ActiveRecord implements IdentityInterface // $_SESSION['name_group_admin'] = "Пользователь"; } + public static function getAdminAgentId() { + $id = Admin::find()->select('id')->where(['name' => self::ADMIN_AGENT_FOR_EXCHANGE_NAME])->scalar(); + return $id; + } + + public function hasPermission($permission) {