PHP code example of cncoders / thinkphp-order
1. Go to this page and download the library: Download cncoders/thinkphp-order 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/ */
cncoders / thinkphp-order example snippets
$cart = array(
array('goods_id' => 1, 'goods_name' => '课程一', 'price' => 9.9, 'num' => 2),
array('goods_id' => 2, 'goods_name' => '课程2', 'price' => 19.9, 'num' => 1),
array('goods_id' => 3, 'goods_name' => '课程3', 'price' => 29.9, 'num' => 3),
);
$decorator = new OrderDecorator($cart);
//先处理成基础订单
$decorator->addDecorator(new BaseDecorator());
//对订单的优惠券处理
$coupon_id = 1;
$coupon_price = 20;
$coupon_where = 100;
$decorator->addDecorator(new CouponDecorator($coupon_id, $coupon_price, $coupon_where, true));
$decorator->addDecorator(new DeliveryDecorator(8, 288));
$order = $decorator->boot();
namespace cncoders\order\interfaces;
interface DecoratorInterface
{
/**
* 添加购物车数据 购物车的原始数据
* @param array $cart
* @return mixed
*/
public function addCartData(array $cart);
/**
* 添加订单数据 (上一个观察者处理的订单数据会通过这个方法传递进来
* @param array $order
* @return mixed
*/
public function addOrderData( array $order);
/**
* 返回处理结果
* @return mixed
*/
public function boot();
}