--- /dev/null
+<?php
+
+namespace app\controllers;
+
+use kartik\select2\Select2;
+use Yii;
+use yii\data\ArrayDataProvider;
+use yii\helpers\ArrayHelper;
+use yii\helpers\Html;
+use yii\web\Controller;
+use yii\web\JsExpression;
+use yii_app\records\Admin;
+use yii_app\records\ApiIntegrationLogs;
+use yii_app\records\Balances;
+use yii_app\records\CityStore;
+use yii_app\records\ExportImportIntegrations;
+use yii_app\records\ExportImportTable;
+use yii_app\records\InfoItemsTableShop0;
+use yii_app\records\Products1c;
+
+class ApiController extends Controller
+{
+ public function actionIntegrations($entity = "city_store", $export_id = 1)
+ {
+ $exportImportIntegrationsList = ExportImportIntegrations::find()
+ ->select([
+ 'id',
+ 'name'
+ ])
+ ->asArray()
+ ->all();
+
+ $entityArr = [];
+ $cnt = 0;
+
+ if ($entity === 'admin') {
+ $admins = Admin::find()
+ ->select([
+ 'id',
+ 'name'
+ ])
+ ->where(['>', 'group_id', 3])
+ ->asArray()
+ ->all();
+
+ $entityArr = $admins;
+ $cnt = count($entityArr);
+
+ } else if ($entity === 'city_store') {
+ $cityStore = CityStore::find()
+ ->select([
+ 'name',
+ 'id'
+ ])
+ ->asArray()
+ ->all();
+
+ $entityArr = $cityStore;
+ $cnt = count($entityArr);
+
+ } else if ($entity === 'products') {
+ $infoItemsTableShop0 = InfoItemsTableShop0::find()
+ ->select([
+ 'name' => 'title',
+ 'id' => 'item_id'
+ ])
+ ->where([
+ 'cat_items_id' => [
+ 2,
+ 1219,
+ 1220,
+ 1224,
+ 1225,
+ 1226,
+ 1227
+ ]
+ ])
+ ->orderBy([
+ 'cat_items_id' => SORT_ASC,
+ 'title' => SORT_ASC
+ ])
+ ->limit(3000)
+ ->asArray()
+ ->all();
+
+ $entityArr = $infoItemsTableShop0;
+
+ $balancesItems = Balances::find()
+ ->select([
+ 'product_id',
+ 'quantity'
+ ])
+ ->where([
+ 'store_id' => "dbd70103-2c7b-11e9-9b87-c85b76f0e893"
+ ])
+ ->asArray()
+ ->all();
+
+ $balances = ArrayHelper::map($balancesItems, 'product_id', 'quantity');
+ $cnt = count($balances);
+
+ }
+
+ $expotImportTableItems = ExportImportTable::find()
+ ->where([
+ 'entity' => $entity,
+ 'export_id' => $export_id
+ ])
+ ->asArray()
+ ->all();
+
+ $inSore = ArrayHelper::map($expotImportTableItems, 'entity_id', 'export_val');
+ $idgrid = ArrayHelper::getColumn($expotImportTableItems, 'export_val');
+
+ $products1C = [];
+ $entity___arr = [];
+ $entity___arr0 = [];
+ if ($entity === 'city_store') {
+ $products1C = Products1c::find()
+ ->where([
+ 'AND',
+ ['tip' => 'city_store'],
+ ['view' => 1]
+ ])
+ ->asArray()
+ ->all();
+
+
+ } else if ($entity === 'admin') {
+ $expotImportTableItems = ExportImportTable::find()
+ ->select([
+ 'export_val',
+ 'entity_id'
+ ])
+ ->where([
+ 'AND',
+ ['entity' => 'admin'],
+ ['export_id' => 1]
+ ])
+ ->asArray()
+ ->all();
+
+ foreach ($expotImportTableItems as $expotImportTableItem) {
+ Admin::updateAll(['guid' => $expotImportTableItem['export_val']], ['id' => $expotImportTableItem['entity_id']]);
+ }
+
+ Products1c::updateAll(['tip' => 'admin'], ['tip' => 'sellers']);
+ $products1C = Products1c::find()
+ ->where([
+ 'tip' => 'admin'
+ ])
+ ->asArray()
+ ->all();
+
+ foreach ($products1C as $row) {
+ $entity___arr[$row["id"]] = $row["name"] . "";
+ $entity___arr0[$row["id"]] = $row["name"];
+ }
+
+ } else if ($entity === 'products') {
+ $products1C = Products1c::find()
+ ->where([
+ 'tip' => 'products_group'
+ ])
+ ->asArray()
+ ->all();
+
+ $group = ArrayHelper::map($products1C, 'id', 'name');
+
+ $products1C = Products1c::find()
+ ->select([
+ 'name',
+ 'id',
+ 'parent_id'
+ ])
+ ->where([
+ 'tip' => 'products'
+ ])
+ ->asArray()
+ ->all();
+
+ foreach ($products1C as $row) {
+ $entity___arr[$row["id"]] = $row["name"] . " <small>(" . $group[$row["parent_id"]] . ")</small>";
+ $entity___arr0[$row["id"]] = $row["name"];
+ }
+ }
+
+ $dataProvider = new ArrayDataProvider([
+ 'allModels' => $entityArr
+ ]);
+
+ $columns = [
+ [
+ 'label' => 'ID в ERP',
+ 'value' => function ($model) {
+ return $model['id'];
+ }
+ ],
+ [
+ 'label' => 'Название в ERP',
+ 'value' => function ($model) {
+ return $model['name'];
+ }
+ ],
+ [
+ 'label' => 'Название в интеграции',
+ 'format' => 'raw',
+ 'value' => function ($model) use ($entity___arr, $inSore) {
+ if (isset($inSore[$model['id']])) {
+ return $entity___arr[$inSore[$model['id']]] ?? '';
+ }
+ return '';
+ }
+ ],
+ [
+ 'label' => 'GUID или ID',
+ 'format' => 'raw',
+ 'value' => function ($model) use ($inSore) {
+ return Html::input('string', '', $inSore[$model['id']] ?? '', ['class' => 'form-control guid_input']);
+ }
+ ],
+ [
+ 'label' => 'Поиск и сопоставление в интеграции',
+ 'format' => 'raw',
+ 'value' => function ($model) use ($inSore) {
+ return Select2::widget([
+ 'name' => $model['id'],
+ 'pluginOptions' => [
+ 'allowClear' => true,
+ 'minimumInputLength' => 3,
+ 'language' => [
+ 'errorLoading' => new JsExpression("function () { return 'Waiting for results...'; }"),
+ ],
+ 'ajax' => [
+ 'url' => 'poisk-item',
+ 'dataType' => 'json',
+ 'data' => new JsExpression('function(params) { return {q:params.term}; }')
+ ],
+ 'escapeMarkup' => new JsExpression('function (markup) { return markup; }'),
+ 'templateResult' => new JsExpression('function(city) { return city.text; }'),
+ 'templateSelection' => new JsExpression('function (city) { return city.text; }'),
+ ],
+ ]);
+ }
+ ],
+ ];
+
+ return $this->render('integrations_index', [
+ 'entity' => $entity,
+ 'export_id' => $export_id,
+ 'exportImportIntegrationsList' => $exportImportIntegrationsList,
+ 'products1C' => $products1C,
+ 'idgrid' => $idgrid,
+ 'dataProvider' => $dataProvider,
+ 'columns' => $columns
+ ]);
+ }
+
+ public function actionIntegrationSave()
+ {
+ if (Yii::$app->request->post('id')) {
+ $entity = Yii::$app->request->post('entity');
+ $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) {
+ $admin = Admin::findOne(['id' => $inid]);
+ $admin->guid = $value;
+ $admin->save();
+ return "Обновили admin id=$inid guid= $value ";
+ }
+
+ if ($expold != $value or $expold == '') {
+
+ $exportImportTableItem = new ExportImportTable(['export_id' => $export_id, 'entity' => $entity, 'entity_id' => $inid, 'export_val' => $value]);
+ $exportImportTableItem->save();
+
+ $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 "Данные сохранены";
+ }
+ }
+ }
+
+ public function actionPoiskItem()
+ {
+ $tip = "admin";
+
+ $s = Yii::$app->request->post('search');
+ $id = Yii::$app->request->post('id');
+ $tip = Yii::$app->request->post('tip');
+ $tip = Yii::$app->request->post('entity') ?? $tip;
+
+ if (strlen($s) > 2) {
+
+ if ($tip == "products" or $tip == "product") {
+ $products1C = Products1c::find()
+ ->select([
+ 'id',
+ 'name'
+ ])
+ ->where([
+ 'tip' => 'products_group'
+ ])
+ ->asArray()
+ ->all();
+
+ $group = ArrayHelper::map($products1C, 'id', 'name');
+
+ $data = Products1c::find()
+ ->select([
+ 'products_1c.id',
+ 'products_1c.parent_id',
+ 'products_1c.name',
+ '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', '%' . $s . '%', false],
+ ])
+ ->orderBy(['prices.price' => SORT_DESC])
+ ->limit(20)
+ ->asArray()
+ ->all();
+
+ } else if ($tip == 'admin') {
+ $data = Products1c::find()
+ ->select([
+ 'products_1c.id',
+ 'products_1c.name',
+ ])
+ ->where([
+ 'AND',
+ ['products_1c.tip' => 'admin'],
+ ['LIKE', 'products_1c.name', '%' . $s . '%', false],
+ ])
+ ->orderBy(['products_1c.name' => SORT_ASC])
+ ->limit(20)
+ ->asArray()
+ ->all();
+
+ }
+
+
+
+ return $data;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+
+/**
+ * This is the model class for table "info_items_table_shop_0".
+ *
+ * @property int $item_id
+ * @property string $title Наименование
+ * @property float $price
+ * @property int $f_id ID товара в сторонней программе
+ * @property string $kod штрих код
+ * @property string $id_1c GUID
+ * @property int $cat_items_id
+ * @property int $cat_id_ishod
+ * @property string $cat_items_id_dop
+ * @property string $cat_items_catalog_arr
+ * @property string $group_arr
+ * @property string $tag_arr тэги, свойства товара
+ * @property string $tags
+ * @property int $tag_main главный тэг
+ * @property int $site_id
+ * @property string $sites_arr
+ * @property int $modul_id
+ * @property string $data
+ * @property string $data_edit
+ * @property string $data_edit_images
+ * @property int $admin_id_edit
+ * @property string $data_start
+ * @property string $data_end
+ * @property string $title_from_url title для url
+ * @property string $title_url
+ * @property string $title_url_dop
+ * @property string $description
+ * @property string $description2
+ * @property int $proizvoditel_id
+ * @property string $content
+ * @property string $url
+ * @property string $image
+ * @property string $image_sm
+ * @property float $price_zakup
+ * @property int $price_zakup_up
+ * @property float $price_old
+ * @property string $price_individ
+ * @property string $price_m2
+ * @property float $m2_korobka
+ * @property int $counter
+ * @property int $counter_down
+ * @property int $counter_com
+ * @property int $counter_poll
+ * @property float $avg_ball
+ * @property int $order
+ * @property string $seo_title
+ * @property string $seo_description
+ * @property string $seo_keywords
+ * @property string $user_ip
+ * @property int $user_access
+ * @property int $user_id
+ * @property string $nick
+ * @property int $admin_id
+ * @property string $moderator
+ * @property string|null $comments
+ * @property string $video
+ * @property string|null $rss
+ * @property int $status
+ * @property string $visible
+ * @property string $rasprodazha
+ * @property string $sale распродажа
+ * @property int $sale_city_id
+ * @property string $instock в наличии
+ * @property int $price_down
+ * @property int $price_30day
+ * @property string $action акция
+ * @property string $exclusive
+ * @property string $novinka
+ * @property string $hit Хит продаж
+ * @property int $speed_delivery Быстрая доставка - матричные букеты
+ * @property string $super_price
+ * @property string $in_lp
+ * @property string $shop_dop Доп. модули
+ * @property int $shop_table
+ * @property int $show_in_catalog видимый (выводить на сайт)
+ * @property string $dop_items
+ * @property int $default_on
+ * @property int $kol
+ * @property string $razmer
+ * @property int $dlina
+ * @property int $glubina
+ * @property int $visota
+ * @property int $shirina
+ * @property int $kol_mest
+ * @property float $massa
+ * @property float $molar_volume объём м3
+ * @property string $srok
+ * @property string $title_proizv
+ * @property string $articul_proizv
+ * @property string $shop_vmeste_array
+ * @property int $price_idivid
+ * @property string $colors_array
+ * @property string $mmebel
+ * @property int $krovat_osnova
+ * @property int $clear_tag
+ * @property int $items_id_site
+ * @property int $items_id_clon
+ * @property string $archive
+ * @property int $sostav составной товар
+ * @property string $setka_arr
+ * @property string $city_arr
+ * @property int $city_all
+ * @property int $no_bonus
+ */
+class InfoItemsTableShop0 extends \yii\db\ActiveRecord
+{
+ /**
+ * {@inheritdoc}
+ */
+ public static function tableName()
+ {
+ return 'info_items_table_shop_0';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function rules()
+ {
+ return [
+ [['item_id', 'title', 'f_id', 'kod', 'id_1c', 'cat_id_ishod', 'cat_items_id_dop', 'cat_items_catalog_arr', 'group_arr', 'tag_arr', 'tags', 'tag_main', 'sites_arr', 'data_edit_images', 'title_from_url', 'title_url', 'title_url_dop', 'description', 'description2', 'proizvoditel_id', 'content', 'url', 'price_zakup', 'price_old', 'm2_korobka', 'seo_title', 'seo_description', 'seo_keywords', 'video', 'sale_city_id', 'price_down', 'price_30day', 'dop_items', 'razmer', 'dlina', 'glubina', 'visota', 'shirina', 'kol_mest', 'massa', 'molar_volume', 'srok', 'title_proizv', 'articul_proizv', 'shop_vmeste_array', 'colors_array', 'items_id_site', 'setka_arr', 'city_arr'], 'required'],
+ [['item_id', 'f_id', 'cat_items_id', 'cat_id_ishod', 'tag_main', 'site_id', 'modul_id', 'admin_id_edit', 'proizvoditel_id', 'price_zakup_up', 'counter', 'counter_down', 'counter_com', 'counter_poll', 'order', 'user_access', 'user_id', 'admin_id', 'status', 'sale_city_id', 'price_down', 'price_30day', 'speed_delivery', 'shop_table', 'show_in_catalog', 'default_on', 'kol', 'dlina', 'glubina', 'visota', 'shirina', 'kol_mest', 'price_idivid', 'krovat_osnova', 'clear_tag', 'items_id_site', 'items_id_clon', 'sostav', 'city_all', 'no_bonus'], 'integer'],
+ [['title', 'cat_items_id_dop', 'cat_items_catalog_arr', 'group_arr', 'tag_arr', 'tags', 'sites_arr', 'title_url_dop', 'description', 'description2', 'content', 'url', 'price_individ', 'price_m2', 'seo_title', 'seo_description', 'seo_keywords', 'moderator', 'comments', 'video', 'rss', 'visible', 'rasprodazha', 'sale', 'instock', 'action', 'exclusive', 'novinka', 'hit', 'super_price', 'in_lp', 'shop_dop', 'dop_items', 'shop_vmeste_array', 'colors_array', 'mmebel', 'archive', 'city_arr'], 'string'],
+ [['price', 'price_zakup', 'price_old', 'm2_korobka', 'avg_ball', 'massa', 'molar_volume'], 'number'],
+ [['data', 'data_edit', 'data_edit_images', 'data_start', 'data_end'], 'safe'],
+ [['kod'], 'string', 'max' => 32],
+ [['id_1c'], 'string', 'max' => 36],
+ [['title_from_url', 'title_url', 'image', 'image_sm', 'title_proizv'], 'string', 'max' => 255],
+ [['user_ip'], 'string', 'max' => 15],
+ [['nick'], 'string', 'max' => 35],
+ [['razmer', 'articul_proizv'], 'string', 'max' => 155],
+ [['srok'], 'string', 'max' => 20],
+ [['setka_arr'], 'string', 'max' => 150],
+ ];
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function attributeLabels()
+ {
+ return [
+ 'item_id' => 'Item ID',
+ 'title' => 'Title',
+ 'price' => 'Price',
+ 'f_id' => 'F ID',
+ 'kod' => 'Kod',
+ 'id_1c' => 'Id 1c',
+ 'cat_items_id' => 'Cat Items ID',
+ 'cat_id_ishod' => 'Cat Id Ishod',
+ 'cat_items_id_dop' => 'Cat Items Id Dop',
+ 'cat_items_catalog_arr' => 'Cat Items Catalog Arr',
+ 'group_arr' => 'Group Arr',
+ 'tag_arr' => 'Tag Arr',
+ 'tags' => 'Tags',
+ 'tag_main' => 'Tag Main',
+ 'site_id' => 'Site ID',
+ 'sites_arr' => 'Sites Arr',
+ 'modul_id' => 'Modul ID',
+ 'data' => 'Data',
+ 'data_edit' => 'Data Edit',
+ 'data_edit_images' => 'Data Edit Images',
+ 'admin_id_edit' => 'Admin Id Edit',
+ 'data_start' => 'Data Start',
+ 'data_end' => 'Data End',
+ 'title_from_url' => 'Title From Url',
+ 'title_url' => 'Title Url',
+ 'title_url_dop' => 'Title Url Dop',
+ 'description' => 'Description',
+ 'description2' => 'Description2',
+ 'proizvoditel_id' => 'Proizvoditel ID',
+ 'content' => 'Content',
+ 'url' => 'Url',
+ 'image' => 'Image',
+ 'image_sm' => 'Image Sm',
+ 'price_zakup' => 'Price Zakup',
+ 'price_zakup_up' => 'Price Zakup Up',
+ 'price_old' => 'Price Old',
+ 'price_individ' => 'Price Individ',
+ 'price_m2' => 'Price M2',
+ 'm2_korobka' => 'M2 Korobka',
+ 'counter' => 'Counter',
+ 'counter_down' => 'Counter Down',
+ 'counter_com' => 'Counter Com',
+ 'counter_poll' => 'Counter Poll',
+ 'avg_ball' => 'Avg Ball',
+ 'order' => 'Order',
+ 'seo_title' => 'Seo Title',
+ 'seo_description' => 'Seo Description',
+ 'seo_keywords' => 'Seo Keywords',
+ 'user_ip' => 'User Ip',
+ 'user_access' => 'User Access',
+ 'user_id' => 'User ID',
+ 'nick' => 'Nick',
+ 'admin_id' => 'Admin ID',
+ 'moderator' => 'Moderator',
+ 'comments' => 'Comments',
+ 'video' => 'Video',
+ 'rss' => 'Rss',
+ 'status' => 'Status',
+ 'visible' => 'Visible',
+ 'rasprodazha' => 'Rasprodazha',
+ 'sale' => 'Sale',
+ 'sale_city_id' => 'Sale City ID',
+ 'instock' => 'Instock',
+ 'price_down' => 'Price Down',
+ 'price_30day' => 'Price 30day',
+ 'action' => 'Action',
+ 'exclusive' => 'Exclusive',
+ 'novinka' => 'Novinka',
+ 'hit' => 'Hit',
+ 'speed_delivery' => 'Speed Delivery',
+ 'super_price' => 'Super Price',
+ 'in_lp' => 'In Lp',
+ 'shop_dop' => 'Shop Dop',
+ 'shop_table' => 'Shop Table',
+ 'show_in_catalog' => 'Show In Catalog',
+ 'dop_items' => 'Dop Items',
+ 'default_on' => 'Default On',
+ 'kol' => 'Kol',
+ 'razmer' => 'Razmer',
+ 'dlina' => 'Dlina',
+ 'glubina' => 'Glubina',
+ 'visota' => 'Visota',
+ 'shirina' => 'Shirina',
+ 'kol_mest' => 'Kol Mest',
+ 'massa' => 'Massa',
+ 'molar_volume' => 'Molar Volume',
+ 'srok' => 'Srok',
+ 'title_proizv' => 'Title Proizv',
+ 'articul_proizv' => 'Articul Proizv',
+ 'shop_vmeste_array' => 'Shop Vmeste Array',
+ 'price_idivid' => 'Price Idivid',
+ 'colors_array' => 'Colors Array',
+ 'mmebel' => 'Mmebel',
+ 'krovat_osnova' => 'Krovat Osnova',
+ 'clear_tag' => 'Clear Tag',
+ 'items_id_site' => 'Items Id Site',
+ 'items_id_clon' => 'Items Id Clon',
+ 'archive' => 'Archive',
+ 'sostav' => 'Sostav',
+ 'setka_arr' => 'Setka Arr',
+ 'city_arr' => 'City Arr',
+ 'city_all' => 'City All',
+ 'no_bonus' => 'No Bonus',
+ ];
+ }
+}