Example #1
0
 /**
  * 改变支付方式
  */
 public function select_payment()
 {
     $json = new EcsJson();
     $result = array('error' => '', 'content' => '', 'need_insure' => 0, 'payment' => 1);
     /* 取得购物类型 */
     $flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;
     /* 获得收货人信息 */
     $consignee = model('Order')->get_consignee($_SESSION['user_id']);
     /* 对商品信息赋值 */
     $cart_goods = model('Order')->cart_goods($flow_type);
     // 取得商品列表,计算合计
     if (empty($cart_goods) || !model('Order')->check_consignee_info($consignee, $flow_type)) {
         $result['error'] = L('no_goods_in_cart');
     } else {
         /* 取得购物流程设置 */
         $this->assign('config', C('CFG'));
         /* 取得订单信息 */
         $order = model('Order')->flow_order_info();
         $order['pay_id'] = intval($_REQUEST['payment']);
         $payment_info = model('Order')->payment_info($order['pay_id']);
         $result['pay_code'] = $payment_info['pay_code'];
         /* 保存 session */
         $_SESSION['flow_order'] = $order;
         /* 计算订单的费用 */
         $total = model('Users')->order_fee($order, $cart_goods, $consignee);
         $this->assign('total', $total);
         /* 取得可以得到的积分和红包 */
         $this->assign('total_integral', model('Order')->cart_amount(false, $flow_type) - $total['integral_money']);
         $result['content'] = ECTouch::$view->fetch('library/order_total.lbi');
     }
     echo $json->encode($result);
     exit;
 }
Example #2
0
 /**
  * 异步调用商品列表
  */
 public function get_goods_list()
 {
     $_POST['filters'] = strip_tags(urldecode($_POST['filters']));
     $_POST['filters'] = json_str_iconv($_POST['filters']);
     $json = new EcsJson();
     $filters = $json->decode($_POST['filters']);
     $arr = get_goods_list($filters);
     $opt = array();
     foreach ($arr as $key => $val) {
         $opt[] = array('value' => $val['goods_id'], 'text' => $val['goods_name']);
     }
     make_json_result($opt);
 }
 /**
  * 添加礼包到购物车
  */
 public function add_package_to_cart()
 {
     $_POST['package_info'] = json_str_iconv($_POST['package_info']);
     $result = array('error' => 0, 'message' => '', 'content' => '', 'package_id' => '');
     if (empty($_POST['package_info'])) {
         $result['error'] = 1;
         die(json_encode($result));
     }
     $json = new EcsJson();
     $package = $json->decode($_POST['package_info']);
     /* 如果是一步购物,先清空购物车 */
     if (C('one_step_buy') == '1') {
         model('Order')->clear_cart();
     }
     /* 商品数量是否合法 */
     if (!is_numeric($package->number) || intval($package->number) <= 0) {
         $result['error'] = 1;
         $result['message'] = L('invalid_number');
     } else {
         /* 添加到购物车 */
         if (model('Order')->add_package_to_cart($package->package_id, $package->number)) {
             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['package_id'] = stripslashes($package->package_id);
         }
     }
     $cart_confirm = C('cart_confirm');
     $result['confirm_type'] = !empty($cart_confirm) ? $cart_confirm : 2;
     die(json_encode($result));
 }
Example #4
0
 public function add_to_gift()
 {
     //对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;
     // 检查:如果商品有规格,而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));
         }
     }
     // 购买礼包商品清空购物车
     model('Order')->clear_cart(CART_GIFT_GOODS);
     // 查询:系统启用了库存,检查输入的商品数量是否有效
     // 查询
     $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 {
         // 更新:添加到购物车
         $_SESSION['flow_type'] = CART_GIFT_GOODS;
         $_SESSION['extension_code'] = "gift_goods";
         $_SESSION['extension_id'] = CART_GIFT_GOODS;
         if (model('Order')->addto_cart($goods->goods_id, $goods->number, $goods->spec, $goods->parent, CART_GIFT_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));
 }
Example #5
0
/**
 * 功能:与 ECShop 交换数据
 *
 * @param   array     $certi    登录参数
 * @param   array     $license  网店license信息
 * @param   bool      $use_lib  使用哪一个json库,0为ec,1为shopex
 * @return  array
 */
function exchange_shop_license($certi, $license, $use_lib = 0) {
    if (!is_array($certi)) {
        return array();
    }

    $params = '';
    foreach ($certi as $key => $value) {
        $params .= '&' . $key . '=' . $value;
    }
    $params = trim($params, '&');

    $transport = new EcsTransport;
    //$transport->connect_timeout = 1;
    $request = $transport->request($license['certi'], $params, 'POST');
    $request_str = json_str_iconv($request['body']);

    if (empty($use_lib)) {
        $json = new EcsJson();
        $request_arr = $json->decode($request_str, 1);
    } else {
        $request_arr = json_decode($request_str, 1);
    }

    return $request_arr;
}
 public function index()
 {
     $result = array('error' => 0, 'message' => '', 'content' => '');
     if (empty($this->act)) {
         $this->cmt = I('request.cmt', '', 'json_str_iconv');
         $result = array('error' => 0, 'message' => '', 'content' => '');
         if (empty($this->act)) {
             /*
              * act 参数为空 默认为添加评论内容
              */
             $json = new EcsJson();
             $cmt = $json->decode($this->cmt);
             $cmt->page = 1;
             $cmt->id = !empty($cmt->id) ? intval($cmt->id) : 0;
             $cmt->type = !empty($cmt->type) ? intval($cmt->type) : 0;
             if (empty($cmt) || !isset($cmt->type) || !isset($cmt->id)) {
                 $result['error'] = 1;
                 $result['message'] = L('invalid_comments');
             } elseif (!is_email($cmt->email)) {
                 $result['error'] = 1;
                 $result['message'] = L('error_email');
             } else {
                 if (intval(C('captcha')) & CAPTCHA_COMMENT && gd_version() > 0) {
                     /* 检查验证码 */
                     if ($_SESSION['ectouch_verify'] !== strtoupper($cmt->captcha)) {
                         $result['error'] = 1;
                         $result['message'] = L('invalid_captcha');
                     } else {
                         $factor = intval(C('comment_factor'));
                         if ($cmt->type == 0 && $factor > 0) {
                             /* 只有商品才检查评论条件 */
                             switch ($factor) {
                                 case COMMENT_LOGIN:
                                     if ($_SESSION['user_id'] == 0) {
                                         $result['error'] = 1;
                                         $result['message'] = L('comment_login');
                                     }
                                     break;
                                 case COMMENT_CUSTOM:
                                     if ($_SESSION['user_id'] > 0) {
                                         $condition = "user_id = '" . $_SESSION['user_id'] . "'" . " AND (order_status = '" . OS_CONFIRMED . "' or order_status = '" . OS_SPLITED . "') " . " AND (pay_status = '" . PS_PAYED . "' OR pay_status = '" . PS_PAYING . "') " . " AND (shipping_status = '" . SS_SHIPPED . "' OR shipping_status = '" . SS_RECEIVED . "') ";
                                         $tmp = $this->model->table('order_info')->field('order_id')->where($condition)->getOne();
                                         if (empty($tmp)) {
                                             $result['error'] = 1;
                                             $result['message'] = L('comment_custom');
                                         }
                                     } else {
                                         $result['error'] = 1;
                                         $result['message'] = L('comment_custom');
                                     }
                                     break;
                                 case COMMENT_BOUGHT:
                                     if ($_SESSION['user_id'] > 0) {
                                         $sql = "SELECT o.order_id" . " FROM " . $this->model->pre . "order_info AS o, " . $this->model->pre . "order_goods AS og " . " WHERE o.order_id = og.order_id" . " AND o.user_id = '" . $_SESSION['user_id'] . "'" . " AND og.goods_id = '" . $cmt->id . "'" . " AND (o.order_status = '" . OS_CONFIRMED . "' or o.order_status = '" . OS_SPLITED . "') " . " AND (o.pay_status = '" . PS_PAYED . "' OR o.pay_status = '" . PS_PAYING . "') " . " AND (o.shipping_status = '" . SS_SHIPPED . "' OR o.shipping_status = '" . SS_RECEIVED . "') " . " LIMIT 1";
                                         $res = $this->model->query($sql);
                                         $tmp = $res[0]['order_id'];
                                         if (empty($tmp)) {
                                             $result['error'] = 1;
                                             $result['message'] = L('comment_brought');
                                         }
                                     } else {
                                         $result['error'] = 1;
                                         $result['message'] = L('comment_brought');
                                     }
                             }
                         }
                         /* 无错误就保存留言 */
                         if (empty($result['error'])) {
                             model('Comment')->add_comment($cmt);
                         }
                     }
                 } else {
                     /* 没有验证码时,用时间来限制机器人发帖或恶意发评论 */
                     if (!isset($_SESSION['send_time'])) {
                         $_SESSION['send_time'] = 0;
                     }
                     $cur_time = gmtime();
                     if ($cur_time - $_SESSION['send_time'] < 30) {
                         // 小于30秒禁止发评论
                         $result['error'] = 1;
                         $result['message'] = L('cmt_spam_warning');
                     } else {
                         $factor = intval(C('comment_factor'));
                         if ($cmt->type == 0 && $factor > 0) {
                             /* 只有商品才检查评论条件 */
                             switch ($factor) {
                                 case COMMENT_LOGIN:
                                     if ($_SESSION['user_id'] == 0) {
                                         $result['error'] = 1;
                                         $result['message'] = L('comment_login');
                                     }
                                     break;
                                 case COMMENT_CUSTOM:
                                     if ($_SESSION['user_id'] > 0) {
                                         $condition = "user_id = '" . $_SESSION['user_id'] . "'" . " AND (o.order_status = '" . OS_CONFIRMED . "' or o.order_status = '" . OS_SPLITED . "') " . " AND (o.pay_status = '" . PS_PAYED . "' OR o.pay_status = '" . PS_PAYING . "') " . " AND (o.shipping_status = '" . SS_SHIPPED . "' OR o.shipping_status = '" . SS_RECEIVED . "') ";
                                         $tmp = $this->model->table('order_info')->field('order_id')->where($condition)->getOne();
                                         if (empty($tmp)) {
                                             $result['error'] = 1;
                                             $result['message'] = L('comment_custom');
                                         }
                                     } else {
                                         $result['error'] = 1;
                                         $result['message'] = L('comment_custom');
                                     }
                                     break;
                                 case COMMENT_BOUGHT:
                                     if ($_SESSION['user_id'] > 0) {
                                         $sql = "SELECT o.order_id" . " FROM " . $this->model->pre . "order_info AS o, " . $this->model->pre . "order_goods AS og " . " WHERE o.order_id = og.order_id" . " AND o.user_id = '" . $_SESSION['user_id'] . "'" . " AND og.goods_id = '" . $cmt->id . "'" . " AND (o.order_status = '" . OS_CONFIRMED . "' or o.order_status = '" . OS_SPLITED . "') " . " AND (o.pay_status = '" . PS_PAYED . "' OR o.pay_status = '" . PS_PAYING . "') " . " AND (o.shipping_status = '" . SS_SHIPPED . "' OR o.shipping_status = '" . SS_RECEIVED . "') " . " LIMIT 1";
                                         $res = $this->model->query($sql);
                                         $tmp = $res[0]['order_id'];
                                         if (empty($tmp)) {
                                             $result['error'] = 1;
                                             $result['message'] = L('comment_brought');
                                         }
                                     } else {
                                         $result['error'] = 1;
                                         $result['message'] = L('comment_brought');
                                     }
                             }
                         }
                         /* 无错误就保存留言 */
                         if (empty($result['error'])) {
                             model('Comment')->add_comment($cmt);
                             $_SESSION['send_time'] = $cur_time;
                         }
                     }
                 }
             }
         }
     } else {
         /*
          * act 参数不为空 默认为评论内容列表 根据 _GET 创建一个静态对象
          */
         $cmt = new stdClass();
         $id = I('get.id');
         $type = I('get.type');
         $page = I('get.page');
         $cmt->id = !empty($id) ? intval($id) : 0;
         $cmt->type = !empty($type) ? intval($type) : 0;
         $rank = I('get.rank');
         $cmt->page = isset($page) && intval($page) > 0 ? intval($page) : 1;
     }
     if ($result['error'] == 0) {
         //全部评价
         $comment = model('Comment')->assign_comment($cmt->id, $cmt->type, 0, $cmt->page);
         $this->assign('comment_list', $comment['comments']);
         $this->assign('pager', $comment['pager']);
         //好评
         $comment_favorable = model('Comment')->assign_comment($cmt->id, $cmt->type, '1');
         $this->assign('comment_fav', $comment_favorable['comments']);
         $this->assign('pager_fav', $comment_favorable['pager']);
         //中评
         $comment_medium = model('Comment')->assign_comment($cmt->id, $cmt->type, '2');
         $this->assign('comment_med', $comment_medium['comments']);
         $this->assign('pager_med', $comment_medium['pager']);
         //差评
         $comment_bad = model('Comment')->assign_comment($cmt->id, $cmt->type, '3');
         $this->assign('comment_bad', $comment_bad['comments']);
         $this->assign('pager_poor', $comment_bad['pager']);
         if ($rank == 1) {
             $comment_favorable = model('Comment')->assign_comment($cmt->id, $cmt->type, '1', $cmt->page);
             $this->assign('comment_fav', $comment_favorable['comments']);
             $this->assign('pager_fav', $comment_favorable['pager']);
         }
         if ($rank == 2) {
             $comment_medium = model('Comment')->assign_comment($cmt->id, $cmt->type, '2', $cmt->page);
             $this->assign('comment_med', $comment_medium['comments']);
             $this->assign('pager_med', $comment_medium['pager']);
         }
         if ($rank == 3) {
             $comment_bad = model('Comment')->assign_comment($cmt->id, $cmt->type, '3', $cmt->page);
             $this->assign('comment_bad', $comment_bad['comments']);
             $this->assign('pager_bad', $comment_bad['pager']);
         } else {
             $comment = model('Comment')->assign_comment($cmt->id, $cmt->type, '0', $cmt->page);
             $this->assign('comment_list', $comment['comments']);
             $this->assign('pager', $comment['pager']);
         }
         $this->assign('rank', $rank);
         $this->assign('comments_info', model('Comment')->get_comment_info($cmt->id, $cmt->type));
         $this->assign('comment_type', $cmt->type);
         $this->assign('id', $cmt->id);
         $this->assign('username', $_SESSION['user_name']);
         $this->assign('email', $_SESSION['email']);
         /* 验证码相关设置 */
         if (intval(C('captcha')) & CAPTCHA_COMMENT && gd_version() > 0) {
             $this->assign('enabled_captcha', 1);
             $this->assign('rand', mt_rand());
         }
         //$result['rank'] = $rank;
         $result['message'] = C('comment_check') ? L('cmt_submit_wait') : L('cmt_submit_done');
         $result['content'] = ECTouch::$view->fetch("library/comments_list.lbi");
     }
     echo json_encode($result);
 }
 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));
 }
Example #8
0
 /**
  * 用户出价处理
  */
 public function bid()
 {
     $json = new EcsJson();
     $result = array('error' => 0, 'content' => '');
     $price = isset($_POST['price']) ? floatval($_POST['price']) : 0;
     $price = round($price, 2);
     $id = isset($_POST['id']) ? intval($_POST['id']) : 0;
     /* 测试是否登陆 */
     if (empty($_SESSION['user_id'])) {
         $result['error'] = 1;
         $result['content'] = L('not_login');
         die($json->encode($result));
     }
     /* 获取活动基本信息用于校验 */
     $row = $this->model->table('goods_activity')->field('act_name,end_time,ext_info')->where('act_id =' . $id)->find();
     if ($row) {
         $info = unserialize($row['ext_info']);
         if ($info) {
             foreach ($info as $key => $val) {
                 $row[$key] = $val;
             }
         }
     }
     if (empty($row)) {
         $result['error'] = 1;
         $result['content'] = L('now_not_snatch');
         die($json->encode($result));
     }
     if ($row['end_time'] < gmtime()) {
         $result['error'] = 1;
         $result['content'] = L('snatch_is_end');
         die($json->encode($result));
     }
     /* 检查出价是否合理 */
     if ($price < $row['start_price'] || $price > $row['end_price']) {
         $result['error'] = 1;
         $result['content'] = sprintf($GLOBALS['_LANG']['not_in_range'], $row['start_price'], $row['end_price']);
         die($json->encode($result));
     }
     /* 检查用户是否已经出同一价格 */
     $count = $this->model->table('snatch_log')->where("snatch_id = '" . $id . "' AND user_id = '{$_SESSION['user_id']}' AND bid_price = '.{$price}.'")->count();
     if ($count > 0) {
         $result['error'] = 1;
         $result['content'] = sprintf(L('also_bid'), price_format($price, false));
         die($json->encode($result));
     }
     /* 检查用户积分是否足够 */
     $pay_points = $this->model->table('users')->field('pay_points')->where("user_id = '{$_SESSION['user_id']}'")->find();
     if ($row['cost_points'] > $pay_points['pay_points']) {
         $result['error'] = 1;
         $result['content'] = L('lack_pay_points');
         die($json->encode($result));
     }
     model('ClipsBase')->log_account_change($_SESSION['user_id'], 0, 0, 0, 0 - $row['cost_points'], sprintf(L('snatch_log'), $row['snatch_name']));
     //扣除用户积分
     $snatch_log['snatch_id'] = $id;
     $snatch_log['user_id'] = $_SESSION['user_id'];
     $snatch_log['bid_price'] = $price;
     $snatch_log['bid_time'] = gmtime();
     $this->model->table('snatch_log')->data($snatch_log)->insert();
     $this->assign('myprice', model('Snatch')->get_myprice($id));
     $this->assign('id', $id);
     $result['content'] = ECTouch::view()->fetch('library/snatch.lbi');
     die($json->encode($result));
 }
 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));
 }