使用ecshop红包验证分析

2009-10-26 15:20 来源:www.chinab4c.com 作者:ecshop专家

   ecshop红包的使用,有着非常的讲究,其实他的计算原则也非常复杂.而且,当你通过红包去抵消一定的购买金额的时候,牵涉到的计算流程也是非常烦琐的,ecshop的红包分好几类型。下面分析,如何进行ecshop红包验证的.

   1:flow.php中.

    $_REQUEST['step'] == 'validate_bonus'.是处理红包验证的动作.

    $bonus_sn = trim($_REQUEST['bonus_sn']);
    $bonus = bonus_info(0, $bonus_sn);

      if ((!empty($bonus) && $bonus['user_id'] == $_SESSION['user_id']) || $bonus_kill == 0)
        {
            $order['bonus_kill'] = $bonus['type_money'];
            $order['bonus_type_sn'] = $bonus['send_type'];//把他的红包的类型传递进去
            //$result['b'] = $order['bonus_type_sn'];
        }

      这里是处理红包,并且传递给订单进行总金额计算的.

    2:includes\lib_order.php中,函数order_fee($order, $goods, $consignee)是用来验证订单金额的.

   /* 红包 */  

  if (!empty($order['bonus_id']))
    {
        $bonus          = bonus_info($order['bonus_id']);
        $total['bonus'] = $bonus['type_money'];
    }
    $total['bonus_formated'] = price_format($total['bonus'], false);

    /* 线下红包 */
     if (!empty($order['bonus_kill']))
    {
        $bonus          = bonus_info(0,$order['bonus_kill']);
        $total['bonus_kill'] = $order['bonus_kill'];
        $total['bonus_kill_formated'] = price_format($total['bonus_kill'], false);
    }

    上面是取得红包的值,进行优惠计算.

    else
    {
        $total['amount'] = $total['goods_price'] - $total['discount'] + $total['tax'] + $total['pack_fee'] + $total['card_fee'] +
            $total['shipping_fee'] + $total['shipping_insure'] + $total['cod_fee'];

        // 减去红包金额
        $use_bonus        = min($total['bonus'], $max_amount); // 实际减去的红包金额
        if(isset($total['bonus_kill']))
        { 
            $use_bonus_kill   = min($total['bonus_kill'], $max_amount);
           
         if($order['bonus_type_sn'] == 5){
          
          $sub = ($total['goods_price'] * $total['bonus_kill'])/100;//这里进行折扣的计算
          $total['amount'] -=  $price = number_format($sub, 2, '.', ''); // 还需要支付的订单金额
         }else{
          $total['amount'] -=  $price = number_format($total['bonus_kill'], 2, '.', ''); // 还需要支付的订单金额
         }
           
         
        }

       通过价格的重新统计。来重新调整价格的格式.从而达到了折扣的计算。

       相关文章:

          ecshop红包下发的功能分析

         修改ecshop注册的时候发送红包

      来源:中国B4C电子商务