Blame view

models/Order.php 5.49 KB
8a7e6ecf   Yarik   Namespaces
1
2
3
4
5
  <?php
      namespace artweb\artbox\ecommerce\models;
      
      use artweb\artbox\models\Customer;
      use Yii;
2b29877e   Alexey Boroda   -Added time colum...
6
      use yii\behaviors\TimestampBehavior;
8a7e6ecf   Yarik   Namespaces
7
      use yii\db\ActiveRecord;
8a7e6ecf   Yarik   Namespaces
8
9
10
11
12
13
      
      /**
       * Class Order
       *
       * @todo    Write docs and refactor
       * @package artweb\artbox\ecommerce\models
2b29877e   Alexey Boroda   -Added time colum...
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
       * @property integer $created_at
       * @property integer $updated_at
       * @property integer $deleted_at
       * @property int     $id
       * @property int     $user_id
       * @property string  $name
       * @property string  $phone
       * @property string  $phone2
       * @property string  $email
       * @property string  $adress
       * @property string  $body
       * @property double  $total
       * @property string  $date_time
       * @property string  $date_dedline
       * @property string  $reserve
       * @property string  $status
       * @property string  $comment
       * @property int     $label
       * @property int     $pay
       * @property int     $numbercard
       * @property int     $delivery
       * @property string  $declaration
       * @property string  $stock
       * @property string  $consignment
       * @property string  $payment
       * @property string  $insurance
       * @property double  $amount_imposed
       * @property string  $shipping_by
       * @property string  $city
8a7e6ecf   Yarik   Namespaces
43
44
45
       */
      class Order extends ActiveRecord
      {
bb962a6d   Alexey Boroda   -Order in process
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
          const PAYMENT_LIST = [
              1 => [
                  'label' => 'Оплатить наличными',
              ],
              2 => [
                  'label' => 'Оплатить на карту Приват Банка',
                  'hint'  => 'оплата поступает 30 минут до суток!',
              ],
              3 => [
                  'label' => 'Оплатить "Правекс-телеграф"',
                  'hint'  => 'оплата денежным переводом поступает от 30 мин. до 4 часов',
              ],
              4 => [
                  'label' => 'Оплатить по безналичному расчету',
                  'hint'  => 'оплата поступает на счет от 1 до 3 рабочих дней! Счет на оплату отправим сразу после обработки заказана на ваш e-mail',
              ],
          ];
          
          const SHIPPING_BY = [
              1 => [
                  'label' => 'Отправитель',
              ],
              2 => [
                  'label' => 'Получатель',
              ],
          ];
8a7e6ecf   Yarik   Namespaces
72
73
74
75
76
77
          
          public static function tableName()
          {
              return 'order';
          }
          
2b29877e   Alexey Boroda   -Added time colum...
78
79
80
81
82
83
84
85
86
          public function behaviors()
          {
              return [
                  [
                      'class' => TimestampBehavior::className(),
                  ],
              ];
          }
          
8a7e6ecf   Yarik   Namespaces
87
88
89
90
          public function rules()
          {
              return [
                  [
bb962a6d   Alexey Boroda   -Order in process
91
92
93
94
                      ['pay'],
                      'boolean',
                  ],
                  [
8a7e6ecf   Yarik   Namespaces
95
                      [
2b29877e   Alexey Boroda   -Added time colum...
96
97
98
99
100
101
102
103
                          'created_at',
                          'updated_at',
                          'deleted_at',
                      ],
                      'integer',
                  ],
                  [
                      [
8a7e6ecf   Yarik   Namespaces
104
105
106
107
108
109
                          'phone',
                      ],
                      'required',
                  ],
                  [
                      [ 'comment' ],
bb962a6d   Alexey Boroda   -Order in process
110
                      'string',
8a7e6ecf   Yarik   Namespaces
111
112
113
114
115
116
                  ],
                  [
                      [ 'email' ],
                      'email',
                  ],
                  [
bb962a6d   Alexey Boroda   -Order in process
117
118
119
120
                      [
                          'phone',
                          'phone2',
                      ],
8a7e6ecf   Yarik   Namespaces
121
122
                      'match',
                      'pattern' => '/^\+38\(\d{3}\)\d{3}-\d{2}-\d{2}$/',
8a7e6ecf   Yarik   Namespaces
123
124
125
126
                  ],
                  [
                      [
                          'name',
8a7e6ecf   Yarik   Namespaces
127
128
129
130
131
                          'numbercard',
                          'body',
                          'declaration',
                          'stock',
                          'consignment',
8a7e6ecf   Yarik   Namespaces
132
133
134
135
136
137
138
139
140
141
142
                          'insurance',
                          'amount_imposed',
                          'shipping_by',
                          'city',
                          'adress',
                          'total',
                          'status',
                      ],
                      'string',
                      'max' => 255,
                  ],
7520dc0e   Alexey Boroda   -Grid with input ...
143
144
145
146
147
148
149
150
151
152
                  [
                      [ 'payment' ],
                      'in',
                      'range' => [
                          1,
                          2,
                          3,
                          4,
                      ],
                  ],
8a7e6ecf   Yarik   Namespaces
153
154
155
156
157
158
              ];
          }
          
          public function attributeLabels()
          {
              return [
2b29877e   Alexey Boroda   -Added time colum...
159
160
161
162
163
164
165
                  'name'       => Yii::t('app', 'order_name'),
                  'phone'      => Yii::t('app', 'order_phone'),
                  'email'      => Yii::t('app', 'order_email'),
                  'comment'    => Yii::t('app', 'order_comment'),
                  'created_at' => Yii::t('app', 'Дата добавления'),
                  'updated_at' => Yii::t('app', 'Дата обновления'),
                  'deleted_at' => Yii::t('app', 'Дата удаления'),
8a7e6ecf   Yarik   Namespaces
166
167
168
              ];
          }
          
8a7e6ecf   Yarik   Namespaces
169
170
171
172
173
174
175
176
177
178
          public function getUser()
          {
              return $this->hasOne(Customer::className(), [ 'id' => 'user_id' ]);
          }
          
          public function getProducts()
          {
              return $this->hasMany(OrderProduct::className(), [ 'order_id' => 'id' ]);
          }
      }