<?php
//侧栏商品列表
function product_hotlist($num=10) {
	global $pe,$db;
	return $db->pe_selectall('product', array('order by'=>'`product_clicknum` desc'), '*', array($num));
}
//侧栏商品列表
function product_selllist($num) {
	global $pe,$db;
	return $db->pe_selectall('product', array('order by'=>'`product_sellnum` desc'), '*', array($num));
}
//商品统计更新
function product_num($type, $product_id) {
	global $db;
	$product_id = intval($product_id);
	switch ($type) {
		case 'sell':
			$db->pe_update('product', array('product_id' => $product_id), "`product_sellnum` = `product_sellnum` + 1 and `product_num` = `product_num` - 1");
		break;
		case 'click':
			$db->pe_update('product', array('product_id' => $product_id), "`product_clicknum` = `product_clicknum` + 1");
		break;
		default:
			if (in_array($type, array('collect', 'ask', 'comment'))) {
				$num = $db->pe_num($type, array('product_id' => $product_id));
				return $db->pe_update('product', array('product_id' => $product_id), array("product_{$type}num" => $num));
			}
		break;
	}
}
?>