/** * 获得推荐商品 * * @access public * @param string $type 推荐类型,可以是 best, new, hot * @return array */ function get_index_best($limit = '') { $time = gmtime(); //取出所有符合条件的商品数据,并将结果存入对应的推荐类型数组中 $sql = 'SELECT g.goods_id, g.goods_name,g.click_count, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, " . "promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, g.goods_img, RAND() AS rnd " . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp " . "ON mp.goods_id = g.goods_id AND mp.user_rank = '{$_SESSION['user_rank']}' "; $sql .= ' WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND g.is_best = "best" '; $sql .= ' ORDER BY g.sort_order, g.last_update DESC'; $sql .= " {$limit}"; $result = $GLOBALS['db']->getAll($sql); foreach ($result as $idx => $row) { if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); $goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; } else { $goods[$idx]['promote_price'] = ''; } $goods[$idx]['id'] = $row['goods_id']; $goods[$idx]['name'] = $row['goods_name']; $goods[$idx]['brief'] = $row['goods_brief']; $goods[$idx]['brand_name'] = isset($goods_data['brand'][$row['goods_id']]) ? $goods_data['brand'][$row['goods_id']] : ''; $goods[$idx]['goods_style_name'] = add_style($row['goods_name'], $row['goods_name_style']); $goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; $goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'], $row['goods_name_style']); $goods[$idx]['market_price'] = price_format($row['market_price']); $goods[$idx]['shop_price'] = price_format($row['shop_price']); $goods[$idx]['thumb'] = '../' . get_image_path($row['goods_id'], $row['goods_thumb'], true); $goods[$idx]['goods_img'] = '../' . get_image_path($row['goods_id'], $row['goods_img']); $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); $goods[$idx]['sell_count'] = selled_count($row['goods_id']); $goods[$idx]['pinglun'] = get_evaluation_sum($row['goods_id']); $goods[$idx]['count'] = selled_count($row['goods_id']); $goods[$idx]['click_count'] = $row['click_count']; } return $goods; }
function brand_get_goodsex($brand_id, $cate, $size, $page, $sort, $order) { $cate_where = $cate > 0 ? 'AND ' . get_children($cate) : ''; /* 获得商品列表 */ $sql = 'SELECT g.goods_id, g.goods_name, g.goods_sn, g.market_price, g.shop_price AS org_price, g.is_new,' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, g.promote_price, " . '(select AVG(r.comment_rank) from ' . $GLOBALS['ecs']->table('comment') . ' as r where r.id_value = g.goods_id AND r.comment_type = 0 AND r.parent_id = 0 AND r.status = 1) AS comment_rank, ' . '(select IFNULL(sum(og.goods_number), 0) from ' . $GLOBALS['ecs']->table('order_goods') . ' as og where og.goods_id = g.goods_id) AS sell_number, ' . 'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ' . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . ' AS mp ' . "ON mp.goods_id = g.goods_id AND mp.user_rank = '{$_SESSION['user_rank']}' " . "WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND g.brand_id = '{$brand_id}' {$cate_where}" . "ORDER BY {$sort} {$order}"; $res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size); $arr = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); } else { $promote_price = 0; } $arr[$row['goods_id']]['goods_id'] = $row['goods_id']; if ($GLOBALS['display'] == 'grid') { $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_name'] = $row['goods_name']; $arr[$row['goods_id']]['goods_sn'] = $row['goods_sn']; $arr[$row['goods_id']]['comment_rank'] = $row['comment_rank']; $arr[$row['goods_id']]['sell_number'] = $row['sell_number']; $arr[$row['goods_id']]['is_new'] = $row['is_new']; $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']]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; $arr[$row['goods_id']]['goods_brief'] = $row['goods_brief']; $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']]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); } return $arr; }
/** * 获取指定用户的收藏商品列表 * @access public * @param int $user_id 用户ID * @param int $num 列表最大数量 * @param int $start 列表其实位置 * @return array $arr */ public function get_collection_goods($user_id, $num = 10, $start = 0) { $sql = 'SELECT g.goods_id, g.goods_name, g.goods_thumb, g.market_price, g.shop_price AS org_price, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, " . 'g.promote_price, g.promote_start_date,g.promote_end_date, c.rec_id, c.is_attention' . ' FROM ' . $this->pre . 'collect_goods AS c' . ' LEFT JOIN ' . $this->pre . 'goods AS g ' . 'ON g.goods_id = c.goods_id ' . ' LEFT JOIN ' . $this->pre . 'member_price AS mp ' . "ON mp.goods_id = g.goods_id AND mp.user_rank = '{$_SESSION['user_rank']}' " . " WHERE c.user_id = '{$user_id}' ORDER BY c.rec_id DESC limit {$start}, {$num}"; $res = $this->query($sql); $goods_list = array(); if (is_array($res)) { foreach ($res as $row) { if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); } else { $promote_price = 0; } $goods_list[$row['goods_id']]['rec_id'] = $row['rec_id']; $goods_list[$row['goods_id']]['is_attention'] = $row['is_attention']; $goods_list[$row['goods_id']]['goods_id'] = $row['goods_id']; $goods_list[$row['goods_id']]['goods_name'] = $row['goods_name']; $goods_list[$row['goods_id']]['goods_thumb'] = get_image_path(0, $row['goods_thumb']); $goods_list[$row['goods_id']]['market_price'] = price_format($row['market_price']); $goods_list[$row['goods_id']]['shop_price'] = price_format($row['shop_price']); $goods_list[$row['goods_id']]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; $goods_list[$row['goods_id']]['url'] = url('goods/index', array('id' => $row['goods_id'])); } } return $goods_list; }
/** * 获取指定用户的收藏商品列表 * * @access public * @param int $user_id 用户ID * @param int $num 列表最大数量 * @param int $start 列表其实位置 * * @return array $arr */ function get_collection_goods($user_id, $num = 10, $start = 0) { $sql = 'SELECT g.goods_id, g.goods_name, g.goods_thumb, g.market_price, g.shop_price AS org_price, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, " . 'g.promote_price, g.promote_start_date,g.promote_end_date, c.rec_id, c.is_attention' . ' FROM ' . $GLOBALS['ecs']->table('collect_goods') . ' AS c' . " LEFT JOIN " . $GLOBALS['ecs']->table('goods') . " AS g " . "ON g.goods_id = c.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 c.user_id = '{$user_id}' ORDER BY c.rec_id DESC"; $res = $GLOBALS['db']->selectLimit($sql, $num, $start); $goods_list = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); } else { $promote_price = 0; } /* 判断是否为正在预售的商品 */ // $pre_sale_id = is_pre_sale_goods($row['goods_id']); // if($pre_sale_id != null) // { // $goods_list[$row['goods_id']]['is_pre_sale'] = 1; // $goods_list[$row['goods_id']]['pre_sale_id'] = $pre_sale_id; // } // else // { // $goods_list[$row['goods_id']]['is_pre_sale'] = 0; // } $goods_list[$row['goods_id']]['rec_id'] = $row['rec_id']; $goods_list[$row['goods_id']]['is_attention'] = $row['is_attention']; $goods_list[$row['goods_id']]['goods_id'] = $row['goods_id']; $goods_list[$row['goods_id']]['goods_name'] = $row['goods_name']; $goods_list[$row['goods_id']]['market_price'] = price_format($row['market_price']); $goods_list[$row['goods_id']]['shop_price'] = price_format($row['shop_price']); $goods_list[$row['goods_id']]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; $goods_list[$row['goods_id']]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); $goods_list[$row['goods_id']]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); } return $goods_list; }
function get_supplier_goods($gtype = 0, $limit = 10) { $gtype = intval($gtype); if ($gtype <= 0) { return; } $sql = "SELECT DISTINCT g.goods_id,g.* FROM " . $GLOBALS['ecs']->table('goods') . " AS g, " . $GLOBALS['ecs']->table('supplier_goods_cat') . " AS gc, " . $GLOBALS['ecs']->table('supplier_cat_recommend') . " AS cr \n\tWHERE cr.recommend_type =" . $gtype . " AND cr.supplier_id =" . $_GET['suppId'] . " AND cr.cat_id = gc.cat_id AND gc.goods_id = g.goods_id \n\tAND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 \n\tORDER BY g.sort_order, g.last_update DESC LIMIT " . $limit; $result = $GLOBALS['db']->getAll($sql); $goods = array(); if ($result) { foreach ($result as $idx => $row) { if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); $goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; } else { $goods[$idx]['promote_price'] = ''; } $goods[$idx]['id'] = $row['goods_id']; $goods[$idx]['name'] = $row['goods_name']; $goods[$idx]['brief'] = $row['goods_brief']; $goods[$idx]['brand_name'] = isset($goods_data['brand'][$row['goods_id']]) ? $goods_data['brand'][$row['goods_id']] : ''; $goods[$idx]['goods_style_name'] = add_style($row['goods_name'], $row['goods_name_style']); $goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; $goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'], $row['goods_name_style']); $goods[$idx]['market_price'] = price_format($row['market_price']); $goods[$idx]['shop_price'] = price_format($row['shop_price']); $goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); $goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); //$goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); } } return $goods; }
function brand_get_goodsex($brand_id, $cate, $size, $page, $sort, $order) { $cate_where = 0 < $cate ? "AND " . get_children($cate) : ""; $sql = "SELECT g.goods_id, g.goods_name, g.goods_sn, g.market_price, g.shop_price AS org_price,g.is_promote, g.is_new, g.is_best, g.is_hot," . ("IFNULL(mp.user_price, g.shop_price * '" . $_SESSION['discount'] . "') AS shop_price, g.promote_price, ") . "(select AVG(r.comment_rank) from " . $GLOBALS['ecs']->table("comment") . " as r where r.id_value = g.goods_id AND r.comment_type = 0 AND r.parent_id = 0 AND r.status = 1) AS comment_rank, (select IFNULL(sum(r.id_value), 0) from " . $GLOBALS['ecs']->table("comment") . " as r where r.id_value = g.goods_id AND r.comment_type = 0 AND r.parent_id = 0 AND r.status = 1) AS comment_count, (select IFNULL(sum(og.goods_number), 0) from " . $GLOBALS['ecs']->table("order_goods") . " as og where og.goods_id = g.goods_id) AS sell_number, g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img FROM " . $GLOBALS['ecs']->table("goods") . " AS g LEFT JOIN " . $GLOBALS['ecs']->table("member_price") . " AS mp " . ("ON mp.goods_id = g.goods_id AND mp.user_rank = '" . $_SESSION['user_rank'] . "' ") . ("WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND g.brand_id = '" . $brand_id . "' {$cate_where}") . ("ORDER BY " . $sort . " {$order}"); $res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size); $arr = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { if (0 < $row['promote_price']) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); } else { $promote_price = 0; } $arr[$row['goods_id']]['goods_id'] = $row['goods_id']; if ($GLOBALS['display'] == "grid") { $arr[$row['goods_id']]['short_name'] = 0 < $GLOBALS['_CFG']['goods_name_length'] ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; } $arr[$row['goods_id']]['goods_name'] = $row['goods_name']; $arr[$row['goods_id']]['goods_sn'] = $row['goods_sn']; $arr[$row['goods_id']]['comment_count'] = $row['comment_count']; $arr[$row['goods_id']]['comment_rank'] = $row['comment_rank']; $arr[$row['goods_id']]['sell_number'] = $row['sell_number']; $arr[$row['goods_id']]['is_promote'] = $row['is_promote']; $arr[$row['goods_id']]['is_new'] = $row['is_new']; $arr[$row['goods_id']]['is_best'] = $row['is_best']; $arr[$row['goods_id']]['is_hot'] = $row['is_hot']; $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']]['promote_price'] = 0 < $promote_price ? price_format($promote_price) : ""; $arr[$row['goods_id']]['goods_brief'] = $row['goods_brief']; $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']]['url'] = build_uri("goods", array("gid" => $row['goods_id']), $row['goods_name']); } return $arr; }
function gz_get_category_recommend_goods($type = '', $cats = '', $brand = 0, $min = 0, $max = 0, $ext = '') { $brand_where = $brand > 0 ? " AND g.brand_id = '{$brand}'" : ''; $price_where = $min > 0 ? " AND g.shop_price >= {$min} " : ''; $price_where .= $max > 0 ? " AND g.shop_price <= {$max} " : ''; $sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, " . 'promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, g.original_img, b.brand_name ' . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_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 g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ' . $brand_where . $price_where . $ext; $num = 0; $type2lib = array('best' => 'recommend_best', 'new' => 'recommend_new', 'hot' => 'recommend_hot', 'promote' => 'recommend_promotion'); $num = get_library_number($type2lib[$type]); switch ($type) { case 'best': $sql .= ' AND is_best = 1'; break; case 'new': $sql .= ' AND is_new = 1'; break; case 'hot': $sql .= ' AND is_hot = 1'; break; case 'promote': $time = gmtime(); $sql .= " AND is_promote = 1 AND promote_start_date <= '{$time}' AND promote_end_date >= '{$time}'"; break; } if (!empty($cats)) { $sql .= " AND (" . $cats . " OR " . get_extension_goods($cats) . ")"; } $order_type = $GLOBALS['_CFG']['recommend_order']; $sql .= $order_type == 0 ? ' ORDER BY g.sort_order, g.last_update DESC' : ' ORDER BY RAND()'; $res = $GLOBALS['db']->selectLimit($sql, $num); $idx = 0; $goods = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); $goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; } else { $goods[$idx]['promote_price'] = ''; } $goods[$idx]['id'] = $row['goods_id']; $goods[$idx]['name'] = $row['goods_name']; $goods[$idx]['brief'] = $row['goods_brief']; $goods[$idx]['brand_name'] = $row['brand_name']; $goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; $goods[$idx]['market_price'] = price_format($row['market_price']); $goods[$idx]['shop_price'] = price_format($row['shop_price']); $goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); $goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); $goods[$idx]['original_img'] = get_image_path($row['goods_id'], $row['original_img']); $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); $goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'], $row['goods_name_style']); $idx++; } return $goods; }
/** * 获得品牌下的商品 * * @access private * @param integer $brand_id * @return array */ function brand_get_goods($brand_id, $cate, $sort, $order, $size, $page) { $cate_where = ($cate > 0) ? 'AND ' . get_children($cate) : ''; $start = ($page - 1) * $size; /* 获得商品列表 */ $sort = $sort =='sales_volume'? 'xl.sales_volume': $sort; $sql = 'SELECT g.goods_id, g.goods_name,g.goods_number, g.market_price, g.shop_price AS org_price, ' . "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, g.promote_price, " . 'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ' . 'FROM ' . $this->pre . 'goods AS g ' . 'LEFT JOIN ' . $this->pre . 'touch_goods AS xl ' . "ON g.goods_id=xl.goods_id " . 'LEFT JOIN ' . $this->pre . 'member_price AS mp ' . "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' " . "WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND g.brand_id = '$brand_id' $cate_where" . "ORDER BY $sort $order LIMIT $start , $size"; $res = $this->query($sql); $arr = array(); foreach ($res as $row) { if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); } else { $promote_price = 0; } $arr[$row['goods_id']]['goods_id'] = $row['goods_id']; if ($GLOBALS['display'] == 'grid') { $arr[$row['goods_id']]['goods_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; } else { $arr[$row['goods_id']]['goods_name'] = $row['goods_name']; } $arr[$row['goods_id']]['discount'] = $row['market_price'] > 0 ? (round((($promote_price > 0 ? $promote_price : $row['shop_price']) / $row['market_price']) * 10)) : 0; $arr[$row['goods_id']]['goods_number'] = $row['goods_number']; $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']]['promote_price'] = ($promote_price > 0) ? price_format($promote_price) : ''; $arr[$row['goods_id']]['goods_brief'] = $row['goods_brief']; $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']]['url'] = build_uri('goods/index', array( 'id' => $row['goods_id'] ), $row['goods_name']); $arr[$row['goods_id']]['sales_count'] = model('GoodsBase')->get_sales_count($row['goods_id']); $arr[$row['goods_id']]['sc'] = model('GoodsBase')->get_goods_collect($row['goods_id']); $arr[$row['goods_id']]['promotion'] = model('GoodsBase')->get_promotion_show($row['goods_id']); $arr[$row['goods_id']]['mysc'] = 0; // 检查是否已经存在于用户的收藏夹 if ($_SESSION['user_id']) { unset($where); // 用户自己有没有收藏过 $where['goods_id'] = $row['goods_id']; $where['user_id'] = $_SESSION['user_id']; $rs = $this->model->table('collect_goods') ->where($where) ->count(); $arr[$row['goods_id']]['mysc'] = $rs; } } return $arr; }
/** * 获得促销商品 * * @access public * @return array */ function get_flash_sale_goods($cats = '') { $time = gmtime(); $order_type = $GLOBALS['_CFG']['recommend_order']; /* 取得促销lbi的数量限制 */ $num = get_library_number("recommend_promotion"); $sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, " . "promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, b.brand_name, " . "g.is_best, g.is_new, g.is_hot, g.is_promote, RAND() AS rnd " . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_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 g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ' . " AND g.is_promote = 1 AND promote_start_date <= '{$time}' AND promote_end_date >= '{$time}' "; $sql .= $order_type == 0 ? ' ORDER BY g.sort_order, g.last_update DESC' : ' ORDER BY rnd'; $result = $GLOBALS['db']->getAll($sql); $goods = array(); foreach ($result as $idx => $row) { if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); $goods[$idx]['promote_price'] = $promote_price > 0 ? $promote_price : ''; } else { $goods[$idx]['promote_price'] = ''; } $sql = 'SELECT sum(goods_number) AS goods_number FROM ' . $GLOBALS['ecs']->table('order_goods') . ' WHERE goods_id =' . $row['goods_id'] . ' GROUP BY goods_id'; $goods_number = $GLOBALS['db']->getOne($sql); if (empty($goods_number)) { $goods_number = 0; } if (!empty($row['promote_end_date'])) { $goods[$idx]['end_date'] = $row['promote_end_date']; } $goods[$idx]['soldnum'] = get_soldnum($row['goods_id']); $goods[$idx]['jiesheng'] = $row['market_price'] - $row['promote_price']; $goods[$idx]['zhekou'] = sprintf("%1\$.1f", $row['promote_price'] / $row['shop_price'] * 10); $goods[$idx]['id'] = $row['goods_id']; $goods[$idx]['number'] = $goods_number; $goods[$idx]['name'] = $row['goods_name']; $goods[$idx]['brief'] = $row['goods_brief']; $goods[$idx]['brand_name'] = $row['brand_name']; $goods[$idx]['goods_style_name'] = add_style($row['goods_name'], $row['goods_name_style']); $goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; $goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'], $row['goods_name_style']); $goods[$idx]['market_price'] = $row['market_price']; $goods[$idx]['shop_price'] = $row['shop_price']; $goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); $goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); $properties = get_goods_properties($row['goods_id']); // 获得商品的规格和属性 $goods[$idx]['pro'] = $properties['pro']['商品属性']; } return $goods; }
/** * 获得分类下的商品 * * @access public * @param string $children * @return array */ function category_get_goods($children, $size, $page) { $display = $GLOBALS['display']; $where = "g.is_on_sale = 1 AND g.is_alone_sale = 1 AND " . "g.is_delete = 0 AND ({$children})"; /* 获得商品列表 */ $sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, g.promote_price, g.goods_type, " . 'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ' . 'FROM ' . $GLOBALS['ecs']->table('supplier_goods_cat') . ' AS sgc ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . "ON sgc.goods_id = g.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 {$where} ORDER BY g.goods_id desc"; $res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size); $arr = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); } else { $promote_price = 0; } /* 处理商品水印图片 */ $watermark_img = ''; if ($promote_price != 0) { $watermark_img = "watermark_promote_small"; } elseif ($row['is_new'] != 0) { $watermark_img = "watermark_new_small"; } elseif ($row['is_best'] != 0) { $watermark_img = "watermark_best_small"; } elseif ($row['is_hot'] != 0) { $watermark_img = 'watermark_hot_small'; } if ($watermark_img != '') { $arr[$row['goods_id']]['watermark_img'] = $watermark_img; } $arr[$row['goods_id']]['goods_id'] = $row['goods_id']; if ($display == 'grid') { $arr[$row['goods_id']]['goods_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; } else { $arr[$row['goods_id']]['goods_name'] = $row['goods_name']; } $arr[$row['goods_id']]['name'] = $row['goods_name']; $arr[$row['goods_id']]['goods_brief'] = $row['goods_brief']; $arr[$row['goods_id']]['goods_style_name'] = add_style($row['goods_name'], $row['goods_name_style']); $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']]['type'] = $row['goods_type']; $arr[$row['goods_id']]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; $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']]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); } return $arr; }
function category_get_goods22() { $where = "g.is_on_sale = 1 and g.is_bind_card='2' AND g.is_alone_sale = 1 AND " . "g.is_delete = 0 "; $id = isset($_REQUEST['id']) ? trim($_REQUEST['id']) : 0; if ($id) { $where .= " and g.cat_id " . db_create_in(array_unique(array_keys(cat_list($id, 0, false)))); } /* 获得商品列表 */ $sql = 'SELECT g.goods_id, g.goods_name,g.cat_id, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, g.promote_price, g.goods_type, " . 'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ' . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . ' AS mp ' . "ON mp.goods_id = g.goods_id AND mp.user_rank = '{$_SESSION['user_rank']}' " . "WHERE {$where} "; $goodlist = $GLOBALS['db']->getAll($sql); $arr = array(); foreach ($goodlist as $row) { if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); } else { $promote_price = 0; } /* 处理商品水印图片 */ $watermark_img = ''; if ($promote_price != 0) { $watermark_img = "watermark_promote_small"; } elseif ($row['is_new'] != 0) { $watermark_img = "watermark_new_small"; } elseif ($row['is_best'] != 0) { $watermark_img = "watermark_best_small"; } elseif ($row['is_hot'] != 0) { $watermark_img = 'watermark_hot_small'; } if ($watermark_img != '') { $arr[$row['goods_id']]['watermark_img'] = $watermark_img; } $arr[$row['goods_id']]['goods_id'] = $row['goods_id']; $arr[$row['goods_id']]['goods_name'] = $row['goods_name']; $arr[$row['goods_id']]['name'] = $row['goods_name']; $arr[$row['goods_id']]['goods_brief'] = $row['goods_brief']; $arr[$row['goods_id']]['goods_style_name'] = add_style($row['goods_name'], $row['goods_name_style']); $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']]['type'] = $row['goods_type']; $arr[$row['goods_id']]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; $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']]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); } return $arr; }
/** * 与浏览记录相关的商品 * int $limit 调用数量 * return $goods */ function insert_browse_related() { if (!empty($_COOKIE['ECS']['history'])) { $where = db_create_in($_COOKIE['ECS']['history'], 'goods_id'); $sql = 'SELECT cat_id FROM ' . $GLOBALS['ecs']->table('goods') . " WHERE {$where} AND is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0"; $res = $GLOBALS['db']->getAll($sql); foreach ($res as $row) { $arr[] = $row['cat_id']; } if (!empty($arr[0])) { $arr = array_flip(array_flip($arr)); $where = implode(" , ", $arr); $sql = 'SELECT * FROM ' . $GLOBALS['ecs']->table('goods') . ' WHERE cat_id=(' . $where . ') ORDER BY RAND() LIMIT ' . $limit; $sql = 'SELECT g.goods_id,g.cat_id, g.goods_name, g.market_price, g.shop_price AS org_price, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, " . 'g.promote_price, promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, g.goods_img ' . "FROM " . $GLOBALS['ecs']->table('goods') . ' AS g ' . "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp " . "ON mp.goods_id = g.goods_id AND mp.user_rank = '{$_SESSION['user_rank']}' " . 'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND ' . "g.is_delete = 0 AND cat_id IN (" . $where . ") AND g.goods_id NOT IN (" . $_COOKIE['ECS']['history'] . ") ORDER BY RAND() LIMIT 25 "; $res = $GLOBALS['db']->getAll($sql); $str = ''; $goods = array(); foreach ($res as $idx => $row) { if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); $goods[$idx]['shop_price'] = $promote_price > 0 ? price_format($promote_price) : ''; } else { $goods[$idx]['shop_price'] = price_format($row['shop_price']); } $goods[$idx]['id'] = $row['goods_id']; $goods[$idx]['name'] = $row['goods_name']; $goods[$idx]['brief'] = $row['goods_brief']; $goods[$idx]['market_price'] = $row['market_price']; $goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; $goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); $goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); $str .= ' <li> <div class="p-img"><a target="_blank" title="' . $goods[$idx]['name'] . '" href="' . $goods[$idx]['url'] . '"><img height="130" width="130" alt="" src="' . $goods[$idx]['thumb'] . '"></a></div> <div class="p-name"><a target="_blank" title="' . $goods[$idx]['name'] . '" href="' . $goods[$idx]['url'] . '">' . $goods[$idx]['short_name'] . '</a></div> <div class="p-price"><strong class="J-p-718168">' . $goods[$idx]['shop_price'] . '</strong></div> </li>'; } } return $str; } }
/** * 获得商品的详细信息 * * @access public * @param integer $goods_id * @return void */ function get_goods_info_detail($goods_id) { $time = gmtime(); $sql = 'SELECT g.*, c.measure_unit, b.brand_id, b.brand_name AS goods_brand, m.type_money AS bonus_money, ' . 'IFNULL(AVG(r.comment_rank), 0) AS comment_rank, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS rank_price " . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('category') . ' AS c ON g.cat_id = c.cat_id ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON g.brand_id = b.brand_id ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('comment') . ' AS r ' . 'ON r.id_value = g.goods_id AND comment_type = 0 AND r.parent_id = 0 AND r.status = 1 ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('bonus_type') . ' AS m ' . "ON g.bonus_type_id = m.type_id AND m.send_start_date <= '{$time}' AND m.send_end_date >= '{$time}'" . " LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp " . "ON mp.goods_id = g.goods_id AND mp.user_rank = '{$_SESSION['user_rank']}' " . "WHERE g.goods_id = '{$goods_id}' AND g.is_delete = 0 " . "GROUP BY g.goods_id"; $row = $GLOBALS['db']->getRow($sql); if ($row !== false) { /* 用户评论级别取整 */ $row['comment_rank'] = ceil($row['comment_rank']) == 0 ? 5 : ceil($row['comment_rank']); /* 获得商品的销售价格 */ $row['market_price'] = price_format($row['market_price']); $row['shop_price_formated'] = price_format($row['shop_price']); /* 修正促销价格 */ if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); } else { $promote_price = 0; } $row['promote_price_org'] = $promote_price; $row['promote_price'] = price_format($promote_price); /* 修正重量显示 */ $row['goods_weight'] = intval($row['goods_weight']) > 0 ? $row['goods_weight'] . $GLOBALS['_LANG']['kilogram'] : $row['goods_weight'] * 1000 . $GLOBALS['_LANG']['gram']; /* 修正上架时间显示 */ $row['add_time'] = local_date($GLOBALS['_CFG']['date_format'], $row['add_time']); /* 促销时间倒计时 */ $time = gmtime(); if ($time >= $row['promote_start_date'] && $time <= $row['promote_end_date']) { $row['gmt_end_time'] = $row['promote_end_date']; } else { $row['gmt_end_time'] = 0; } /* 是否显示商品库存数量 */ $row['goods_number'] = $GLOBALS['_CFG']['use_storage'] == 1 ? $row['goods_number'] : ''; /* 修正积分:转换为可使用多少积分(原来是可以使用多少钱的积分) */ $row['integral'] = $GLOBALS['_CFG']['integral_scale'] ? round($row['integral'] * 100 / $GLOBALS['_CFG']['integral_scale']) : 0; /* 修正优惠券 */ $row['bonus_money'] = $row['bonus_money'] == 0 ? 0 : price_format($row['bonus_money'], false); return $row; } else { return false; } }
/** * 获取指定用户的收藏商品列表 * * @access public * @param int $user_id 用户ID * @param int $num 列表最大数量 * @param int $start 列表其实位置 * * @return array $arr */ function get_collection_goods($user_id, $num = 10, $start = 0) { $sql = 'SELECT g.goods_id, g.goods_name, g.market_price,g.goods_img, g.shop_price AS org_price, '. "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ". 'g.promote_price, g.promote_start_date,g.promote_end_date, c.rec_id, c.is_attention' . ' FROM ' . $GLOBALS['ecs']->table('collect_goods') . ' AS c' . " LEFT JOIN " . $GLOBALS['ecs']->table('goods') . " AS g ". "ON g.goods_id = c.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 c.user_id = '$user_id' ORDER BY c.rec_id DESC"; $res = $GLOBALS['db'] -> selectLimit($sql, $num, $start); $goods_list = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); } else { $promote_price = 0; } $goods_list[$row['goods_id']]['rec_id'] = $row['rec_id']; $goods_list[$row['goods_id']]['is_attention'] = $row['is_attention']; $goods_list[$row['goods_id']]['goods_id'] = $row['goods_id']; $goods_list[$row['goods_id']]['goods_img'] = $row['goods_img']; $goods_list[$row['goods_id']]['goods_name'] = $row['goods_name']; $goods_list[$row['goods_id']]['market_price'] = price_format($row['market_price']); $goods_list[$row['goods_id']]['shop_price'] = price_format($row['shop_price']); $goods_list[$row['goods_id']]['promote_price'] = ($promote_price > 0) ? price_format($promote_price) : ''; $goods_list[$row['goods_id']]['url'] = build_uri('goods', array('gid'=>$row['goods_id']), $row['goods_name']); } return $goods_list; }
function getGoodsByKey($key) { $key = $this->getstr($key); $size = 10; $page = 1; $condi = "(goods_sn like '%{$key}%' or goods_name like '%{$key}%' or keywords like '%{$key}%' or goods_desc like '%{$key}%')"; $condi .= " and is_delete = 0 and is_on_sale = 1 and is_alone_sale = 1"; $res = $GLOBALS['db']->SelectLimit("select goods_id,goods_name,shop_price,promote_price,promote_start_date,promote_end_date,goods_img,goods_thumb from {$GLOBALS['ecs']->table('goods')} where {$condi} {$order}", $size, ($page - 1) * $size); while ($row = $GLOBALS['db']->FetchRow($res)) { $promote_price = 0; if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); } $arr[$row['goods_id']]['goods_id'] = $row['goods_id']; $arr[$row['goods_id']]['goods_name'] = $row['goods_name']; $arr[$row['goods_id']]['shop_price'] = price_format($row['shop_price']); $arr[$row['goods_id']]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; $arr[$row['goods_id']]['goods_img'] = $row['goods_img']; $arr[$row['goods_id']]['thumb'] = $row['goods_thumb']; $arr[$row['goods_id']]['url'] = "mobile/goods.php?id=" . $row['goods_id']; } return $arr; }
/** * 获得文章关联的商品 * * @access public * @param integer $id * @return array */ function article_related_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('goods_article') . ' ga ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ON g.goods_id = ga.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 ga.article_id = '{$id}' AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0"; $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 * * @return 活动名称 */ function get_snatch($id) { $sql = "SELECT g.goods_id, g.goods_sn, g.is_real, g.goods_name, g.extension_code, g.market_price, g.shop_price AS org_price, product_id, " . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, " . "g.promote_price, g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb, " . "ga.act_name AS snatch_name, ga.start_time, ga.end_time, ga.ext_info, ga.act_desc AS `desc` " . "FROM " . $GLOBALS['ecs']->table('goods_activity') . " AS ga " . "LEFT JOIN " . $GLOBALS['ecs']->table('goods') . " AS g " . "ON g.goods_id = ga.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 ga.act_id = '{$id}' AND g.is_delete = 0"; $goods = $GLOBALS['db']->GetRow($sql); if ($goods) { $promote_price = bargain_price($goods['promote_price'], $goods['promote_start_date'], $goods['promote_end_date']); $goods['formated_market_price'] = price_format($goods['market_price']); $goods['formated_shop_price'] = price_format($goods['shop_price']); $goods['formated_promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; $goods['goods_thumb'] = get_image_path($goods['goods_id'], $goods['goods_thumb'], true); $goods['url'] = build_uri('goods', array('gid' => $goods['goods_id']), $goods['goods_name']); $goods['start_time'] = local_date($GLOBALS['_CFG']['time_format'], $goods['start_time']); $info = unserialize($goods['ext_info']); if ($info) { foreach ($info as $key => $val) { $goods[$key] = $val; } $goods['is_end'] = gmtime() > $goods['end_time']; $goods['formated_start_price'] = price_format($goods['start_price']); $goods['formated_end_price'] = price_format($goods['end_price']); $goods['formated_max_price'] = price_format($goods['max_price']); } /* 将结束日期格式化为格林威治标准时间时间戳 */ $goods['gmt_end_time'] = $goods['end_time']; $goods['end_time'] = local_date($GLOBALS['_CFG']['time_format'], $goods['end_time']); $goods['snatch_time'] = sprintf($GLOBALS['_LANG']['snatch_start_time'], $goods['start_time'], $goods['end_time']); return $goods; } else { return false; } }
/** * 获取某一个省份的特产商品 * @return array */ function get_special_goods($condition) { if ($_SESSION['user_rank']) { $time = gmtime(); $sql_special_goods = 'SELECT g.goods_id, g.goods_name,g.sort_order, g.last_update,g.is_special,g.market_price, g.shop_price AS org_price, g.promote_price, g.province_id, g.province_name, g.city_id, g.city_name, g.area_id, g.area_name, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, " . "g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb, g.goods_img, RAND() AS rnd " . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp " . " ON mp.goods_id = g.goods_id WHERE mp.user_rank = '{$_SESSION['user_rank']}' AND g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND g.is_special = 1 AND g.province_id = '{$condition[province_id]}' ORDER BY g.sort_order, g.last_update DESC LIMIT {$condition['begin_item']},{$condition['end_item']} "; } else { $sql_special_goods = " SELECT goods_id, goods_name,sort_order, last_update,is_special,market_price, shop_price,promote_price,promote_start_date, promote_end_date,goods_thumb, province_id, province_name, city_id, city_name, area_id, area_name,goods_img FROM " . $GLOBALS['ecs']->table('goods') . " WHERE is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0 AND is_special = 1 AND province_id = '{$condition[province_id]}' ORDER BY sort_order, last_update DESC LIMIT {$condition['begin_item']},{$condition['end_item']} "; } $special_goods = $GLOBALS['db']->getAll($sql_special_goods); foreach ($special_goods as $k => $v) { $special_goods[$k]['short_name'] = mb_substr($v['goods_name'], 0, 5, 'utf-8'); if ($v['promote_price'] > 0) { $promote_price = bargain_price($v['promote_price'], $v['promote_start_date'], $v['promote_end_date']); $special_goods[$k]['promote_price'] = $promote_price > 0 ? number_format($promote_price, 2, '.', '') : ''; } } //dump($special_goods); return $special_goods; }
/** * 获得指定的品牌下的商品 * * @access public * @param integer $brand_id 品牌的ID * @param integer $num 数量 * @param integer $cat_id 分类编号 * @param string $order_rule 指定商品排序规则 * @return void */ function assign_brand_goods($brand_id, $num = 0, $cat_id = 0, $order_rule = '') { $sql = 'SELECT g.goods_id, g.goods_name, g.market_price, g.shop_price AS org_price, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, " . 'g.promote_price, g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb, g.goods_img ' . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp " . "ON mp.goods_id = g.goods_id AND mp.user_rank = '{$_SESSION['user_rank']}' " . "WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND g.brand_id = '{$brand_id}'"; if ($cat_id > 0) { $sql .= get_children($cat_id); } $order_rule = empty($order_rule) ? ' ORDER BY g.sort_order, g.goods_id DESC' : $order_rule; $sql .= $order_rule; if ($num > 0) { $res = $GLOBALS['db']->selectLimit($sql, $num); } else { $res = $GLOBALS['db']->query($sql); } $idx = 0; $goods = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); } else { $promote_price = 0; } $goods[$idx]['id'] = $row['goods_id']; $goods[$idx]['name'] = $row['goods_name']; $goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; $goods[$idx]['market_price'] = price_format($row['market_price']); $goods[$idx]['shop_price'] = price_format($row['shop_price']); $goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; $goods[$idx]['brief'] = $row['goods_brief']; $goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); $goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); $idx++; } /* 分类信息 */ $sql = 'SELECT brand_name FROM ' . $GLOBALS['ecs']->table('brand') . " WHERE brand_id = '{$brand_id}'"; $brand['id'] = $brand_id; $brand['name'] = $GLOBALS['db']->getOne($sql); $brand['url'] = build_uri('brand', array('bid' => $brand_id), $brand['name']); $brand_goods = array('brand' => $brand, 'goods' => $goods); return $brand_goods; }
/** * 获得促销商品 * * @access public * @param string $order_rule 指定商品排序规则 * @return array */ function wap_get_promote_goods($order_rule = '') { $time = gmtime(); /* 取得促销lbi的数量限制 */ $sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, " . "promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, b.brand_name, " . "g.is_best, g.is_new, g.is_hot, g.is_promote, RAND() AS rnd " . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_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 g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ' . " AND g.is_promote = 1 AND promote_start_date <= '{$time}' AND promote_end_date >= '{$time}' "; $order_rule = empty($order_rule) ? 'ORDER BY g.sort_order, g.last_update DESC' : $order_rule; $sql .= $order_rule; $result = $GLOBALS['db']->getAll($sql); $goods = array(); foreach ($result as $idx => $row) { if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); $goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; } else { $goods[$idx]['promote_price'] = ''; } $goods[$idx]['id'] = $row['goods_id']; $goods[$idx]['name'] = $row['goods_name']; $goods[$idx]['brief'] = $row['goods_brief']; $goods[$idx]['brand_name'] = $row['brand_name']; $goods[$idx]['goods_style_name'] = add_style($row['goods_name'], $row['goods_name_style']); $goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; $goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'], $row['goods_name_style']); $goods[$idx]['market_price'] = price_format($row['market_price']); $goods[$idx]['shop_price'] = price_format($row['shop_price']); $goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); $goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); } return $goods; }
/* 获取品牌 */ $sql = "SELECT b.brand_id, b.brand_name, b.brand_logo, COUNT(g.goods_id) AS goods_num " . " FROM " . $ecs->table('goods') . " AS g " . " LEFT JOIN " . $ecs->table('brand') . " AS b ON g.brand_id=b.brand_id " . " WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 AND b.brand_id > 0 " . $in_goods . " GROUP BY g.brand_id "; $brand_list = $db->getAll($sql); foreach ($brand_list as $key => $val) { $brand_list[$key]['url'] = $url . '&brand=' . $val['brand_id']; } /* 获取分类 */ $sql = "SELECT c.cat_id, c.cat_name, COUNT(g.goods_id) AS goods_num " . " FROM " . $ecs->table('goods') . " AS g " . " LEFT JOIN " . $ecs->table('category') . " AS c ON c.cat_id = g.cat_id " . " WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 " . $in_goods . " GROUP BY g.cat_id "; $cat_list = $db->getAll($sql); foreach ($cat_list as $key => $val) { $cat_list[$key]['url'] = $url . '&category=' . $val['cat_id']; } $idx = 0; while ($row = $db->fetchRow($res)) { if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); } else { $promote_price = 0; } $goods[$idx]['id'] = $row['goods_id']; $goods[$idx]['name'] = $row['goods_name']; $goods[$idx]['short_name'] = $_CFG['goods_name_length'] > 0 ? sub_str($row['goods_name'], $_CFG['goods_name_length']) : $row['goods_name']; $goods[$idx]['market_price'] = $row['market_price']; $goods[$idx]['shop_price'] = price_format($row['shop_price']); $goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; $goods[$idx]['brief'] = $row['goods_brief']; $goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); $idx++; } $picks[] = array('name' => $_LANG['remove_all'], 'url' => 'pick_out.php');
/** * 获得指定分类下的商品 * * @access public * @param integer $cat_id 分类ID * @param integer $num 数量 * @param string $from 来自web/wap的调用 * @param string $order_rule 指定商品排序规则 * @return array */ function assign_cat_goods($cat_id, $num = 0, $from = 'web', $order_rule = '') { $children = get_children($cat_id); $sql = 'SELECT g.goods_id, g.goods_name, g.market_price, g.shop_price AS org_price, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, " . 'g.promote_price, promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, g.goods_img ' . "FROM " . $this->pre . 'goods AS g ' . "LEFT JOIN " . $this->pre . "member_price AS mp " . "ON mp.goods_id = g.goods_id AND mp.user_rank = '{$_SESSION['user_rank']}' " . 'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND ' . 'g.is_delete = 0 AND (' . $children . 'OR ' . model('Goods')->get_extension_goods($children) . ') '; $order_rule = empty($order_rule) ? 'ORDER BY g.sort_order, g.goods_id DESC' : $order_rule; $sql .= $order_rule; if ($num > 0) { $sql .= ' LIMIT ' . $num; } $res = $this->query($sql); $goods = array(); foreach ($res as $idx => $row) { if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); $goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; } else { $goods[$idx]['promote_price'] = ''; } $goods[$idx]['id'] = $row['goods_id']; $goods[$idx]['name'] = $row['goods_name']; $goods[$idx]['brief'] = $row['goods_brief']; $goods[$idx]['market_price'] = price_format($row['market_price']); $goods[$idx]['short_name'] = C('goods_name_length') > 0 ? sub_str($row['goods_name'], C('goods_name_length')) : $row['goods_name']; $goods[$idx]['shop_price'] = price_format($row['shop_price']); $goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); $goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); $goods[$idx]['url'] = url('goods/index', array('id' => $row['goods_id'])); } return $goods; }
function get_cat_recommend_goods($type = "", $cats = "", $cat_num = 0, $brand = 0, $min = 0, $max = 0, $ext = "") { $brand_where = 0 < $brand ? " AND g.brand_id = '" . $brand . "'" : ""; $price_where = 0 < $min ? " AND g.shop_price >= " . $min . " " : ""; $price_where .= 0 < $max ? " AND g.shop_price <= " . $max . " " : ""; $sql = "SELECT g.goods_id, g.goods_name, g.goods_name_style,g.goods_sn, g.market_price, g.shop_price AS org_price, g.promote_price, " . ("IFNULL(mp.user_price, g.shop_price * '" . $_SESSION['discount'] . "') AS shop_price, ") . "(select AVG(r.comment_rank) from " . $GLOBALS['ecs']->table("comment") . " as r where r.id_value = g.goods_id AND r.comment_type = 0 AND r.parent_id = 0 AND r.status = 1) AS comment_rank, (select IFNULL(sum(og.goods_number), 0) from " . $GLOBALS['ecs']->table("order_goods") . " as og where og.goods_id = g.goods_id) AS sell_number, promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, b.brand_name, b.brand_id, g.is_best, g.is_new, g.is_hot, g.is_promote FROM " . $GLOBALS['ecs']->table("goods") . " AS g LEFT JOIN " . $GLOBALS['ecs']->table("brand") . " AS b ON b.brand_id = g.brand_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 g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 " . $brand_where . $price_where . $ext; $num = 0; $type2lib = array("best" => "recommend_best", "new" => "recommend_new", "hot" => "recommend_hot", "promote" => "recommend_promotion"); if ($cat_num == 0) { $num = get_library_number($type2lib[$type]); } else { $num = $cat_num; } switch ($type) { case "best": $sql .= " AND is_best = 1"; break; case "new": $sql .= " AND is_new = 1"; break; case "hot": $sql .= " AND is_hot = 1"; break; case "promote": $time = gmtime(); $sql .= " AND is_promote = 1 AND promote_start_date <= '" . $time . "' AND promote_end_date >= '{$time}'"; } if (!empty($cats)) { $sql .= " AND (" . $cats . " OR " . get_extension_goods($cats) . ")"; } $order_type = $GLOBALS['_CFG']['recommend_order']; $sql .= $order_type == 0 ? " ORDER BY g.sort_order, g.last_update DESC" : " ORDER BY RAND()"; $res = $GLOBALS['db']->selectLimit($sql, $num); $idx = 0; $goods = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { if (0 < $row['promote_price']) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); $goods[$idx]['promote_price'] = 0 < $promote_price ? price_format($promote_price) : ""; } else { $goods[$idx]['promote_price'] = ""; } $row['comment_rank'] = ceil($row['comment_rank']) == 0 ? 5 : ceil($row['comment_rank']); $goods[$idx]['id'] = $row['goods_id']; $goods[$idx]['name'] = $row['goods_name']; $goods[$idx]['goods_sn'] = $row['goods_sn']; $goods[$idx]['comment_rank'] = $row['comment_rank']; $goods[$idx]['sell_number'] = $row['sell_number']; $goods[$idx]['is_new'] = $row['is_new']; $goods[$idx]['is_best'] = $row['is_best']; $goods[$idx]['is_hot'] = $row['is_hot']; $goods[$idx]['is_promote'] = $row['is_promote']; $goods[$idx]['brief'] = $row['goods_brief']; $goods[$idx]['brand_id'] = $row['brand_id']; $goods[$idx]['brand_name'] = $row['brand_name']; $goods[$idx]['short_name'] = 0 < $GLOBALS['_CFG']['goods_name_length'] ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; $goods[$idx]['market_price'] = price_format($row['market_price']); $goods[$idx]['shop_price'] = price_format($row['shop_price']); $goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], TRUE); $goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); $goods[$idx]['url'] = build_uri("goods", array("gid" => $row['goods_id']), $row['goods_name']); $goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'], $row['goods_name_style']); ++$idx; } return $goods; }
function get_on_top_goods($id, $num = 5) { $sql = 'SELECT cat_id,cat_name FROM ' . $GLOBALS['ecs']->table('category') . ' WHERE is_on_top = 1 AND parent_id =' . $id; $res = $GLOBALS['db']->getAll($sql); foreach ($res as $idx => $row) { $arr[$idx]['cat_url'] = build_uri('category', array('cid' => $row['cat_id']), $row['cat_name']); $arr[$idx]['cat_name'] = $row['cat_name']; $children = get_children($row['cat_id']); $sql = 'SELECT g.goods_id, g.goods_name, g.market_price, g.shop_price AS org_price, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, " . 'g.promote_price, promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, g.goods_img ' . "FROM " . $GLOBALS['ecs']->table('goods') . ' AS g ' . "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp " . "ON mp.goods_id = g.goods_id AND mp.user_rank = '{$_SESSION['user_rank']}' " . 'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND ' . 'g.is_delete = 0 AND (' . $children . ') '; $order_rule = 'ORDER BY g.sort_order, g.goods_id DESC'; $sql .= $order_rule; if ($num > 0) { $sql .= ' LIMIT ' . $num; } $goods_res = $GLOBALS['db']->getAll($sql); $goods = array(); foreach ($goods_res as $goods_idx => $goods_row) { if ($goods_row['promote_price'] > 0) { $promote_price = bargain_price($goods_row['promote_price'], $goods_row['promote_start_date'], $goods_row['promote_end_date']); $goods[$goods_idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; } else { $goods[$goods_idx]['promote_price'] = ''; } $goods[$goods_idx]['id'] = $goods_row['goods_id']; $goods[$goods_idx]['name'] = $goods_row['goods_name']; $goods[$goods_idx]['brief'] = $goods_row['goods_brief']; $goods[$goods_idx]['market_price'] = price_format($goods_row['market_price']); $goods[$goods_idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($goods_row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $goods_row['goods_name']; $goods[$goods_idx]['shop_price'] = price_format($goods_row['shop_price']); $goods[$goods_idx]['thumb'] = get_image_path($goods_row['goods_id'], $goods_row['goods_thumb'], true); $goods[$goods_idx]['goods_img'] = get_image_path($goods_row['goods_id'], $goods_row['goods_img']); $goods[$goods_idx]['url'] = build_uri('goods', array('gid' => $goods_row['goods_id']), $goods_row['goods_name']); } $arr[$idx]['goods'] = $goods; } return $arr; }
function get_catindex_recommend_goods($type = '', $cats = '') { $sql = 'SELECT g.goods_id, g.goods_name,g.goods_brief, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, " . 'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb, goods_img ' . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp " . "ON mp.goods_id = g.goods_id AND mp.user_rank = '{$_SESSION['user_rank']}' " . 'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 '; switch ($type) { case 'best': $sql .= ' AND is_best = 1'; break; case 'new': $sql .= ' AND is_new = 1'; break; case 'hot': $sql .= ' AND is_hot = 1'; break; } if (!empty($cats)) { $sql .= " AND (" . $cats . " OR " . get_extension_goods($cats) . ")"; } $sql .= ' ORDER BY g.sort_order, g.last_update DESC '; $res = $GLOBALS['db']->selectLimit($sql, 8); $idx = 0; $goods = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); } else { $promote_price = 0; } $goods[$idx]['promote_price'] = $promote_price; $goods[$idx]['shop_price'] = price_format($row['shop_price']); $goods[$idx]['id'] = $row['goods_id']; $goods[$idx]['goods_brief'] = $row['goods_brief']; $goods[$idx]['goods_name'] = $row['goods_name']; $goods[$idx]['brief'] = $row['goods_brief']; $goods[$idx]['brand_name'] = $row['brand_name']; $goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; $goods[$idx]['market_price'] = price_format($row['market_price']); $goods[$idx]['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true); $goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']); $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); $goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'], $row['goods_name_style']); $idx++; } return $goods; }
/** * 获得分类下的商品 * * @access public * @param string $children * @return array */ function category_get_goods($children, $brand, $min, $max, $ext, $size, $page, $sort, $order) { $filter = isset($_REQUEST['filter']) ? intval($_REQUEST['filter']) : 0; $display = $GLOBALS['display']; $where = "g.is_on_sale = 1 AND g.is_alone_sale = 1 AND " . "g.is_delete = 0 AND ({$children} OR " . get_extension_goods($children) . ')'; if ($filter == 1) { $where .= ' AND g.supplier_id=0 '; } elseif ($filter == 2) { $where .= ' AND g.supplier_id>0 '; } else { } if ($brand > 0) { /* 代码修改_start By www.68ecshop.com */ if (strstr($brand, '_')) { $brand_sql = str_replace("_", ",", $brand); $where .= "AND g.brand_id in ({$brand_sql}) "; } else { $where .= "AND g.brand_id={$brand} "; } /* 代码修改_end By www.68ecshop.com */ } if ($min > 0) { $where .= " AND g.shop_price >= {$min} "; } if ($max > 0) { $where .= " AND g.shop_price <= {$max} "; } if ($sort == goods_number) { $where .= " AND g.goods_number != 0 "; } /* 获得商品列表 */ $sort = $sort == 'shop_price' ? 'shop_p' : $sort; $sql = "SELECT g.goods_id, g.goods_name, g.goods_name_style, g.click_count, g.goods_number, g.market_price, " . " g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, " . " IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, g.promote_price, " . " IF(g.promote_price != '' " . " AND g.promote_start_date < " . gmtime() . " AND g.promote_end_date > " . gmtime() . ", g.promote_price, shop_price) " . " AS shop_p, g.goods_type, " . " g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb, g.goods_img " . " FROM " . $GLOBALS['ecs']->table('goods') . " AS g " . " LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp " . " ON mp.goods_id = g.goods_id " . " AND mp.user_rank = '{$_SESSION['user_rank']}' " . " WHERE {$where} {$ext} " . " ORDER BY {$sort} {$order}"; if ($sort == 'salenum') { $sql = "SELECT IFNULL(o.num,0) AS salenum, g.goods_id, g.goods_name, g.click_count, g.goods_number, g.goods_name_style, " . " g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, " . " IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, g.promote_price, g.goods_type, " . " g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img " . " FROM " . $GLOBALS['ecs']->table('goods') . " AS g " . " LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp " . " ON mp.goods_id = g.goods_id " . " AND mp.user_rank = '{$_SESSION['user_rank']}' " . " LEFT JOIN " . " (SELECT " . " SUM(og.`goods_number`) " . " AS num,og.goods_id " . " FROM " . " ecs_order_goods AS og, " . " ecs_order_info AS oi " . " WHERE oi.pay_status = 2 " . " AND oi.order_status >= 1 " . " AND oi.order_id = og.order_id " . " GROUP BY og.goods_id) " . " AS o " . " ON o.goods_id = g.goods_id " . " WHERE {$where} {$ext} " . " ORDER BY {$sort} {$order}"; } $res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size); $arr = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); } else { $promote_price = 0; } /* 处理商品水印图片 */ $watermark_img = ''; if ($promote_price != 0) { $watermark_img = "watermark_promote_small"; } elseif ($row['is_new'] != 0) { $watermark_img = "watermark_new_small"; } elseif ($row['is_best'] != 0) { $watermark_img = "watermark_best_small"; } elseif ($row['is_hot'] != 0) { $watermark_img = 'watermark_hot_small'; } if ($watermark_img != '') { $arr[$row['goods_id']]['watermark_img'] = $watermark_img; } $arr[$row['goods_id']]['goods_id'] = $row['goods_id']; if ($display == 'grid') { $arr[$row['goods_id']]['goods_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; } else { $arr[$row['goods_id']]['goods_name'] = $row['goods_name']; } $arr[$row['goods_id']]['goods_number'] = $row['goods_number']; $arr[$row['goods_id']]['name'] = $row['goods_name']; $arr[$row['goods_id']]['is_promote'] = $row['is_promote']; $arr[$row['goods_id']]['is_new'] = $row['is_new']; $arr[$row['goods_id']]['is_hot'] = $row['is_hot']; $arr[$row['goods_id']]['is_best'] = $row['is_best']; $arr[$row['goods_id']]['goods_brief'] = $row['goods_brief']; $arr[$row['goods_id']]['goods_style_name'] = add_style($row['goods_name'], $row['goods_name_style']); $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']]['type'] = $row['goods_type']; $arr[$row['goods_id']]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; $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']]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); $arr[$row['goods_id']]['comment_count'] = get_comment_count($row['goods_id']); $arr[$row['goods_id']]['count'] = selled_count($row['goods_id']); $arr[$row['goods_id']]['click_count'] = $row['click_count']; /* 检查是否已经存在于用户的收藏夹 */ $sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('collect_goods') . " WHERE user_id='{$_SESSION['user_id']}' AND goods_id = " . $row['goods_id']; if ($GLOBALS['db']->GetOne($sql) > 0) { $arr[$row['goods_id']]['is_collet'] = 1; } else { $arr[$row['goods_id']]['is_collet'] = 0; } } 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 string $children * @return array */ function category_get_goods($children, $brand, $min, $max, $ext, $size, $page, $sort, $order) { $display = $GLOBALS['display']; $where = "g.is_on_sale = 1 AND g.is_alone_sale = 1 AND " . "g.is_delete = 0 AND ({$children} OR " . get_extension_goods($children) . ')'; if ($brand > 0) { $where .= "AND g.brand_id={$brand} "; } if ($min > 0) { $where .= " AND g.shop_price >= {$min} "; } if ($max > 0) { $where .= " AND g.shop_price <= {$max} "; } /* 获得商品列表 */ $sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, g.promote_price, g.goods_type, " . 'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ' . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . ' AS mp ' . "ON mp.goods_id = g.goods_id AND mp.user_rank = '{$_SESSION['user_rank']}' " . "WHERE {$where} {$ext} ORDER BY {$sort} {$order}"; $res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size); $arr = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); } else { $promote_price = 0; } /* 处理商品水印图片 */ $watermark_img = ''; if ($promote_price != 0) { $watermark_img = "watermark_promote_small"; } elseif ($row['is_new'] != 0) { $watermark_img = "watermark_new_small"; } elseif ($row['is_best'] != 0) { $watermark_img = "watermark_best_small"; } elseif ($row['is_hot'] != 0) { $watermark_img = 'watermark_hot_small'; } if ($watermark_img != '') { $arr[$row['goods_id']]['watermark_img'] = $watermark_img; } $arr[$row['goods_id']]['goods_id'] = $row['goods_id']; if ($display == 'grid') { $arr[$row['goods_id']]['goods_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; } else { $arr[$row['goods_id']]['goods_name'] = $row['goods_name']; } $arr[$row['goods_id']]['name'] = $row['goods_name']; $arr[$row['goods_id']]['goods_brief'] = $row['goods_brief']; $arr[$row['goods_id']]['goods_style_name'] = add_style($row['goods_name'], $row['goods_name_style']); $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']]['type'] = $row['goods_type']; //zhong 改开始 if ($row['market_price'] > 0) { $arr[$row['goods_id']]['zhekou'] = round($row['shop_price'] / $row['market_price'] * 100) / 10 + "" . "折"; } $goods_id = $row['goods_id']; $count = $GLOBALS['db']->getOne("SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('comment') . " where comment_type=0 and id_value ='{$goods_id}'"); $arr[$row['goods_id']]['review_count'] = $count; //zhong 改结束 $arr[$row['goods_id']]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : ''; $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']]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); } return $arr; }
/** * 取得商品最终使用价格 * * @param string $goods_id 商品编号 * @param string $goods_num 购买数量 * @param boolean $is_spec_price 是否加入规格价格 * @param mix $spec 规格ID的数组或者逗号分隔的字符串 * * @return 商品最终购买价格 */ function get_final_price($goods_id, $goods_num = '1', $is_spec_price = false, $spec = array()) { $final_price = '0'; //商品最终购买价格 $volume_price = '0'; //商品优惠价格 $promote_price = '0'; //商品促销价格 $user_price = '0'; //商品会员价格 //取得商品优惠价格列表 $price_list = get_volume_price_list($goods_id, '1'); if (!empty($price_list)) { foreach ($price_list as $value) { if ($goods_num >= $value['number']) { $volume_price = $value['price']; } } } //取得商品促销价格列表 /* 取得商品信息 */ $sql = "SELECT g.promote_price, g.promote_start_date, g.promote_end_date, " . "IFNULL(mp.user_price, g.shop_price * '" . $_SESSION['discount'] . "') AS shop_price " . " FROM " . $GLOBALS['ecs']->table('goods') . " AS g " . " LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp " . "ON mp.goods_id = g.goods_id AND mp.user_rank = '" . $_SESSION['user_rank'] . "' " . " WHERE g.goods_id = '" . $goods_id . "'" . " AND g.is_delete = 0"; $goods = $GLOBALS['db']->getRow($sql); /* 计算商品的促销价格 */ if ($goods['promote_price'] > 0) { $promote_price = bargain_price($goods['promote_price'], $goods['promote_start_date'], $goods['promote_end_date']); } else { $promote_price = 0; } //取得商品会员价格列表 $user_price = $goods['shop_price']; //比较商品的促销价格,会员价格,优惠价格 if (empty($volume_price) && empty($promote_price)) { //如果优惠价格,促销价格都为空则取会员价格 $final_price = $user_price; } elseif (!empty($volume_price) && empty($promote_price)) { //如果优惠价格为空时不参加这个比较。 $final_price = min($volume_price, $user_price); } elseif (empty($volume_price) && !empty($promote_price)) { //如果促销价格为空时不参加这个比较。 $final_price = min($promote_price, $user_price); } elseif (!empty($volume_price) && !empty($promote_price)) { //取促销价格,会员价格,优惠价格最小值 $final_price = min($volume_price, $promote_price, $user_price); } else { $final_price = $user_price; } //如果需要加入规格价格 if ($is_spec_price) { if (!empty($spec)) { $spec_price = spec_price($spec); $final_price += $spec_price; } } //返回商品最终购买价格 return $final_price; }
/** * 获得分类下的商品 * * @access public * @param string $children * @return array */ function category_get_goods($children, $brand, $min, $max, $ext, $size, $page, $sort, $order) { $display = $GLOBALS['display']; $where = "g.is_on_sale = 1 AND g.is_alone_sale = 1 AND " . "g.is_delete = 0 AND ({$children} OR " . get_extension_goods($children) . ')'; if ($brand > 0) { $where .= "AND g.brand_id={$brand} "; } if ($min > 0) { $where .= " AND g.shop_price >= {$min} "; } if ($max > 0) { $where .= " AND g.shop_price <= {$max} "; } /* 获得商品列表 */ $sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.is_new, g.is_best, g.is_hot, g.shop_price AS org_price, ' . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price, g.promote_price, g.goods_type, " . 'g.promote_start_date, g.promote_end_date, g.goods_brief, g.goods_thumb , g.goods_img ' . 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('member_price') . ' AS mp ' . "ON mp.goods_id = g.goods_id AND mp.user_rank = '{$_SESSION['user_rank']}' " . "WHERE {$where} {$ext} ORDER BY {$sort} {$order}"; //echo $sql."<br>size==".$size; // print_r($sql); $res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size); $arr = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { if ($row['promote_price'] > 0) { $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']); } else { $promote_price = 0; } /* 处理商品水印图片 */ $watermark_img = ''; if ($promote_price != 0) { $watermark_img = "watermark_promote_small"; } elseif ($row['is_new'] != 0) { $watermark_img = "watermark_new_small"; } elseif ($row['is_best'] != 0) { $watermark_img = "watermark_best_small"; } elseif ($row['is_hot'] != 0) { $watermark_img = 'watermark_hot_small'; } if ($watermark_img != '') { $arr[$row['goods_id']]['watermark_img'] = $watermark_img; } $arr[$row['goods_id']]['goods_id'] = $row['goods_id']; if ($display == 'grid') { $arr[$row['goods_id']]['goods_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name']; } else { $arr[$row['goods_id']]['goods_name'] = $row['goods_name']; } $properties = get_goods_properties($row['goods_id']); // 获得商品的规格和属性 $arr[$row['goods_id']]['properties_pro'] = $properties['pro']['商品属性']; $arr[$row['goods_id']]['soldnum'] = get_soldnum($row['goods_id']); $arr[$row['goods_id']]['comments_number'] = get_comments_number($row['goods_id']); $arr[$row['goods_id']]['brief'] = $row['goods_brief']; $arr[$row['goods_id']]['is_new'] = $row['is_new'] ? $row['is_new'] : 0; $arr[$row['goods_id']]['is_best'] = $row['is_best'] ? $row['is_best'] : 0; $arr[$row['goods_id']]['is_hot'] = $row['is_hot'] ? $row['is_hot'] : 0; $arr[$row['goods_id']]['name'] = $row['goods_name']; $arr[$row['goods_id']]['goods_brief'] = $row['goods_brief']; $arr[$row['goods_id']]['goods_style_name'] = add_style($row['goods_name'], $row['goods_name_style']); $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']]['type'] = $row['goods_type']; $arr[$row['goods_id']]['promote_price'] = $promote_price > 0 ? $promote_price : ''; $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']]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']); } return $arr; }