Example #1
0
function cart_goods_recommend($rtype)
{
    $sql_hot = "select goods_id, goods_name, goods_thumb, shop_price, market_price from " . $GLOBALS['ecs']->table('goods') . " where " . $rtype . "=1 order by  goods_id desc limit 0,10 ";
    $res_hot = $GLOBALS['db']->query($sql_hot);
    $hotgoods_list = array();
    while ($row_hot = $GLOBALS['db']->fetchRow($res_hot)) {
        $row_hot['goods_name'] = sub_str($row_hot['goods_name'], 20);
        $row_hot['url'] = build_uri('goods', array('gid' => $row_hot['goods_id']), $row_hot['goods_name']);
        $row_hot['goods_thumb'] = get_pc_url() . '/' . get_image_path($row_hot['goods_id'], $row_hot['goods_thumb'], true);
        $row_hot['shop_price'] = price_format($row_hot['shop_price']);
        $row_hot['market_price'] = price_format($row_hot['market_price']);
        $hotgoods_list[] = $row_hot;
    }
    return $hotgoods_list;
}
Example #2
0
         $sql = "SELECT goods_id AS id, goods_name AS name FROM " . $ecs->table('goods') . " WHERE goods_id " . db_create_in($row['act_range_ext']);
     }
     $act_range_ext = $db->getAll($sql);
     $row['act_range_ext'] = $act_range_ext;
 } else {
     $row['act_range'] = $_LANG['far_all'];
 }
 //优惠方式
 $row['act_type_num'] = $row['act_type'];
 switch ($row['act_type']) {
     case 0:
         $row['act_type'] = $_LANG['fat_goods'];
         $row['gift'] = unserialize($row['gift']);
         if (is_array($row['gift'])) {
             foreach ($row['gift'] as $k => $v) {
                 $row['gift'][$k]['thumb'] = get_pc_url() . '/' . get_image_path($v['id'], $db->getOne("SELECT goods_thumb FROM " . $ecs->table('goods') . " WHERE goods_id = '" . $v['id'] . "'"), true);
             }
         }
         break;
     case 1:
         $row['act_type'] = $_LANG['fat_price'];
         $row['act_type_ext'] .= $_LANG['unit_yuan'];
         $row['gift'] = array();
         break;
     case 2:
         $row['act_type'] = $_LANG['fat_discount'];
         $row['act_type_ext'] .= "%";
         $row['gift'] = array();
         break;
 }
 if ($row['supplier_id'] > 0) {
Example #3
0
/**
 * 获得指定分类下的推荐商品
 *
 * @access  public
 * @param   string      $type       推荐类型,可以是 best, new, hot, promote
 * @param   string      $cats       分类的ID
 * @param   integer     $brand      品牌的ID
 * @param   integer     $min        商品价格下限
 * @param   integer     $max        商品价格上限
 * @param   string      $ext        商品扩展查询
 * @return  array
 */
function 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.goods_brief, g.market_price,g.is_best,g.is_new,g.is_hot,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 ' . '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]['goods_brief'] = $row['goods_brief'];
        $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_pc_url() . '/' . get_image_path($row['goods_id'], $row['goods_thumb'], true);
        $goods[$idx]['goods_img'] = get_pc_url() . '/' . 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;
}
Example #4
0
/**
 * 取得某用户等级当前时间可以享受的优惠活动
 * @param   int     $user_rank      用户等级id,0表示非会员  
 * @param   int     $is_have        是否判断已经选择赠品
 * @return  array
 */
function favourable_list($user_rank, $is_have = true)
{
    /* 购物车中已有的优惠活动及数量 */
    $used_list = cart_favourable();
    /* 当前用户可享受的优惠活动 */
    $favourable_list = array();
    $user_rank = ',' . $user_rank . ',';
    $now = gmtime();
    if (isset($_REQUEST['suppid'])) {
        $tj = " AND supplier_id=" . $_REQUEST['suppid'];
    } else {
        $tj = '';
    }
    $sql = "SELECT * " . "FROM " . $GLOBALS['ecs']->table('favourable_activity') . " WHERE CONCAT(',', user_rank, ',') LIKE '%" . $user_rank . "%'" . " AND start_time <= '{$now}' AND end_time >= '{$now}'" . $tj . " AND act_type = '" . FAT_GOODS . "'" . " ORDER BY sort_order";
    $res = $GLOBALS['db']->query($sql);
    while ($favourable = $GLOBALS['db']->fetchRow($res)) {
        $favourable['start_time'] = local_date($GLOBALS['_CFG']['time_format'], $favourable['start_time']);
        $favourable['end_time'] = local_date($GLOBALS['_CFG']['time_format'], $favourable['end_time']);
        $favourable['formated_min_amount'] = price_format($favourable['min_amount'], false);
        $favourable['formated_max_amount'] = price_format($favourable['max_amount'], false);
        $favourable['gift'] = unserialize($favourable['gift']);
        $_REQUEST['suppid'] = $favourable['supplier_id'] = $favourable['supplier_id'];
        foreach ($favourable['gift'] as $key => $value) {
            $favourable['gift'][$key]['formated_price'] = price_format($value['price'], false);
            $goods_thumb = $GLOBALS['db']->getOne("SELECT `goods_thumb` FROM " . $GLOBALS['ecs']->table('goods') . " WHERE `goods_id`='{$value['id']}'");
            $favourable['gift'][$key]['goods_thumb'] = get_pc_url() . '/' . get_image_path($value['id'], $goods_thumb, true);
            $sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('goods') . " WHERE is_on_sale = 1 AND goods_id = " . $value['id'];
            $is_sale = $GLOBALS['db']->getOne($sql);
            if (!$is_sale) {
                unset($favourable['gift'][$key]);
            }
        }
        $favourable['act_range_desc'] = act_range_desc($favourable);
        $favourable['act_type_desc'] = sprintf($GLOBALS['_LANG']['fat_ext'][$favourable['act_type']], $favourable['act_type_ext']);
        /* 是否能享受 */
        $favourable['available'] = favourable_available($favourable);
        if ($favourable['available'] && $is_have) {
            /* 是否尚未享受 */
            $favourable['available'] = !favourable_used($favourable, $used_list);
        }
        $favourable_list[] = $favourable;
    }
    return $favourable_list;
}