<?php
namespace Helpers;

/**
 * Strategy 计算手续费策略
 */
class Strategy {

    /**
     * @param $current_amount
     * @param $total_amount
     * @param $cleared_amount
     * @param $total_tip
     * @param $cleared_tip
     * 计算微信手续费公式，计算单位是分
     */
    public static function getWxTip($current_amount, $total_amount, $cleared_amount, $total_tip, $cleared_tip) {

        $left_amount = $total_amount - $cleared_amount;
        if($left_amount == 0) {
            return $left_amount;
        }

        return round($current_amount/$left_amount * ($total_tip - $cleared_tip));
    }

    /**
     * @param $current_amount
     * @param $total_amount
     * @param $cleared_amount
     * @param $total_tip
     * @param $cleared_tip
     * @return false|float
     * 计算平台手续费
     */
    public static function getTip($current_amount, $total_amount, $cleared_amount, $total_tip, $cleared_tip) {

        $left_amount = $total_amount - $cleared_amount;
        if($left_amount == 0) {
            return $left_amount;
        }

        return round($current_amount/$left_amount * ($total_tip - $cleared_tip));
    }
}