我想把A 函数的 返回的值 调用到 B 函数一个数组中 该怎么实现?A函数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;
}
B函数
function get_goods_properties($goods_id)
{
/* 对属性进行重新排序和分组 */
$sql = "SELECT attr_group ".
"FROM " . $GLOBALS['ecs']->table('goods_type') . " AS gt, " . $GLOBALS['ecs']->table('goods') . " AS g ".
"WHERE g.goods_id='$goods_id' AND gt.cat_id=g.goods_type";
$grp = $GLOBALS['db']->getOne($sql); if (!empty($grp))
{
$groups = explode("\n", strtr($grp, "\r", ''));
} /* 获得商品的规格 */
//2009/11/17增加读取attr_css字段
$sql = "SELECT a.attr_id, a.attr_name, a.attr_group, a.is_linked, a.attr_type,d.shop_price,m.user_rank,m.user_price, ".
"g.goods_attr_id, g.attr_value, g.attr_css,g.attr_price " .
'FROM ' . $GLOBALS['ecs']->table('goods_attr') . ' AS g ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('attribute') . ' AS a ON a.attr_id = g.attr_id ' .
'left JOIN'.$GLOBALS['ecs']->table('goods').'AS d ON d.goods_id=g.goods_id '.
'left JOIN'.$GLOBALS['ecs']->table('member_price').'AS m ON m.goods_id=g.goods_id '.
"WHERE g.goods_id = '$goods_id' " .
'ORDER BY a.sort_order, g.attr_price, g.goods_attr_id';
$res = $GLOBALS['db']->getAll($sql);
$arr['pro'] = array(); // 属性
$arr['spe'] = array(); // 规格
$arr['lnk'] = array(); // 关联的属性
foreach ($res AS $row)
{
if ($row['attr_type'] == 0)
{
$group = (isset($groups[$row['attr_group']])) ? $groups[$row['attr_group']] : $GLOBALS['_LANG']['goods_attr']; $arr['pro'][$group][$row['attr_id']]['name'] = $row['attr_name'];
$arr['pro'][$group][$row['attr_id']]['value'] = $row['attr_value'];
$arr['pro'][$group][$row['attr_id']]['css'] = $row['attr_css']; }
else
{
$arr['spe'][$row['attr_id']]['attr_type'] = $row['attr_type'];
$arr['spe'][$row['attr_id']]['name'] = $row['attr_name'];
$arr['spe'][$row['attr_id']]['values'][] = array(
'label' => $row['attr_value'],
// 'price' => $row['attr_price'],
'format_price' => price_format(abs($row['attr_price']+$row['user_price']), false),
'id' => $row['goods_attr_id']);
} if ($row['is_linked'] == 1)
{
/* 如果该属性需要关联,先保存下来 */
$arr['lnk'][$row['attr_id']]['name'] = $row['attr_name'];
$arr['lnk'][$row['attr_id']]['value'] = $row['attr_value'];
}
} return $arr;
}
主要是想在B函数里实现'format_price' => price_format(abs($row['attr_price']+$row['final_price ']), false),这句话的功能 $row['attr_price'] 是B函数的值 final_price 是A函数的值
{
$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;
}
B函数
function get_goods_properties($goods_id)
{
/* 对属性进行重新排序和分组 */
$sql = "SELECT attr_group ".
"FROM " . $GLOBALS['ecs']->table('goods_type') . " AS gt, " . $GLOBALS['ecs']->table('goods') . " AS g ".
"WHERE g.goods_id='$goods_id' AND gt.cat_id=g.goods_type";
$grp = $GLOBALS['db']->getOne($sql); if (!empty($grp))
{
$groups = explode("\n", strtr($grp, "\r", ''));
} /* 获得商品的规格 */
//2009/11/17增加读取attr_css字段
$sql = "SELECT a.attr_id, a.attr_name, a.attr_group, a.is_linked, a.attr_type,d.shop_price,m.user_rank,m.user_price, ".
"g.goods_attr_id, g.attr_value, g.attr_css,g.attr_price " .
'FROM ' . $GLOBALS['ecs']->table('goods_attr') . ' AS g ' .
'LEFT JOIN ' . $GLOBALS['ecs']->table('attribute') . ' AS a ON a.attr_id = g.attr_id ' .
'left JOIN'.$GLOBALS['ecs']->table('goods').'AS d ON d.goods_id=g.goods_id '.
'left JOIN'.$GLOBALS['ecs']->table('member_price').'AS m ON m.goods_id=g.goods_id '.
"WHERE g.goods_id = '$goods_id' " .
'ORDER BY a.sort_order, g.attr_price, g.goods_attr_id';
$res = $GLOBALS['db']->getAll($sql);
$arr['pro'] = array(); // 属性
$arr['spe'] = array(); // 规格
$arr['lnk'] = array(); // 关联的属性
foreach ($res AS $row)
{
if ($row['attr_type'] == 0)
{
$group = (isset($groups[$row['attr_group']])) ? $groups[$row['attr_group']] : $GLOBALS['_LANG']['goods_attr']; $arr['pro'][$group][$row['attr_id']]['name'] = $row['attr_name'];
$arr['pro'][$group][$row['attr_id']]['value'] = $row['attr_value'];
$arr['pro'][$group][$row['attr_id']]['css'] = $row['attr_css']; }
else
{
$arr['spe'][$row['attr_id']]['attr_type'] = $row['attr_type'];
$arr['spe'][$row['attr_id']]['name'] = $row['attr_name'];
$arr['spe'][$row['attr_id']]['values'][] = array(
'label' => $row['attr_value'],
// 'price' => $row['attr_price'],
'format_price' => price_format(abs($row['attr_price']+$row['user_price']), false),
'id' => $row['goods_attr_id']);
} if ($row['is_linked'] == 1)
{
/* 如果该属性需要关联,先保存下来 */
$arr['lnk'][$row['attr_id']]['name'] = $row['attr_name'];
$arr['lnk'][$row['attr_id']]['value'] = $row['attr_value'];
}
} return $arr;
}
主要是想在B函数里实现'format_price' => price_format(abs($row['attr_price']+$row['final_price ']), false),这句话的功能 $row['attr_price'] 是B函数的值 final_price 是A函数的值
'format_price' => price_format(abs($row['attr_price']+$row['final_price ']), false),这句话的功能 $row['attr_price']