Commit a4e099fb7454fb69d6885e8992e5ebd3fe44f487
1 parent
040df559
16.05.16 ann fotorama gallery
Showing
5 changed files
with
138 additions
and
17 deletions
Show diff stats
common/models/Customers.php
@@ -21,6 +21,8 @@ use yii\behaviors\TimestampBehavior; | @@ -21,6 +21,8 @@ use yii\behaviors\TimestampBehavior; | ||
21 | */ | 21 | */ |
22 | class Customers extends User | 22 | class Customers extends User |
23 | { | 23 | { |
24 | + | ||
25 | + const SCENARIO_ORDER = 'order'; | ||
24 | /** | 26 | /** |
25 | * @inheritdoc | 27 | * @inheritdoc |
26 | */ | 28 | */ |
@@ -42,6 +44,16 @@ class Customers extends User | @@ -42,6 +44,16 @@ class Customers extends User | ||
42 | // [['email'], 'unique'], | 44 | // [['email'], 'unique'], |
43 | // [['password_reset_token'], 'unique'], | 45 | // [['password_reset_token'], 'unique'], |
44 | // [['phone'], 'unique'], | 46 | // [['phone'], 'unique'], |
47 | + [ | ||
48 | + ['username', 'auth_key', 'password_hash', 'email', 'phone'], | ||
49 | + 'required', | ||
50 | + 'on'=>[Customers::SCENARIO_DEFAULT] | ||
51 | + ], | ||
52 | + [ | ||
53 | + ['username', 'auth_key', 'password_hash', 'email', 'phone'], | ||
54 | + 'safe', | ||
55 | + 'on'=>[Customers::SCENARIO_ORDER] | ||
56 | + ], | ||
45 | ]; | 57 | ]; |
46 | } | 58 | } |
47 | 59 |
common/models/Orders.php
@@ -96,6 +96,28 @@ class Orders extends \yii\db\ActiveRecord | @@ -96,6 +96,28 @@ class Orders extends \yii\db\ActiveRecord | ||
96 | ]; | 96 | ]; |
97 | } | 97 | } |
98 | 98 | ||
99 | + | ||
100 | + public function afterSave($insert, $changedAttributes) | ||
101 | + { | ||
102 | + parent::afterSave($insert, $changedAttributes); | ||
103 | + if($this->isNewRecord){ | ||
104 | + $customer = Customers::find()->where(['phone'=> $this->phone])->one(); | ||
105 | + if($customer instanceof Customers){ | ||
106 | + $this->customer_id = $customer->id; | ||
107 | + $this->save(); | ||
108 | + } else { | ||
109 | + $customer = new Customers(['scenario' => Customers::SCENARIO_ORDER]); | ||
110 | + $customer->email = $this->email; | ||
111 | + $customer->phone = $this->phone; | ||
112 | + $customer->username = $this->name; | ||
113 | + $this->customer_id = $customer->id; | ||
114 | + $this->save(); | ||
115 | + } | ||
116 | + } | ||
117 | + | ||
118 | + | ||
119 | + } | ||
120 | + | ||
99 | /** | 121 | /** |
100 | * @return \yii\db\ActiveQuery | 122 | * @return \yii\db\ActiveQuery |
101 | */ | 123 | */ |
1 | +<?php | ||
2 | + | ||
3 | +namespace common\models; | ||
4 | + | ||
5 | +use Yii; | ||
6 | + | ||
7 | +/** | ||
8 | + * This is the model class for table "remote_orders". | ||
9 | + * | ||
10 | + * @property string $ID_Client | ||
11 | + * @property string $Price_old | ||
12 | + * @property string $ID_Product | ||
13 | + * @property string $Quantity | ||
14 | + * @property string $Rate | ||
15 | + * @property string $Sum | ||
16 | + * @property integer $Payment_type | ||
17 | + * @property string $ID | ||
18 | + * @property string $Date | ||
19 | + */ | ||
20 | +class RemoteOrders extends \yii\db\ActiveRecord | ||
21 | +{ | ||
22 | + /** | ||
23 | + * @inheritdoc | ||
24 | + */ | ||
25 | + public static function tableName() | ||
26 | + { | ||
27 | + return 'remote_orders'; | ||
28 | + } | ||
29 | + | ||
30 | + /** | ||
31 | + * @inheritdoc | ||
32 | + */ | ||
33 | + public function rules() | ||
34 | + { | ||
35 | + return [ | ||
36 | + [['Price_old', 'Quantity', 'Rate', 'Sum'], 'number'], | ||
37 | + [['Payment_type'], 'integer'], | ||
38 | + [['Date'], 'safe'], | ||
39 | + [['ID_Client', 'ID_Product', 'ID'], 'string', 'max' => 20], | ||
40 | + ]; | ||
41 | + } | ||
42 | + | ||
43 | + /** | ||
44 | + * @inheritdoc | ||
45 | + */ | ||
46 | + public function attributeLabels() | ||
47 | + { | ||
48 | + return [ | ||
49 | + 'ID_Client' => 'Id Client', | ||
50 | + 'Price_old' => 'Price Old', | ||
51 | + 'ID_Product' => 'Id Product', | ||
52 | + 'Quantity' => 'Quantity', | ||
53 | + 'Rate' => 'Rate', | ||
54 | + 'Sum' => 'Sum', | ||
55 | + 'Payment_type' => 'Payment Type', | ||
56 | + 'ID' => 'ID', | ||
57 | + 'Date' => 'Date', | ||
58 | + ]; | ||
59 | + } | ||
60 | +} |
common/widgets/BasketHead.php
@@ -26,25 +26,12 @@ class BasketHead extends Widget | @@ -26,25 +26,12 @@ class BasketHead extends Widget | ||
26 | $sessionData = \Yii::$app->session->get('order'); | 26 | $sessionData = \Yii::$app->session->get('order'); |
27 | unset($sessionData['order_id']); | 27 | unset($sessionData['order_id']); |
28 | $count = count($sessionData); | 28 | $count = count($sessionData); |
29 | - $price = 0; | ||
30 | - if(is_array($sessionData) && !empty($sessionData)){ | ||
31 | 29 | ||
32 | - $variant = ProductVariant::find()->where(['product_variant_id'=>array_keys($sessionData)])->indexBy('product_variant_id')->all(); | 30 | + return $this->render('basket_head',[ |
31 | + 'count' => $count | ||
32 | + ]); | ||
33 | 33 | ||
34 | 34 | ||
35 | - foreach ($sessionData as $k => $item) { | ||
36 | - $sessionData[$k]['item'] = $variant[$k]; | ||
37 | - $price += $variant[$k]->price * $sessionData[$k]['num']; | ||
38 | - } | ||
39 | - | ||
40 | - | ||
41 | - return $this->render('basket_head',[ | ||
42 | - 'items'=>$sessionData, | ||
43 | - 'count' => $count, | ||
44 | - 'price' => $price | ||
45 | - ]); | ||
46 | - | ||
47 | - } | ||
48 | 35 | ||
49 | } | 36 | } |
50 | } | 37 | } |
51 | \ No newline at end of file | 38 | \ No newline at end of file |
frontend/controllers/OrdersController.php
@@ -5,6 +5,7 @@ namespace frontend\controllers; | @@ -5,6 +5,7 @@ namespace frontend\controllers; | ||
5 | use common\models\Customers; | 5 | use common\models\Customers; |
6 | use common\models\OrderItems; | 6 | use common\models\OrderItems; |
7 | use common\models\Orders; | 7 | use common\models\Orders; |
8 | +use common\models\RemoteOrders; | ||
8 | use common\modules\product\models\ProductVariant; | 9 | use common\modules\product\models\ProductVariant; |
9 | use common\widgets\BasketModal; | 10 | use common\widgets\BasketModal; |
10 | use Yii; | 11 | use Yii; |
@@ -77,7 +78,7 @@ class OrdersController extends Controller | @@ -77,7 +78,7 @@ class OrdersController extends Controller | ||
77 | if(!empty($order_id)){ | 78 | if(!empty($order_id)){ |
78 | $order_model = Orders::findOne($order_id); | 79 | $order_model = Orders::findOne($order_id); |
79 | } else{ | 80 | } else{ |
80 | - $order_model = new Orders; | 81 | + $this->redirect(['orders/first']); |
81 | } | 82 | } |
82 | 83 | ||
83 | unset($sessionData['order_id']); | 84 | unset($sessionData['order_id']); |
@@ -89,6 +90,45 @@ class OrdersController extends Controller | @@ -89,6 +90,45 @@ class OrdersController extends Controller | ||
89 | 90 | ||
90 | foreach ($sessionData as $k => $item) { | 91 | foreach ($sessionData as $k => $item) { |
91 | $itemModel = OrderItems::find()->where(['order_id'=>$order_id, 'item_id'=> $variant[$k]->product_variant_id])->one(); | 92 | $itemModel = OrderItems::find()->where(['order_id'=>$order_id, 'item_id'=> $variant[$k]->product_variant_id])->one(); |
93 | + | ||
94 | + $remoteItemModel = RemoteOrders::find()->where(['ID'=>$order_id, 'ID_Product'=> $variant[$k]->product_variant_id])->one(); | ||
95 | + | ||
96 | + | ||
97 | + $payment = [ | ||
98 | + '1' => 'Оплата наличными', | ||
99 | + '2' => 'Оплата по безналичному расчету. Код ЕГРПОУ', | ||
100 | + '3' => 'Приват 24', | ||
101 | + '4' => 'Согласовать с менеджером', | ||
102 | + ]; | ||
103 | + | ||
104 | + | ||
105 | + | ||
106 | + | ||
107 | + if($remoteItemModel instanceof RemoteOrders){ | ||
108 | + $itemModel->ID = $order_id; | ||
109 | + $itemModel->ID_Client = $order_model->customer_id; | ||
110 | + $itemModel->ID_Product = $variant[$k]->product_variant_id; | ||
111 | + $itemModel->Quantity = $sessionData[$k]['num']; | ||
112 | + $itemModel->Price_old = $variant[$k]->price; | ||
113 | + $itemModel->Date = date("Y-m-d H:i:s"); | ||
114 | +// $itemModel->Rate = ''; | ||
115 | + $itemModel->Sum = $variant[$k]->price * $sessionData[$k]['num']; | ||
116 | + $itemModel->Payment_type = $payment[$order_model->payment]; | ||
117 | + $itemModel->save(); | ||
118 | + } else { | ||
119 | + $itemModel = new RemoteOrders(); | ||
120 | + $itemModel->ID = $order_id; | ||
121 | + $itemModel->ID_Client = $order_model->customer_id; | ||
122 | + $itemModel->ID_Product = $variant[$k]->product_variant_id; | ||
123 | + $itemModel->Quantity = $sessionData[$k]['num']; | ||
124 | + $itemModel->Price_old = $variant[$k]->price; | ||
125 | + $itemModel->Date = date("Y-m-d H:i:s"); | ||
126 | +// $itemModel->Rate = ''; | ||
127 | + $itemModel->Sum = $variant[$k]->price * $sessionData[$k]['num']; | ||
128 | + $itemModel->Payment_type = $payment[$order_model->payment]; | ||
129 | + $itemModel->save(); | ||
130 | + } | ||
131 | + | ||
92 | if($itemModel instanceof OrderItems){ | 132 | if($itemModel instanceof OrderItems){ |
93 | $itemModel->order_id = $order_id; | 133 | $itemModel->order_id = $order_id; |
94 | $itemModel->item_id = $variant[$k]->product_variant_id; | 134 | $itemModel->item_id = $variant[$k]->product_variant_id; |