PHP code example of jc91715 / promote
1. Go to this page and download the library: Download jc91715/promote 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/ */
jc91715 / promote example snippets
Jc91715\Promote\PromoteManage;
use Jc91715\Promote\Promote\AbstractPromote;
use Jc91715\Promote\Rule\abstractRule;
use Jc91715\Promote\Action\ActionInterface;
class Promote extends AbstractPromote
{
}
class Rule extends abstractRule
{
public function across()
{
echo "通过规则,购A\n";
return true;
}
}
class Rule1 extends abstractRule
{
public function across()
{
echo "通过规则,打八折\n";
return true;
}
public function execute()
{
echo "执行行为,订单打八折\n";
}
}
class Action implements ActionInterface
{
public function execute()
{
echo "执行行为,赠B\n";
}
}
//特殊规则Rule和Action分离
$promote = new Promote();
$rule = new Rule();
$action = new Action();
$promote->addRule($rule);
$promote->addAction($action);
//一般规则只有Rule
$promote1 = new Promote();
$rule1= new Rule1();
$promote1->addRule($rule1);
$promoteManage=new PromoteManage();
$promoteManage->addPromote($promote);
$promoteManage->addPromote($promote1);
$promoteManage->apply();