Blame view

frontend/controllers/GoodsController.php 5.88 KB
62dba7d8   Mihail   add goods control...
1
2
3
4
5
6
7
8
9
10
  <?php
  /**
   * Created by PhpStorm.
   * User: vitaliy
   * Date: 08.11.15
   * Time: 22:06
   */
  
  namespace frontend\controllers;
  
f0a8acb5   Mihail   add sort function...
11
  use common\components\CustomVarDamp;
62dba7d8   Mihail   add goods control...
12
  use Yii;
f0a8acb5   Mihail   add sort function...
13
  use yii\data\SqlDataProvider;
62dba7d8   Mihail   add goods control...
14
15
16
17
18
  use yii\web\Controller;
  
  class GoodsController extends Controller {
      public $layout = '/internal';
  
f0a8acb5   Mihail   add sort function...
19
      public function actionIndex($name = '')
62dba7d8   Mihail   add goods control...
20
21
      {
  
f0a8acb5   Mihail   add sort function...
22
23
24
25
26
       $query = $this->getQuery();
  
          $provider = new SqlDataProvider([
              'sql' => $query,
              'pagination' => false,
b1a1ffd5   Mihail   add params to goo...
27
28
29
30
              'params' => [':article' => '0092S40090',
                  ':brand' => 'BOSCH',
                  ':margin_id' => '1',
                  ':currency_id' => '1'],
f0a8acb5   Mihail   add sort function...
31
32
33
34
35
36
37
38
39
40
41
42
43
              'sort' => [
                  'attributes' => [
                      'box',
                      'delivery',
                      'price'
                  ],
              ],
          ]);
  
  
          return $this->render('index',[
              'dataProvider' => $provider
          ]);
62dba7d8   Mihail   add goods control...
44
45
46
      }
  
  
f0a8acb5   Mihail   add sort function...
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
      private function getQuery(){
          $query = <<< MySQL
              select straight_join `w_details`.`ARTICLE` as `name`,
                       `w_details`.`BRAND` as `brand`,
                       `w_details`.`BOX` as `box`,
                       `w_details`.`ADD_BOX` as `add_box`,
                       `w_details`.`IMPORT_ID` as `importer_id`,
                       `w_importers`.`name` as `importer_name`,
    `w_importers`.`delivery`,
                       if (`w_details_description`.`description` = '',
                           if (`w_details_description`.`tecdoc_description` = '',
                               `w_details_description`.`supplier_description`,
                               `w_details_description`.`tecdoc_description`
                           ),
                           `w_details_description`.`description`
                       ) as `description`,
  
                       if (`w_details_description`.`tecdoc_article` = '',
                           if (`w_details_description`.`article` = '',
                               if (`w_details`.`FULL_ARTICLE` = '',
                                   `w_details`.`ARTICLE`,
                                   `w_details`.`FULL_ARTICLE`
                               ),
                               `w_details_description`.`article`
                           ),
                           `w_details_description`.`tecdoc_article`
                       ) as `article`,
    `w_details`.`ID`,
                       if (`w_details_description`.`image` = '',
                           if (`w_details_description`.`tecdoc_image` = '',
                               '',
                               concat('ital_origin/images/tecdoc/big/',`w_details_description`.`tecdoc_image`)
                           ),
                           concat('ital_origin/images/goods/big/',`w_details_description`.`image`)
                       ) as `image`,
    `w_details_description`.`tecdoc_id`,
                       round(if(`w_margins_groups`.`koef` is not null,
                                `w_details`.`PRICE`*`w_margins_groups`.`koef`,
                                if (`w_margins_importers`.`koef` is not null,
                                    `w_details`.`PRICE`*`w_margins_importers`.`koef`,
                                    `w_details`.`PRICE`*`w_margins`.`koef`
                                )
                             )*`t`.`rate`/`w_currency`.`rate`,2) as `price`,
  
                       round(if(`input_groups`.`koef` is not null,
                                `w_details`.`PRICE`*`input_groups`.`koef`,
                                `w_details`.`PRICE`
                             )*`t`.`rate`/`w_currency`.`rate`,2) as `input_price`,
  
                       round(if(`input_groups`.`koef` is not null,
                                `w_details`.`PRICE`*`input_groups`.`koef`,
                                `w_details`.`PRICE`
                             )*`t`.`rate`/`default`.`rate`,2) as `input_price_default`,
  
                       round(if(`w_margins_groups`.`koef` is not null,
                                `w_details`.`PRICE`*`w_margins_groups`.`koef`,
                                if (`w_margins_importers`.`koef` is not null,
                                    `w_details`.`PRICE`*`w_margins_importers`.`koef`,
                                    `w_details`.`PRICE`*`w_margins`.`koef`
                                )
                             )*`t`.`rate`/`default`.`rate`,2) as `price_default`,
  
                       `w_brands`.`ID` as `brand_id`
  from `w_details`
    inner join `w_brands` on `w_brands`.`BRAND` = `w_details`.`BRAND`
    left join `w_details_description` on `w_details_description`.`name` = `w_details`.`ARTICLE` and
                                         `w_details_description`.`brand` = `w_details`.`BRAND`
    inner join `w_importers` on 	`w_importers`.`id` = `w_details`.`IMPORT_ID` and
                                 `w_importers`.`active` = 1
b1a1ffd5   Mihail   add params to goo...
116
    inner join `w_margins` on `w_margins`.`id` =:margin_id
f0a8acb5   Mihail   add sort function...
117
    left join `w_margins_importers` on `w_margins_importers`.`importer_id` = `w_details`.`IMPORT_ID` and
b1a1ffd5   Mihail   add params to goo...
118
                                       `w_margins_importers`.`margin_id`=:margin_id
f0a8acb5   Mihail   add sort function...
119
    left join `w_margins_groups` on `w_margins_groups`.`importer_id` = `w_details`.`IMPORT_ID` and
b1a1ffd5   Mihail   add params to goo...
120
                                    `w_margins_groups`.`margin_id`  =:margin_id and
f0a8acb5   Mihail   add sort function...
121
                                    `w_margins_groups`.`group` = `w_details`.`group`
b1a1ffd5   Mihail   add params to goo...
122
    inner join `w_currency` on `w_currency`.`id` =:currency_id
f0a8acb5   Mihail   add sort function...
123
124
125
126
127
    inner join `w_currency` as `t` on `t`.`id` = `w_importers`.`currency_id`
    inner join `w_currency` as `default` on `default`.`is_default` = 1
    left join `w_margins_groups` as `input_groups` on `input_groups`.`importer_id` = `w_details`.`IMPORT_ID` and
                                                      `input_groups`.`margin_id` = 8 and
                                                      `input_groups`.`group` = `w_details`.`group`
b1a1ffd5   Mihail   add params to goo...
128
  where `w_details`.`ARTICLE` =:article and `w_details`.`BRAND` =:brand and (`w_details`.`BOX` > 0 or `w_details`.`ADD_BOX`)
f0a8acb5   Mihail   add sort function...
129
130
131
132
  MySQL;
  
          return $query;
  }
62dba7d8   Mihail   add goods control...
133
134
135
  
  
  }