From: Alexander Smirnov Date: Wed, 27 Mar 2024 16:41:01 +0000 (+0300) Subject: fix integration api X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=a2ec9a2d97992c877f2a199f1b53b8fda8ba7001;p=yii-erp24%2F.git fix integration api --- diff --git a/erp24/controllers/ApiController.php b/erp24/controllers/ApiController.php index fec55e3..6904286 100644 --- a/erp24/controllers/ApiController.php +++ b/erp24/controllers/ApiController.php @@ -216,7 +216,9 @@ class ApiController extends Controller 'label' => 'GUID или ID', 'format' => 'raw', 'value' => function ($model) use ($inSore) { - return Html::input('string', '', $inSore[$model['id']] ?? '', ['class' => 'form-control guid_input']); + return Html::input('string', '', $inSore[$model['id']] ?? '', [ + 'data-id' => $model['id'], + 'class' => 'form-control guid_input']); } ], [ @@ -232,7 +234,7 @@ class ApiController extends Controller 'errorLoading' => new JsExpression("function () { return 'Waiting for results...'; }"), ], 'ajax' => [ - 'url' => 'poisk-item', + 'url' => 'poisk-items?entity=' . Yii::$app->request->get('entity') ?? 'admin', 'dataType' => 'json', 'data' => new JsExpression('function(params) { return {q:params.term}; }') ], @@ -240,6 +242,9 @@ class ApiController extends Controller 'templateResult' => new JsExpression('function(city) { return city.text; }'), 'templateSelection' => new JsExpression('function (city) { return city.text; }'), ], + 'pluginEvents' => [ + 'change' => 'function() { $(".guid_input[data-id=' . $model['id'] . ']").val($(this).val()); }' + ] ]); } ], @@ -263,27 +268,93 @@ class ApiController extends Controller $export_id = Yii::$app->request->post('export_id'); $value = Yii::$app->request->post('val'); $inid = Yii::$app->request->post('id'); - $expold = Yii::$app->request->post('expold'); - if ($entity == "admin" && $export_id == 1) { + if ($entity == "admin") { $admin = Admin::findOne(['id' => $inid]); $admin->guid = $value; - $admin->save(); - return "Обновили admin id=$inid guid= $value "; + $admin->save(false); } - if ($expold != $value or $expold == '') { + $exportImportTable = ExportImportTable::find()->where(['export_id' => 1, 'entity' => $entity, 'entity_id' => $inid])->one(); + if (!$exportImportTable) { + $exportImportTable = new ExportImportTable; + $exportImportTable->export_id = 1; + $exportImportTable->entity = $entity; + $exportImportTable->entity_id = $inid; + } + $expold = $exportImportTable->export_val; - $exportImportTableItem = new ExportImportTable(['export_id' => $export_id, 'entity' => $entity, 'entity_id' => $inid, 'export_val' => $value]); - $exportImportTableItem->save(); + $exportImportTable->export_val = $value; + $exportImportTable->save(false); - $apiIntegrationLogs = new ApiIntegrationLogs(['admin_id' => Yii::$app->user->id, 'date' => time(), 'export_id' => $export_id, 'entity' => $entity, 'entity_id' => $inid, 'export_val' => $value, 'export_val_old' => $expold]); - $apiIntegrationLogs->save(); - return "Данные сохранены"; - } + $apiIntegrationLogs = new ApiIntegrationLogs([ + 'admin_id' => Yii::$app->user->id, + 'date' => date("Y-m-d H:i:s"), + 'export_id' => $export_id, + 'entity' => $entity, + 'entity_id' => $inid, + 'export_val' => $value, + 'export_val_old' => $expold ?? '' + ]); + $apiIntegrationLogs->save(false); + + return "Данные сохранены"; } } + public function actionPoiskItems($q) { + Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; + $out = ['results' => ['id' => '', 'text' => '']]; + + $tip = "admin"; + $tip = Yii::$app->request->get('entity') ?? $tip; + + if ($tip == "products") { + $data = Products1c::find() + ->select([ + 'products_1c.id', + 'products_1c.parent_id', + 'products_1c.name as text', + 'products_1c.code', + 'products_1c.articule', + 'prices.price' + ]) + ->innerJoin('prices', 'products_1c.id = prices.product_id') + ->where([ + 'AND', + ['products_1c.tip' => 'products'], + ['LIKE', 'products_1c.name', '%' . $q . '%', false], + ]) + ->orderBy(['prices.price' => SORT_DESC]) + ->limit(20) + ->asArray() + ->all(); + + $out['results'] = array_values($data); + + } else if ($tip == 'admin' || $tip == 'city_store') { + $data = Products1c::find() + ->select([ + 'products_1c.id', + 'products_1c.name as text', + ]) + ->where([ + 'AND', + ['products_1c.tip' => $tip], + ['LIKE', 'products_1c.name', '%' . $q . '%', false], + ]) + ->orderBy(['products_1c.name' => SORT_ASC]) + ->limit(20) + ->asArray() + ->all(); + + $out['results'] = array_values($data); + + } + + return $out; + } + public function actionPoiskItem() { $tip = "admin"; diff --git a/erp24/views/api/integrations_index.php b/erp24/views/api/integrations_index.php index e416e82..e4807e9 100644 --- a/erp24/views/api/integrations_index.php +++ b/erp24/views/api/integrations_index.php @@ -18,11 +18,10 @@ use yii\web\View; $this->registerJs(<<registerJs(<<