Blame view

common/models/GoodsView.php 2.72 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
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
  <?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
   * @property double $price
   * @property string $brand_id
  
   */
  class GoodsView extends \backend\components\base\BaseActiveRecord
  {
      /**
       * @inheritdoc
       */
      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]
          ];
      }
  
      /**
       * @return string
       */
      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
  
          return round($this->price * ($this->rate/$rate) * $koef, 2);
      }
  
  
      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',
          ];
      }
  }