'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']);
}
],
[
'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}; }')
],
'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()); }'
+ ]
]);
}
],
$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";