Esempio n. 1
0
	public function checkout () {
		global $ecs,$db,$_CFG;
		/*------------------------------------------------------ */
	    //-- 订单确认
	    /*------------------------------------------------------ */
	
	    #取得购物类型
	    $flow_type = isset($_SESSION['flow_type']) ? intval($_SESSION['flow_type']) : CART_GENERAL_GOODS;
		
		/*
	    #团购标志
	    if ($flow_type == CART_GROUP_BUY_GOODS)
	    {
	        $smarty->assign('is_group_buy', 1);
	    }
	    #积分兑换商品
	    elseif ($flow_type == CART_EXCHANGE_GOODS)
	    {
	        $smarty->assign('is_exchange_goods', 1);
	    }
	    else
	    {
		*/
		#正常购物流程  清空其他购物流程情况
		$_SESSION['flow_order']['extension_code'] = '';
		/*}*/
	
	    /* 检查购物车中是否有商品 */
	    $sql = "SELECT COUNT(*) FROM " . $ecs->table('cart') ." WHERE session_id = '" . SESS_ID . "' " .
	           "AND parent_id = 0 AND is_gift = 0 AND rec_type = '$flow_type'";
	
	    if ($db->getOne($sql) == 0)
	    {
			$msg = rpcLang('flow.php', 'no_goods_in_cart');
			jsonExit("{\"status\":\"$msg\"}");
	    }
	
	    /*
	     * 检查用户是否已经登录
	     * 如果用户已经登录了则检查是否有默认的收货地址
	     * 如果没有登录则跳转到登录和注册页面
	     */
	    if (empty($_SESSION['direct_shopping']) && $_SESSION['user_id'] == 0)
	    {
			$msg = rpcLang('user.php', 'nologin');
			jsonExit("{\"status\":\"$msg\"}");
	    }
	
	    $consignee = get_consignee($_SESSION['user_id']);
	
	    #检查收货人信息是否完整
	    if (!check_consignee_info($consignee, $flow_type))
	    {
			$msg = rpcLang('flow.php', 'user_address_not_full');
			jsonExit("{\"status\":\"$msg\"}");
	    }
	
	    //$_SESSION['flow_consignee'] = $consignee;
	    
	    #对商品信息赋值
	    $cart_goods = cart_goods($flow_type); // 取得商品列表,计算合计
	
		/*
	    $smarty->assign('goods_list', $cart_goods);
	    #对是否允许修改购物车赋值
	    if ($flow_type != CART_GENERAL_GOODS || $_CFG['one_step_buy'] == '1')
	    {
	        $smarty->assign('allow_edit_cart', 0);
	    }
	    else
	    {
	        $smarty->assign('allow_edit_cart', 1);
	    }
	    
	    #取得购物流程设置
	    $smarty->assign('config', $_CFG);
		*/
	
	    /*
	     * 取得订单信息
	     */
	    $order = flow_order_info();
	
	    /* 计算折扣 */
	    if ($flow_type != CART_EXCHANGE_GOODS && $flow_type != CART_GROUP_BUY_GOODS)
	    {
	        $discount = compute_discount();
			
	    }
	
	    /*
	     * 计算订单的费用
	     */
	    $total = order_fee($order, $cart_goods, $consignee);
		
	    #取得配送列表
	    $region            = array($consignee['country'], $consignee['province'], $consignee['city'], $consignee['district']);
		#快递方式集合
		$shipping_list     = available_shipping_list($region);
		#购物车重量
	    $cart_weight_price = cart_weight_price($flow_type);
	    $insure_disabled   = true;
	    $cod_disabled      = true;
	
	    #查看购物车中是否全为免运费商品,若是则把运费赋为零s
	    $sql = 'SELECT count(*) FROM ' . $ecs->table('cart') . " WHERE `session_id` = '" . SESS_ID. "' AND `extension_code` != 'package_buy' AND `is_shipping` = 0";
	    $shipping_count = $db->getOne($sql);
	    foreach ($shipping_list AS $key => $val)
	    {
	        $shipping_cfg = unserialize_config($val['configure']);
	        $shipping_fee = ($shipping_count == 0 AND $cart_weight_price['free_shipping'] == 1) ? 0 : shipping_fee($val['shipping_code'], unserialize($val['configure']),
	        $cart_weight_price['weight'], $cart_weight_price['amount'], $cart_weight_price['number']);
	
	        $shipping_list[$key]['format_shipping_fee'] = price_format($shipping_fee, false);
	        $shipping_list[$key]['shipping_fee']        = $shipping_fee;
	        $shipping_list[$key]['free_money']          = price_format($shipping_cfg['free_money'], false);
	        $shipping_list[$key]['insure_formated']     = strpos($val['insure'], '%') === false ?
	        price_format($val['insure'], false) : $val['insure'];
	
	        #当前的配送方式是否支持保价
	        if ($val['shipping_id'] == $order['shipping_id'])
	        {
	            $insure_disabled = ($val['insure'] == 0);
	            $cod_disabled    = ($val['support_cod'] == 0);
	        }
	    }
		#取得支付列表
	    if ($order['shipping_id'] == 0)
	    {
	        $cod        = true;
	        $cod_fee    = 0;
	    }
	    else
	    {
	        $shipping = shipping_info($order['shipping_id']);
	        $cod = $shipping['support_cod'];
	
	        if ($cod)
	        {
	            #如果是团购,且保证金大于0,不能使用货到付款
	            if ($flow_type == CART_GROUP_BUY_GOODS)
	            {
	                $group_buy_id = $_SESSION['extension_id'];
	                if ($group_buy_id <= 0)
	                {
	                    show_message('error group_buy_id');
	                }
	                $group_buy = group_buy_info($group_buy_id);
	                if (empty($group_buy))
	                {
	                    show_message('group buy not exists: ' . $group_buy_id);
	                }
	
	                if ($group_buy['deposit'] > 0)
	                {
	                    $cod = false;
	                    $cod_fee = 0;
	
	                    #赋值保证金
	                    $smarty->assign('gb_deposit', $group_buy['deposit']);
	                }
	            }
	
	            if ($cod)
	            {
	                $shipping_area_info = shipping_area_info($order['shipping_id'], $region);
	                $cod_fee            = $shipping_area_info['pay_fee'];
	            }
	        }
	        else
	        {
	            $cod_fee = 0;
	        }
	    }
	    
	
	    # 给货到付款的手续费加<span id>,以便改变配送的时候动态显示
	    $payment_list = available_payment_list(1, $cod_fee);
	    if(isset($payment_list))
	    {
	        foreach ($payment_list as $key => $payment)
	        {
	            if ($payment['is_cod'] == '1')
	            {
	                $payment_list[$key]['format_pay_fee'] = '<span id="ECS_CODFEE">' . $payment['format_pay_fee'] . '</span>';
	            }
	            #如果有易宝神州行支付 如果订单金额大于300 则不显示
	            if ($payment['pay_code'] == 'yeepayszx' && $total['amount'] > 300)
	            {
	                unset($payment_list[$key]);
	            }
	            #如果有余额支付
	            if ($payment['pay_code'] == 'balance')
	            {
	                #如果未登录,不显示
	                if ($_SESSION['user_id'] == 0)
	                {
	                    unset($payment_list[$key]);
	                }
	                else
	                {
	                    if ($_SESSION['flow_order']['pay_id'] == $payment['pay_id'])
	                    {
	                        $smarty->assign('disable_surplus', 1);
	                    }
	                }
	            }
	        }
	    }
	
		$pack_list = array();
		$card_list = array();
	    /* 取得包装与贺卡 */
	    if ($total['real_goods_count'] > 0)
	    {
	        #只有有实体商品,才要判断包装和贺卡
	        if (!isset($_CFG['use_package']) || $_CFG['use_package'] == '1')
	        {
				#如果使用包装,取得包装列表及用户选择的包装
				$pack_list = pack_list();
	        }
	
	        #如果使用贺卡,取得贺卡列表及用户选择的贺卡
	        if (!isset($_CFG['use_card']) || $_CFG['use_card'] == '1')
	        {
				$card_list = card_list();
			}
	    }
	
	    /* 
		$user_info = user_info($_SESSION['user_id']);
		#如果使用余额,取得用户余额
	    if ((!isset($_CFG['use_surplus']) || $_CFG['use_surplus'] == '1') && $_SESSION['user_id'] > 0  && $user_info['user_money'] > 0)
	    {
	        // 能使用余额
	        $smarty->assign('allow_use_surplus', 1);
	        $smarty->assign('your_surplus', $user_info['user_money']);
	    }
		
		#如果使用积分,取得用户可用积分及本订单最多可以使用的积分
	    if ((!isset($_CFG['use_integral']) || $_CFG['use_integral'] == '1')
	        && $_SESSION['user_id'] > 0
	        && $user_info['pay_points'] > 0
	        && ($flow_type != CART_GROUP_BUY_GOODS && $flow_type != CART_EXCHANGE_GOODS))
	    {
	        // 能使用积分
	        $smarty->assign('allow_use_integral', 1);
	        $smarty->assign('order_max_integral', flow_available_points());  // 可用积分
	        $smarty->assign('your_integral',      $user_info['pay_points']); // 用户积分
	    }*/
		
	    #如果使用红包,取得用户可以使用的红包及用户选择的红包
	    if ((!isset($_CFG['use_bonus']) || $_CFG['use_bonus'] == '1') && ($flow_type != CART_GROUP_BUY_GOODS && $flow_type != CART_EXCHANGE_GOODS))
	    {
	        #取得用户可用红包
	        $user_bonus = zy_user_bonus($_SESSION['user_id'], $total['goods_price']);
	        if (!empty($user_bonus))
	        {
	            foreach ($user_bonus AS $key => $val)
	            {
	                $user_bonus[$key]['bonus_money_formated'] = price_format($val['type_money'], false);
	            }
	        }
	        #能使用红包
	        //$smarty->assign('allow_use_bonus', 1);
	    }
		/*
	    # 如果使用缺货处理,取得缺货处理列表
	    if (!isset($_CFG['use_how_oos']) || $_CFG['use_how_oos'] == '1')
	    {
	        if (is_array($GLOBALS['_LANG']['oos']) && !empty($GLOBALS['_LANG']['oos']))
	        {
	            $smarty->assign('how_oos_list', $GLOBALS['_LANG']['oos']);
	        }
	    }*/
		
	    #如果能开发票,取得发票内容列表
	    if ((!isset($_CFG['can_invoice']) || $_CFG['can_invoice'] == '1')	&& isset($_CFG['invoice_content']) 
			&& trim($_CFG['invoice_content']) != '' && $flow_type != CART_EXCHANGE_GOODS)
	    {
	        $inv_content_list = explode("\n", str_replace("\r", '', $_CFG['invoice_content']));
	       
	        $inv_type_list = array();
	        foreach ($_CFG['invoice_type']['type'] as $key => $type)
	        {
	            if (!empty($type))
	            {
	                $inv_type_list[$type] = $type . ' [' . floatval($_CFG['invoice_type']['rate'][$key]) . '%]';
	            }
	        }
	        $inv_content_list = implode(",", $inv_content_list);
	        $inv_list = array ('inv_content_list'=>$inv_content_list,'inv_type_list'=>$inv_type_list);
	       
	    }
		
	
	    #保存session
	    $_SESSION['flow_order'] = $order;
	   /* $pay_code = rpcLang('flow.php', 'pay_code_name');
		foreach ($payment_list as $value) {
			
			foreach ($value as $k=>$v){
				
			    if (strpos($v, $pay_code) !== false) {
			        $payment_list = $value;
			        $payment_list = preg_replace('/<.*?>|\[.*?\]/', '', $payment_list);
	    			$payment_list = array($payment_list);
			    }
			}
		}*/
	   
		$checkout_order = array('cart_goods'=>$cart_goods,
								'total'=>$total,
								'pack_list'=>$pack_list,
								'card_list'=>$card_list,
								'shipping_list'=>$shipping_list,
								'payment_list'=>$payment_list,
								'inv_list'=>$inv_list,
								'consignee'=>$consignee,);
		if (!empty($user_bonus)) {
	    	$checkout_order ['user_bonus'] = $user_bonus;
	    }
	  // print_r($checkout_order);die;
		jsonExit($checkout_order);
	}
Esempio n. 2
0
     /* 过滤掉使用余额支付 */
     foreach ($payment_list as $key => $payment) {
         if ($payment['pay_code'] == 'balance') {
             unset($payment_list[$key]);
         }
     }
     $smarty->assign('payment_list', $payment_list);
 } elseif ('other' == $step) {
     /* 查询是否存在实体商品 */
     $exist_real_goods = exist_real_goods($order_id);
     $smarty->assign('exist_real_goods', $exist_real_goods);
     if ($exist_real_goods) {
         /* 取得包装列表 */
         $smarty->assign('pack_list', pack_list());
         /* 取得贺卡列表 */
         $smarty->assign('card_list', card_list());
     }
 } elseif ('money' == $step) {
     /* 查询是否存在实体商品 */
     $exist_real_goods = exist_real_goods($order_id);
     $smarty->assign('exist_real_goods', $exist_real_goods);
     /* 取得用户信息 */
     if ($order['user_id'] > 0) {
         $user = user_info($order['user_id']);
         /* 计算可用余额 */
         $smarty->assign('available_user_money', $order['surplus'] + $user['user_money']);
         /* 计算可用积分 */
         $smarty->assign('available_pay_points', $order['integral'] + $user['pay_points']);
         /* 取得用户可用红包 */
         $user_bonus = user_bonus($order['user_id'], $order['goods_amount']);
         if ($order['bonus_id'] > 0) {
Esempio n. 3
0
File: flow.php Progetto: noikiy/mdwp
    /* 取得包装与贺卡 */
    if ($total['real_goods_count'] > 0)
    {
        #只有有实体商品,才要判断包装和贺卡
        if (!isset($_CFG['use_package']) || $_CFG['use_package'] == '1')
        {
			#如果使用包装,取得包装列表及用户选择的包装
            //$smarty->assign('pack_list', pack_list());
			$pack_list = pack_list();
        }

        #如果使用贺卡,取得贺卡列表及用户选择的贺卡
        if (!isset($_CFG['use_card']) || $_CFG['use_card'] == '1')
        {
            //$smarty->assign('card_list', card_list());
			$card_list = card_list();
		}
    }

    /* 
	$user_info = user_info($_SESSION['user_id']);
	#如果使用余额,取得用户余额
    if ((!isset($_CFG['use_surplus']) || $_CFG['use_surplus'] == '1') && $_SESSION['user_id'] > 0  && $user_info['user_money'] > 0)
    {
        // 能使用余额
        $smarty->assign('allow_use_surplus', 1);
        $smarty->assign('your_surplus', $user_info['user_money']);
    }
	
	#如果使用积分,取得用户可用积分及本订单最多可以使用的积分
    if ((!isset($_CFG['use_integral']) || $_CFG['use_integral'] == '1')