<?php namespace Place\Api;
use Dever;
use Place;
use Place\Lib\Main;
class Cart extends Main
{
    protected $login = true;
    protected $entry = true;

    # 获取购物车
    public function list()
    {
        $data['list'] = Dever::load('cart', 'goods')->getList();
        return Place::result($data);
    }

    # 购物车增减
    public function up()
    {
        $id = Dever::input('type_id', 'is_numeric', '资源ID');
        $sku_id = Dever::input('price_id', 'is_numeric', '价格ID');
        $num = Dever::input('num', 'is_numeric', '数量', 1);
        return Dever::load('cart', 'goods')->up($id, $sku_id, $num);
    }

    # 购物车选中状态
    public function edit()
    {
        $id = Dever::input('type_id', 'is_numeric', '资源ID');
        $sku_id = Dever::input('price_id', 'is_numeric', '价格ID');
        $status = Dever::input('status', 'is_numeric', '选中状态', 1);
        return Dever::load('cart', 'goods')->edit($id, $sku_id, $status);
    }

    # 删除购物车某个商品
    public function delete()
    {
        $id = Dever::input('type_id', 'is_numeric', '资源ID');
        $sku_id = Dever::input('price_id', 'is_numeric', '价格ID');
        return Dever::load('cart', 'goods')->delete($id, $sku_id);
    }

    # 清空购物车
    public function drop()
    {
        return Dever::load('cart', 'goods')->drop();
    }

    # 购物车下单
    public function confirm()
    {
        return Dever::load('cart', 'goods')->confirm();
    }

    # 拉起支付
    public function pay()
    {
        $info = $this->confirm();
        return Dever::load('order', 'place')->pay($info, 3, 'goods');
    }
}