示例#1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Order();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     //        print_r($_POST);
     //        exit;
     if (!$_POST['delivery_address']) {
         echo '<script>alert("您还没有添加收货地址!")</script>';
         echo '<script type="text/javascript">history.go(-1)</script>';
         die;
     } else {
         if (isset($_POST)) {
             $model->attributes = $_POST;
             $model->order_id = F::get_order_id();
             $model->user_id = Yii::app()->user->id ? Yii::app()->user->id : '0';
             $model->create_time = time();
             $cri = new CDbCriteria(array('condition' => 'contact_id =' . $_POST['delivery_address'] . ' AND user_id = ' . Yii::app()->user->id));
             $address = AddressResult::model()->find($cri);
             $model->receiver_name = $address->contact_name;
             $model->receiver_country = $address->country;
             $model->receiver_state = $address->state;
             $model->receiver_city = $address->city;
             $model->receiver_district = $address->district;
             $model->receiver_address = $address->address;
             $model->receiver_zip = $address->zipcode;
             $model->receiver_mobile = $address->mobile_phone;
             $model->receiver_phone = $address->phone;
             if ($model->save()) {
                 $cart = Yii::app()->cart;
                 $mycart = $cart->contents();
                 foreach ($mycart as $mc) {
                     $OrderItem = new OrderItem();
                     $OrderItem->order_id = $model->order_id;
                     $OrderItem->item_id = $mc['id'];
                     $OrderItem->title = $mc['title'];
                     $OrderItem->pic_url = serialize($mc['pic_url']);
                     $OrderItem->sn = $mc['sn'];
                     $OrderItem->num = $mc['qty'];
                     $OrderItem->price = $mc['price'];
                     $OrderItem->amount = $mc['subtotal'];
                     $OrderItem->save();
                 }
                 $cart->destroy();
                 $this->redirect(array('success'));
             }
         }
     }
     //        $this->render('create', array(
     //            'model' => $model,
     //        ));
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = AddressResult::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
示例#3
0
    /**
     * name: actionAddAddressByAjax
     * function:add address when buy product var use new address
     * @author: shuai.du@jago-ag.cn
     */
    public function actionAddAddressByAjax()
    {
        $model = new AddressResult();
        if (isset($_POST['AddressResult']) && Yii::app()->request->isAjaxRequest) {
            $model->attributes = $_POST['AddressResult'];
            $result = array();
            if ($model->save()) {
                echo 'success@';
                echo $model->contact_id . '@';
                //                echo $model->contact_id;
                //                echo '<li>'. CHtml::radioButton('delivery_address',true,array('value' => $model->contact_id,'id' => 'delivery_address'.$model->contact_id)).CHtml::tag('span', array(
                //                            'class' => 'buyer-address shop_selection'),
                //                        $model->s->name . '&nbsp;' . $model->c->name . '&nbsp;' . $model->d->name . '&nbsp;' . $model->address . '&nbsp;(' . $model->contact_name . '&nbsp;收)&nbsp;' . $model->mobile_phone).'</li>';
                $this->renderPartial('address', array('model' => $model));
            } else {
                $errors = $model->getErrors();
                foreach ($errors as $error) {
                    ?>
                    <li><?php 
                    echo $error[0];
                    ?>
</li>
            <?php 
                }
            }
        }
    }
示例#4
0
    <div style="margin-top:10px"></div>

<?php 
if (Yii::app()->user->id) {
    ?>
    <div class="box address-panel">
        <div class="box-title container_24"><span
                style="float:right"><?php 
    echo CHtml::link('管理收货地址', array('/member/delivery_address/admin'), array('target' => '_blank'));
    ?>
</span>收货地址
        </div>
        <div class="box-content">
            <?php 
    $cri = new CDbCriteria(array('condition' => 'user_id = ' . Yii::app()->user->id));
    $AddressResult = AddressResult::model()->findAll($cri);
    if ($AddressResult) {
        echo '<ul id="address_list">';
        foreach ($AddressResult as $address) {
            $default_address = $address->is_default == 1 ? 'default_address' : '';
            echo '<li class=' . $default_address . '>' . CHtml::radioButton('delivery_address', $address->is_default == 1 ? TRUE : FALSE, array('value' => $address->contact_id, 'class' => 'delivery-address', 'id' => 'delivery_address' . $address->contact_id));
            echo CHtml::tag('span', array('class' => 'buyer-address shop_selection'), $address->s->name . '&nbsp;' . $address->c->name . '&nbsp;' . $address->d->name . '&nbsp;' . $address->address . '&nbsp;(' . $address->contact_name . '&nbsp;收)&nbsp;' . $address->mobile_phone);
            echo '</li>';
        }
        echo '</ul>';
    }
    ?>
            <div style="margin-top: 10px">
                <a class="btn btn-primary" data-toggle="modal" data-target ='#addressModal' data-backdrop = "true"> 使用新地址</a>
            </div>
        </div>