Esempio n. 1
0
 public function getProviders()
 {
     $model = new Providers();
     $providers = $model->getData();
     $this->error_message = "Thành công";
     return $this->ResponseData($providers);
 }
Esempio n. 2
0
 public function run()
 {
     // Ключ кеша
     $key = $this->providerId . '_' . $this->filename . '_' . filectime(Yii::$app->params['uploadFolder'] . $this->filename);
     if (Yii::$app->cache->exists($key)) {
         $arRes = Yii::$app->cache->get($key);
     } else {
         // Удалить старые предложения поставщика
         \app\models\Offers::deleteAll('providers_id = :providers_id', [':providers_id' => $this->providerId]);
         // Сохранить дату последней загрузки прайса
         $provider = \app\models\Providers::findOne($this->providerId);
         $provider->date_last_down = time();
         $provider->save();
         // Получить файл
         $arrCSV = file(Yii::$app->params['uploadFolder'] . $this->filename);
         // Обработка каждой строки файла
         $arrToAccord = [];
         foreach ($arrCSV as $k => $strCSV) {
             // Строку в массив
             $arStrCSV = str_getcsv($strCSV, ';');
             // Пропустить неполные строки
             if (strlen(trim($arStrCSV[$this->arrAccords['name']])) == 0 || strlen(trim($arStrCSV[$this->arrAccords['price']])) == 0 || strlen(trim($arStrCSV[$this->arrAccords['quantity']])) == 0) {
                 continue;
             }
             // Нормализовать массив строки от текущего поставщика
             $arResRow = $this->normalizeStrOfPrice($arStrCSV);
             // Получить тип товара
             $arResRow = $this->getGoodType($arResRow);
             if (isset($this->arrAccords['identifier'])) {
                 // Задан артикул
                 $res = $this->getAccordsByIdentifier($arResRow);
             } else {
                 // Не задан артикул
                 $res = $this->getAccordsByName($arResRow);
             }
             if ($res instanceof Accords) {
                 // Есть соответствие
                 // Пишем в таблицу предложений
                 $offer = new \app\models\Offers();
                 $offer->quantity = $arResRow['quantity'];
                 $offer->price = $arResRow['price'];
                 $offer->goods_id = $res->goods_id;
                 $offer->providers_id = $res->providers_id;
                 $offer->save();
             } else {
                 // Нет соответствия
                 // Вывести на согласование
                 $arResRow['k'] = $k;
                 $arrToAccord[$k] = $arResRow;
             }
             //                if ($k > 10)
             //                    break;
             //            break;
         }
         // Сохранить полученные данные в кеш
         $arRes = ['arrToAccord' => $arrToAccord, 'arGoodTypes' => $this->arGoodTypes, 'providerId' => $this->providerId, 'key' => $key];
         Yii::$app->cache->set($key, $arRes);
     }
     return $arRes;
 }
Esempio n. 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Providers::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'date_last_down' => $this->date_last_down]);
     $query->andFilterWhere(['like', 'meta', $this->meta])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'id_script', $this->id_script]);
     return $dataProvider;
 }
 public function getDirections(Request $request, $from_city, $to_city)
 {
     $params = (object) ["from_city" => $from_city, 'to_city' => $to_city];
     $selected_directions = (new Directions())->getDirection($params);
     $directions = Directions::with(["stations", "stations.city"])->whereIn('id', $selected_directions)->get()->filter(function ($item) {
         return $item->stations->count() != 0;
     });
     if ($directions->count() == 0) {
         return Response::HTTP_BAD_REQUEST;
     } else {
         $data['directions'] = $directions;
         $data['providers'] = \App\Models\Providers::all();
         return response()->json($data);
     }
 }
Esempio n. 5
0
 /**
  * Lists all Discounts models.
  * @return mixed
  */
 public function actionIndex($providerId = null, $typePrice = null)
 {
     $session = Yii::$app->session;
     $session->open();
     if ($providerId) {
         $session['providerIdFullName'] = $providerId;
         $provider = \app\models\Providers::findOne($providerId);
         $session['providerIdFullNameName'] = $provider->name;
         $this->redirect('/' . $this->id);
     }
     $arrPriceType = \yii\helpers\ArrayHelper::map(\app\models\PriceType::find()->all(), 'id', 'name');
     if ($typePrice) {
         $session['typePrice'] = $typePrice;
         $session['typePriceName'] = $arrPriceType[$typePrice];
         $this->redirect('/' . $this->id);
     }
     $searchModel = new DiscountsSearch();
     $arParams = Yii::$app->request->queryParams;
     $arParams['DiscountsSearch']['providers_id'] = $session['providerIdFullName'];
     //        if ($session['typePrice'])
     $arParams['DiscountsSearch']['price_type_id'] = $session['typePrice'];
     $dataProvider = $searchModel->search($arParams);
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'providerName' => $session['providerIdFullNameName'], 'arrPriceType' => $arrPriceType, 'typePrice' => $session['typePrice'], 'typePriceName' => $session['typePriceName']]);
 }
Esempio n. 6
0
 private function profileTyreBitrix($mode = 'run', $priceType = null)
 {
     if ($mode == 'info') {
         return ['name' => 'Экспорт шин в Битрикс', 'description' => 'Экспорт шин в Битрикс'];
     }
     if ($mode == 'run') {
         function saveRow($curGoodId, $arOffers, &$arStrToSave)
         {
             $arrGood = Goods::getName($curGoodId, 'array');
             $arRow['good']['id'] = $curGoodId;
             $arRow['good']['heigth'] = $arrGood['values']['tyre_heigth'];
             $arRow['good']['width'] = $arrGood['values']['tyre_width'];
             $arRow['good']['dia'] = $arrGood['values']['tyre_dia'];
             $arRow['good']['i_load'] = $arrGood['values']['tyre_i_load'];
             $arRow['good']['i_speed'] = $arrGood['values']['tyre_i_speed'];
             $arRow['good']['model'] = $arrGood['values']['tyre_model'];
             $arRow['good']['rf'] = $arrGood['values']['tyre_rf'] ? 'да' : '';
             $arRow['good']['brand'] = $arrGood['values']['tyre_brand'];
             $arRow['good']['season'] = $arrGood['values']['tyre_season'];
             $arRow['good']['type_auto'] = $arrGood['values']['tyre_type_auto'];
             $arRow['good']['spike'] = $arrGood['values']['tyre_spike'] ? 'да' : '';
             $arRow['offers'] = $arOffers;
             $arStrToSave[] = serialize($arRow);
         }
         function saveOffer($arOffer, &$arStrToSave)
         {
             $curGoodId = $arOffer['goods_id'];
             if (!isset($arStrToSave[$curGoodId])) {
                 $arrGood = Goods::getName($curGoodId, 'array');
                 $arRow['id'] = $curGoodId;
                 $arRow['goods_type'] = $arOffer['goods_type_type'];
                 $arRow['name'] = Goods::getName($curGoodId);
                 $arRow['heigth'] = $arrGood['values']['tyre_heigth'];
                 $arRow['width'] = $arrGood['values']['tyre_width'];
                 $arRow['dia'] = $arrGood['values']['tyre_dia'];
                 $arRow['i_load'] = $arrGood['values']['tyre_i_load'];
                 $arRow['i_speed'] = $arrGood['values']['tyre_i_speed'];
                 $arRow['model'] = $arrGood['values']['tyre_model'];
                 $arRow['rf'] = $arrGood['values']['tyre_rf'] ? 44 : '';
                 $arRow['brand'] = $arrGood['values']['tyre_brand'];
                 $arRow['season'] = $arrGood['values']['tyre_season'];
                 $arRow['type_auto'] = $arrGood['values']['tyre_type_auto'];
                 $arRow['spike'] = $arrGood['values']['tyre_spike'] ? 3 : '';
                 $arStrToSave[$curGoodId]['g'] = $arRow;
             }
             unset($arOffer['name'], $arOffer['goods_type_type']);
             $arStrToSave[$curGoodId]['o'][$arOffer['providers_id']] = $arOffer;
         }
         function clearFiles($file)
         {
             file_put_contents($file, '');
         }
         function saveFiles($file, $arStrToSave)
         {
             return;
             foreach ($arStrToSave as $gId => $arGO) {
                 $arStrToSave[$gId] = json_encode($arGO);
             }
             print count($arStrToSave) . '<br>';
             file_put_contents($file, implode(chr(10), $arStrToSave), FILE_APPEND);
         }
         $folder_local = $_SERVER['DOCUMENT_ROOT'] . '/unload/';
         $file_name = 'tyre_bitrix.txt';
         $file = $folder_local . $file_name;
         clearFiles($file);
         // Очистить файл
         $arStrToSave = [];
         // Список поставщиков
         $arProviders = \yii\helpers\ArrayHelper::map(\app\models\Providers::find()->all(), 'id', 'name');
         // Список оферов шин
         $sql = "select * from offers as O INNER JOIN goods as G where O.goods_id = G.id and G.goods_type_type = 'tyre'";
         $arOffers = \Yii::$app->db->createCommand($sql)->queryAll();
         //            exit();
         $curGoodId = 0;
         foreach ($arOffers as $k => $arOffer) {
             print $k . '--<br>';
             saveOffer($arOffer, $arStrToSave);
             if ($k % 10 == 0) {
                 // Сохранить на диск
                 saveFiles($file, $arStrToSave);
                 $arStrToSave = [];
             }
         }
         if (count($arStrToSave) > 0) {
             saveFiles($file, $arStrToSave);
         }
         // передать на сайт
         $folder_remout = '/home/s/shina93/shincenter/public_html/upload/';
         copy($file, $folder_remout . $file_name);
         //            $host = 'brevitas.timeweb.ru';
         //            $user = '******';
         //            $password = '******';
         //            $this->sendTrouthFTP($host, $user, $password, $folder_local, $file_name, $folder_remout);
     }
 }
Esempio n. 7
0
 public function actionDoFiler($goodsType, $goodsProvider = false)
 {
     header('Content-Type: utf-8');
     $oGoodsType = \app\models\GoodsType::findOne($goodsType);
     if (!$oGoodsType instanceof \app\models\GoodsType) {
         throw new Exception('Не верный тип товара');
     }
     $GoodsParamsName = $oGoodsType->getGoodsParamsNames()->orderBy('sort')->all();
     $arParamsType = \yii\helpers\ArrayHelper::map($GoodsParamsName, 'id', 'name');
     //                $arParamsType = [['id'=>'providers_id', 'name'=>'Поставщик']] + $arParamsType;
     $sql = 'select * from offers as O INNER JOIN goods as G INNER JOIN goods_t_' . $goodsType . ' as GT ' . 'where O.goods_id = G.id and G.id = GT.goods_id ';
     $arAnd = ['G.goods_type_type = :GT'];
     $arParams = [':GT' => $goodsType];
     if ($goodsProvider) {
         $arAnd[] = 'O.providers_id = :providers_id';
         $arParams[':providers_id'] = $goodsProvider;
     }
     foreach ($_GET as $k => $v) {
         if (strlen($v) > 0 && isset($arParamsType[$k])) {
             $arAnd[] = "GT.{$k} = :{$k}";
             $arParams[":{$k}"] = $v;
         }
     }
     $sql .= ' and ' . implode(' and ', $arAnd);
     $connection = \Yii::$app->db;
     $command = $connection->createCommand($sql);
     $command->bindValues($arParams);
     $items = $command->queryAll();
     $goodsValues = \app\models\GoodsParams::find()->all();
     //                $arrGoodsValues = \yii\helpers\ArrayHelper::toArray($goodsValues, ['app\models\GoodsParams'=>['id', 'value', 'public_value']]);
     $arrGoodsValues = \yii\helpers\ArrayHelper::map($goodsValues, 'id', 'value');
     //                print ('<pre>');print_r($arrGoodsValues);print('</pre>');exit('100');
     $providers = \app\models\Providers::find()->all();
     $arProviders = \yii\helpers\ArrayHelper::map($providers, 'id', 'name');
     $session = Yii::$app->session;
     $session->open();
     print $this->renderPartial('list', ['arParamsType' => $arParamsType, 'items' => $items, 'arrGoodsValues' => $arrGoodsValues, 'arProviders' => $arProviders, 'typePrice' => $session['typePrice']]);
 }
Esempio n. 8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getProviders()
 {
     return $this->hasOne(Providers::className(), ['id' => 'providers_id']);
 }