<?php
namespace app\workerapi\controller\shops;

use app\workerapi\controller\BaseApiController;
use app\workerapi\lists\shops\ShopCartLists;
use app\workerapi\logic\shops\ShopCartLogic;
use app\workerapi\validate\shops\ShopCartValidate;

/**
 * 商城购物车
 */
class CartController extends BaseApiController
{
    public function addCart()
    {
        $params = (new ShopCartValidate())->post()->goCheck('add',['worker_id'=>$this->userId]);
        $result = ShopCartLogic::add($params);
        if(false === $result ){
            return $this->fail(ShopCartLogic::getError() ?: '系统错误');
        }
        return $this->success('加入购物车成功', [], 1, 0);
    }

    public function cartList()
    {

        return $this->dataLists(new ShopCartLists());
    }

    public function delCart()
    {
        $params = (new ShopCartValidate())->post()->goCheck('delete',['worker_id'=>$this->userId]);
        $result = ShopCartLogic::delete($params);
        if(false === $result ){
            return $this->fail(ShopCartLogic::getError() ?: '系统错误');
        }
        return $this->success('删除购物车成功', [], 1, 0);
    }

    public function editCart()
    {
        $params = (new ShopCartValidate())->post()->goCheck('edit',['worker_id'=>$this->userId]);
        $result = ShopCartLogic::edit($params);
        if(false === $result ){
            return $this->fail(ShopCartLogic::getError() ?: '系统错误');
        }
        return $this->success('修改购物车成功', [], 1, 0);
    }
}