function get_total_amount() { $dao = D("Cart"); $sessionID = Cookie::get('sessionID'); $this->totalWeight = $weight = $dao->cart_total_weight($sessionID); //总重量 $cartTotal = $dao->cart_total($sessionID); //产品总价格 $this->cartTotal = getprice_str($cartTotal); $this->itemTotal = $itemTotal = $dao->get_item_totalcount($sessionID); //总数量 $this->itemCount = $dao->get_item_count($sessionID); //总类数 $this->discount = $discount = $dao->discount($cartTotal); //打折信息 $totalAmonut = round($discount['price'], 2); $shipping_id = $_POST['shipping_id']; $delivery = $_POST['delivery']; $shippingModel = D('Shipping'); $member_id = Cookie::get('memberID'); if ($shipping_id && $delivery == 0 && $member_id) { //会员本身地址 $memberShippingAddress = Cookie::get('memberShippingAddress'); $shipping_price = $shippingModel->get_shipping_fee($shipping_id, $memberShippingAddress['country'], $memberShippingAddress['state'], $memberShippingAddress['city'], $weight); } else { //其它地址 $shipping_price = $shippingModel->get_shipping_fee($shipping_id, $_POST['country'], $_POST['state'], $_POST['city'], $weight); } $shipping_price = $shipping_price['price']; //没有运费取保险金 if (!$shipping_price) { $insure = $shippingModel->get_insure($shipping_id); $shipping_price = $shipping_price ? $shipping_price : $insure ? $insure : 0; } $payment = $_POST['payment']; if ($payment) { $fee = get_orders_Fees($totalAmonut, $itemTotal, $payment); $fee['insurance'] > 0 && $this->assign('insurance', getprice_str($fee['insurance'])); $fee['paymoney'] > 0 && $this->assign('paymoney', getprice_str($fee['paymoney'])); $totalAmonut = $fee['total']; //加上其它金额 } //满金额免运费, 总金额大于免运费 $free_shipping = GetValue('free_shipping'); $this->free_shipping = $free_shipping; if ($free_shipping && $totalAmonut >= $free_shipping) { $shipping_price = 0; } $this->shippingPrice = getprice_str($shipping_price); //运费 $totalAmonut += $shipping_price; //总价加上运费 $cpdao = D("Coupon"); $coupon = $cpdao->validate($_POST['coupon']); if ($coupon) { $totalAmonut -= $coupon['amount']; $this->coupon = getprice_str($coupon['amount']); } //读取订单信息 $this->list = $dao->display_contents($sessionID); //购物车列表 $this->totalAmount = getprice_str($totalAmonut); //全部总价 if ($this->free_shipping) { $this->actual_totalAmonut = $totalAmonut - $this->free_shipping; } echo $this->fetch('Ajax:get_total_amount'); }
public function checkout() { $cart_model = D("Cart"); if ($cart_model->get_item_count($this->sessionID) < 1) { $this->jumpUrl = U('Index/index'); $this->error("Your shopping cart does not have any products!"); } if ($this->memberID <= 0 && GetSettValue('quickbuy') == 0 && !$_SESSION['guest']) { Session::set('back', U('Cart/checked_payment')); $this->redirect('Member-Public/Login'); } if (!isset($_POST['shipping_id']) || empty($_POST['shipping_id'])) { $this->error('Please select SHIPPING METHOD! '); } if (!isset($_POST['payment_module_code']) || empty($_POST['payment_module_code'])) { $this->error('Please select PAYMENT METHOD! '); } if (!empty($_POST['coupon'])) { $dao = D("Coupon"); $coupon = $dao->validate($_POST['coupon']); if ($coupon) { } else { $this->error('The coupon is invalid! '); } } $orders_model = D("Orders"); $shipping_model = D("Shipping"); $shippingaddress_model = D("Shippingaddress"); $payment_model = D('Payment'); if ($delivery_list = $orders_model->create()) { $delivery = $_POST['delivery']; //0会员本身地址,1其它地址 if ($delivery == 0) { $member_model = D('Members'); $delivery_list['member_id'] = $this->memberID; $this->member_info = $member_info = $member_model->find($this->memberID); $delivery_list['delivery_email'] = $member_info['email']; $delivery_list['delivery_firstname'] = $member_info['firstname']; $delivery_list['delivery_lastname'] = $member_info['lastname']; $member_info = $shippingaddress_model->get_shippingaddress($this->memberID); $delivery_list['delivery_address'] = $member_info['address']; $delivery_list['delivery_country'] = $member_info['country']; $delivery_list['delivery_state'] = $member_info['state']; $delivery_list['delivery_city'] = $member_info['city']; $delivery_list['delivery_zip'] = $member_info['zip']; $delivery_list['delivery_telephone'] = $member_info['telphone']; } $delivery_list['total_weight'] = $cart_model->cart_total_weight($this->sessionID); $delivery_list['shippingmoney'] = $shipping_model->get_shipping_fee($delivery_list["shipping_id"], $delivery_list['delivery_country'], $delivery_list['delivery_state'], $delivery_list['delivery_city'], $delivery_list['total_weight']); $delivery_list['shippingmoney'] = $delivery_list['shippingmoney']['price']; //没有价格取保险金 !$delivery_list['shippingmoney'] ? $delivery_list['shippingmoney'] = $shipping_model->get_insure($delivery_list["shipping_id"]) : ''; $delivery_list['shipping_method'] = $delivery_list['shipping_module_code'] = $shipping_model->get_name($delivery_list["shipping_id"]); $products_total = $cart_model->cart_total($this->sessionID); //产品总价格 $discount = $cart_model->discount($products_total); //打折信息 $sum_total = round($discount['price'], 2); //打折后价格 $delivery_list['discount'] = $discount['text']; $itemTotal = $cart_model->get_item_totalcount($this->sessionID); //总数量 $payment_id = $payment_model->get_id($delivery_list["payment_module_code"]); $fee = get_orders_Fees($sum_total, $itemTotal, $payment_id); //最小订单金额 if ($fee['minimum_money'] && $fee["total"] <= $fee['minimum_money']) { $this->error("Not be less than " . $fee['minimum_money'] . " minimum!"); } $delivery_list['paymoney'] = $fee["paymoney"]; $delivery_list['insurance'] = $fee["insurance"]; $delivery_list['orders_total'] = $fee['total'] + $delivery_list['shippingmoney']; //总价加上运费 $delivery_list['products_total'] = $fee['products_total']; //判断手动和选择 $delivery_list['delivery_country'] = is_numeric($delivery_list['delivery_country']) ? get_region_name($delivery_list['delivery_country']) : $delivery_list['delivery_country']; $delivery_list['delivery_state'] = is_numeric($delivery_list['delivery_state']) ? get_region_name($delivery_list['delivery_state']) : $delivery_list['delivery_state']; $delivery_list['delivery_city'] = is_numeric($delivery_list['delivery_city']) ? get_region_name($delivery_list['delivery_city']) : $delivery_list['delivery_city']; //货币符号 $delivery_list['currencies_code'] = $_SESSION['currency']['code'] ? $_SESSION['currency']['code'] : "\$"; //如果使用了优惠券 if ($coupon) { $delivery_list['orders_total'] -= $coupon['amount']; $delivery_list['coupon'] = $coupon['amount']; //记录优惠了多少价格 } //生成订单 $orders_model->create($delivery_list); //过滤 if ($orders_id = $orders_model->add()) { //保存优惠券使用者 $dao = D("Coupon"); $dao->where(array('coupon' => $_POST['coupon']))->save(array('user' => $delivery_list['delivery_lastname'] . ' ' . $delivery_list['delivery_firstname'], 'status' => 0)); //处理orders_products表 $list = $cart_model->display_contents($this->sessionID); $orders_products_model = D("Orders_products"); for ($row = 0; $count = count($list), $row < $count; $row++) { $data['orders_id'] = $orders_id; $data['products_model'] = serialize($list[$row]['model']); $data['products_id'] = $list[$row]['pid']; $data['products_name'] = $list[$row]['name']; $data['products_price'] = $list[$row]['price']; $data['products_pricespe'] = $list[$row]['pricespe']; $data['products_quantity'] = $list[$row]['count']; $data['products_total'] = $list[$row]['total']; if ($orders_products_model->create($data)) { $orders_products_model->add(); } } //清除购物车 $cart_model->clear_cart($this->sessionID); //发送邮件 //邮件变量 $this->itemTotal = $itemTotal; //总数量 $this->totalWeight = $delivery_list['total_weight']; //总重量 $this->orders_data = $delivery_list; //订单数据 $this->list = $list; //购物车产品 $this->cartTotal = getprice_str($products_total); //产品总价格 $fee['insurance'] > 0 && $this->assign('insurance', getprice_str($fee['insurance'])); $fee['paymoney'] > 0 && $this->assign('paymoney', getprice_str($fee['paymoney'])); $this->discount = $discount; //打折 $this->shippingPrice = getprice_str($delivery_list['shippingmoney']); //运费 $this->totalAmount = getprice_str($delivery_list['orders_total']); //全部总价 $this->this_script = "http://" . $_SERVER['HTTP_HOST']; $sendto = array($delivery_list['delivery_email'], GetSettValue('mailcopyTo')); //抄送 $body = $this->fetch("MailTpl:checkout"); sendmail($sendto, GetSettValue('sitename') . " - new order(SN:" . $orders_model->sn . ")!", $body); $this->redirect('Cart/payment', array('id' => $orders_id)); } else { $this->error($orders_model->getError()); } } else { $this->error(self::$Model->getError()); } }
/** * 未使用 * */ function getShippingFee() { $dao = D("Shipping"); $list = $dao->where("code='" . $_REQUEST["code"] . "'")->find(); $fee = get_orders_Fees($_REQUEST["total"]); //echo $dao->getlastsql(); if ($list) { $r = get_shipping_fee($list["id"], $_REQUEST["country"], $_REQUEST["state"], $_REQUEST["weight"]); $fee["Shipping_money"] = $r; $fee["Shipping_money_str"] = getprice_str($r); $fee['procuts_total'] = $_REQUEST["total"] + $r; if ($fee['procuts_total'] <= GetSettValue("min_freepaymoney")) { $fee['procuts_total'] = $fee['insurance'] + $fee['procuts_total']; $fee['paymoney'] = number_format((double) $fee['procuts_total'] * (double) GetSettValue("paymoney"), 2, '.', ''); } else { $fee['paymoney'] = 0; } //$fee ['procuts_total']=$f; $fee['paymoney_str'] = getprice_str($fee['paymoney']); $fee['procuts_total_str'] = getprice_str($fee['procuts_total'] + $fee["paymoney"]); $fee['procuts_total'] = $fee['procuts_total'] + $fee["paymoney"]; echo json_encode($fee); } else { echo json_encode("error"); } }
public function check_payment() { $payment_module_code = I('post.payment_module_code', ''); $coupon = I('post.coupon', ''); if ($this->memberID <= 0 && GetValue('quickbuy') == 0) { $this->redirect('Admin/login'); } $cartModel = D('Cart'); if ($cartModel->get_item_count($this->sessionID) < 1) { $this->error("Your shopping cart does not have any goods."); } if (empty($payment_module_code)) { $this->error('Please select PAYMENT METHOD.'); } $couponModel = D('Coupon'); if (!empty($coupon)) { if (!$couponModel->validate($coupon)) { $this->error('The coupon is invalid.'); } } $ordersModel = D('Orders'); $shippingModel = D('Shipping'); $shippingaddressModel = D('Shippingaddress'); $paymentModel = D('Payment'); if ($delivery_list = $ordersModel->create()) { $delivery = $_POST['delivery']; //0会员本身地址,1其它地址 if ($delivery == 0) { $memberModel = D('Members'); $delivery_list['member_id'] = $this->memberID; $this->member_info = $member_info = $memberModel->find($this->memberID); $delivery_list['delivery_email'] = $member_info['email']; $delivery_list['delivery_firstname'] = $member_info['firstname']; $delivery_list['delivery_lastname'] = $member_info['lastname']; $address = $shippingaddressModel->get_shippingaddress($this->memberID); $delivery_list['delivery_address'] = $address['address']; $delivery_list['delivery_country'] = $address['country']; $delivery_list['delivery_state'] = $address['state']; $delivery_list['delivery_city'] = $address['city']; $delivery_list['delivery_zip'] = $address['zip']; $delivery_list['delivery_telephone'] = $address['telphone']; } $delivery_list['total_weight'] = $cartModel->cart_total_weight($this->sessionID); if ($delivery_list['shipping_id']) { $delivery_list['shippingmoney'] = $shippingModel->get_shipping_fee($delivery_list['shipping_id'], $delivery_list['delivery_country'], $delivery_list['delivery_state'], $delivery_list['delivery_city'], $delivery_list['total_weight']); } else { $delivery_list['shippingmoney']['price'] = 0; } $delivery_list['shippingmoney'] = $delivery_list['shippingmoney']['price']; //没有价格取保险金 if (empty($delivery_list['shippingmoney'])) { $delivery_list['shippingmoney'] = $shippingModel->get_insure($delivery_list["shipping_id"]); } $delivery_list['shipping_method'] = $delivery_list['shipping_module_code'] = $shippingModel->get_name($delivery_list["shipping_id"]); $products_total = $cartModel->cart_total($this->sessionID); //产品总价格 $discount = $cartModel->discount($products_total); //打折信息 $sum_total = round($discount['price'], 2); //打折后价格 $delivery_list['discount'] = $discount['text']; $itemTotal = $cartModel->get_item_totalcount($this->sessionID); //总数量 $payment_id = $paymentModel->get_id($delivery_list["payment_module_code"]); $fee = get_orders_Fees($sum_total, $itemTotal, $payment_id); //最小订单金额 if ($fee['minimum_money'] && $fee["total"] <= $fee['minimum_money']) { $this->error("Not be less than " . $fee['minimum_money'] . " minimum!"); } //满金额免运费, 总金额大于免运费 $free_shipping = GetValue('free_shipping'); $this->free_shipping = $free_shipping; if ($free_shipping && $fee['total'] >= $free_shipping) { $delivery_list['shippingmoney'] = 0; } $delivery_list['paymoney'] = $fee["paymoney"]; $delivery_list['insurance'] = $fee["insurance"]; $delivery_list['orders_total'] = $fee['total'] + $delivery_list['shippingmoney']; //总价加上运费 $delivery_list['products_total'] = $fee['products_total']; //判断手动和选择 $delivery_list['delivery_country'] = is_numeric($delivery_list['delivery_country']) ? get_region_name($delivery_list['delivery_country']) : $delivery_list['delivery_country']; $delivery_list['delivery_state'] = is_numeric($delivery_list['delivery_state']) ? get_region_name($delivery_list['delivery_state']) : $delivery_list['delivery_state']; $delivery_list['delivery_city'] = is_numeric($delivery_list['delivery_city']) ? get_region_name($delivery_list['delivery_city']) : $delivery_list['delivery_city']; //货币符号 $delivery_list['currencies_code'] = $_SESSION['currency']['code'] ? $_SESSION['currency']['code'] : '$'; //如果使用了优惠券 if ($coupon) { $delivery_list['orders_total'] -= $coupon['amount']; $delivery_list['coupon'] = $coupon['amount']; //记录优惠了多少价格 } //生成订单 $ordersModel->create($delivery_list); //过滤 if ($orders_id = $ordersModel->add()) { //保存优惠券使用者 $couponModel->where(array('coupon' => $coupon))->save(array('user' => $delivery_list['delivery_lastname'] . ' ' . $delivery_list['delivery_firstname'], 'status' => 0)); //处理orders_products表 $orders_products_model = D('OrdersProducts'); $list = $cartModel->get_cart_list($this->sessionID); if ($list) { foreach ($list as $k => $v) { $data['orders_id'] = $orders_id; $data['products_model'] = serialize($v['model']); $data['products_id'] = $v['pid']; $data['products_name'] = $v['name']; $data['products_price'] = $v['price']; $data['products_pricespe'] = $v['pricespe']; $data['products_quantity'] = $v['count']; $data['products_total'] = $v['total']; if ($orders_products_model->create($data)) { $orders_products_model->add(); } } } //清除购物车 $cartModel->clear_cart($this->sessionID); //发送邮件 /* //邮件变量 $this->assign('itemTotal', $itemTotal); //总数量 $this->assign('totalWeight', $delivery_list['total_weight']); //总重量 $this->assign('orders_data', $delivery_list); //订单数据 $this->assign('list', $list); //购物车产品 $this->assign('cartTotal', getprice_str($products_total)); //产品总价格 if($fee['insurance']) { $this->assign('insurance',getprice_str($fee['insurance'])); } if($fee['paymoney']>0) { $this->assign('paymoney',getprice_str($fee['paymoney'])); } $this->assign('discount', $discount); //打折 $this->assign('shippingPrice', getprice_str($delivery_list['shippingmoney'])); //运费 $this->assign('totalAmount', getprice_str($delivery_list['orders_total'])); //全部总价 $this->assign('this_script', "http://".$_SERVER['HTTP_HOST']); $sendto = array($delivery_list['delivery_email'],GetValue('mailcopyTo')); //抄送 $body = $this->fetch("MailTpl:checkout"); sendmail($sendto,GetValue('sitename')." - new order(SN:".$orders_model->sn.")!",$body) ; */ $this->success('The operation success.', U('Cart/pment', array('id' => $orders_id))); } else { $this->error($ordersModel->getError()); } } else { $this->error($ordersModel->getError()); } }