public function actionDownload() { $request = Yii::$app->getRequest()->get(); if ($request['company'] == 'letual') { $command = Yii::$app->getDb()->createCommand('SELECT * FROM letual_product'); $attr = new LetualProduct(); $reader = $command->query(); } elseif ($request['company'] == 'rive') { $command = Yii::$app->getDb()->createCommand('SELECT * FROM rivegauche_product'); $attr = new RivegaucheProduct(); $reader = $command->query(); } elseif ($request['company'] == 'ile') { $command = Yii::$app->getDb()->createCommand('SELECT * FROM iledebeaute_product'); $attr = new IledebeauteProduct(); $reader = $command->query(); } elseif ($request['company'] == 'eli') { $command = Yii::$app->getDb()->createCommand('SELECT * FROM elize_product'); $attr = new ElizeProduct(); $reader = $command->query(); } else { $let = []; } $filename = sprintf('%s_%s.xls', $request['company'], date_format(new \DateTime(), 'Y-m-d')); $export = new ExportExcel($filename, count($attr->getAttributes()), $reader->count() + 1); $export->openWriter(); $export->openWorkbook(); $export->writeDocumentProperties(); $export->writeStyles(); $export->openWorksheet(); //title row $export->resetRow(); $export->openRow(true); foreach ($attr->getAttributes() as $code => $format) { $export->appendCellString($attr->getAttributeLabel($code)); } $export->closeRow(); $export->flushRow(); while ($row = $reader->read()) { $export->resetRow(); $export->openRow(); foreach ($attr->getAttributes() as $code => $format) { $export->appendCellString($row[$code]); } $export->closeRow(); $export->flushRow(); } //close all $export->closeWorksheet(); $export->closeWorkbook(); $export->closeWriter(); header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename=' . basename($filename)); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($export->getBaseFullFileName())); readfile($export->getBaseFullFileName()); }
/** * @return string */ public function actionArticleUpdate() { if ($pArticle = reset($_POST['PodruzkaProduct'])['article']) { if ($pp = PodruzkaProduct::find()->where(['article' => $pArticle])->one()) { if (!empty($_POST['l_id'])) { if ($lp = LetualProduct::find()->where(['article' => $_POST['l_id']])->one()) { $pp->l_id = $lp->id; } } else { $pp->l_id = null; } if (!empty($_POST['r_id'])) { if ($rp = RivegaucheProduct::find()->where(['article' => $_POST['r_id']])->one()) { $pp->r_id = $rp->id; } } else { $pp->r_id = null; } if (!empty($_POST['i_id'])) { if ($ip = IledebeauteProduct::find()->where(['article' => $_POST['i_id']])->one()) { $pp->i_id = $ip->id; } } else { $pp->i_id = null; } if (!empty($_POST['e_id'])) { if ($ep = ElizeProduct::find()->where(['article' => $_POST['e_id']])->one()) { $pp->e_id = $ep->id; } } else { $pp->e_id = null; } $pp->save(); return json_encode(['result' => true]); } } return json_encode(['result' => false]); }
/** * @param Response $result */ private function saveElizeResult(Response $result) { $product = ElizeProduct::findOne(['article' => $result->getArticle()]); if (!$product) { $product = new ElizeProduct(); } $product->attributes = $result->toArray(); $product->new_price = !empty($result->getNewPrice()) ? $result->getNewPrice() : null; $product->old_price = !empty($result->getPrice()) ? $result->getPrice() : null; $product->deleted_at = '0000-00-00 00:00:00'; try { $ePrice = new ElizePrice(); $ePrice->article = $result->getArticle(); $ePrice->old_price = $product->old_price; $ePrice->new_price = $product->new_price; if ($product->save()) { $ePrice->save(); } else { \Yii::error(sprintf('Ошибка сохранения артикула E: %s data: %s', $result->getArticle(), json_encode($result->toArray())), 'cron'); } } catch (\Exception $e) { \Yii::error(sprintf('Exception %s сохранения артикула E %s data: %s', $e->getMessage(), $result->getArticle(), json_encode($result->toArray())), 'cron'); } }
/** * Finds the ElizeProduct model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return ElizeProduct the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = ElizeProduct::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return array */ public static function getStatistics() { $query = ElizeProduct::find(); $query->select(['count(id) as counts', 'DATE_FORMAT(created_at, "%Y-%m-%d") as dates']); $query->groupBy(['DATE_FORMAT(created_at, "%Y-%m-%d")']); $query->orderBy('created_at'); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 50]]); return $dataProvider; }
/** * Возвращает строку с инпутами для таблицы с формой сопоставления * * @param $model * * @return string */ public static function getArticleMatchingForm($model) { $result = Html::activeLabel($model, 'l_id'); $result .= Html::input('', 'l_id', !empty($lp = LetualProduct::find()->where(['id' => $model->l_id])->one()) ? $lp->article : '', ['class' => 'kv-editable-input form-control']); $result .= Html::activeLabel($model, 'r_id'); $result .= Html::input('', 'r_id', !empty($lp = RivegaucheProduct::find()->where(['id' => $model->r_id])->one()) ? $lp->article : '', ['class' => 'kv-editable-input form-control']); $result .= Html::activeLabel($model, 'e_id'); $result .= Html::input('', 'e_id', !empty($ep = ElizeProduct::find()->where(['id' => $model->e_id])->one()) ? $ep->article : '', ['class' => 'kv-editable-input form-control']); $result .= Html::activeLabel($model, 'i_id'); $result .= Html::input('', 'i_id', !empty($lp = IledebeauteProduct::find()->where(['id' => $model->i_id])->one()) ? $lp->article : '', ['class' => 'kv-editable-input form-control']); return $result; }