Blame view

common/models/GoodsView.php 4.67 KB
1412c23a   Mihail   add crocc search ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
  <?php
  
  namespace common\models;
  
  use Yii;
  
  /**
   * This is the model class for table "{{%goods_view}}".
   *
   * @property string $name
   * @property string $brand
   * @property string $box
   * @property string $add_box
   * @property string $importer_id
   * @property string $importer_name
   * @property double $rate
   * @property string $currency_id
   * @property string $delivery
   * @property string $description
   * @property string $article
   * @property string $ID
   * @property string $image
   * @property string $tecdoc_id
b13c67c3   Mihail   output price in g...
24
   * @property double $price - цена в гривнях
1412c23a   Mihail   add crocc search ...
25
26
27
28
29
30
31
   * @property string $brand_id
  
   */
  class GoodsView extends \backend\components\base\BaseActiveRecord
  {
      /**
       * @inheritdoc
b13c67c3   Mihail   output price in g...
32
       * служебный аттрибут для определения отдельного вывода кроссов и оригинальных деталей
1412c23a   Mihail   add crocc search ...
33
       */
b13c67c3   Mihail   output price in g...
34
      public $crosses;
a58f01f1   Mihail   add crocc search ...
35
  
1412c23a   Mihail   add crocc search ...
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
      public static function tableName()
      {
          return '{{%goods_view}}';
      }
  
      /**
       * @inheritdoc
       */
      public function rules()
      {
          return [
              [['name', 'brand', 'box', 'importer_id', 'importer_name', 'rate', 'delivery', 'price'], 'required'],
              [['box', 'add_box', 'importer_id', 'currency_id', 'ID', 'tecdoc_id', 'brand_id'], 'integer'],
              [['rate', 'price'], 'number'],
              [['name', 'brand'], 'string', 'max' => 100],
              [['importer_name', 'delivery'], 'string', 'max' => 254],
              [['description'], 'string', 'max' => 255],
              [['article'], 'string', 'max' => 150],
              [['image'], 'string', 'max' => 229]
          ];
      }
  
      /**
b13c67c3   Mihail   output price in g...
59
       * @return float - price in custom margin_id and currency
1412c23a   Mihail   add crocc search ...
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
       */
      public function getOutputPrice()
      {
          $price_margin_id = Yii::$app->session->getFlash('price_margin_id',1);
          $price_currency_id = Yii::$app->session->getFlash('price_currency_id',1);
  
          $koef =  Margins::getDb()->cache( function ($db) use ($price_margin_id) {
              return (float) Margins::findOne($price_margin_id)->koef;
          });
  
          $rate = Currency::getDb()->cache( function ($db) use ($price_currency_id) {
              return (float) Currency::findOne($price_currency_id)->rate;
          });
  
          if(!$rate)
              $rate = 1; // если 0, то 1
  
b13c67c3   Mihail   output price in g...
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
          return round(( $this->price / $rate) * $koef, 2);
      }
      /**
       * @return float - price in custom margin_id and in USD
       */
      public function getOutputPriceUSD()
      {
          $price_margin_id = Yii::$app->session->getFlash('price_margin_id',1);
  
          $koef =  Margins::getDb()->cache( function ($db) use ($price_margin_id) {
              return (float) Margins::findOne($price_margin_id)->koef;
          });
  
          $rate = Currency::getDb()->cache( function ($db) {
              return (float) Currency::findOne(2)->rate;
          });
  
          if(!$rate)
              $rate = 1; // если 0, то 1
  
          return round( ($this->price / $rate) * $koef, 2);
      }
  
      /**
       * @return float - price in custom margin_id in EUR
       */
      public function getOutputPriceEUR()
      {
          $price_margin_id = Yii::$app->session->getFlash('price_margin_id',1);
  
          $koef =  Margins::getDb()->cache( function ($db) use ($price_margin_id) {
              return (float) Margins::findOne($price_margin_id)->koef;
          });
  
          $rate = Currency::getDb()->cache( function ($db) {
              return (float) Currency::findOne(3)->rate;
          });
  
          if(!$rate)
              $rate = 1; // если 0, то 1
  
          return round( ($this->price/$rate) * $koef, 2);
      }
      /**
       * @return float - price in custom margin_id and in UAH
       */
      public function getOutputPriceUAH()
      {
          $price_margin_id = Yii::$app->session->getFlash('price_margin_id',1);
  
          $koef =  Margins::getDb()->cache( function ($db) use ($price_margin_id) {
              return (float) Margins::findOne($price_margin_id)->koef;
          });
  
          return round($this->price * $koef, 2);
1412c23a   Mihail   add crocc search ...
132
133
      }
  
d25c7763   Mihail   add crocc search ...
134
135
      public static function primaryKey()
      {
df73f762   Mihail   add crocc search ...
136
          return ['name','brand', 'importer_id'];
d25c7763   Mihail   add crocc search ...
137
      }
a58f01f1   Mihail   add crocc search ...
138
139
  
  
1412c23a   Mihail   add crocc search ...
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
      public function attributeLabels()
      {
          return [
              'name' => 'Name',
              'brand' => 'Brand',
              'box' => 'Box',
              'add_box' => 'Add Box',
              'importer_id' => 'Importer ID',
              'importer_name' => 'Importer Name',
              'rate' => 'Rate',
              'currency_id' => 'Currency ID',
              'delivery' => 'Delivery',
              'description' => 'Description',
              'article' => 'Article',
              'ID' => 'ID',
              'image' => 'Image',
              'tecdoc_id' => 'Tecdoc ID',
              'price' => 'Price',
              'brand_id' => 'Brand ID',
          ];
      }
  }