/** * 获得商品的货品列表 * * @access public * @params integer $goods_id * @params string $conditions * @return array */ function product_list($goods_id, $conditions = '') { /* 过滤条件 */ $param_str = '-' . $goods_id; $result = get_filter($param_str); if ($result === false) { $day = getdate(); $today = local_mktime(23, 59, 59, $day['mon'], $day['mday'], $day['year']); $filter['goods_id'] = $goods_id; $filter['keyword'] = empty($_REQUEST['keyword']) ? '' : trim($_REQUEST['keyword']); $filter['stock_warning'] = empty($_REQUEST['stock_warning']) ? 0 : intval($_REQUEST['stock_warning']); if (isset($_REQUEST['is_ajax']) && $_REQUEST['is_ajax'] == 1) { $filter['keyword'] = json_str_iconv($filter['keyword']); } $filter['sort_by'] = empty($_REQUEST['sort_by']) ? 'product_id' : trim($_REQUEST['sort_by']); $filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'DESC' : trim($_REQUEST['sort_order']); $filter['extension_code'] = empty($_REQUEST['extension_code']) ? '' : trim($_REQUEST['extension_code']); $filter['page_count'] = isset($filter['page_count']) ? $filter['page_count'] : 1; $where = ''; /* 库存警告 */ if ($filter['stock_warning']) { $where .= ' AND goods_number <= warn_number '; } /* 关键字 */ if (!empty($filter['keyword'])) { $where .= " AND (product_sn LIKE '%" . $filter['keyword'] . "%')"; } $where .= $conditions; /* 记录总数 */ $sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('products') . " AS p WHERE goods_id = {$goods_id} {$where}"; $filter['record_count'] = $GLOBALS['db']->getOne($sql); $sql = "SELECT product_id, goods_id, goods_attr, product_sn, product_number\n FROM " . $GLOBALS['ecs']->table('products') . " AS g\n WHERE goods_id = {$goods_id} {$where}\n ORDER BY {$filter['sort_by']} {$filter['sort_order']}"; $filter['keyword'] = stripslashes($filter['keyword']); //set_filter($filter, $sql, $param_str); } else { $sql = $result['sql']; $filter = $result['filter']; } $row = $GLOBALS['db']->getAll($sql); /* 处理规格属性 */ $goods_attr = product_goods_attr_list($goods_id); foreach ($row as $key => $value) { $_goods_attr_array = explode('|', $value['goods_attr']); if (is_array($_goods_attr_array)) { $_temp = ''; foreach ($_goods_attr_array as $_goods_attr_value) { $_temp[] = $goods_attr[$_goods_attr_value]; } $row[$key]['goods_attr'] = $_temp; } } return array('product' => $row, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']); }
$goods_sns = str_replace("\n", ',', str_replace("\r", '', $_POST['sn_list'])); $sql = "SELECT DISTINCT goods_id FROM " . $ecs->table('goods') . " WHERE goods_sn " . db_create_in($goods_sns); $goods_ids = join(',', $db->getCol($sql)); $where = " WHERE goods_id " . db_create_in($goods_ids); } $sql = "SELECT DISTINCT goods_id, goods_sn, goods_name, market_price, shop_price, goods_number, integral, give_integral, brand_id, is_real FROM " . $ecs->table('goods') . $where; $smarty->assign('goods_list', $db->getAll($sql)); /* 取编辑商品的货品列表 */ $product_exists = false; $sql = "SELECT * FROM " . $ecs->table('products') . $where; $product_list = $db->getAll($sql); if (!empty($product_list)) { $product_exists = true; $_product_list = array(); foreach ($product_list as $value) { $goods_attr = product_goods_attr_list($value['goods_id']); $_goods_attr_array = explode('|', $value['goods_attr']); if (is_array($_goods_attr_array)) { $_temp = ''; foreach ($_goods_attr_array as $_goods_attr_value) { $_temp[] = $goods_attr[$_goods_attr_value]; } $value['goods_attr'] = implode(',', $_temp); } $_product_list[$value['goods_id']][] = $value; } $smarty->assign('product_list', $_product_list); //释放资源 unset($product_list, $sql, $_product_list); } $smarty->assign('product_exists', $product_exists);