Esempio n. 1
0
 public function discount($price)
 {
     $discount_enable = GetValue('discount_enable');
     //判断是否有折扣
     $discount = 1;
     $r = array();
     if ($discount_enable) {
         $model = D('Discount');
         $list = $model->select();
         foreach ($list as $k => $v) {
             if ($price >= $v['minmoney'] && $price <= $v['maxmoney']) {
                 $discount = $v['discount'];
                 break;
             }
         }
     }
     if ($discount < 1) {
         $r['price'] = round($price * $discount, 2);
         //保留两位
         $r['text'] = getprice_str($price) . '*<Span style="color:red;font-weight:bold;">' . $discount * 100 . '%</span>=' . getprice_str($r['price']);
     } else {
         $r['price'] = $price;
         $r['text'] = "";
     }
     return $r;
 }
Esempio n. 2
0
 function good($pid)
 {
     $dao = D("Products");
     if (isset($_POST['id'])) {
         $pid = intval($_POST['id']);
     }
     $this->pid = $pid;
     $list = $dao->where("id=" . $pid)->find();
     if ($list) {
         $dao->viewcounts($pid);
         //添加用户最近浏览的产品
         if (!isset($_SESSION['product_history'])) {
             $_SESSION['product_history'] = $pid;
         } else {
             if (!($broswer_history_num = GetValue('broswer_history_num'))) {
                 $broswer_history_num = 100;
             }
             $history_array = explode(',', $_SESSION['product_history']);
             array_push($history_array, (int) $pid);
             $history_array = array_unique($history_array);
             if (count($history_array) > $broswer_history_num) {
                 array_shift($history_array);
             }
             $_SESSION['product_history'] = implode(',', $history_array);
         }
         //ajax属性价格
         if (isset($_POST['attr_id'])) {
             $products_attr_model = D("Products_attr");
             $map['id'] = array('in', $_POST['attr_id']);
             $products_attr = $products_attr_model->where($map)->select();
             $attrs = array();
             if ($products_attr) {
                 $attrs['price'] = 0;
                 foreach ($products_attr as $attr) {
                     $attrs['price'] += $attr['attr_price'];
                 }
                 if ($attrs['price']) {
                     $attrs['product_price'] = getprice_str(VipPrice($list['pricespe']) + $attrs['price']);
                     $attrs['attr_price'] = '(' . getprice_str(VipPrice($list['pricespe'])) . ($attrs['price'] > 0 ? '+' : '') . getprice_str($attrs['price']) . ')';
                 } else {
                     $attrs['product_price'] = getprice_str($list['pricespe']);
                     $attrs['attr_price'] = '';
                 }
                 die(json_encode($attrs));
             }
         }
         //产品主图、细节图片、详情图片   start
         $zoomcount = productzoompiccount($list);
         //  产品放大镜图片数量
         $list["zoomcount"] = $zoomcount;
         $tempzoompics = array();
         for ($i = 1; $i <= $zoomcount; $i++) {
             $tempzoompics[$i - 1] = productzoompicpath($list, $i);
         }
         $list["tempzoompics"] = $tempzoompics;
         //    dump($tempzoompics);
         $detailcount = productdetailpiccount($list);
         //产品详细图片数量
         $list["detailcount"] = $detailcount;
         $tempdetailpics = array();
         for ($i = 1; $i <= $detailcount; $i++) {
             $tempdetailpics[$i - 1] = productdetailpicpath($list, $i);
         }
         $list["tempdetailpics"] = $tempdetailpics;
         //产品主图、细节图片、详情图片   end
         $this->list = $list;
         //获取Vip价格
         $this->vipPrice = VipPrice(get_real_price($list["price"], $list["pricespe"]));
         //上一产品,下一产品
         $prev = $dao->where(array("id" => array("lt", $pid), 'cateid' => $list['cateid']))->order('id desc')->find();
         $next = $dao->where(array("id" => array("gt", $pid), 'cateid' => $list['cateid']))->order('id asc')->find();
         if ($prev) {
             $this->prev = build_url($prev, 'pro_url');
         }
         if ($next) {
             $this->next = build_url($next, 'pro_url');
         }
         //获取产品属性
         $attrlist = $dao->get_attrs($list['cateid'], $pid);
         if ($attrlist) {
             foreach ($attrlist as $k => $val) {
                 $attrs[$val['name']] = $val;
             }
         }
         $this->attrs = $attrs;
         $this->attrcount = count($attrlist[0]['attrs']);
         //获取产品自身属性和关联产品的属性
         $product_ids = array($pid);
         $related_products_id = D('Products_related')->where("products_id={$pid}")->select();
         if ($related_products_id) {
             foreach ($related_products_id as $val) {
                 array_push($product_ids, $val['related_products_id']);
             }
         }
         sort($product_ids);
         foreach ($product_ids as $product_id) {
             $product_info = D('Products')->where("id=" . $product_id)->find();
             $related_attr_list[$product_id] = D('Products_attr')->get_attrs($product_info['cateid'], $product_id);
             $related_attr_list[$product_id]['product'] = $product_info;
         }
         $this->related_attr_list = $related_attr_list;
         if (!($realted_num = GetValue('realted_num'))) {
             $realted_num = 6;
         }
         //相同尺码相同颜色
         $Pro_attrView = D('Pro_attrView');
         $att_values = implode(',', array_map('reset', $Pro_attrView->field('attr_value')->where(array('products_id' => $pid))->select()));
         $attrs_same = array();
         foreach ($attrlist as $k => $attr) {
             $attrs_same[$k]['name'] = $attr['name'];
             $attrs_same[$k]['pro'] = $Pro_attrView->where(array('attr_value' => array('in', $att_values), 'cateid' => $list['cateid']))->group('id')->limit(5)->select();
         }
         $this->attrs_same = $attrs_same;
         //获取同类产品,用户还买了什么产品
         $sameclass = $dao->where(array('cateid' => $list['cateid']))->limit($realted_num)->select();
         $sameclass = $dao->rand($sameclass);
         //类别产品数量
         $this->cate_count = $dao->where(array('cateid' => $list['cateid']))->count();
         //产品位置
         $this->postion = reset($dao->field('count(*)+1 as postion')->where("id<'" . $pid . "' and cateid='" . $list['cateid'] . "'")->order('id desc')->find());
         //获取关联产品
         $Products_related_Model = D('Products_related');
         $related = $Products_related_Model->field('b.*')->table(C('DB_PREFIX') . 'products_related a')->join(C('DB_PREFIX') . 'products b on a.related_products_id=b.id')->where(array('a.products_id' => $pid))->limit($realted_num)->select();
         //获取关联产品的属性
         if ($related) {
             foreach ($related as $k => $val) {
                 $attrs = $dao->get_attrs($val['cateid'], $val['id']);
                 if ($attrs) {
                     foreach ($attrs as $at) {
                         $related[$k]['attrs'][$at['name']] = $at;
                     }
                 }
             }
         }
         //没有关联产品则随机
         //empty($related)? $related = $sameclass: $related = $dao->rand($related);
         $this->related = $related;
         $this->sameclass = $sameclass;
         //欢迎词
         $dao = D('Ad');
         $this->welcome = $dao->where(array('remark' => '产品内页欢迎词'))->getField('content');
         //获取产品相册
         $dao = D("Products_gallery");
         $gallerys = $dao->where("pid=" . $pid)->order("sort desc")->select();
         if (GetValue('auto_find_gallery')) {
             if (file_exists(__ROOT__ . $list['bigimage'])) {
                 $bigimage = pathinfo(__ROOT__ . $list['bigimage']);
                 $filename = $bigimage['filename'];
                 $dirname = $bigimage['dirname'];
                 $files = glob($dirname . '/' . $filename . '_*');
                 foreach ($files as $f) {
                     $gallerys[]['img_url'] = $f;
                 }
             }
         }
         $this->gallerys = $gallerys;
         $this->catep = get_catep_arr($list['cateid']);
         $classModel = D("Cate");
         //类别信息
         $this->cate = $cate = $classModel->where(array('id' => $list['cateid']))->find();
         $classid = $list['cateid'];
         $this->cateid = $classid;
         //SEO相关
         if (!empty($list['pagekey']) || !$classid) {
             $this->assign('pagekeywords', $list['pagekey']);
         } else {
             $this->assign('pagekeywords', $classModel->getKeywords($classid));
         }
         if (!empty($list['pagedec']) || !$classid) {
             $this->assign('pagedesc', $list['pagedec']);
         } else {
             $this->assign('pagedesc', $classModel->getDescription($classid));
         }
         if (!empty($list['pagetitle']) || !$classid) {
             $this->assign('pagetitle', $list['pagetitle']);
         } else {
             $this->assign('pagetitle', $classModel->getPageTitle($classid));
         }
         //评论数
         $products_ask = D('Products_ask');
         $this->review_num = $products_ask->where('products_id=' . $pid)->count();
         $this->review_list = $products_ask->where('products_id=' . $pid)->select();
         if (in_array($list['activity'], array('1'))) {
             switch ($list['activity']) {
                 case 1:
                     $PL_model = D('Products_lot');
                     $PL = array();
                     $PL['list'] = $PL_model->where("product_id={$pid}")->order('mincount asc')->select();
                     if ($PL['list']) {
                         $PL['minprice'] = $PL_model->where("product_id={$pid}")->order("maxcount desc")->getField('price');
                         $PL['maxprice'] = $PL_model->where("product_id={$pid}")->order("mincount asc")->getField('price');
                         $this->assign("PL", $PL);
                         $this->display('Empty:disp_lot');
                         die;
                     }
                     break;
             }
         }
         $this->display("Empty:disp");
     } else {
         $this->redirect('Index/index');
     }
 }
Esempio n. 3
0
 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');
 }
    <tr>
	 <td>
    <div id="btn_width">
		<div style="float:left; display:inline;"><a href="###"  onclick="return jQuery.addtocart();" ><img src="../Public/images/button_buy.jpg" alt="" border="0" /></a></div>
		<div style="float:right;"><a href="###"  onclick="jQuery.savecart();" id="savecart" ><img src="../Public/images/button_in_cart.jpg" alt="" border="0"/></a></div>
    </div>
    
	 <div id="cart_info">
    <div id="cart_alert" style="display:none"></div>
				<div id="cart_ok"  style="display:none">
					<img src="../Public/images/add_ok.jpg" border="0" usemap="#Map">
					<span class="cart_ok_content">Shopping Cart <a><?php 
echo itemCount();
?>
</a> items Total <?php 
echo getprice_str(cart_total());
?>
</span>
					<span><a href="###"  onclick="location.href='<?php 
echo U('Cart/disp');
?>
';" ><img src="../Public/images/button_check.jpg" alt="" border="0" /></a>
						<a href="###" onclick="jQuery.hide_cart_ok_content();"><img src="../Public/images/button_shopping.jpg" alt="" border="0" /></a>
					</span>
					
					<map name="Map" id="Map">
					  <area shape="rect" coords="198,-1,214,13" href="###" onclick="jQuery.hide_cart_ok_content();" />
					</map>
				</div>
    </div>
    </td>
 public function add_cart()
 {
     $count = I('post.count', 0, 'intval');
     $pid = I('post.id', 0, 'intval');
     $post = $_POST;
     if ($count <= 0) {
         $this->error("You did not select any product.");
     }
     if (empty($pid)) {
         $this->error("Please add goods to cart again.");
     }
     //强制登录
     if ($this->memberID <= 0 && GetValue('quickbuy') == 0) {
         $this->error('Please Log on.', U('MemberPublic/Login'));
     }
     $cartModel = D('Cart');
     $productModel = D('Products');
     $prolist = $productModel->where("id='{$pid}'")->find();
     $attrlist = $productModel->get_attrs($prolist['cateid'], $pid);
     //属性列表
     $i = 0;
     $attributes = array_keys($post['attr']);
     $attr_data = $no_select = array();
     //print_r($attrlist);
     //强制值不为空
     foreach ($attrlist as $k => $v) {
         if (($v['input_type'] == 0 || $v['input_type'] == 1) && in_array($v['name'], $attributes) && $post['attr'][$v['name']]) {
             $attr_data[$i]['name'] = $v['name'];
             $attr_value = explode('__', $post['attr'][$v['name']]);
             $attr_data[$i]['value'] = $attr_value[0];
             $attr_data[$i]['attr_price'] = $attr_value[1];
             $i++;
         } else {
             $no_select[] = $v['name'];
         }
     }
     if (count($no_select) > 0) {
         $this->error("Please select " . implode(',', $no_select) . '.');
     }
     $cartModel->add_item($this->sessionID, $pid, $count, serialize($attr_data));
     if (IS_AJAX) {
         $item_count = itemCount();
         $total_count = TotalCount();
         $price_total = getprice_str(cart_total());
         $data = array('status' => 1, 'info' => "Add {$_POST['count']} items Goods To Cart Successful</span>", 'item_count' => $item_count, 'total_count' => $total_count, 'price_total' => $price_total);
         $this->ajaxReturn($data);
     } else {
         $this->redirect('Cart/index');
     }
 }
Esempio n. 6
0
 /**
  * 未使用
  *
  */
 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");
     }
 }
Esempio n. 7
0
 public function payment()
 {
     //如果是快速购物则强制登录
     if ($this->memberID <= 0 && GetSettValue('quickbuy') == 0 && !$_SESSION['guest']) {
         Session::set('back', U('Cart/checked_payment'));
         $this->redirect('Member-Public/Login');
     }
     $orders_id = $_GET['id'];
     if (get_orders_status($orders_id) == L("orders_status_2")) {
         $this->error(L("orders_error_paied"));
     }
     //读取支付代码
     self::$Model = D("Orders");
     $list = self::$Model->where("id=" . $orders_id)->find();
     //转化成美元支付
     /*if($_SESSION ['currency']['symbol']!='USD'){
     		self::$Model=D('Currencies');
     		$rate=self::$Model->get_usd_rate();
     		$list['orders_total']=$list['orders_total']*$rate;
     		}*/
     if (!$list) {
         $this->redirect('Index/index');
     }
     $list['orders_total'] = round($list['orders_total'], 2);
     //四舍五入保留两位
     /**
      * 在线支付
      */
     $pname = $list['payment_module_code'];
     self::$Model = D('Payment');
     $payment_title = self::$Model->where(array('name' => $pname))->getField('title');
     //模板变量
     $this->title = ucwords($payment_title) . ' Payment';
     //标题
     $this->list = $list;
     import('@.ORG.Payment.' . $pname);
     if (class_exists($pname)) {
         $p = new $pname();
         $content = $p->create_form($list);
         //创建表单
         $this->content = $content;
         //用户说明
         $remark = GetSettValue($pname . '_desc');
         if ($remark) {
             $remark = str_replace(array('{sn}', '{time}', '{payname}', '{total}', '{go}', '{admin_email}'), array($list['sn'], toDate($list['dateline']), $list['payment_module_code'], getprice_str($list['orders_total']), "<input type=\"button\" value=\"Click Here\" onclick=\"document.forms['pay_form'].submit();\" />", GetSettValue('email')), $remark);
         }
         $this->remark = $remark;
         $this->display();
     } else {
         $this->error('Please select a payment method!');
     }
 }
 public function pment()
 {
     $orders_id = I('get.id', 0, 'intval');
     //如果是快速购物则强制登录
     if ($this->memberID <= 0 && GetValue('quickbuy') == 0) {
         $this->redirect('Admin/login');
     }
     //判断订单是否已支付成功
     $order_status = get_orders_status($orders_id);
     if ($order_status == '2') {
         $this->error('Orders Paid');
     }
     //读取支付代码
     $ordersModel = D('Orders');
     $list = $ordersModel->where("id='{$orders_id}'")->find();
     if (empty($list)) {
         $this->redirect('Index/index');
     }
     $list['orders_total'] = round($list['orders_total'], 2);
     //四舍五入保留两位
     /**
      * 在线支付
      */
     $pname = $list['payment_module_code'];
     $paymentModel = D('Payment');
     $payment_title = $paymentModel->where("name='{$pname}'")->getField('title');
     //模板变量
     $this->assign('title', ucwords($payment_title) . ' Payment');
     //标题
     $this->assign('list', $list);
     import("@.Org.Payment." . $pname);
     if (class_exists($pname)) {
         $p = new $pname();
         $content = $p->create_form($list);
         //创建表单
         $this->assign('content', $content);
         //用户说明
         $remark = GetValue($pname . '_desc');
         if ($remark) {
             $remark = str_replace(array('{sn}', '{time}', '{payname}', '{total}', '{go}', '{admin_email}'), array($list['sn'], toDate($list['dateline']), $list['payment_module_code'], getprice_str($list['orders_total']), "<input type=\"button\" value=\"Click Here\" onclick=\"document.forms['pay_form'].submit();\" />", GetValue('email')), $remark);
         }
         $this->assign('remark', $remark);
         $this->display('Cart-payment');
     } else {
         $this->error('Please select a payment method.', U('Orders/index'));
     }
 }