public function getpriceInfo($pid, $count, $model)
 {
     $list = $this->where("id='{$pid}'")->find();
     if (empty($list)) {
         return false;
     }
     $model_price = $this->model_attr_price($model);
     $list['price'] = (double) (VipPrice($list['price']) + $model_price);
     $list['pricespe'] = (double) (VipPrice($list['pricespe']) + $model_price);
     $list['count'] = $count;
     $ginfo = get_members_group(session('memberID'));
     $list['discount'] = $ginfo['discount'] ? $ginfo['discount'] : 1;
     $list['price_total'] = $list['price'] * $count;
     $list['pricespe_total'] = $list['pricespe'] * $count;
     //优惠活动,1为批发
     if (in_array($list['activity'], array('1'))) {
         switch ($list['activity']) {
             case 1:
                 $PL_model = D('Products_lot');
                 $data = $PL_model->where(array('product_id' => $pid))->select();
                 $maxcount = $PL_model->where("product_id='{$pid}'")->order("maxcount desc")->find();
                 foreach ($data as $k => $v) {
                     if ($count >= $v['mincount'] && $count <= $v['maxcount']) {
                         $list['pricespe'] = $list['price'] = (double) $v['price'];
                         $list['price_total'] = $list['price'] * $count;
                         $list['pricespe_total'] = $list['pricespe'] * $count;
                         break 2;
                     } elseif ($count >= $maxcount['maxcount']) {
                         $list['pricespe'] = $list['price'] = (double) $maxcount['price'];
                         $list['price_total'] = $list['price'] * $count;
                         $list['pricespe_total'] = $list['pricespe'] * $count;
                         break 2;
                     }
                 }
                 break;
         }
     }
     if ($list['price_total'] <= $list['pricespe_total'] && $list['price_total']) {
         $list['total'] = $list['price_total'];
     } else {
         $list['total'] = $list['pricespe_total'];
     }
     if ($discount > 0) {
         $list['total'] = $list['total'] * $discount;
     }
     return $list;
 }
示例#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');
     }
 }