Author: : liaoxianwen@ymt360.com
Inheritance: extends MY_Controller
Exemplo n.º 1
0
 public function verify()
 {
     parent::verify();
     // Each course has to have a course ID
     if (empty($this->data->courseId)) {
         throw new \Exception(Lang::txt('No course id'));
     }
 }
Exemplo n.º 2
0
 public function actionUpdate()
 {
     $sku = Sku::model()->findByPk(substr($_POST['sku_id'], 3));
     if ($sku->stock < $_POST['qty']) {
         echo '<div id="error-message" style="color:red">库存数量不足。</div>';
     } else {
         $item = CartItem::model()->with('skus')->findByPk(intval($_POST['item_id']));
         $item->cartProps = empty($_POST['props']) ? '' : $_POST['props'];
         $quantity = empty($_POST['qty']) ? 1 : intval($_POST['qty']);
         Yii::app()->cart->update($item, $quantity);
     }
 }
Exemplo n.º 3
0
 public function verify()
 {
     parent::verify();
     // Check if the download file is set
     if (empty($this->data->meta['downloadFile']) || !$this->data->meta['downloadFile']) {
         throw new \Exception(Lang::txt('Download file must be set'));
     }
     // Check if the download file really exists
     $storefrontConfig = Component::params('com_storefront');
     $dir = $storefrontConfig->get('downloadFolder');
     $file = PATH_ROOT . $dir . DS . $this->data->meta['downloadFile'];
     if (!file_exists($file)) {
         throw new \Exception(Lang::txt('Download file doesn\'t exist'));
     }
 }
Exemplo n.º 4
0
 public function getParams()
 {
     $params = array();
     if ($this->logo_url != NULL) {
         $params['logo_url'] = $this->logo_url;
     }
     if ($this->code_type != NULL) {
         $params['code_type'] = $this->code_type;
     }
     if ($this->brand_name != NULL) {
         $params['brand_name'] = $this->brand_name;
     }
     if ($this->title != NULL) {
         $params['title'] = $this->title;
     }
     if ($this->sub_title != NULL) {
         $params['sub_title'] = $this->sub_title;
     }
     if ($this->color != NULL) {
         $params['color'] = $this->color;
     }
     if ($this->notice != NULL) {
         $params['notice'] = $this->notice;
     }
     if ($this->description != NULL) {
         $params['description'] = $this->description;
     }
     if ($this->date_info != NULL) {
         $params['date_info'] = $this->date_info->getParams();
     }
     if ($this->sku != NULL) {
         $params['sku'] = $this->sku->getParams();
     }
     if ($this->location_id_list != NULL) {
         $params['location_id_list'] = $this->location_id_list;
     }
     if ($this->use_custom_code != NULL) {
         $params['use_custom_code'] = $this->use_custom_code;
     }
     if ($this->bind_openid != NULL) {
         $params['bind_openid'] = $this->bind_openid;
     }
     if ($this->can_share != NULL) {
         $params['can_share'] = $this->can_share;
     }
     if ($this->can_give_friend != NULL) {
         $params['can_give_friend'] = $this->can_give_friend;
     }
     if ($this->get_limit != NULL) {
         $params['get_limit'] = $this->get_limit;
     }
     if ($this->service_phone != NULL) {
         $params['service_phone'] = $this->service_phone;
     }
     if ($this->source != NULL) {
         $params['source'] = $this->source;
     }
     if ($this->custom_url_name != NULL) {
         $params['custom_url_name'] = $this->custom_url_name;
     }
     if ($this->custom_url != NULL) {
         $params['custom_url'] = $this->custom_url;
     }
     if ($this->custom_url_sub_title != NULL) {
         $params['custom_url_sub_title'] = $this->custom_url_sub_title;
     }
     if ($this->promotion_url_name != NULL) {
         $params['promotion_url_name'] = $this->promotion_url_name;
     }
     if ($this->promotion_url != NULL) {
         $params['promotion_url'] = $this->promotion_url;
     }
     if ($this->promotion_url_sub_title != NULL) {
         $params['promotion_url_sub_title'] = $this->promotion_url_sub_title;
     }
     /**
      * 以下字段都是用以微信摇一摇的时候设置
      */
     if ($this->get_custom_code_mode != NULL) {
         $params['get_custom_code_mode'] = $this->get_custom_code_mode;
     }
     if ($this->can_shake != NULL) {
         $params['can_shake'] = $this->can_shake;
     }
     if ($this->shake_slogan_title != NULL) {
         $params['shake_slogan_title'] = $this->shake_slogan_title;
     }
     if ($this->shake_slogan_sub_title != NULL) {
         $params['shake_slogan_sub_title'] = $this->shake_slogan_sub_title;
     }
     if ($this->use_limit != NULL) {
         $params['use_limit'] = $this->use_limit;
     }
     // -----以下字段在v2.0废弃了--------------
     if ($this->url_name_type != NULL) {
         $params['url_name_type'] = $this->url_name_type;
     }
     if ($this->promotion_url_name_type != NULL) {
         $params['promotion_url_name_type'] = $this->promotion_url_name_type;
     }
     return $params;
 }
Exemplo n.º 5
0
?>
</del></li>
                    <li class="price2">本店价:<em><?php 
echo $model->currency . $model->shop_price;
?>
</em></li>
                    <li class="click_count">浏览次数:<?php 
echo $model->click_count;
?>
次</li>
                    <?php 
/**
 * 显示
 */
$cri = new CDbCriteria(array('condition' => 'item_id =' . $model->item_id));
$sku_list = Sku::model()->findAll($cri);
foreach ($sku_list as $skus) {
    $props = CJSON::decode($skus->props, TRUE);
    $count = count($props);
    for ($i = 0; $i < $count; $i++) {
        $p[$i][] = $props[$i];
    }
}
for ($i = 0; $i < $count; $i++) {
    foreach (array_unique($p[$i]) as $k => $v) {
        $new_v = explode(':', $v);
        $new_arr[$new_v[0]][] = $new_v[1];
    }
}
foreach ($new_arr as $k => $v) {
    $list = ItemProp::model()->findByPk($k);
Exemplo n.º 6
0
    /**
     * Delete an option and everything related to it
     *
     * @param	void
     * @return	void
     */
    public function delete()
    {
        // Delete the option record
        $sql = 'DELETE FROM `#__storefront_options` WHERE `oId` = ' . $this->db->quote($this->getId());
        $this->db->setQuery($sql);
        //print_r($this->db->replacePrefix($this->db->getQuery()));
        $this->db->query();
        // Find all SKUs that use this option before removing all references
        $sql = 'SELECT o.`sId` FROM `#__storefront_sku_options` o
				LEFT JOIN `#__storefront_skus` s ON o.`sId` = s.`sId`
				WHERE o.`oId` = ' . $this->db->quote($this->getId());
        $sql .= ' AND s.`sActive` = 1';
        $this->db->setQuery($sql);
        $sIds = $this->db->loadColumn();
        // Delete the SKU-option relation
        $sql = 'DELETE FROM `#__storefront_sku_options` WHERE `oId` = ' . $this->db->quote($this->getId());
        $this->db->setQuery($sql);
        //print_r($this->db->replacePrefix($this->db->getQuery()));
        $this->db->query();
        // Update dependencies, disable SKUs that became invalid
        $skusDisabled = false;
        foreach ($sIds as $sId) {
            $sku = new Sku($sId);
            if ($sku->getActiveStatus()) {
                try {
                    $sku->verify();
                } catch (\Exception $e) {
                    $sku->unpublish();
                    $skusDisabled = true;
                }
            }
        }
        if ($skusDisabled) {
            $this->addMessage('Some SKUs were unpublished because of the recent update. Check each SKU to fix the issues.');
        }
    }
Exemplo n.º 7
0
 public function actionAjaxGetSkus()
 {
     if (!Yii::app()->request->isAjaxRequest) {
         exit;
     }
     $id = $_POST["item_id"];
     $skus = Sku::getSkusData($id);
     echo CJSON::encode($skus, true);
     Yii::app()->end();
 }
Exemplo n.º 8
0
 public function actionCheckStock()
 {
     $number = $_GET['number'];
     $sku_id = $_GET['sku_id'];
     $sku = Sku::model()->findByPk($sku_id);
     $criteria = new CDbCriteria();
     $criteria->addCondition('item_id=:item_id');
     $criteria->addCondition('price=:price');
     $criteria->addCondition('props_name=:props_name');
     $criteria->params[':item_id'] = $sku->item_id;
     $criteria->params[':price'] = $sku->price;
     $criteria->params[':props_name'] = $sku->props_name;
     $orderItem = OrderItem::model()->find($criteria);
     if ($sku->stock + $orderItem->quantity < $number || $number <= 0) {
         echo 0;
     } else {
         echo 1;
     }
 }
Exemplo n.º 9
0
 public function getParams()
 {
     $params = array();
     if ($this->isNotNull($this->logo_url)) {
         $params['logo_url'] = $this->logo_url;
     }
     if ($this->isNotNull($this->code_type)) {
         $params['code_type'] = $this->code_type;
     }
     if ($this->isNotNull($this->brand_name)) {
         $params['brand_name'] = $this->brand_name;
     }
     if ($this->isNotNull($this->title)) {
         $params['title'] = $this->title;
     }
     if ($this->isNotNull($this->sub_title)) {
         $params['sub_title'] = $this->sub_title;
     }
     if ($this->isNotNull($this->color)) {
         $params['color'] = $this->color;
     }
     if ($this->isNotNull($this->notice)) {
         $params['notice'] = $this->notice;
     }
     if ($this->isNotNull($this->description)) {
         $params['description'] = $this->description;
     }
     if ($this->isNotNull($this->date_info)) {
         $params['date_info'] = $this->date_info->getParams();
     }
     if ($this->isNotNull($this->sub_merchant_info)) {
         $params['sub_merchant_info'] = $this->sub_merchant_info->getParams();
     }
     if ($this->isNotNull($this->sku)) {
         $params['sku'] = $this->sku->getParams();
     }
     if ($this->isNotNull($this->location_id_list)) {
         $params['location_id_list'] = $this->location_id_list;
     }
     if ($this->isNotNull($this->use_custom_code)) {
         $params['use_custom_code'] = $this->use_custom_code;
     }
     if ($this->isNotNull($this->bind_openid)) {
         $params['bind_openid'] = $this->bind_openid;
     }
     if ($this->isNotNull($this->can_share)) {
         $params['can_share'] = $this->can_share;
     }
     if ($this->isNotNull($this->can_give_friend)) {
         $params['can_give_friend'] = $this->can_give_friend;
     }
     if ($this->isNotNull($this->get_limit)) {
         $params['get_limit'] = $this->get_limit;
     }
     if ($this->isNotNull($this->service_phone)) {
         $params['service_phone'] = $this->service_phone;
     }
     if ($this->isNotNull($this->source)) {
         $params['source'] = $this->source;
     }
     if ($this->isNotNull($this->custom_url_name)) {
         $params['custom_url_name'] = $this->custom_url_name;
     }
     if ($this->isNotNull($this->custom_url)) {
         $params['custom_url'] = $this->custom_url;
     }
     if ($this->isNotNull($this->custom_url_sub_title)) {
         $params['custom_url_sub_title'] = $this->custom_url_sub_title;
     }
     if ($this->isNotNull($this->promotion_url_name)) {
         $params['promotion_url_name'] = $this->promotion_url_name;
     }
     if ($this->isNotNull($this->promotion_url)) {
         $params['promotion_url'] = $this->promotion_url;
     }
     if ($this->isNotNull($this->promotion_url_sub_title)) {
         $params['promotion_url_sub_title'] = $this->promotion_url_sub_title;
     }
     if ($this->isNotNull($this->center_title)) {
         $params['center_title'] = $this->center_title;
     }
     if ($this->isNotNull($this->center_sub_title)) {
         $params['center_sub_title'] = $this->center_sub_title;
     }
     if ($this->isNotNull($this->center_url)) {
         $params['center_url'] = $this->center_url;
     }
     if ($this->isNotNull($this->use_all_locations)) {
         $params['use_all_locations'] = $this->use_all_locations;
     }
     /**
      * 以下字段都是用以微信摇一摇的时候设置
      */
     if ($this->isNotNull($this->get_custom_code_mode)) {
         $params['get_custom_code_mode'] = $this->get_custom_code_mode;
     }
     if ($this->isNotNull($this->can_shake)) {
         $params['can_shake'] = $this->can_shake;
     }
     if ($this->isNotNull($this->shake_slogan_title)) {
         $params['shake_slogan_title'] = $this->shake_slogan_title;
     }
     if ($this->isNotNull($this->shake_slogan_sub_title)) {
         $params['shake_slogan_sub_title'] = $this->shake_slogan_sub_title;
     }
     if ($this->isNotNull($this->use_limit)) {
         $params['use_limit'] = $this->use_limit;
     }
     // -----以下字段在v2.0废弃了--------------
     if ($this->isNotNull($this->url_name_type)) {
         $params['url_name_type'] = $this->url_name_type;
     }
     if ($this->isNotNull($this->promotion_url_name_type)) {
         $params['promotion_url_name_type'] = $this->promotion_url_name_type;
     }
     return $params;
 }
Exemplo n.º 10
0
 public function actionAjaxGetSkus()
 {
     if (!Yii::app()->request->isAjaxRequest && empty($_POST['item_id'])) {
         return;
     }
     $skus = Sku::model()->findAllByAttributes(array("item_id" => $_POST["item_id"]));
     $data = array();
     foreach ($skus as $sku) {
         $arr = array();
         $arr['sku_id'] = $sku->sku_id;
         $arr['props'] = F::convert_props_js_id($sku->props);
         //            $arr['props'] = str_replace(":","-",$arr['props']);
         $arr['price'] = $sku->price;
         $arr['stock'] = $sku->stock;
         $arr['outer_id'] = $sku->outer_id;
         $data[] = $arr;
     }
     echo json_encode($data);
 }
Exemplo n.º 11
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);
     if (!$_POST['delivery_address'] && !Yii::app()->user->isGuest) {
         echo '<script>alert("您还没有添加收货地址!")</script>';
         echo '<script type="text/javascript">history.go(-1)</script>';
     } else {
         if (isset($_POST)) {
             $transaction = $model->dbConnection->beginTransaction();
             try {
                 $cart = Yii::app()->cart;
                 if (!Yii::app()->user->isGuest) {
                     $model->attributes = $_POST;
                     $model->user_id = Yii::app()->user->id ? Yii::app()->user->id : '0';
                     $cri = new CDbCriteria(array('condition' => 'contact_id =' . $_POST['delivery_address'] . ' AND user_id = ' . Yii::app()->user->id));
                     $address = AddressResult::model()->find($cri);
                     $model->receiver_country = $address->country;
                     $model->receiver_name = $address->contact_name;
                     $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;
                 } else {
                     $address = $_POST['AddressResult'];
                     $model->user_id = '0';
                     $model->receiver_name = $address['contact_name'];
                     $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'];
                     $model->payment_method_id = $_POST['payment_method_id'];
                     $model->memo = $_POST['memo'];
                 }
                 $model->create_time = time();
                 $model->order_id = F::get_order_id();
                 $model->total_fee = 0;
                 if (isset($_POST['keys'])) {
                     foreach ($_POST['keys'] as $key) {
                         $item = $cart->itemAt($key);
                         $model->total_fee += $item['quantity'] * $item['price'];
                     }
                 } else {
                     $item = Item::model()->findBypk($_POST['item_id']);
                     $model->total_fee = $item->price * $_POST['quantity'];
                 }
                 if ($model->save()) {
                     if (empty($_POST['keys'])) {
                         $item = Item::model()->findBypk($_POST['item_id']);
                         $sku = Sku::model()->findByPk($_POST['sku_id']);
                         if ($sku->stock < $_POST['quantity']) {
                             throw new Exception('stock is not enough!');
                         }
                         $OrderItem = new OrderItem();
                         //                            $OrderItem->order_id = $model->order_id;
                         //                            $OrderItem->item_id = $item->item_id;
                         //                            $OrderItem->title = $item->title;
                         //                            $OrderItem->desc = $item->desc;
                         //                            $OrderItem->pic = $item->getMainPic();
                         //                            $OrderItem->props_name = $sku->props_name;
                         //                            $OrderItem->price = $item->price;
                         //                            $OrderItem->quantity = $_POST['quantity'];
                         //                            $OrderItem->total_price = $OrderItem->quantity * $OrderItem->price;
                         if (!$OrderItem::model()->saveOrderItem($OrderItem, $model->order_id, $item, $sku->props_name, $_POST['quantity'])) {
                             throw new Exception('save order item fail');
                         }
                     } else {
                         foreach ($_POST['keys'] as $key) {
                             $item = $cart->itemAt($key);
                             $sku = Sku::model()->findByPk($item['sku']['sku_id']);
                             if ($sku->stock < $item['quantity']) {
                                 throw new Exception('stock is not enough!');
                             }
                             $sku->stock -= $item['quantity'];
                             if (!$sku->save()) {
                                 throw new Exception('cut down stock fail');
                             }
                             $OrderItem = new OrderItem();
                             $OrderItem->order_id = $model->order_id;
                             $OrderItem->item_id = $item['item_id'];
                             $OrderItem->title = $item['title'];
                             $OrderItem->desc = $item['desc'];
                             $OrderItem->pic = $item->getMainPic();
                             $OrderItem->props_name = $sku['props_name'];
                             $OrderItem->price = $item['price'];
                             $OrderItem->quantity = $item['quantity'];
                             $OrderItem->total_price = $OrderItem->quantity * $OrderItem->price;
                             if (!$OrderItem->save()) {
                                 throw new Exception('save order item fail');
                             }
                             $cart->remove($key);
                         }
                     }
                 } else {
                     throw new Exception('save order fail');
                 }
                 $transaction->commit();
                 $this->redirect(array('success'));
             } catch (Exception $e) {
                 $transaction->rollBack();
                 $this->redirect(array('fail'));
             }
         }
     }
 }
Exemplo n.º 12
0
 /**
  * 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 $id the ID of the model to be loaded
  * @return Sku the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Sku::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }