Beispiel #1
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getShopOrderItems()
 {
     return $this->hasMany(ShopOrderItem::className(), ['order_id' => 'id']);
 }
Beispiel #2
0
 public function actionShiWuOrder($slug)
 {
     $shopOrder = new ShopOrder();
     $shopProducts = ShopProduct::findOne(['slug' => $slug]);
     //myVarDump($shopOrder->validate());
     if ($shopOrder->load(\Yii::$app->request->post()) && $shopOrder->validate()) {
         $transaction = $shopOrder->getDb()->beginTransaction();
         $shopOrder->user_id = \Yii::$app->user->getId();
         $shopOrder->setOrderSn();
         $shopOrder->save(false);
         $shopOrderItem = new ShopOrderItem();
         $shopOrderItem->order_id = $shopOrder->id;
         $shopOrderItem->title = $shopProducts['title'];
         $shopOrderItem->price = $shopProducts['price'];
         $shopOrderItem->product_id = $shopProducts['id'];
         $shopOrderItem->quantity = 1;
         if (!$shopOrderItem->save(false)) {
             $transaction->rollBack();
             \Yii::$app->session->addFlash('error', '暂时不能处理您的订单!');
             return $this->redirect(['catalog/list']);
         }
         $transaction->commit();
         \Yii::$app->cart->removeAll();
         \Yii::$app->session->addFlash('success', '谢谢您的订单,我们会尽快处理!');
         $shopOrder->sendEmail();
         return $this->redirect(['product/my-order']);
     }
     return $this->render('shi-wu-order', ['shopOrder' => $shopOrder, 'shopProducts' => $shopProducts]);
 }
Beispiel #3
0
$this->render('_breadcrumbs');
?>

	<div class="container content">
		<div class="headline">
			<a href="<?php 
echo Url::toRoute(['product/my-order']);
?>
"><h2>我的订单</h2></a>
		</div>

		<div class="row">
			<div class="col-lg-12">
				<?php 
echo \yii\grid\GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'order_sn', ['attribute' => '名称', 'value' => function ($model) {
    return \common\models\ShopOrderItem::findOne(['order_id' => $model->id])->title;
}], ['attribute' => 'user_id', 'value' => function ($model) {
    return $model->user ? $model->user->username : null;
}], 'phone', 'created_at:datetime', ['class' => \common\grid\EnumColumn::className(), 'attribute' => 'status', 'enum' => ShopOrder::getStatus()], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{delete}', 'buttons' => ['delete' => function ($url, $model, $key) {
    return Html::a('<span class="glyphicon glyphicon glyphicon-trash"></span>', ['/product/my-order-delete', 'id' => $model->id], ['title' => '删除', 'aria-labe' => '删除', 'data-confirm' => "您确定要删除此项吗?", 'data-method' => 'post']);
}]]], 'layout' => "{items}\n{summary}\n{pager}"]);
?>
			</div>
		</div>
	</div>

-->

<?php 
$js = <<<JS
Beispiel #4
0
	<p>
		<?php 
echo Html::a(Yii::t('backend', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']);
?>
		<?php 
echo Html::a(Yii::t('backend', 'Delete'), ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => Yii::t('backend', 'Are you sure you want to delete this item?'), 'method' => 'post']]);
?>
	</p>

	<?php 
echo DetailView::widget(['model' => $model, 'attributes' => ['order_sn', ['attribute' => 'user_id', 'value' => $model->user->username], 'created_at:datetime', 'updated_at:datetime', 'phone', 'address:ntext', 'email:email', 'notes:ntext', ['attribute' => 'status', 'value' => ArrayHelper::getValue(ShopOrder::getStatus(), $model->status)]]]);
?>

	<div class="col-lg-12">
		<h4>该订单包含商品信息:</h4>
		<?php 
$orderItems = \common\models\ShopOrderItem::find()->where(['order_id' => $model->id])->all();
?>
		<?php 
foreach ($orderItems as $k => $v) {
    ?>
			<?php 
    echo DetailView::widget(['model' => $v, 'attributes' => ['title', 'price', 'product_id', 'quantity']]);
    ?>
		<?php 
}
?>
	</div>

</div>