public function caculatecard($card_id, $dispatch_price, $lotterydiscountprice, $taskcut, $goodsarr, $totalprice, $discountprice, $isdiscountprice, $liveid, $isSubmit = 0)
{
global $_W;
$openid = $_W["openid"];
$uniacid = $_W["uniacid"];
if( empty($goodsarr) )
{
return false;
}
if( p("membercard") )
{
$data = p("membercard")->getMemberCard($card_id);
}
if( empty($data) )
{
return NULL;
}
if( is_array($goodsarr) )
{
$goods = array( );
$member_discount = intval($data["member_discount"]);
$discount_rate = floatval($data["discount_rate"]);
if( isset($data["shipping"]) && $data["shipping"] == 1 )
{
$dispatch_price = 0;
}
$gprice = 0;
$cardgoodprice = 0;
$newtotalprice = 0;
$deductprice = 0;
$discountprice = 0;
$isdiscountprice = 0;
foreach( $goodsarr as $k => &$g )
{
if( $g["status"] != 2 )
{
if( 0 < $liveid )
{
$live_product = pdo_fetch("SELECT * FROM " . tablename("ewei_shop_goods") . " WHERE id = '" . $g["goodsid"] . "'");
if( $live_product )
{
$g["marketprice"] = $live_product["marketprice"];
}
}
$gprice = (double) $g["marketprice"] * (double) $g["total"];
$newtotalprice = 0 + $gprice;
if( $g["discounttype"] == 2 )
{
if( 0 < $data["discount"] )
{
$cardgoodprice += $gprice - (double) $g["discountunitprice"] * (double) $g["total"];
$goodprice = $gprice - (double) $g["discountunitprice"] * (double) $g["total"];
if( 0 < $discount_rate )
{
$deductprice += $goodprice * (1 - $discount_rate / 10);
$discountprice += (double) $g["discountunitprice"] * (double) $g["total"];
}
else
{
$discountprice -= (double) $g["discountunitprice"] * (double) $g["total"];
}
}
else
{
$discountprice = 0;
if( 0 < $discount_rate )
{
$deductprice += $gprice * (1 - $discount_rate / 10);
$cardgoodprice += $gprice * (1 - $discount_rate / 10);
}
}
}
else
{
if( $g["discounttype"] == 1 )
{
$cardgoodprice += $gprice - (double) $g["isdiscountunitprice"] * (double) $g["total"];
$goodprice = $gprice - (double) $g["isdiscountunitprice"] * (double) $g["total"];
if( 0 < $data["discount"] )
{
$deductprice += $goodprice * (1 - $discount_rate / 10);
$isdiscountprice += $g["isdiscountunitprice"] * (double) $g["total"];
}
else
{
$isdiscountprice -= (double) $g["isdiscountunitprice"] * (double) $g["total"];
if( 0 < $discount_rate )
{
$deductprice += $gprice * (1 - $discount_rate / 10);
$cardgoodprice += $gprice * (1 - $discount_rate / 10);
}
}
}
else
{
if( $g["discounttype"] == 0 )
{
if( $g["isnodiscount"] == 1 )
{
$cardgoodprice += $gprice;
if( $data["discount"] )
{
if( 0 < $discount_rate )
{
$deductprice += $cardgoodprice * (1 - $discount_rate / 10);
}
}
else
{
if( 0 < $discount_rate )
{
$deductprice += $gprice * (1 - $discount_rate / 10);
$cardgoodprice += $gprice * (1 - $discount_rate / 10);
}
}
}
else
{
$cardgoodprice += $gprice;
if( $data["discount"] )
{
if( 0 < $discount_rate )
{
$deductprice += $cardgoodprice * (1 - $discount_rate / 10);
}
}
else
{
if( 0 < $discount_rate )
{
$deductprice += $gprice * (1 - $discount_rate / 10);
$cardgoodprice += $gprice * (1 - $discount_rate / 10);
}
}
}
}
}
}
}
}
$carddeduct_text = "";
if( $data["discount_rate"] )
{
$carddeduct_text = "会员卡优惠";
}
}
$sale_plugin = com("sale");
$saleset = false;
if( $sale_plugin )
{
$saleset = $_W["shopset"]["sale"];
$saleset["enoughs"] = $sale_plugin->getEnoughs();
}
if( $saleset )
{
foreach( $saleset["enoughs"] as $e )
{
if( floatval($e["enough"]) <= $totalprice - $discountprice - $isdiscountprice - $deductprice && 0 < floatval($e["money"]) )
{
$deductenough_money = floatval($e["money"]);
$deductenough_enough = floatval($e["enough"]);
break;
}
}
}
$taskreward = $_SESSION["taskcut"];
if( $taskreward && p("task") )
{
$taskcut = 0;
}
$totalprice = $totalprice - $deductprice;
$return_array = array( );
$return_array["carddeductprice"] = (double) $deductprice;
$return_array["cardgoodprice"] = (double) $cardgoodprice;
$return_array["carddeduct_text"] = $carddeduct_text;
$return_array["totalprice"] = (double) $totalprice;
$return_array["dispatch_price"] = (double) $dispatch_price;
$return_array["cardname"] = $data["name"];
$return_array["taskcut"] = (double) $taskcut;
$return_array["lotterydiscountprice"] = 0;
$return_array["discountprice"] = (double) $discountprice;
$return_array["isdiscountprice"] = (double) $isdiscountprice;
$return_array["live_id"] = $liveid;
$return_array["shipping"] = $data["shipping"];
$return_array["cardgoodprice"] = (double) $cardgoodprice;
$return_array["goodsprice"] = (double) $newtotalprice;
$return_array["deductenough_money"] = (double) $deductenough_money;
$return_array["deductenough_enough"] = (double) $deductenough_enough;
$return_array["\$goodsarr"] = $goodsarr;
return $return_array;
}