Commit df73f7629e4421d0e34ece5f042e6bc9a2587487

Authored by Mihail
1 parent 4bf0d870

add crocc search in goods view

common/models/GoodsView.php
... ... @@ -78,7 +78,7 @@ class GoodsView extends \backend\components\base\BaseActiveRecord
78 78  
79 79 public static function primaryKey()
80 80 {
81   - return ['name','brand'];
  81 + return ['name','brand', 'importer_id'];
82 82 }
83 83  
84 84  
... ...
common/models/GoodsViewSearch.php
... ... @@ -62,7 +62,7 @@ class GoodsViewSearch extends GoodsView
62 62  
63 63 $dataProvider = new ActiveDataProvider([
64 64 'query' => $query,
65   - 'key' => 'article',
  65 + 'key' => 'name',
66 66 'sort' => [
67 67 'attributes' => [
68 68 'box',
... ... @@ -79,6 +79,26 @@ class GoodsViewSearch extends GoodsView
79 79 {
80 80 $query = GoodsView::find()->innerJoin('w_details_crosses', '`w_details_crosses`.`CROSS_ARTICLE` = `name` and `w_details_crosses`.`CROSS_BRAND` = w_goods_view.`brand`');
81 81  
  82 +
  83 +// ->select([
  84 +// 'name' => 'Name',
  85 +// 'brand' => 'w_details_crosses.CROSS_BRAND',
  86 +// 'box' => 'Box',
  87 +// 'add_box' => 'add_box',
  88 +// 'importer_id' => 'importer_id',
  89 +// 'importer_name' => 'importer_name',
  90 +// 'rate' => 'Rate',
  91 +// 'currency_id' => 'currency_id',
  92 +// 'delivery' => 'Delivery',
  93 +// 'description' => 'Description',
  94 +// 'article' => 'w_details_crosses.CROSS_ARTICLE',
  95 +// 'ID' => 'w_goods_view.ID',
  96 +// 'image' => 'Image',
  97 +// 'tecdoc_id' => 'tecdoc_id',
  98 +// 'price' => 'Price',
  99 +// 'brand_id' => 'brand_id',
  100 +// ]);
  101 +
82 102 // $pagination = [
83 103 // 'pageSize' => 20,
84 104 // ];
... ... @@ -99,7 +119,7 @@ class GoodsViewSearch extends GoodsView
99 119  
100 120 $dataProvider = new ActiveDataProvider([
101 121 'query' => $query,
102   - 'key' => 'article',
  122 + 'key' => 'name',
103 123 'sort' => [
104 124 'attributes' => [
105 125 'box',
... ...
frontend/controllers/GoodsController.php
... ... @@ -17,138 +17,30 @@ use yii\web\Controller;
17 17 class GoodsController extends Controller {
18 18 public $layout = '/internal';
19 19  
20   - public function actionIndex($name, $id)
  20 + public function actionIndex( $name , $id )
21 21 {
22 22  
23   - print('name = '.$name."<br>");
24   - print('id = '. $id);
25   - die();
  23 + $arr_name = explode('_',$name);
  24 + $brand = $arr_name[0];
  25 + $article = $arr_name[1];
26 26  
27 27  
28   - $arr = ['GoodsViewSearch' => ['name' => '0092S40090',
29   - 'brand' => 'BOSCH']];
  28 + $arr = ['GoodsViewSearch' => ['name' => $article,
  29 + 'brand' => $brand]];
30 30  
31 31 Yii::$app->session->setFlash('price_currency_id', 1);
32 32 Yii::$app->session->setFlash('price_margin_id', 1);
33 33  
34 34 $searchModel = new GoodsViewSearch();
35   - $goods_provider = $searchModel->searchCrosses($arr);
36   -
37   -
38   -//$cross_arr = DetailsCrosses::find()->select('ARTICLE, BRAND')->where(['CROSS_ARTICLE' => '0092S40090', 'CROSS_BRAND' => 'BOSCH'])->asArray()->all();
39   -//
40   -// $article_condition = "'" . implode("','", array_column($cross_arr,'ARTICLE')) . "'";
41   -// $brand_condition = "'" . implode("','", array_column($cross_arr,'BRAND')) . "'";
42   -//
43   -// $crosses_provider = new SqlDataProvider([
44   -// 'sql' => $query,
45   -// 'key' => 'article',
46   -// 'pagination' => false,
47   -// 'params' => [':article' => $article_condition,
48   -// ':brand' => $brand_condition],
49   -// 'sort' => [
50   -// 'attributes' => [
51   -// 'box',
52   -// 'delivery',
53   -// 'price'
54   -// ],
55   -// ],
56   -// ]);
  35 + $goods_provider = $searchModel->search($arr);
57 36  
  37 + $crosses_provider = $searchModel->searchCrosses($arr);
58 38  
59 39 return $this->render('index',[
60 40 'goods_data_provider' => $goods_provider,
61   - 'crosses_data_provider' => $goods_provider,
  41 + 'crosses_data_provider' => $crosses_provider,
62 42 ]);
63 43 }
64 44  
65 45  
66   - private function getQuery(){
67   - $query = <<< MySQL
68   - select straight_join `w_details`.`ARTICLE` as `name`,
69   - `w_details`.`BRAND` as `brand`,
70   - `w_details`.`BOX` as `box`,
71   - `w_details`.`ADD_BOX` as `add_box`,
72   - `w_details`.`IMPORT_ID` as `importer_id`,
73   - `w_importers`.`name` as `importer_name`,
74   - `w_importers`.`delivery`,
75   - if (`w_details_description`.`description` = '',
76   - if (`w_details_description`.`tecdoc_description` = '',
77   - `w_details_description`.`supplier_description`,
78   - `w_details_description`.`tecdoc_description`
79   - ),
80   - `w_details_description`.`description`
81   - ) as `description`,
82   -
83   - if (`w_details_description`.`tecdoc_article` = '',
84   - if (`w_details_description`.`article` = '',
85   - if (`w_details`.`FULL_ARTICLE` = '',
86   - `w_details`.`ARTICLE`,
87   - `w_details`.`FULL_ARTICLE`
88   - ),
89   - `w_details_description`.`article`
90   - ),
91   - `w_details_description`.`tecdoc_article`
92   - ) as `article`,
93   - `w_details`.`ID`,
94   - if (`w_details_description`.`image` = '',
95   - if (`w_details_description`.`tecdoc_image` = '',
96   - '',
97   - concat('ital_origin/images/tecdoc/big/',`w_details_description`.`tecdoc_image`)
98   - ),
99   - concat('ital_origin/images/goods/big/',`w_details_description`.`image`)
100   - ) as `image`,
101   - `w_details_description`.`tecdoc_id`,
102   - round(if(`w_margins_groups`.`koef` is not null,
103   - `w_details`.`PRICE`*`w_margins_groups`.`koef`,
104   - if (`w_margins_importers`.`koef` is not null,
105   - `w_details`.`PRICE`*`w_margins_importers`.`koef`,
106   - `w_details`.`PRICE`*`w_margins`.`koef`
107   - )
108   - )*`t`.`rate`/`w_currency`.`rate`,2) as `price`,
109   -
110   - round(if(`input_groups`.`koef` is not null,
111   - `w_details`.`PRICE`*`input_groups`.`koef`,
112   - `w_details`.`PRICE`
113   - )*`t`.`rate`/`w_currency`.`rate`,2) as `input_price`,
114   -
115   - round(if(`input_groups`.`koef` is not null,
116   - `w_details`.`PRICE`*`input_groups`.`koef`,
117   - `w_details`.`PRICE`
118   - )*`t`.`rate`/`default`.`rate`,2) as `input_price_default`,
119   -
120   - round(if(`w_margins_groups`.`koef` is not null,
121   - `w_details`.`PRICE`*`w_margins_groups`.`koef`,
122   - if (`w_margins_importers`.`koef` is not null,
123   - `w_details`.`PRICE`*`w_margins_importers`.`koef`,
124   - `w_details`.`PRICE`*`w_margins`.`koef`
125   - )
126   - )*`t`.`rate`/`default`.`rate`,2) as `price_default`,
127   -
128   - `w_brands`.`ID` as `brand_id`
129   -from `w_details`
130   - inner join `w_brands` on `w_brands`.`BRAND` = `w_details`.`BRAND`
131   - left join `w_details_description` on `w_details_description`.`name` = `w_details`.`ARTICLE` and
132   - `w_details_description`.`brand` = `w_details`.`BRAND`
133   - inner join `w_importers` on `w_importers`.`id` = `w_details`.`IMPORT_ID` and
134   - `w_importers`.`active` = 1
135   - inner join `w_margins` on `w_margins`.`id` = @margin
136   - left join `w_margins_importers` on `w_margins_importers`.`importer_id` = `w_details`.`IMPORT_ID` and
137   - `w_margins_importers`.`margin_id`= @margin
138   - left join `w_margins_groups` on `w_margins_groups`.`importer_id` = `w_details`.`IMPORT_ID` and
139   - `w_margins_groups`.`margin_id` = @margin and
140   - `w_margins_groups`.`group` = `w_details`.`group`
141   - inner join `w_currency` on `w_currency`.`id` = @currency
142   - inner join `w_currency` as `t` on `t`.`id` = `w_importers`.`currency_id`
143   - inner join `w_currency` as `default` on `default`.`is_default` = 1
144   - left join `w_margins_groups` as `input_groups` on `input_groups`.`importer_id` = `w_details`.`IMPORT_ID` and
145   - `input_groups`.`margin_id` = 8 and
146   - `input_groups`.`group` = `w_details`.`group`
147   -where `w_details`.`ARTICLE` In(:article) and `w_details`.`BRAND` In(:brand) and (`w_details`.`BOX` > 0 or `w_details`.`ADD_BOX` > 0)
148   -MySQL;
149   -
150   - return $query;
151   -}
152   -
153   -
154 46 }
155 47 \ No newline at end of file
... ...