Commit d57c8c004b7569193dd17271644131a1370a21e1
1 parent
eb33627d
-Blocking in process
Showing
5 changed files
with
103 additions
and
9 deletions
Show diff stats
controllers/OrderController.php
| ... | ... | @@ -11,12 +11,14 @@ |
| 11 | 11 | use yii\web\Controller; |
| 12 | 12 | use yii\filters\VerbFilter; |
| 13 | 13 | use yii\data\ActiveDataProvider; |
| 14 | + use yii\web\ForbiddenHttpException; | |
| 14 | 15 | use yii\web\HttpException; |
| 15 | 16 | use artweb\artbox\ecommerce\models\Order; |
| 16 | 17 | use artweb\artbox\ecommerce\models\OrderProduct; |
| 17 | 18 | use artweb\artbox\ecommerce\models\ProductVariant; |
| 18 | 19 | use yii\web\NotFoundHttpException; |
| 19 | 20 | use developeruz\db_rbac\behaviors\AccessBehavior; |
| 21 | + use yii\web\Response; | |
| 20 | 22 | |
| 21 | 23 | class OrderController extends Controller |
| 22 | 24 | { |
| ... | ... | @@ -102,9 +104,11 @@ |
| 102 | 104 | public function actionView($id) |
| 103 | 105 | { |
| 104 | 106 | $model = $this->findModel($id); |
| 105 | - $dataProvider = new ActiveDataProvider([ | |
| 106 | - 'query' => $model->getProducts(), | |
| 107 | - ]); | |
| 107 | + $dataProvider = new ActiveDataProvider( | |
| 108 | + [ | |
| 109 | + 'query' => $model->getProducts(), | |
| 110 | + ] | |
| 111 | + ); | |
| 108 | 112 | return $this->render( |
| 109 | 113 | 'view', |
| 110 | 114 | [ |
| ... | ... | @@ -286,6 +290,10 @@ |
| 286 | 290 | |
| 287 | 291 | $model = $this->findModel($id); |
| 288 | 292 | |
| 293 | + if ($model->isBlocked() && $model->edit_id !== \Yii::$app->user->id) { | |
| 294 | + throw new ForbiddenHttpException(); | |
| 295 | + } | |
| 296 | + | |
| 289 | 297 | $dataProvider = new ActiveDataProvider( |
| 290 | 298 | [ |
| 291 | 299 | 'query' => $model->getProducts() |
| ... | ... | @@ -293,7 +301,12 @@ |
| 293 | 301 | ] |
| 294 | 302 | ); |
| 295 | 303 | |
| 304 | + if (empty( $model->manager_id )) { | |
| 305 | + $model->manager_id = \Yii::$app->user->id; | |
| 306 | + } | |
| 307 | + | |
| 296 | 308 | if ($model->load(Yii::$app->request->post()) && $model->save()) { |
| 309 | + $this->unblockOrder($model->id); | |
| 297 | 310 | return $this->redirect([ 'index' ]); |
| 298 | 311 | } else { |
| 299 | 312 | return $this->render( |
| ... | ... | @@ -317,12 +330,12 @@ |
| 317 | 330 | ]; |
| 318 | 331 | if (!is_null($q)) { |
| 319 | 332 | $result = ProductVariant::find()// ->select( |
| 320 | - // [ | |
| 321 | - // 'id', | |
| 322 | - // 'sku', | |
| 323 | - // 'product_lang.title AS name' | |
| 324 | - // ] | |
| 325 | - // ) | |
| 333 | + // [ | |
| 334 | + // 'id', | |
| 335 | + // 'sku', | |
| 336 | + // 'product_lang.title AS name' | |
| 337 | + // ] | |
| 338 | + // ) | |
| 326 | 339 | ->joinWith('product.lang') |
| 327 | 340 | ->where( |
| 328 | 341 | [ |
| ... | ... | @@ -368,4 +381,31 @@ |
| 368 | 381 | throw new NotFoundHttpException('The requested page does not exist.'); |
| 369 | 382 | } |
| 370 | 383 | } |
| 384 | + | |
| 385 | + public function actionBlockOrder() | |
| 386 | + { | |
| 387 | + if (!empty( \Yii::$app->request->post() )) { | |
| 388 | + \Yii::$app->response->format = Response::FORMAT_JSON; | |
| 389 | + | |
| 390 | + $model = $this->findModel(\Yii::$app->request->post('id')); | |
| 391 | + | |
| 392 | + $model->edit_time = time(); | |
| 393 | + $model->edit_id = \Yii::$app->user->id; | |
| 394 | + | |
| 395 | + if ($model->save()) { | |
| 396 | + return [ 'success' => true ]; | |
| 397 | + } else { | |
| 398 | + return [ 'success' => false ]; | |
| 399 | + } | |
| 400 | + } | |
| 401 | + } | |
| 402 | + | |
| 403 | + protected function unblockOrder($id) | |
| 404 | + { | |
| 405 | + $model = $this->findModel($id); | |
| 406 | + | |
| 407 | + $model->edit_time = 0; | |
| 408 | + $model->edit_id = 0; | |
| 409 | + $model->save(); | |
| 410 | + } | |
| 371 | 411 | } | ... | ... |
models/Order.php
| ... | ... | @@ -21,6 +21,8 @@ |
| 21 | 21 | * @property string $check |
| 22 | 22 | * @property string $sms |
| 23 | 23 | * @property int $id |
| 24 | + * @property integer $edit_id | |
| 25 | + * @property integer $edit_time | |
| 24 | 26 | * @property integer $manager_id |
| 25 | 27 | * @property int $user_id |
| 26 | 28 | * @property string $name |
| ... | ... | @@ -111,6 +113,8 @@ |
| 111 | 113 | 'reason', |
| 112 | 114 | 'label', |
| 113 | 115 | 'manager_id', |
| 116 | + 'edit_time', | |
| 117 | + 'edit_id', | |
| 114 | 118 | ], |
| 115 | 119 | 'integer', |
| 116 | 120 | ], |
| ... | ... | @@ -287,4 +291,18 @@ |
| 287 | 291 | { |
| 288 | 292 | $this->hasOne(User::className(), [ 'id' => 'manager_id' ]); |
| 289 | 293 | } |
| 294 | + | |
| 295 | + public function isBlocked() | |
| 296 | + { | |
| 297 | + if ($this->edit_id === 0 ) { | |
| 298 | + return false; | |
| 299 | + } else { | |
| 300 | + if ( $this->edit_time + 7200 > time()) { | |
| 301 | + return true; | |
| 302 | + } | |
| 303 | + else { | |
| 304 | + return false; | |
| 305 | + } | |
| 306 | + } | |
| 307 | + } | |
| 290 | 308 | } |
| 291 | 309 | \ No newline at end of file | ... | ... |
models/ProductVideo.php
views/order/_form.php
| ... | ... | @@ -5,6 +5,7 @@ |
| 5 | 5 | use artweb\artbox\ecommerce\models\OrderPayment; |
| 6 | 6 | use artweb\artbox\ecommerce\models\OrderProduct; |
| 7 | 7 | use backend\models\SmsTemplate; |
| 8 | + use common\models\User; | |
| 8 | 9 | use kartik\grid\GridView; |
| 9 | 10 | use kartik\widgets\DatePicker; |
| 10 | 11 | use kartik\widgets\Select2; |
| ... | ... | @@ -181,6 +182,22 @@ JS; |
| 181 | 182 | ), |
| 182 | 183 | [ 'prompt' => \Yii::t('app', 'Выберите доставку ...') ] |
| 183 | 184 | ) ?> |
| 185 | + | |
| 186 | + <?php | |
| 187 | + if (\Yii::$app->user->identity->isAdmin()) { | |
| 188 | + echo $form->field($model, 'manager_id') | |
| 189 | + ->dropDownList( | |
| 190 | + ArrayHelper::map( | |
| 191 | + User::find() | |
| 192 | + ->asArray() | |
| 193 | + ->all(), | |
| 194 | + 'id', | |
| 195 | + 'username' | |
| 196 | + ), | |
| 197 | + [ 'prompt' => \Yii::t('app', 'Менеджер') ] | |
| 198 | + ) ; | |
| 199 | + } | |
| 200 | + ?> | |
| 184 | 201 | |
| 185 | 202 | </div> |
| 186 | 203 | <div class="col-sm-6"> | ... | ... |
views/order/update.php
| ... | ... | @@ -16,6 +16,21 @@ |
| 16 | 16 | 'label' => \Yii::t('app', 'Заказы'), |
| 17 | 17 | ]; |
| 18 | 18 | $this->params[ 'breadcrumbs' ][] = $this->title; |
| 19 | + | |
| 20 | + $js = ' | |
| 21 | +$.ajax({ | |
| 22 | + type: "POST", | |
| 23 | + url: "/admin/ecommerce/order/block-order", | |
| 24 | + data: { | |
| 25 | + id: ' . $model->id . ' | |
| 26 | + }, | |
| 27 | + success: function() { | |
| 28 | + console.log("Ura"); | |
| 29 | + } | |
| 30 | +});'; | |
| 31 | + | |
| 32 | + $this->registerJs($js, View::POS_READY); | |
| 33 | + | |
| 19 | 34 | ?> |
| 20 | 35 | <div class="order-update"> |
| 21 | 36 | <div class="container"><h1><?php echo Html::encode($this->title) ?></h1></div> | ... | ... |