Blame view

app/models/Order.php 2.66 KB
bf807468   Alex Savenko   first commit
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
  <?php

  namespace app\models;

  

  use Yii;

  

  class Order extends \yii\db\ActiveRecord

  {

      

      public static function tableName()

      {

          return 'orders';

      }    

      

      public function rules()

      {

          return [

              [['name', 'phone'], 'required','whenClient' => true],

              //['email', 'email'],

              [['body','patronymic','surname'], 'safe'],

              

              [

                  [

                      'total',

                  ],

                  'number',

                  'min' => 100,

              ],

              

              [['email'],'email'],

          ];

      }

      

      public function attributeLabels()

      {

          return [

              'name' => 'Имя',

              'phone'=>'Телефон',

              'body'=>'Сообщение',

              'adress'=>'Адрес',

              'patronymic'=>'Отчество',

              'surname'=>'Фамилия',

              'email'=>'E-mail',

              'total' => 'Общая сумма',

          ];

      }

      

  	public function beforeSave($insert) {

              $this->date_time = new \yii\db\Expression('NOW()');

              return parent::beforeSave($insert);

  	}

          

          public function beforeDelete() {

              return parent::beforeDelete();

          }    

      

      public function contact($email,$body)

      {

          if ($this->validate()) {

                          $body .= 'Вся сумма: '.$this->total;

                          $body .= "\n\r";            

                          $body .= 'Имя: '.$this->name;

                          $body .= "\n\r";

                          $body .= 'Фамилия: '.$this->surname;

                          $body .= "\n\r";

                          $body .= 'Отчество: '.$this->patronymic;

                          $body .= "\n\r";

                          $body .= 'E-mail: '.$this->email;

                          $body .= "\n\r";                        

                          $body .= 'Телефон: '.$this->phone;

                          $body .= "\n\r";

                          $body .= 'Адрес: '.$this->adress;

                          $body .= "\n\r";

                          $body .= 'Сообщение: '.$this->body;

                          $body .= "\n\r"; 

                          

              Yii::$app->mailer->compose()

                  ->setTo($email)

                  ->setFrom(['send@artweb.ua' => 'send'])

                  ->setSubject('Заказ на сайте Бубочка')

                  ->setTextBody($body)

                  ->send();

              return true;

          } else {

              return false;

          }

      }    

      

  }