/** * 根据预售活动编号取得预售活动信息 * @param int $pre_sale_id 预售活动id * @param int $current_num 本次购买数量(计算当前价时要加上的数量) * @return array * status 状态:</br> * formated_start_date 格式化预售开始时间</br> * formated_end_date 格式化预售结束时间</br> * formated_retainage_start 尾款支付开始时间</br> * formated_retainage_end 尾款支付结束时间</br> * formated_deposit 格式化后的保证金</br> * formated_sale_price 格式化后的预售价格</br> * price_ladder 阶梯价格[amount: 数量, price: 价格, formated_price: 格式化后的价格]</br> * total_order 总订单数</br> * total_goods 总商品数</br> * valid_order 有效订单数</br> * valid_goods 有效商品数</br> * cur_price 当前阶梯价格</br> * formated_cur_price 格式化后的当前阶梯价格</br> * cur_amount 当前阶梯数量</br> * gift_integral 赠送积分</br> * status 预售活动状态</br> */ function pre_sale_info($pre_sale_id, $current_num = 0) { /* 取得团购活动信息 */ $pre_sale_id = intval($pre_sale_id); $sql = "SELECT b.*,g.*, b.act_id AS pre_sale_id, b.act_desc AS pre_sale_desc, b.start_time, b.end_time " . "FROM " . $GLOBALS['ecs']->table('goods_activity') . " AS b " . "LEFT JOIN " . $GLOBALS['ecs']->table('goods') . " AS g ON b.goods_id = g.goods_id " . "WHERE act_id = '{$pre_sale_id}' " . "AND act_type = '" . GAT_PRE_SALE . "'"; $pre_sale = $GLOBALS['db']->getRow($sql); /* 如果为空,返回空数组 */ if (empty($pre_sale)) { return array(); } $ext_info = unserialize($pre_sale['ext_info']); $pre_sale = array_merge($pre_sale, $ext_info); /* 格式化时间 */ $pre_sale['formated_start_date'] = local_date('Y-m-d H:i', $pre_sale['start_time']); $pre_sale['formated_end_date'] = local_date('Y-m-d H:i', $pre_sale['end_time']); // 尾款支付的开始和结束时间 $pre_sale['formated_retainage_start'] = local_date('Y-m-d H:i', $pre_sale['retainage_start']); $pre_sale['formated_retainage_end'] = local_date('Y-m-d H:i', $pre_sale['retainage_end']); /* 格式化预售价格和保证金 */ $pre_sale['formated_sale_price'] = price_format($pre_sale['sale_price'], false); $pre_sale['formated_deposit'] = price_format($pre_sale['deposit'], false); // 本地时间,用于倒计时显示,符合JS格式 $pre_sale['local_end_date'] = local_date('Y, m-1, d, H, i, s', $pre_sale['end_time']); /* 处理价格阶梯 */ $price_ladder = $pre_sale['price_ladder']; /* 价格阶梯必须为有效,而且一定会有价格阶梯 */ if (!is_array($price_ladder) || empty($price_ladder)) { // 如果阶梯价格设置为空则设置默认值 // 这种情况应该不允许出现 $price_ladder = array(array('amount' => 0, 'price' => 0)); } else { // 遍历阶梯价格 foreach ($price_ladder as $key => $amount_price) { // 格式化每一个阶梯价格 $price_ladder[$key]['formated_price'] = price_format($amount_price['price'], false); } } $pre_sale['price_ladder'] = $price_ladder; $pre_sale['price_ladder_count'] = count($price_ladder); /* 统计信息 */ $stat = pre_sale_stat($pre_sale_id, $pre_sale['deposit']); // 合并统计信息 $pre_sale = array_merge($pre_sale, $stat); /* 计算当前价 */ $cur_price = $price_ladder[0]['price']; // 初始化 $cur_amount = $stat['valid_goods'] + $current_num; // 当前数量 // 计算最低价格 foreach ($price_ladder as $amount_price) { if ($cur_amount >= $amount_price['amount']) { $cur_price = $amount_price['price']; } else { break; } } // 获取商品描述 $pre_sale['goods_desc'] = $GLOBALS['db']->getOne("select goods_desc from " . $GLOBALS['ecs']->table('goods') . " where goods_id=" . $pre_sale['goods_id']); $pre_sale['cur_price'] = $cur_price; $pre_sale['$cur_amount'] = $cur_amount; $pre_sale['formated_cur_price'] = price_format($cur_price, false); // 计算折扣 if ($pre_sale['shop_price'] == 0) { $pre_sale['zhekou'] = 0; } else { $pre_sale['zhekou'] = number_format(intval($pre_sale['cur_price']) / intval($pre_sale['shop_price']), 2) * 100; } // 计算节省金额 $pre_sale['jiesheng'] = $pre_sale['shop_price'] - $pre_sale['cur_price']; /* 最终价 */ $pre_sale['trans_price'] = $pre_sale['cur_price']; $pre_sale['formated_trans_price'] = $pre_sale['formated_cur_price']; $pre_sale['trans_amount'] = $pre_sale['valid_goods']; /* 状态 */ $pre_sale['status'] = pre_sale_status($pre_sale); if (isset($GLOBALS['_LANG']['gbs'][$pre_sale['status']])) { $pre_sale['status_desc'] = $GLOBALS['_LANG']['gbs'][$group_buy['status']]; } $pre_sale['start_time'] = $pre_sale['formated_start_date']; $pre_sale['end_time'] = $pre_sale['formated_end_date']; $pre_sale['retainage_start'] = $pre_sale['formated_retainage_start']; $pre_sale['retainage_end'] = $pre_sale['formated_retainage_end']; return $pre_sale; }
function pre_sale_list() { $result = get_filter(); if ($result === false) { /* 过滤条件 */ $filter['keyword'] = empty($_REQUEST['keyword']) ? '' : trim($_REQUEST['keyword']); if (isset($_REQUEST['is_ajax']) && $_REQUEST['is_ajax'] == 1) { $filter['keyword'] = json_str_iconv($filter['keyword']); } $filter['sort_by'] = empty($_REQUEST['sort_by']) ? 'act_id' : trim($_REQUEST['sort_by']); $filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']); $where = !empty($filter['keyword']) ? " AND goods_name LIKE '%" . mysql_like_quote($filter['keyword']) . "%'" : ''; $sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('goods_activity') . " WHERE act_type = '" . GAT_PRE_SALE . "' {$where}"; $filter['record_count'] = $GLOBALS['db']->getOne($sql); /* 分页大小 */ $filter = page_and_size($filter); /* 查询 */ $sql = "SELECT * " . "FROM " . $GLOBALS['ecs']->table('goods_activity') . " WHERE act_type = '" . GAT_PRE_SALE . "' {$where} " . " ORDER BY {$filter['sort_by']} {$filter['sort_order']} " . " LIMIT " . $filter['start'] . ", {$filter['page_size']}"; $filter['keyword'] = stripslashes($filter['keyword']); set_filter($filter, $sql); } else { $sql = $result['sql']; $filter = $result['filter']; } $res = $GLOBALS['db']->query($sql); $list = array(); while ($row = $GLOBALS['db']->fetchRow($res)) { $ext_info = unserialize($row['ext_info']); $stat = pre_sale_stat($row['act_id'], $ext_info['deposit']); $arr = array_merge($row, $stat, $ext_info); /* 处理价格阶梯 */ $price_ladder = $arr['price_ladder']; if (!is_array($price_ladder) || empty($price_ladder)) { $price_ladder = array(array('amount' => 0, 'price' => 0)); } else { foreach ($price_ladder as $key => $amount_price) { $price_ladder[$key]['formated_price'] = price_format($amount_price['price']); } } /* 计算当前价 */ $cur_price = $price_ladder[0]['price']; // 初始化 $cur_amount = $stat['valid_goods']; // 当前数量 foreach ($price_ladder as $amount_price) { if ($cur_amount >= $amount_price['amount']) { $cur_price = $amount_price['price']; } else { break; } } $arr['cur_price'] = $cur_price; $status = pre_sale_status($arr); $arr['start_time'] = local_date($GLOBALS['_CFG']['date_format'], $arr['start_time']); $arr['end_time'] = local_date($GLOBALS['_CFG']['date_format'], $arr['end_time']); $arr['cur_status'] = $GLOBALS['_LANG']['pss'][$status]; $list[] = $arr; } $arr = array('item' => $list, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']); return $arr; }
/** * 取得某页的所有预售活动 * * @param int $size * 每页记录数 * @param int $page * 当前页 * @return array */ function pre_sale_list($size, $page) { /* 取得预售活动 */ $ps_list = array(); $now = gmtime(); // $sql = "SELECT b.*, IFNULL(g.goods_thumb, '') AS goods_thumb, b.act_id AS // pre_sale_id, " . "b.start_time AS start_date, b.end_time AS end_date, // g.shop_price " . "FROM " . $GLOBALS['ecs']->table('goods_activity') . " // AS b " . "LEFT JOIN " . $GLOBALS['ecs']->table('goods') . " AS g ON // b.goods_id = g.goods_id " . "WHERE b.act_type = '" . GAT_PRE_SALE . "' " // . "AND b.start_time <= '$now' AND b.is_finished < '" . PSS_SUCCEED . "' // ORDER BY b.act_id DESC"; $sql = "SELECT b.*, IFNULL(g.goods_thumb, '') AS goods_thumb, b.act_id AS pre_sale_id, " . "b.start_time AS start_date, b.end_time AS end_date, g.shop_price " . "FROM " . $GLOBALS['ecs']->table('goods_activity') . " AS b " . "LEFT JOIN " . $GLOBALS['ecs']->table('goods') . " AS g ON b.goods_id = g.goods_id " . "WHERE b.act_type = '" . GAT_PRE_SALE . "' " . " AND b.is_finished < '" . PSS_SUCCEED . "' ORDER BY b.act_id DESC"; $res = $GLOBALS['db']->selectLimit($sql, $size, ($page - 1) * $size); while ($pre_sale = $GLOBALS['db']->fetchRow($res)) { $ext_info = unserialize($pre_sale['ext_info']); $pre_sale = array_merge($pre_sale, $ext_info); $stat = pre_sale_stat($row['act_id'], $ext_info['deposit']); $pre_sale = array_merge($pre_sale, $stat); /* 格式化时间 */ $pre_sale['formated_start_date'] = local_date($GLOBALS['_CFG']['time_format'], $pre_sale['start_time']); $pre_sale['formated_end_date'] = local_date($GLOBALS['_CFG']['time_format'], $pre_sale['end_time']); // 本地时间,用于倒计时显示,符合JS格式 $pre_sale['local_end_date'] = local_date('Y, m-1, d, H, i, s', $pre_sale['end_time']); $pre_sale['local_start_date'] = local_date('Y, m-1, d, H, i, s', $pre_sale['start_time']); /* 格式化保证金 */ $pre_sale['formated_deposit'] = price_format($pre_sale['deposit'], false); /* 处理价格阶梯 */ $price_ladder = $pre_sale['price_ladder']; if (!is_array($price_ladder) || empty($price_ladder)) { $price_ladder = array(array('amount' => 0, 'price' => 0)); } else { foreach ($price_ladder as $key => $amount_price) { $price_ladder[$key]['formated_price'] = price_format($amount_price['price']); } } $pre_sale['price_ladder'] = $price_ladder; /* 计算当前价 */ $cur_price = $price_ladder[0]['price']; // 初始化 $cur_amount = $stat['valid_goods']; // 当前数量 foreach ($price_ladder as $amount_price) { if ($cur_amount >= $amount_price['amount']) { $cur_price = $amount_price['price']; } else { break; } } $pre_sale['cur_price'] = $cur_price; $pre_sale['formated_cur_price'] = price_format($cur_price, false); $pre_sale['formated_shope_price'] = price_format($pre_sale['shope_price'], false); $status = pre_sale_status($pre_sale); $pre_sale['start_time'] = local_date($GLOBALS['_CFG']['date_format'], $pre_sale['start_time']); $pre_sale['end_time'] = local_date($GLOBALS['_CFG']['date_format'], $pre_sale['end_time']); $pre_sale['cur_status'] = $GLOBALS['_LANG']['pss'][$status]; $pre_sale['status'] = $status; /* 处理图片 */ if (empty($pre_sale['goods_thumb'])) { $pre_sale['goods_thumb'] = get_image_path($pre_sale['goods_id'], $pre_sale['goods_thumb'], true); } /* 处理链接 */ $pre_sale['url'] = build_uri('pre_sale', array('pre_sale_id' => $pre_sale['pre_sale_id'])); /* 加入数组 */ $ps_list[] = $pre_sale; } return $ps_list; }