Commit 741ecd87cd5ec8231a0f825ad5c6321b646c8594
1 parent
afcbaa24
add migration for view Details Currency and change check-price view
Showing
7 changed files
with
137 additions
and
36 deletions
 
Show diff stats
backend/controllers/CheckPriceController.php
| ... | ... | @@ -8,6 +8,7 @@ use yii\filters\AccessControl; | 
| 8 | 8 | use backend\components\base\BaseController; | 
| 9 | 9 | use yii\filters\VerbFilter; | 
| 10 | 10 | use backend\models\Details; | 
| 11 | +use common\models\DetailsCurrency; | |
| 11 | 12 | use backend\models\ImportersFiles; | 
| 12 | 13 | use backend\models\Importers; | 
| 13 | 14 | use yii\base\ErrorException; | 
| ... | ... | @@ -61,7 +62,7 @@ class CheckPriceController extends BaseController | 
| 61 | 62 | |
| 62 | 63 | public function actionIndex() | 
| 63 | 64 | { | 
| 64 | - //$query = (new Query())->select('*')->from('{{%importer_files}}')->where(['not', ['time_end' => null]])->orderBy(['upload_time' => SORT_DESC]); | |
| 65 | + | |
| 65 | 66 | $query = Importers::find()->where(['active' => true])->orderBy(['price_date_update' => SORT_DESC]); | 
| 66 | 67 | $provider = new ActiveDataProvider([ | 
| 67 | 68 | 'query' => $query, | 
| ... | ... | @@ -79,11 +80,12 @@ class CheckPriceController extends BaseController | 
| 79 | 80 | public function actionView ($id, $date_update) | 
| 80 | 81 | { | 
| 81 | 82 | |
| 82 | - $query = Details::find()->where(['IMPORT_ID' => $id, 'timestamp' => $date_update])->limit(20); | |
| 83 | + $query = DetailsCurrency::find()->where(['IMPORT_ID' => $id, 'timestamp' => $date_update])->limit(20); | |
| 83 | 84 | |
| 84 | - $importer = Importers::findOne($id)->name; | |
| 85 | + $importer = Importers::findOne( $id ); | |
| 85 | 86 | $date = Yii::$app->formatter->asDate( $date_update, 'yyyy-MM-dd' ); | 
| 86 | 87 | |
| 88 | + | |
| 87 | 89 | $provider = new ActiveDataProvider([ | 
| 88 | 90 | 'query' => $query, | 
| 89 | 91 | 'pagination' => false, | ... | ... | 
backend/models/Currency.php
backend/models/Importers.php
| ... | ... | @@ -5,6 +5,7 @@ namespace backend\models; | 
| 5 | 5 | use common\components\CustomVarDamp; | 
| 6 | 6 | use Yii; | 
| 7 | 7 | use backend\components\base\BaseActiveRecord; | 
| 8 | +use backend\models\Currency; | |
| 8 | 9 | |
| 9 | 10 | /** | 
| 10 | 11 | * | 
| ... | ... | @@ -89,6 +90,15 @@ class Importers extends BaseActiveRecord | 
| 89 | 90 | ]; | 
| 90 | 91 | } | 
| 91 | 92 | |
| 93 | + public function getCurrency () | |
| 94 | + { | |
| 95 | + return $this->hasOne(Currency::className(), ['id' => 'currency_id'])->one()->name; | |
| 96 | + } | |
| 97 | + | |
| 98 | + public function getCurrencyRate () | |
| 99 | + { | |
| 100 | + return $this->hasOne(Currency::className(), ['id' => 'currency_id'])->one()->rate; | |
| 101 | + } | |
| 92 | 102 | |
| 93 | 103 | public function getKeys () | 
| 94 | 104 | { | ... | ... | 
backend/views/check-price/view.php
| ... | ... | @@ -8,24 +8,29 @@ use yii\bootstrap\Modal; | 
| 8 | 8 | /* @var $this yii\web\View */ | 
| 9 | 9 | /* @var $searchModel backend\models\CatalogSearch */ | 
| 10 | 10 | /* @var $dataProvider yii\data\ActiveDataProvider */ | 
| 11 | -$this->title = 'Прайс ' . Html::encode( "{$importer} от {$date}" ); | |
| 11 | +$this->title = 'Прайс ' . Html::encode("{$importer->name} от {$date}"); | |
| 12 | 12 | $this->params['breadcrumbs'][] = $this->title; | 
| 13 | 13 | |
| 14 | 14 | ?> | 
| 15 | -<div class="catalog-index"> | |
| 16 | - | |
| 17 | - <h1><?= Html::encode($this->title) ?></h1> | |
| 18 | - | |
| 19 | - <?= GridView::widget( ['dataProvider' => $dataProvider, | |
| 20 | - | |
| 21 | - ] ); | |
| 22 | - | |
| 23 | - | |
| 24 | - ?> | |
| 25 | - | |
| 26 | - | |
| 27 | - | |
| 28 | -</div> | |
| 15 | + <div class="catalog-index"> | |
| 16 | + | |
| 17 | + <h1><?= Html::encode($this->title) ?></h1> | |
| 18 | + | |
| 19 | + <?= GridView::widget( ['dataProvider' => $dataProvider, | |
| 20 | + 'columns' => [ | |
| 21 | + ['attribute' => 'FULL_ARTICLE'], | |
| 22 | + ['attribute' => 'ARTICLE'], | |
| 23 | + ['attribute' => 'BRAND'], | |
| 24 | + ['attribute' => 'DESCR'], | |
| 25 | + ['attribute' => 'BOX'], | |
| 26 | + ['attribute' => 'ADD_BOX'], | |
| 27 | + ['attribute' => 'GROUP'], | |
| 28 | + ['attribute' => 'name'], | |
| 29 | + ['attribute' => 'PRICE'], | |
| 30 | + ] | |
| 31 | + ] ); ?> | |
| 32 | + | |
| 33 | + </div> | |
| 29 | 34 | <?php | 
| 30 | 35 | |
| 31 | 36 | ?> | 
| 32 | 37 | \ No newline at end of file | ... | ... | 
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace common\models; | |
| 4 | + | |
| 5 | +use Yii; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * This is the model class for table "{{%details_currency}}". | |
| 9 | + * | |
| 10 | + * @property string $ID | |
| 11 | + * @property string $IMPORT_ID | |
| 12 | + * @property string $BRAND | |
| 13 | + * @property string $ARTICLE | |
| 14 | + * @property string $FULL_ARTICLE | |
| 15 | + * @property double $PRICE | |
| 16 | + * @property string $DESCR | |
| 17 | + * @property string $BOX | |
| 18 | + * @property string $ADD_BOX | |
| 19 | + * @property string $GROUP | |
| 20 | + * @property string $timestamp | |
| 21 | + * @property string $name | |
| 22 | + * @property double $rate | |
| 23 | + */ | |
| 24 | +class DetailsCurrency extends \backend\components\base\BaseActiveRecord | |
| 25 | +{ | |
| 26 | + /** | |
| 27 | + * @inheritdoc | |
| 28 | + */ | |
| 29 | + public static function tableName() | |
| 30 | + { | |
| 31 | + return '{{%details_currency}}'; | |
| 32 | + } | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * @inheritdoc | |
| 36 | + */ | |
| 37 | + public function rules() | |
| 38 | + { | |
| 39 | + return [ | |
| 40 | + [['ID', 'IMPORT_ID', 'BOX', 'ADD_BOX'], 'integer'], | |
| 41 | + [['IMPORT_ID', 'BRAND', 'ARTICLE', 'FULL_ARTICLE', 'PRICE', 'DESCR', 'BOX', 'name', 'rate'], 'required'], | |
| 42 | + [['PRICE', 'rate'], 'number'], | |
| 43 | + [['timestamp'], 'safe'], | |
| 44 | + [['BRAND', 'ARTICLE'], 'string', 'max' => 100], | |
| 45 | + [['FULL_ARTICLE'], 'string', 'max' => 150], | |
| 46 | + [['DESCR', 'GROUP'], 'string', 'max' => 200], | |
| 47 | + [['name'], 'string', 'max' => 50] | |
| 48 | + ]; | |
| 49 | + } | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * @inheritdoc | |
| 53 | + */ | |
| 54 | + public function attributeLabels() | |
| 55 | + { | |
| 56 | + return [ | |
| 57 | + 'ID' => Yii::t('app', 'ID'), | |
| 58 | + 'IMPORT_ID' => Yii::t('app', 'Import ID'), | |
| 59 | + 'BRAND' => Yii::t('app', 'Бренд'), | |
| 60 | + 'ARTICLE' => Yii::t('app', 'Имя'), | |
| 61 | + 'FULL_ARTICLE' => Yii::t('app', 'Артикул'), | |
| 62 | + 'PRICE' => Yii::t('app', 'Цена'), | |
| 63 | + 'DESCR' => Yii::t('app', 'Описание'), | |
| 64 | + 'BOX' => Yii::t('app', 'Кол-во'), | |
| 65 | + 'ADD_BOX' => Yii::t('app', 'В пути'), | |
| 66 | + 'GROUP' => Yii::t('app', 'Группа RG'), | |
| 67 | + 'timestamp' => Yii::t('app', 'Дата обновления'), | |
| 68 | + 'name' => Yii::t('app', 'Валюта'), | |
| 69 | + 'rate' => Yii::t('app', 'Курс'), | |
| 70 | + ]; | |
| 71 | + } | |
| 72 | +} | ... | ... | 
console/migrations/m151016_130143_add_fk_currency_to_Importers.php
| ... | ... | @@ -7,17 +7,6 @@ class m151016_130143_add_fk_currency_to_Importers extends Migration | 
| 7 | 7 | { | 
| 8 | 8 | public function safeUp() | 
| 9 | 9 | { | 
| 10 | -// // сначала отберем записи которых нет уже в поставщиках | |
| 11 | -// $id_arr = (new \yii\db\Query()) | |
| 12 | -// ->select(['{{%importers_files}}.id']) | |
| 13 | -// ->from('{{%importers_files}}') | |
| 14 | -// ->leftJoin('{{%importers}}', 'importer_id = {{%importers}}.id') | |
| 15 | -// ->where(['name' => null]) | |
| 16 | -// ->all(); | |
| 17 | -// $id_arr = array_column($id_arr,'id'); | |
| 18 | -// // удалим их | |
| 19 | -// $this->delete('{{%importers_files}}',['id' => $id_arr]); | |
| 20 | - | |
| 21 | 10 | $this->addForeignKey('currency_fk', '{{%importers}}', 'currency_id', '{{%currency}}', 'id'); | 
| 22 | 11 | } | 
| 23 | 12 | ... | ... | 
console/migrations/m151016_144435_addViewDetailsCurrency.php
0 → 100644
| 1 | +<?php | |
| 2 | + | |
| 3 | +use yii\db\Schema; | |
| 4 | +use yii\db\Migration; | |
| 5 | + | |
| 6 | +class m151016_144435_addViewDetailsCurrency extends Migration | |
| 7 | +{ | |
| 8 | + public function up() | |
| 9 | + { | |
| 10 | + | |
| 11 | + $view = <<< MySQL | |
| 12 | + create view w_details_currency as | |
| 13 | + select w_details.*, w_currency.name, w_currency.rate from w_details | |
| 14 | + inner join w_importers on w_importers.id = w_details.import_id | |
| 15 | + inner join w_currency on w_currency.id = w_importers.currency_id; | |
| 16 | +MySQL; | |
| 17 | + | |
| 18 | + $this->execute($view); | |
| 19 | + | |
| 20 | + } | |
| 21 | + | |
| 22 | + public function down() | |
| 23 | + { | |
| 24 | + // вернем все как было | |
| 25 | + $drop_view = 'drop view if exists w_details_currency'; | |
| 26 | + | |
| 27 | + $this->execute($drop_view); | |
| 28 | + | |
| 29 | + } | |
| 30 | +} | ... | ... | 
