caching = true; } $affiliate = unserialize($GLOBALS['_CFG']['affiliate']); $smarty->assign('affiliate', $affiliate); /*------------------------------------------------------ */ //-- INPUT /*------------------------------------------------------ */ $goods_id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0; /* 代码增加_start By xiaohua */ if ($goods_id==0) { if (!empty($_REQUEST['defurl'])) { $define_url=trim($_REQUEST['defurl']); $goods_id=$db->getOne("select goods_id from ". $ecs->table("goods")." where define_url='$define_url' " ); $goods_id=$goods_id ? $goods_id : intval($_REQUEST['defurl']); } } /* 代码增加_end By xiaohua */ /*------------------------------------------------------ */ //-- 改变属性、数量时重新计算商品价格 /*------------------------------------------------------ */ if (!empty($_REQUEST['act']) && $_REQUEST['act'] == 'price') { include('includes/cls_json.php'); $json = new JSON; $res = array('err_msg' => '', 'result' => '', 'qty' => 1); $attr_id = isset($_REQUEST['attr']) ? explode(',', $_REQUEST['attr']) : array(); $number = (isset($_REQUEST['number'])) ? intval($_REQUEST['number']) : 1; if ($goods_id == 0) { $res['err_msg'] = $_LANG['err_change_attr']; $res['err_no'] = 1; } else { if ($number == 0) { $res['qty'] = $number = 1; } else { $res['qty'] = $number; } $shop_price = get_final_price($goods_id, $number, true, $attr_id); $res['result'] = price_format($shop_price * $number); } die($json->encode($res)); } /*------------------------------------------------------ */ //-- 商品购买记录ajax处理 /*------------------------------------------------------ */ if (!empty($_REQUEST['act']) && $_REQUEST['act'] == 'gotopage') { include('includes/cls_json.php'); $json = new JSON; $res = array('err_msg' => '', 'result' => ''); $goods_id = isset($_REQUEST['id']) ? intval($_REQUEST['id']) : 0; $page = (isset($_REQUEST['page'])) ? intval($_REQUEST['page']) : 1; if (!empty($goods_id)) { $need_cache = $GLOBALS['smarty']->caching; $need_compile = $GLOBALS['smarty']->force_compile; $GLOBALS['smarty']->caching = false; $GLOBALS['smarty']->force_compile = true; /* 商品购买记录 */ // ECShop 紀? $sql = 'SELECT u.user_name, og.goods_number,oi.address,oi.pay_time,oi.shipping_time, oi.add_time, IF(oi.order_status IN (2, 3, 4), 0, 1) AS order_status ' . 'FROM ' . $ecs->table('order_info') . ' AS oi LEFT JOIN ' . $ecs->table('users') . ' AS u ON oi.user_id = u.user_id, ' . $ecs->table('order_goods') . ' AS og ' . 'WHERE oi.order_id = og.order_id AND og.goods_id = ' . $goods_id . ' ORDER BY oi.add_time DESC LIMIT ' . (($page > 1) ? ($page-1) : 0) * 100 . ',100'; $bought_notes = $GLOBALS['db']->getAll($sql); foreach ($bought_notes as $key => $val) { $chinese = mb_detect_encoding($val['address'], "big5, gb2312"); if ($chinese == "BIG-5") $val['address'] = substr($val['address'], 10, -10); else $val['address'] = mb_substr($val['address'], 0, -5, 'utf-8'); //seo内链插件 start if(file_exists('data/auto_neilian.php')) { $content = file_get_contents("data/auto_neilian.php"); $array = explode("\r\n",$content); foreach ($array AS $value) { $tmp = explode("---",$value); if ($tmp !== false) if($tmp[1]) $str = "".$tmp[0].""; else $str = "".$tmp[0].""; $str_1 = $tmp[0]; $str_2 = $str; $tmp2 = $val['address']; if (substr($tmp2[0],0,1)!="a" && substr($tmp2[0],0,1)!="A") $val['address'] = str_ireplace($str_1,$str_2,$tmp2); } } //seo内链插件 end $val['user_name'] = mb_substr($val['user_name'], 0, -3, 'utf-8'); //$strlen = strlen($val['address']); //$right = $strlen-7; //$left = $strlen -25; //$val['address']=mb_substr($val['address'],0,$right); //$val['address']=mb_substr($val['address'],10,strlen($val['address'])-15); $bought_notes[$key]['user_name'] = $val['user_name']."*****"; if ($chinese == "BIG-5") $bought_notes[$key]['address'] = '**********'.$val['address']; else $bought_notes[$key]['address'] = $val['address']."*******"; $bought_notes[$key]['add_time'] = local_date("Y-m-d", $val['add_time']); $bought_notes[$key]['pay_time'] = local_date("Y-m-d", $val['pay_time']); if ($val['shipping_time'] != "0") $bought_notes[$key]['shipping_time'] = local_date("Y-m-d", $val['shipping_time']); else { if ($bought_notes[$key]['pay_time'] != "") { if (date("Y-m-d", strtotime(date("Y-m-d", $val['pay_time']) . " +3 weeks")) > date("Y-m-d")) $bought_notes[$key+$old_key]['shipping_time'] = ""; else $bought_notes[$key+$old_key]['shipping_time'] = date("Y-m-d", strtotime(date("Y-m-d", $val['pay_time']) . " +3 weeks")); } else $bought_notes[$key+$old_key]['shipping_time'] = ""; } } $sql = 'SELECT count(*) ' . 'FROM ' . $ecs->table('order_info') . ' AS oi LEFT JOIN ' . $ecs->table('users') . ' AS u ON oi.user_id = u.user_id, ' . $ecs->table('order_goods') . ' AS og ' . 'WHERE oi.order_id = og.order_id AND og.goods_id = ' . $goods_id; $count = $db->getOne($sql); /* 商品购买记录分页样式 */ $pager = array(); $pager['page'] = $page; $pager['size'] = $size = 100; $pager['record_count'] = $count; $pager['page_count'] = $page_count = ($count > 0) ? intval(ceil($count / $size)) : 1;; $pager['page_first'] = "javascript:gotoBuyPage(1,$goods_id)"; $pager['page_prev'] = $page > 1 ? "javascript:gotoBuyPage(" .($page-1). ",$goods_id)" : 'javascript:;'; $pager['page_next'] = $page < $page_count ? 'javascript:gotoBuyPage(' .($page + 1) . ",$goods_id)" : 'javascript:;'; $pager['page_last'] = $page < $page_count ? 'javascript:gotoBuyPage(' .$page_count. ",$goods_id)" : 'javascript:;'; $smarty->assign('notes', $bought_notes); $smarty->assign('pager', $pager); $res['result'] = $GLOBALS['smarty']->fetch('library/bought_notes.lbi'); $GLOBALS['smarty']->caching = $need_cache; $GLOBALS['smarty']->force_compile = $need_compile; } die($json->encode($res)); } /*------------------------------------------------------ */ //-- PROCESSOR /*------------------------------------------------------ */ $cache_id = $goods_id . '-' . $_SESSION['user_rank'].'-'.$_CFG['lang']; $cache_id = sprintf('%X', crc32($cache_id)); if (!$smarty->is_cached('goods.dwt', $cache_id)) { $smarty->assign('image_width', $_CFG['image_width']); $smarty->assign('image_height', $_CFG['image_height']); $smarty->assign('helps', get_shop_help()); // 网店帮助 $smarty->assign('id', $goods_id); $smarty->assign('type', 0); $smarty->assign('cfg', $_CFG); $smarty->assign('promotion', get_promotion_info($goods_id));//促销信息 $smarty->assign('promotion_info', get_promotion_info()); /* 获得商品的信?*/ $goods = get_goods_info($goods_id); if ($goods === false) { /* 如果没有找到任何记录则跳回到首页 */ ecs_header("Location: ./\n"); exit; } else { //seo内链插件 start if(file_exists('data/auto_neilian.php')){ $content = file_get_contents("data/auto_neilian.php"); $array = explode("\r\n",$content); foreach ($array AS $value){ $tmp = explode("---",$value); if ($tmp !== false){ if($tmp[1]){ $str = "湖北快三"; } else{ $str = "".$tmp[0].""; } $str_1 = $tmp[0]; $str_2 = $str; $tmp1 = explode("<",$goods['goods_desc']); foreach ($tmp1 as $key=>$item){ $tmp2 = explode(">",$item); if (sizeof($tmp2)>1) { if (substr($tmp2[0],0,1)!="a" && substr($tmp2[0],0,1)!="A"){ $tmp2[1] = str_ireplace($str_1,$str_2,$tmp2[1]); $tmp1[$key] = implode(">",$tmp2); } } } $goods['goods_desc'] = implode("<",$tmp1); } } } //seo内链插件 end if ($goods['brand_id'] > 0) { $goods['goods_brand_url'] = build_uri('brand', array('bid'=>$goods['brand_id']), $goods['goods_brand']); } $shop_price = $goods['shop_price']; $linked_goods = get_linked_goods($goods_id); $goods['goods_style_name'] = add_style($goods['goods_name'], $goods['goods_name_style']); /* 购买该商品可以得到多少钱的红?*/ if ($goods['bonus_type_id'] > 0) { $time = gmtime(); $sql = "SELECT type_money FROM " . $ecs->table('bonus_type') . " WHERE type_id = '$goods[bonus_type_id]' " . " AND send_type = '" . SEND_BY_GOODS . "' " . " AND send_start_date <= '$time'" . " AND send_end_date >= '$time'"; $goods['bonus_money'] = floatval($db->getOne($sql)); if ($goods['bonus_money'] > 0) { $goods['bonus_money'] = price_format($goods['bonus_money']); } } $smarty->assign('goods', $goods); $smarty->assign('goods_id', $goods['goods_id']); $smarty->assign('promote_end_time', $goods['gmt_end_time']); $smarty->assign('categories', get_categories_tree($goods['cat_id'])); // 分类? if (mb_substr($goods['goods_brief'], 0, 1, 'utf-8') == "?) $smarty->assign('calc_length', mb_substr($goods['goods_brief'], 0, 1, 'utf-8')); else $smarty->assign('calc_length', "?); if (mb_substr($goods['goods_brief'], 2, 1, 'utf-8') == "? || mb_substr($goods['goods_brief'], 2, 1, 'utf-8') == "?) $smarty->assign('calc_width', mb_substr($goods['goods_brief'], 2, 1, 'utf-8')); else $smarty->assign('calc_width', "?); if (mb_substr($goods['goods_brief'], 0, 1, 'utf-8') == "?) $smarty->assign('calc_height', mb_substr($goods['goods_brief'], 4, 1, 'utf-8')); else $smarty->assign('calc_height', "?); /* meta */ $smarty->assign('keywords', htmlspecialchars($goods['keywords'])); $smarty->assign('description', htmlspecialchars($goods['goods_brief'])); $catlist = array(); foreach(get_parent_cats($goods['cat_id']) as $k=>$v) { $catlist[] = $v['cat_id']; } assign_template('c', $catlist); /* 上一个商品下一个商?*/ $prev_gid = $db->getOne("SELECT goods_id FROM " .$ecs->table('goods'). " WHERE cat_id=" . $goods['cat_id'] . " AND goods_id > " . $goods['goods_id'] . " AND is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0 LIMIT 1"); if (!empty($prev_gid)) { $prev_good['url'] = build_uri('goods', array('gid' => $prev_gid), $goods['goods_name']); $smarty->assign('prev_good', $prev_good);//上一个商? } $next_gid = $db->getOne("SELECT max(goods_id) FROM " . $ecs->table('goods') . " WHERE cat_id=".$goods['cat_id']." AND goods_id < ".$goods['goods_id'] . " AND is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0"); if (!empty($next_gid)) { $next_good['url'] = build_uri('goods', array('gid' => $next_gid), $goods['goods_name']); $smarty->assign('next_good', $next_good);//下一个商? } $position = assign_ur_here($goods['cat_id'], $goods['goods_name']); /* current position */ //$smarty->assign('page_title', $position['title']); // 页面标题 $smarty->assign('page_title', trim($goods['seo_title']) ? $goods['seo_title']:$position['title']); // 页面标题 $smarty->assign('ur_here', $position['ur_here']); // 当前位置 $properties = get_goods_properties($goods_id); // 获得商品的规格和属? $smarty->assign('properties', $properties['pro']); // 商品属? $smarty->assign('specification', $properties['spe']); // 商品规格 $smarty->assign('attribute_linked', get_same_attribute_goods($properties)); // 相同属性的关联商品 $smarty->assign('related_goods', $linked_goods); // 关联商品 $smarty->assign('goods_article_list', get_linked_articles($goods_id)); $smarty->assign('goods_real_image', get_customer_image($goods_id)); // 关联文章 $smarty->assign('fittings', get_goods_fittings(array($goods_id))); // 配件 $smarty->assign('rank_prices', get_user_rank_prices($goods_id, $shop_price)); // 会员等级价格 $smarty->assign('pictures', get_goods_gallery($goods_id)); // 商品相册 $smarty->assign('bought_goods', get_also_bought($goods_id)); // 购买了该商品的用户还购买了哪些商? $smarty->assign('goods_rank', get_goods_rank($goods_id)); // 商品的销售排? $smarty->assign('how_to_buy', get_how_to_buy()); // 如何購買 //获取tag $tag_array = get_tags($goods_id); $smarty->assign('tags', $tag_array); // 商品的标? //获取关联礼包 $package_goods_list = get_package_goods_list($goods['goods_id']); $smarty->assign('package_goods_list',$package_goods_list); // 获取关联礼包 /* 代码增加_start By . */ $package_goods_list_120 = get_package_goods_list_120($goods['goods_id']); $smarty->assign('package_goods_list_120',$package_goods_list_120); // /* 代码增加_end By . */ assign_dynamic('goods'); $volume_price_list = get_volume_price_list($goods['goods_id'], '1'); $smarty->assign('volume_price_list',$volume_price_list); // 商品优惠价格区间 } } /* 记录浏览历史 */ if (!empty($_COOKIE['ECS']['history'])) { $history = explode(',', $_COOKIE['ECS']['history']); array_unshift($history, $goods_id); $history = array_unique($history); while (count($history) > $_CFG['history_number']) { array_pop($history); } setcookie('ECS[history]', implode(',', $history), gmtime() + 3600 * 24 * 30); } else { setcookie('ECS[history]', $goods_id, gmtime() + 3600 * 24 * 30); } /* 更新点击次数 */ $db->query('UPDATE ' . $ecs->table('goods') . " SET click_count = click_count + 37 WHERE goods_id = '$_REQUEST[id]'"); $smarty->assign('now_time', gmtime()); // 当前系统时间 $smarty->display('goods.dwt', $cache_id); /*------------------------------------------------------ */ //-- PRIVATE FUNCTION /*------------------------------------------------------ */ /** * 获得指定商品的关联商? * * @access public * @param integer $goods_id * @return array */ function get_linked_goods($goods_id) { $sql = 'SELECT g.goods_id, g.goods_name, g.goods_thumb, g.goods_img, g.shop_price AS org_price, ' . "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ". 'g.market_price, g.promote_price, g.promote_start_date, g.promote_end_date ' . 'FROM ' . $GLOBALS['ecs']->table('link_goods') . ' lg ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ON g.goods_id = lg.link_goods_id ' . "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ". "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ". "WHERE lg.goods_id = '$goods_id' AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ". "LIMIT " . $GLOBALS['_CFG']['related_goods_number']; $res = $GLOBALS['db']->query($sql); $arr = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { $arr[$row['goods_id']]['goods_id'] = $row['goods_id']; $arr[$row['goods_id']]['goods_name'] = $row['goods_name']; $arr[$row['goods_id']]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; $arr[$row['goods_id']]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); $arr[$row['goods_id']]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); $arr[$row['goods_id']]['market_price'] = price_format($row['market_price']); $arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']); $arr[$row['goods_id']]['url'] = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']); if ($row['promote_price'] > 0) { $arr[$row['goods_id']]['promote_price'] = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); $arr[$row['goods_id']]['formated_promote_price'] = price_format($arr[$row['goods_id']]['promote_price']); } else { $arr[$row['goods_id']]['promote_price'] = 0; } } return $arr; } /** * 获得指定商品的关联文? * * @access public * @param integer $goods_id * @return void */ function get_linked_articles($goods_id) { $sql = 'SELECT a.* ' . 'FROM ' . $GLOBALS['ecs']->table('goods_article') . ' AS g, ' . $GLOBALS['ecs']->table('article') . ' AS a ' . "WHERE g.article_id = a.article_id AND g.goods_id = '$goods_id' AND a.is_open = 1 " . 'ORDER BY a.add_time DESC'; $res = $GLOBALS['db']->query($sql); $arr = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { $row['url'] = $row['open_type'] != 1 ? build_uri('article', array('aid'=>$row['article_id']), $row['title']) : trim($row['file_url']); $row['add_time'] = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']); $row['short_title'] = $GLOBALS['_CFG']['article_title_length'] > 0 ? sub_str($row['title'], $GLOBALS['_CFG']['article_title_length']) : $row['title']; $arr[] = $row; } return $arr; } /** * 获得如何購買 * * @access public * @return void */ function get_how_to_buy() { $sql = 'SELECT * FROM ' . $GLOBALS['ecs']->table('article') . ' WHERE article_id = "46"'; $res = $GLOBALS['db']->query($sql); $arr = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { $arr[] = $row; } return $arr; } /** * 获得指定商品的各会员等级对应的价? * * @access public * @param integer $goods_id * @return array */ function get_user_rank_prices($goods_id, $shop_price) { $sql = "SELECT rank_id, IFNULL(mp.user_price, r.discount * $shop_price / 100) AS price, r.rank_name, r.discount " . 'FROM ' . $GLOBALS['ecs']->table('user_rank') . ' AS r ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . " AS mp ". "ON mp.goods_id = '$goods_id' AND mp.user_rank = r.rank_id " . "WHERE r.show_price = 1 OR r.rank_id = '$_SESSION[user_rank]'"; $res = $GLOBALS['db']->query($sql); $arr = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { $arr[$row['rank_id']] = array( 'rank_name' => htmlspecialchars($row['rank_name']), 'price' => price_format($row['price'])); } return $arr; } /** * 获得购买过该商品的人还买过的商品 * * @access public * @param integer $goods_id * @return array */ function get_also_bought($goods_id) { $sql = 'SELECT COUNT(b.goods_id ) AS num, g.goods_id, g.goods_name, g.goods_thumb, g.goods_img, g.shop_price, g.promote_price, g.promote_start_date, g.promote_end_date ' . 'FROM ' . $GLOBALS['ecs']->table('order_goods') . ' AS a ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('order_goods') . ' AS b ON b.order_id = a.order_id ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ON g.goods_id = b.goods_id ' . "WHERE a.goods_id = '$goods_id' AND b.goods_id <> '$goods_id' AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 " . 'GROUP BY b.goods_id ' . 'ORDER BY num DESC ' . 'LIMIT ' . $GLOBALS['_CFG']['bought_goods']; $res = $GLOBALS['db']->query($sql); $key = 0; $arr = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { $arr[$key]['goods_id'] = $row['goods_id']; $arr[$key]['goods_name'] = $row['goods_name']; $arr[$key]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; $arr[$key]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); $arr[$key]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); $arr[$key]['shop_price'] = price_format($row['shop_price']); $arr[$key]['url'] = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']); if ($row['promote_price'] > 0) { $arr[$key]['promote_price'] = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); $arr[$key]['formated_promote_price'] = price_format($arr[$key]['promote_price']); } else { $arr[$key]['promote_price'] = 0; } $key++; } return $arr; } /** * 获得指定商品的销售排? * * @access public * @param integer $goods_id * @return integer */ function get_goods_rank($goods_id) { /* 统计时间?*/ $period = intval($GLOBALS['_CFG']['top10_time']); if ($period == 1) // 一? { $ext = " AND o.add_time > '" . local_strtotime('-1 years') . "'"; } elseif ($period == 2) // 半年 { $ext = " AND o.add_time > '" . local_strtotime('-6 months') . "'"; } elseif ($period == 3) // 三个? { $ext = " AND o.add_time > '" . local_strtotime('-3 months') . "'"; } elseif ($period == 4) // 一个月 { $ext = " AND o.add_time > '" . local_strtotime('-1 months') . "'"; } else { $ext = ''; } /* 查询该商品销?*/ $sql = 'SELECT IFNULL(SUM(g.goods_number), 0) ' . 'FROM ' . $GLOBALS['ecs']->table('order_info') . ' AS o, ' . $GLOBALS['ecs']->table('order_goods') . ' AS g ' . "WHERE o.order_id = g.order_id " . "AND o.order_status = '" . OS_CONFIRMED . "' " . "AND o.shipping_status " . db_create_in(array(SS_SHIPPED, SS_RECEIVED)) . " AND o.pay_status " . db_create_in(array(PS_PAYED, PS_PAYING)) . " AND g.goods_id = '$goods_id'" . $ext; $sales_count = $GLOBALS['db']->getOne($sql); if ($sales_count > 0) { /* 只有在商品销售量大于0时才去计算该商品的排?*/ $sql = 'SELECT DISTINCT SUM(goods_number) AS num ' . 'FROM ' . $GLOBALS['ecs']->table('order_info') . ' AS o, ' . $GLOBALS['ecs']->table('order_goods') . ' AS g ' . "WHERE o.order_id = g.order_id " . "AND o.order_status = '" . OS_CONFIRMED . "' " . "AND o.shipping_status " . db_create_in(array(SS_SHIPPED, SS_RECEIVED)) . " AND o.pay_status " . db_create_in(array(PS_PAYED, PS_PAYING)) . $ext . " GROUP BY g.goods_id HAVING num > $sales_count"; $res = $GLOBALS['db']->query($sql); $rank = $GLOBALS['db']->num_rows($res) + 1; if ($rank > 10) { $rank = 0; } } else { $rank = 0; } return $rank; } /** * 获得商品选定的属性的附加总价? * * @param integer $goods_id * @param array $attr * * @return void */ function get_attr_amount($goods_id, $attr) { $sql = "SELECT is_mask_price FROM " . $GLOBALS['ecs']->table('goods') . " WHERE goods_id='$goods_id'"; if ($GLOBALS['db']->getOne($sql) == 1) return -1; else $sql = "SELECT SUM(attr_price) FROM " . $GLOBALS['ecs']->table('goods_attr') . " WHERE goods_id='$goods_id' AND " . db_create_in($attr, 'goods_attr_id'); return $GLOBALS['db']->getOne($sql); } /** * 取得跟商品关联的礼包列表 * * @param string $goods_id 商品编号 * * @return 礼包列表 */ function get_package_goods_list($goods_id) { $now = gmtime(); $sql = "SELECT MAX(pg.goods_id), ga.act_id, ga.act_name, ga.act_desc, ga.goods_name, ga.start_time, ga.end_time, ga.is_finished, ga.ext_info FROM " . $GLOBALS['ecs']->table('goods_activity') . " AS ga, " . $GLOBALS['ecs']->table('package_goods') . " AS pg WHERE pg.package_id = ga.act_id AND ga.start_time <= '" . $now . "' AND ga.end_time >= '" . $now . "' AND pg.goods_id = " . $goods_id . " GROUP BY pg.goods_id ORDER BY ga.act_id"; $res = $GLOBALS['db']->getAll($sql); foreach ($res as $tempkey => $value) { $subtotal = 0; $row = unserialize($value['ext_info']); unset($value['ext_info']); if ($row) { foreach ($row as $key=>$val) { $res[$tempkey][$key] = $val; } } $sql = "SELECT pg.package_id, pg.goods_id, pg.goods_number, pg.admin_id, p.goods_attr, g.goods_sn, g.goods_name, g.market_price, g.goods_thumb, IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS rank_price FROM " . $GLOBALS['ecs']->table('package_goods') . " AS pg LEFT JOIN ". $GLOBALS['ecs']->table('goods') . " AS g ON g.goods_id = pg.goods_id LEFT JOIN ". $GLOBALS['ecs']->table('products') . " AS p ON p.product_id = pg.product_id LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' WHERE pg.package_id = " . $value['act_id']. " ORDER BY pg.package_id, pg.goods_id"; $goods_res = $GLOBALS['db']->getAll($sql); foreach($goods_res as $key => $val) { $goods_id_array[] = $val['goods_id']; $goods_res[$key]['goods_thumb'] = get_image_path($val['goods_id'], $val['goods_thumb'], true); $goods_res[$key]['market_price'] = price_format($val['market_price']); $goods_res[$key]['rank_price'] = price_format($val['rank_price']); $subtotal += $val['rank_price'] * $val['goods_number']; } /* 取商品属?*/ $sql = "SELECT ga.goods_attr_id, ga.attr_value FROM " .$GLOBALS['ecs']->table('goods_attr'). " AS ga, " .$GLOBALS['ecs']->table('attribute'). " AS a WHERE a.attr_id = ga.attr_id AND a.attr_type = 1 AND " . db_create_in($goods_id_array, 'goods_id'); $result_goods_attr = $GLOBALS['db']->getAll($sql); $_goods_attr = array(); foreach ($result_goods_attr as $value) { $_goods_attr[$value['goods_attr_id']] = $value['attr_value']; } /* 处理货品 */ $format = '[%s]'; foreach($goods_res as $key => $val) { if ($val['goods_attr'] != '') { $goods_attr_array = explode('|', $val['goods_attr']); $goods_attr = array(); foreach ($goods_attr_array as $_attr) { $goods_attr[] = $_goods_attr[$_attr]; } $goods_res[$key]['goods_attr_str'] = sprintf($format, implode('?, $goods_attr)); } } $res[$tempkey]['goods_list'] = $goods_res; $res[$tempkey]['subtotal'] = price_format($subtotal); $res[$tempkey]['saving'] = price_format(($subtotal - $res[$tempkey]['package_price'])); $res[$tempkey]['package_price'] = price_format($res[$tempkey]['package_price']); } return $res; } /* 代码增加_start By . */ function get_package_goods_list_120($goods_id) { $now = gmtime(); $sql = "SELECT ga.act_id,ga.ext_info FROM " . $GLOBALS['ecs']->table('goods_activity') . " AS ga, " . $GLOBALS['ecs']->table('package_goods') . " AS pg WHERE pg.package_id = ga.act_id AND ga.start_time <= '" . $now . "' AND ga.end_time >= '" . $now . "' AND pg.goods_id = " . $goods_id . " GROUP BY pg.package_id ORDER BY ga.act_id"; $res = $GLOBALS['db']->getAll($sql); foreach ($res as $tempkey => $value) { $subtotal = 0; $i=1; //获取礼包? $row = unserialize($value['ext_info']); unset($value['ext_info']); if ($row) { foreach ($row as $key=>$val) { $res[$tempkey][$key] = $val; } } $sql = "SELECT pg.package_id, pg.goods_id, pg.product_id, pg.goods_number, pg.admin_id, p.goods_attr, g.goods_sn, g.goods_name, g.market_price, g.goods_thumb, IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS rank_price, g.goods_sn AS short_name, g.goods_sn AS url FROM " . $GLOBALS['ecs']->table('package_goods') . " AS pg LEFT JOIN ". $GLOBALS['ecs']->table('goods') . " AS g ON g.goods_id = pg.goods_id LEFT JOIN ". $GLOBALS['ecs']->table('products') . " AS p ON p.product_id = pg.product_id LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' WHERE pg.package_id = " . $value['act_id']. " ORDER BY pg.package_id, pg.goods_id"; $goods_ress = $GLOBALS['db']->query($sql); $goods_res = array(); while ($row = $GLOBALS['db']->fetchRow($goods_ress)) { if ($row['goods_id'] == $goods_id ) { $goods_res[0]=$row; } else { $goods_res[$i]=$row; $i++; } } foreach($goods_res as $key => $val) { $goods_id_array[] = $val['goods_id']; $sql = mysql_query("SELECT attr_value FROM ".$GLOBALS['ecs']->table('goods_attr')." WHERE goods_id = '".$val['goods_id']."' AND attr_id IN (SELECT attr_id FROM ".$GLOBALS['ecs']->table('attribute')." WHERE attr_name = '商品描述')"); if (mysql_num_rows($sql) == 1) $goods_res[$key]['short_name'] = mysql_result($sql, 0); $goods_res[$key]['url'] = build_uri('goods', array('gid'=>$val['goods_id']), $val['goods_name']); $goods_res[$key]['goods_thumb'] = get_image_path($val['goods_id'], $val['goods_thumb'], true); $goods_res[$key]['market_price'] = price_format($val['market_price']); $goods_res[$key]['rank_price'] = $val['rank_price'] * $val['goods_number']; $goods_res[$key]['goods_number'] = $val['goods_number']; $subtotal += $val['rank_price'] * $val['goods_number']; } /* 取商品属?*/ $sql = "SELECT ga.goods_attr_id, ga.attr_value FROM " .$GLOBALS['ecs']->table('goods_attr'). " AS ga, " .$GLOBALS['ecs']->table('attribute'). " AS a WHERE a.attr_id = ga.attr_id AND a.attr_type = 1 AND " . db_create_in($goods_id_array, 'goods_id'); $result_goods_attr = $GLOBALS['db']->getAll($sql); $_goods_attr = array(); foreach ($result_goods_attr as $value) { $_goods_attr[$value['goods_attr_id']] = $value['attr_value']; } /* 处理货品 */ $format = '[%s]'; foreach($goods_res as $key => $val) { if ($val['goods_attr'] != '') { $goods_attr_array = explode('|', $val['goods_attr']); $goods_attr = array(); foreach ($goods_attr_array as $_attr) { $goods_attr[] = $_goods_attr[$_attr]; } $goods_res[$key]['goods_attr_str'] = sprintf($format, implode('?, $goods_attr)); } } ksort($goods_res); //重新排序数组 /* 重新计算套餐内的商品折扣?*/ $res[$tempkey]['total_price']=$subtotal + $res[$tempkey]['install_price']; $res[$tempkey]['discount'] = round($res[$tempkey]['package_price'] / $res[$tempkey]['total_price'] * 100, 0); $last = $res[$tempkey]['discount'] % 10; switch($last) { case 0: $last = 0; break; case 1: $last = 0; break; case 2: $last = 0; break; case 3: $last = 0; break; case 4: $last = 5; break; case 5: $last = 5; break; case 6: $last = 5; break; case 7: $last = 5; break; case 8: $last = 5; break; case 9: $last = 0; break; } $res[$tempkey]['discount'] = substr($res[$tempkey]['discount'], 0, 1).$last; $res[$tempkey]['total_price'] = number_format($res[$tempkey]['total_price'], 0, '', ','); $res[$tempkey]['package_price'] = number_format($res[$tempkey]['package_price'], 0, '', ','); $res[$tempkey]['goods_list'] = $goods_res; } return $res; } /* 代码增加_start By . */ function get_customer_image($goods_id) { $sql = "SELECT content FROM ".$GLOBALS['ecs']->table('article')." WHERE article_id IN (SELECT article_id FROM ".$GLOBALS['ecs']->table('goods_article')." WHERE goods_id = '$goods_id') AND title LIKE '%客戶實拍'"; return $GLOBALS['db']->getOne($sql); } ?>
  • ͳкɫ 罨츣 2018-09-18
  • Ϻ԰ռȳ 2018-07-25
  • лɭרйҵ 2018-07-25
  • ϰƽͬ˹̹ͳҮл̸ 2018-07-24
  • ˰ѡƸչ 2018-07-23
  • СίίԱί 2018-07-22
  • ʦ۶ ¸齲۶-ʱѶ 2018-07-22
  • ̫2018ﰺ˿֮·̫гĻ 2018-07-21
  • ŮԱýǡ 2018-07-20
  • ʮŴҰйλ 2018-07-20
  • йͦԱ۲죩 2018-07-19