Пример #1
0
 /**
  * 立即购买
  */
 public function add_to_cart()
 {
     //对goods处理
     $_POST['goods'] = strip_tags(urldecode($_POST['goods']));
     $_POST['goods'] = json_str_iconv($_POST['goods']);
     if (!empty($_REQUEST['goods_id']) && empty($_POST['goods'])) {
         if (!is_numeric($_REQUEST['goods_id']) || intval($_REQUEST['goods_id']) <= 0) {
             ecs_header("Location:./\n");
         }
         $goods_id = intval($_REQUEST['goods_id']);
         exit;
     }
     // 初始化返回数组
     $result = array('error' => 0, 'message' => '', 'content' => '', 'goods_id' => '', 'product_spec' => '');
     if (empty($_POST['goods'])) {
         $result['error'] = 1;
         die(json_encode($result));
     }
     $json = new EcsJson();
     $goods = $json->decode($_POST['goods']);
     $result['goods_id'] = $goods->goods_id;
     $result['product_spec'] = $goods->spec;
     // 检查:如果商品有规格,而post的数据没有规格,把商品的规格属性通过JSON传到前台
     if (empty($goods->spec) and empty($goods->quick)) {
         $sql = "SELECT a.attr_id, a.attr_name, a.attr_type, " . "g.goods_attr_id, g.attr_value, g.attr_price " . 'FROM ' . $this->model->pre . 'goods_attr AS g ' . 'LEFT JOIN ' . $this->model->pre . 'attribute AS a ON a.attr_id = g.attr_id ' . "WHERE a.attr_type != 0 AND g.goods_id = '" . $goods->goods_id . "' " . 'ORDER BY a.sort_order, g.attr_price, g.goods_attr_id';
         $res = $this->model->query($sql);
         if (!empty($res)) {
             $spe_arr = array();
             foreach ($res as $row) {
                 $spe_arr[$row['attr_id']]['attr_type'] = $row['attr_type'];
                 $spe_arr[$row['attr_id']]['name'] = $row['attr_name'];
                 $spe_arr[$row['attr_id']]['attr_id'] = $row['attr_id'];
                 $spe_arr[$row['attr_id']]['values'][] = array('label' => $row['attr_value'], 'price' => $row['attr_price'], 'format_price' => price_format($row['attr_price'], false), 'id' => $row['goods_attr_id']);
             }
             $i = 0;
             $spe_array = array();
             foreach ($spe_arr as $row) {
                 $spe_array[] = $row;
             }
             $result['error'] = ERR_NEED_SELECT_ATTR;
             $result['goods_id'] = $goods->goods_id;
             $result['parent'] = $goods->parent;
             $result['message'] = $spe_array;
             die(json_encode($result));
         }
     }
     // 更新:如果是一步购物,先清空购物车
     if (C('one_step_buy') == '1') {
         model('Order')->clear_cart();
     }
     // 查询:系统启用了库存,检查输入的商品数量是否有效
     // 查询
     $arrGoods = $this->model->table('goods')->field('goods_name,goods_number,extension_code')->where('goods_id =' . $goods->goods_id)->find();
     $goodsnmber = model('Users')->get_goods_number($goods->goods_id);
     $goodsnmber += $goods->number;
     if (intval(C('use_storage')) > 0) {
         if ($arrGoods['goods_number'] < $goodsnmber) {
             $result['error'] = 1;
             $result['message'] = sprintf(L('stock_insufficiency'), $arrGoods['goods_name'], $arrGoods['goods_number'], $arrGoods['goods_number']);
             if (C('use_how_oos') == 1) {
                 $result['message'] = L('oos_tips');
             }
             die(json_encode($result));
         }
     }
     // 检查:商品数量是否合法
     if (!is_numeric($goods->number) || intval($goods->number) <= 0) {
         $result['error'] = 1;
         $result['message'] = L('invalid_number');
     } else {
         // 更新:添加到购物车
         if (model('Order')->addto_cart($goods->goods_id, $goods->number, $goods->spec, $goods->parent)) {
             if (C('cart_confirm') > 2) {
                 $result['message'] = '';
             } else {
                 $result['message'] = C('cart_confirm') == 1 ? L('addto_cart_success_1') : L('addto_cart_success_2');
             }
             $result['content'] = insert_cart_info();
             $result['one_step_buy'] = C('one_step_buy');
         } else {
             $result['message'] = ECTouch::err()->last_message();
             $result['error'] = ECTouch::err()->error_no;
             $result['goods_id'] = stripslashes($goods->goods_id);
             if (is_array($goods->spec)) {
                 $result['product_spec'] = implode(',', $goods->spec);
             } else {
                 $result['product_spec'] = $goods->spec;
             }
         }
     }
     $cart_confirm = C('cart_confirm');
     $result['confirm_type'] = !empty($cart_confirm) ? C('cart_confirm') : 2;
     // 返回购物车商品总数量
     $result['cart_number'] = insert_cart_info_number();
     die(json_encode($result));
 }
Пример #2
0
 public function receive_gift()
 {
     //对goods处理
     $_POST['goods'] = strip_tags(urldecode($_POST['gift']));
     $_POST['goods'] = json_str_iconv($_POST['gift']);
     // 初始化返回数组
     $result = array('error' => 0, 'message' => '', 'content' => '', 'goods_id' => '', 'product_spec' => '');
     if (empty($_POST['goods'])) {
         $result['error'] = 1;
         die(json_encode($result));
     }
     $json = new EcsJson();
     $gift = $json->decode($_POST['gift']);
     $result['sn'] = $gift->sn;
     $result['product_spec'] = $gift->spec;
     // 购买礼包商品清空购物车
     model('Order')->clear_cart(CART_RECEIVE_GIFTS);
     // 查询:系统启用了库存,检查输入的商品数量是否有效
     // 查询
     $Gift = $this->model->table('gift_sn')->field('goods_name,amount,sn_id,goods_id')->where("sn_id='" . $gift->sn . "'")->find();
     if ($gift->number > $Gift['amount']) {
         $result['error'] = 1;
         $result['message'] = sprintf(L('stock_insufficiency'), $Gift['goods_name'], $Gift['goods_number'], $Gift['goods_number']);
         if (C('use_how_oos') == 1) {
             $result['message'] = L('oos_tips');
         }
         die(json_encode($result));
     }
     // 检查:商品数量是否合法
     if (!is_numeric($gift->number) || intval($gift->number) <= 0) {
         $result['error'] = 1;
         $result['message'] = L('invalid_number');
     } else {
         // 更新:添加到购物车
         $_SESSION['flow_type'] = CART_RECEIVE_GIFTS;
         $_SESSION['extension_code'] = "receive_gift";
         $_SESSION['extension_id'] = CART_RECEIVE_GIFTS;
         if (model('Order')->addto_cart($Gift['goods_id'], $gift->number, $gift->spec, $gift->parent, CART_RECEIVE_GIFTS)) {
             if (C('cart_confirm') > 2) {
                 $result['message'] = '';
             } else {
                 $result['message'] = C('cart_confirm') == 1 ? L('addto_cart_success_1') : L('addto_cart_success_2');
             }
             $result['content'] = insert_cart_info();
             $result['one_step_buy'] = C('one_step_buy');
         } else {
             $result['message'] = ECTouch::err()->last_message();
             $result['error'] = ECTouch::err()->error_no;
             $result['goods_id'] = stripslashes($Gift['goods_id']);
             if (is_array($goods->spec)) {
                 $result['product_spec'] = implode(',', $gift->spec);
             } else {
                 $result['product_spec'] = $gift->spec;
             }
         }
     }
     $cart_confirm = C('cart_confirm');
     $result['confirm_type'] = !empty($cart_confirm) ? C('cart_confirm') : 2;
     // 返回购物车商品总数量
     $result['cart_number'] = insert_cart_info_number();
     die(json_encode($result));
 }
Пример #3
0
 }
 /* 检查:商品数量是否合法 */
 if (!is_numeric($goods->number) || intval($goods->number) <= 0) {
     $result['error'] = 1;
     $result['message'] = $_LANG['invalid_number'];
 } else {
     // 更新:添加到购物车
     if (addto_cart($goods->goods_id, $goods->number, $goods->spec, $goods->parent)) {
         if ($_CFG['cart_confirm'] > 2) {
             $result['message'] = '';
         } else {
             $result['message'] = $_CFG['cart_confirm'] == 1 ? $_LANG['addto_cart_success_1'] : $_LANG['addto_cart_success_2'];
         }
         $result['content'] = insert_cart_info();
         $result['one_step_buy'] = $_CFG['one_step_buy'];
         $result['cart_number'] = insert_cart_info_number();
     } else {
         $result['message'] = $err->last_message();
         $result['error'] = $err->error_no;
         $result['goods_id'] = stripslashes($goods->goods_id);
         if (is_array($goods->spec)) {
             $result['product_spec'] = implode(',', $goods->spec);
         } else {
             $result['product_spec'] = $goods->spec;
         }
     }
 }
 $rows = $GLOBALS['db']->getRow("select goods_brief,shop_price,goods_name,goods_thumb from " . $GLOBALS['ecs']->table('goods') . " where goods_id=" . $goods->goods_id);
 $result['goods_thumb'] = $config['site_url'] . $rows['goods_thumb'];
 $result['cart_goods_name'] = $rows['goods_name'];
 $sql = 'SELECT SUM(goods_number) AS number, SUM(goods_price * goods_number) AS amount' . ' FROM ' . $GLOBALS['ecs']->table('cart') . " WHERE session_id = '" . SESS_ID . "' AND rec_type = '" . CART_GENERAL_GOODS . "'";
 public function add_to_cart_cf()
 {
     //对goods处理
     $_POST['goods'] = strip_tags(urldecode($_POST['goods']));
     $_POST['goods'] = json_str_iconv($_POST['goods']);
     if (!empty($_REQUEST['goods_id']) && empty($_POST['goods'])) {
         if (!is_numeric($_REQUEST['goods_id']) || intval($_REQUEST['goods_id']) <= 0) {
             ecs_header("Location:./\n");
         }
         exit;
     }
     // 初始化返回数组
     $result = array('error' => 0, 'message' => '', 'content' => '', 'goods_id' => '', 'product_spec' => '');
     if (empty($_POST['goods'])) {
         $result['error'] = 1;
         die(json_encode($result));
     }
     $json = new EcsJson();
     $goods = $json->decode($_POST['goods']);
     $result['goods_id'] = $goods->goods_id;
     $result['product_spec'] = $goods->spec;
     // 清空众筹购物车
     model('Order')->clear_cart(CART_CF_GOODS);
     //TODO 查询众筹库存
     /*
             $arrGoods = $this->model->table('goods')->field('goods_name,goods_number,extension_code')->where('goods_id =' . $goods->goods_id)->find();
             $goodsnmber = model('Users')->get_goods_number($goods->goods_id);
             $goodsnmber+=$goods->number;
     if ($arrGoods ['goods_number'] < $goodsnmber) {
                 $result['error'] = 1;
                 $result['message'] = sprintf(L('stock_insufficiency'), $arrGoods ['goods_name'], $arrGoods ['goods_number'], $arrGoods ['goods_number']);
                 if (C('use_how_oos') == 1){
                     $result['message'] =L('oos_tips');
                 }
                 die(json_encode($result));
             }
     */
     // 检查:商品数量是否合法
     if (!is_numeric($goods->number) || intval($goods->number) <= 0) {
         $result['error'] = 1;
         $result['message'] = L('invalid_number');
     } else {
         // 更新:添加到购物车
         $_SESSION['flow_type'] = CART_CF_GOODS;
         $_SESSION['extension_code'] = "Crowdfunding";
         $_SESSION['extension_id'] = CART_CF_GOODS;
         if (model('Order')->addto_cart($goods->goods_id, $goods->number, $goods->spec, $goods->parent, CART_CF_GOODS)) {
             if (C('cart_confirm') > 2) {
                 $result['message'] = '';
             } else {
                 $result['message'] = C('cart_confirm') == 1 ? L('addto_cart_success_1') : L('addto_cart_success_2');
             }
             $result['content'] = insert_cart_info();
             $result['one_step_buy'] = C('one_step_buy');
         } else {
             $result['message'] = ECTouch::err()->last_message();
             $result['error'] = ECTouch::err()->error_no;
             $result['goods_id'] = stripslashes($goods->goods_id);
             if (is_array($goods->spec)) {
                 $result['product_spec'] = implode(',', $goods->spec);
             } else {
                 $result['product_spec'] = $goods->spec;
             }
         }
     }
     $cart_confirm = C('cart_confirm');
     $result['confirm_type'] = !empty($cart_confirm) ? C('cart_confirm') : 2;
     // 返回购物车商品总数量
     $result['cart_number'] = insert_cart_info_number();
     die(json_encode($result));
 }