Blame view

console/migrations/m151030_123511_addCartBillsView.php 1.18 KB
f68e7edd   Mihail   add bills models,...
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
  <?php
  
  use yii\db\Migration;
  
  
  class m151030_123511_addCartBillsView extends Migration
  {
      public function up()
      {
  
          $view = <<< MySQL
          create view w_cart_bills_view as
         select 	`w_cart_bills`.`id` as `id`,
  				`w_cart_bills`.`account_id`,
  				`w__user`.`name` as `manager_name`,
  				unix_timestamp(`w_cart_bills`.`timestamp`) as `dt`,
  				`w_cart_bills`.`f1` as `name`,
  				`w_cart_bills`.`f2` as `phone`,
  				`w_cart_bills`.`f3` as `email`,
  				`w_cart_bills`.`delivery`,
  				`w_cart_bills`.`status` as `status_id`,
  				`w_dic_statuses`.`name` as `status`,
  				`w_cart_bills`.`message`,`w_cart_bills`.`safe_bill`,
                  SumBill(`w_cart_bills`.`id`) as `sum`,
  				`w_accounts`.`scode`
  			from `w_cart_bills`
  			left join `w_accounts` on `w_accounts`.`id` = `w_cart_bills`.`account_id`
  			left join `w__user` on `w__user`.`id` = `w_cart_bills`.`manager_id`
  			inner join `w_dic_statuses` on `w_dic_statuses`.`id` = `w_cart_bills`.`status`;
  MySQL;
  
          $this->execute($view);
  
      }
  
      public function down()
      {
          // вернем все как было
          $drop_view = 'drop view if exists w_cart_bills_view';
  
          $this->execute($drop_view);
  
      }
  }