PHP code example of renjiangfeng / laravel-calculator-discount

1. Go to this page and download the library: Download renjiangfeng/laravel-calculator-discount library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

renjiangfeng / laravel-calculator-discount example snippets


 [
    'status_verify'         => false,//是否对优惠的状态验证
    'time_verify'         => false,//是否对优惠的开始时间和结束时间验证
    /**
     * 对应的数据模型
     **/
    'discount_model'        => App\Discount::class,
    'discount_action_model' => App\DiscountAction::class,
    'discount_rule_model'   => App\DiscountRule::class,
];



namespace App\Http\Controllers;

use Eric\LaravelCalculatorDiscount\CalculatorDiscount;

class IndexController extends Controller
{
    public function index(){
      $CalculatorDiscount =   new CalculatorDiscount();
      //优惠类型:订单总金额
      $condition = [
            'amount'=>20000
        ];
        //优惠类型:固定分类
        $condition = [
            'category_id'=>1
            //'category_id'=>[1,2]
        ];
        //优惠类型:固定商品
        $condition = [
            'product_id'=>1
            //'product_id'=>[1,2]
        ];
      $discount_id = 7;//优惠记录ID
       $res =  $CalculatorDiscount->VerifyRule($condition,$discount_id);
        return $res;
        // $res  true  代表满足优惠条件
        // $res  false  代表不满足优惠条件
    }
    public function action(){
        $CalculatorDiscount =   new CalculatorDiscount();
        $total = 20000;//订单总金额
        $discount_id = 7;//优惠记录ID
        $Discounted_price =  $CalculatorDiscount->getDiscountAction($discount_id,$total);
        return $Discounted_price;//优惠的金额
    }
}