ShoppingCart.php 7.82 KB
<?php

use Action\AbstractAction;
use Index\CartModel;
use Plugin\Helpers;

/**
 * 购物车
 */
class ShoppingCartController extends AbstractAction
{
    
    protected $_uid;
    
    /**
     * 通过当前用户审判是否跳到登录
     *
     * @param int $useSession (true:从服务端session中检查, false:从客户端cookie中检查)
     * @return void
     */
    protected function auditJumpLogin($useSession = true)
    {
        $uid = $this->getUid($useSession);
        if (!$uid) {
            $this->go(Helpers::url('/signin.html', array('refer' => $this->server('HTTP_REFERER', SITE_MAIN))));
        }
    }

    /*
     * 首页
     */
    public function indexAction()
    {
        $this->setTitle('购物车');
        $this->setNavHeader('购物车');

        $data = array(
            'shoppingCartPage' => true,
            'shoppingCart' => CartModel::getCartData($this->_uid)
        );

        // 渲染模板
        $this->_view->display('index', $data);
    }

    /**
     * 移出购物车
     */
    public function delAction()
    {
        $result = array();

        if ($this->isAjax()) {
            $productId = $this->post('id', 0);
            $result = CartModel::removeFromCart($this->_uid, $productId);
        }

        if (empty($result)) {
            echo ' ';
        } else {
            $this->echoJson($result);
        }
    }

    /**
     * 移入收藏夹
     */
    public function colAction()
    {
        $result = array();

        if ($this->isAjax()) {
            $productId = $this->post('id', 0);
            $result = CartModel::addToFav($this->_uid, $productId);
        }

        if (empty($result)) {
            echo ' ';
        } else {
            $this->echoJson($result);
        }
    }

    /**
     * 修改购物车商品数据
     */
    public function modifyAction()
    {
        $result = array();

        if ($this->isAjax()) {

            $params = array();
            $params['old_product_sku'] = $this->post('old_product_sku', 0);
            $params['new_product_sku'] = $this->post('new_product_sku', 0);
            $params['buy_number'] = $this->post('buy_number', 0);
            $params['selected'] = $this->post('selected', null);
            $result = CartModel::modifyCartProduct($this->_uid, $params);
        }

        if (empty($result)) {
            echo ' ';
        } else {
            $this->echoJson($result);
        }
    }

    public function giftAdvanceAction()
    {
        $data = array(
            'advance' => array(
                array(
                    'title' => '【izzue】加¥19购袜子',
                    'goods' => array(
                        'id' => 1,
                        'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/09/17/03/014cacfa5c458b9732c68adf1af15d7a45.jpg?imageMogr2/thumbnail/120x120/extent/120x120/background/d2hpdGU=/position/center/quality/90',
                        'name' => 'Life.After.Life纯棉短袜',
                        'salePrice' => 19,
                        'price' => 99,
                        'count' => 1
                    )
                ),
                array(
                    'title' => '【银鳞堂】加¥9购手绳',
                    'goods' => array(
                        'id' => 1,
                        'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/10/03/10/01bc1878f9154e77ac4f7a6003c954f1b8.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',
                        'name' => '银鳞堂民族风牛皮手绳',
                        'salePrice' => 9,
                        'price' => 19,
                        'count' => 1
                    )
                )
            )
        );

        $data = array(
            'gift' => array(
                'id' => 1,
                'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/09/17/03/014cacfa5c458b9732c68adf1af15d7a45.jpg?imageMogr2/thumbnail/120x120/extent/120x120/background/d2hpdGU=/position/center/quality/90',
                'name' => 'Life.After.Life纯棉短袜',
                'color' => '黄色',
                'size' => 'L',
                'price' => 0,
                'count' => 1
            )
        );

        $this->_view->display('gift-advance', array('giftAdvancePage' => true, 'pageHeader' => array(
                'navBack' => true, 'navTitle' => '加价购'), 'shoppingCart' => $data));
    }

    public function orderEnsureAction()
    {
        $data = array(
            'orderEnsurePage' => true,
            'orderEnsure' => array(
                'name' => '申建军',
                'phoneNum' => '12345678',
                'address' => '江苏省南京市建邺区',
                'dispatchMode' => array(
                    array(
                        'id' => 1,
                        'name' => '普通快递¥10'
                    ),
                    array(
                        'id' => 2,
                        'name' => '顺丰速运¥15(仅支持顺丰克配送的地区)'
                    )
                ),
                'dispatchTime' => array(
                    array(
                        'id' => 1,
                        'name' => '工作日、双休日、节假日均可送货'
                    ),
                    array(
                        'id' => 2,
                        'name' => '只工作日送货'
                    ),
                    array(
                        'id' => 3,
                        'name' => '只双休日、节假日送货'
                    )
                ),
                'goods' => array(
                    array(
                        'id' => 1,
                        'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/11/04/05/01ce2aff32fc3c90584f516167cd526d91.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',
                        'name' => 'Adidas Originals ZX FLUXM22508',
                        'color' => '黄',
                        'size' => '43',
                        'price' => '699.00',
                        'count' => '2'
                    ),
                    array(
                        'id' => 1,
                        'thumb' => 'http://img10.static.yhbimg.com/goodsimg/2015/11/04/05/0188f1aca49ac478a565ec029b5d2d4a6c.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',
                        'name' => 'B.Duck浴室玩伴mini浮水鸭',
                        'gift' => true,
                        'color' => '黄',
                        'size' => '43',
                        'price' => '0.00',
                        'count' => '1'
                    )
                ),
                'coupon' => array(
                    'count' => 1,
                    'notUsed' => true
                ),
                'yohoCoin' => '0',
                'invoice' => true,
                'sumPrice' => 900,
                'salePrice' => 90,
                'freight' => 0,
                'price' => 810
            )
        );

        $this->_view->display('order-ensure', $data);
    }

    /**
     * 读取chose-panel内容
     */
    public function tplAction()
    {
        if ($this->isAjax()) {
            $data = file_get_contents('../../../template/m.yohobuy.com/partials/shopping-cart/chose-panel.phtml');

            echo($data);
        }
    }

    public function goodinfoAction()
    {
        $result = array();

        if ($this->isAjax()) {
            $num = $this->get('buy_num', 1);
            $skn = $this->get('id', 1);
            $result = CartModel::cartProductData($this->_uid, $skn, $num); // 测试skn的ID为51172055
            $result['num'] = $num;
        }

        if (empty($result)) {
            echo ' ';
        } else {
            $this->echoJson($result);
        }
    }

}