Blame view

yohobuy/m.yohobuy.com/application/controllers/ShoppingCart.php 6.46 KB
xuqi authored
1 2 3
<?php

use Action\AbstractAction;
4
use Index\CartModel;
5
use Index\UserModel;
6
use Plugin\Helpers;
xuqi authored
7 8 9 10 11 12

/**
 * 购物车
 */
class ShoppingCartController extends AbstractAction
{
hf authored
13 14 15
    /*
     * 购物车首页
     */
16
xuqi authored
17 18
    public function indexAction()
    {
hf authored
19 20
        $this->setTitle('购物车');
        $this->setNavHeader('购物车');
21
hf authored
22 23
        $shoppingKey = Helpers::getShoppingKeyByCookie();
        $uid = $this->getUid(true);
24
xuqi authored
25
        $data = array(
hf authored
26 27
            'shoppingCartPage' => true,
            'shoppingCart' => CartModel::getCartData($uid, $shoppingKey)
xuqi authored
28
        );
29
xuqi authored
30
        // 渲染模板
31
        $this->_view->display('index', $data);
xuqi authored
32
    }
33
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
	/**
	 * 移出购物车
	 */
	public function delAction()
	{
		$result = array();

		if ($this->isAjax()) {
			$productId = $this->post('id', 0);
			$uid = $this->getUid(true);
			$shoppingKey = $this->getSession('shoppingKey');
			$result = CartModel::removeFromCart($uid, $productId, $shoppingKey);
		}

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

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

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

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

	/*
	 * 获取购物车商品数据
	 */
	public function goodinfoAction()
	{
		$result = array();

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

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

	/*
	 * 获取购物车加价购商品数据
	 */
	public function giftinfoAction()
	{
		$result = array();

		if ($this->isAjax()) {
			$skn = $this->get('skn', null);
			$promotionId = $this->get('promotionId', null);
			$result = CartModel::giftProductData($skn, $promotionId);
		}

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

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

		if ($this->isAjax()) {
			$shoppingKey = $this->getSession('shoppingKey');
			$uid = $this->getUid(true);

			$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($uid, $params, $shoppingKey);
		}

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

	/**
	 * 购物车结算请求
	 */
	public function orderEnsureAction()
	{
		$this->setTitle('购物车');
		$this->setNavHeader('购物车');

		$cartType = $this->post('cartType', 'ordinary');
毕凯 authored
152
		$cookieData = $this->getCookie('order-info', null);
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
		$uid = $this->getUid(true);
		$data = array(
			'orderEnsurePage' => true,
			'orderEnsure' => CartModel::cartPay($uid, $cartType, $cookieData)
		);


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

	/**
	 * 购物车选择改变字段,重新运算订单数据
	 */
	public function orderComputeAction()
	{
		$result = array();

		if ($this->isAjax()) {
			$cartType = $this->post('cartType', 'ordinary');
			$deliveryWay = $this->post('deliveryWay', 1);
			$paymentType = $this->post('paymentType', 1);
			$couponCode = $this->post('paymentType', null);
			$yohoCoin = $this->post('paymentType', null);
			$uid = $this->getUid(true);
			$result = CartModel::orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin);
		}

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

	/**
	 * 购物车输入优惠券码使用优惠券
	 */
	public function couponSearchAction()
	{
		$result = array();

		if ($this->isAjax()) {
			$couponCode = $this->get('couponCode', '');
			$uid = $this->getUid(true);
			$result = CartModel::searchCoupon($uid, $couponCode);
		}

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

	/**
	 * 购物车结算--获取优惠券列表
	 */
	public function couponListAction()
	{
		$result = array();

		if ($this->isAjax()) {
			$uid = $this->getUid(true);
			$page = $this->get('page', 1);
			$result = CartModel::getCouponList($uid);
		}

		if (empty($result)) {
			echo ' ';
		} else {
			$this->echoJson($result);
		}
	}
hf authored
226
xuqi authored
227
    /**
228
     * 下单流程 选择地址
xuqi authored
229
     */
hf authored
230 231
    public function selectAddressAction()
    {
232 233 234 235
        // 设置网站标题
        $this->setTitle('选择地址');
        $this->setNavHeader('选择地址', Helpers::url('/shoppingCart/orderEnsure'));
236
	    $uid = $this->getUid(true);
237 238 239 240 241 242 243
        $address = UserModel::getAddressData($uid);

        $this->_view->display('select-address', array(
            'selectAddressPage' => true,
            'pageFooter' => true,
            'address' => $address
        ));
xuqi authored
244 245 246
    }

    /**
247 248
     * 下单流程 选择优惠券
     */
hf authored
249 250
    public function selectCouponAction()
    {
251 252 253 254 255
        // 设置网站标题
        $this->setTitle('选择优惠券');
        $this->setNavHeader('选择优惠券', Helpers::url('/shoppingCart/orderEnsure'));
        $this->_view->display('select-coupon', array(
            'selectCouponPage' => true,
256
            'pageFooter' => true
257
        ));
xuqi authored
258
    }
hf authored
259
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
	/**
	 * 确认结算订单
	 */
	public function orderSubAction()
	{
		$result = array();

		if ($this->isAjax()) {
			$uid = $this->getUid(true);
			$addressId = $this->post('addressId', null);
			$cartType = $this->post('cartType', 'ordinary'); // 默认普通购物车
			$deliveryTime = $this->post('deliveryTime', 1); // 默认只工作日配送
			$deliveryWay = $this->post('deliveryWay', 1); // 默认普通快递
			$invoiceTitle = $this->post('invoiceTitle', null);
			$invoiceId = $this->post('invoiceId', null);
			$paymentId = $this->post('paymentId', 15);
			$paymentType = $this->post('paymentType', 1); // 默认在线支付
			$remark = $this->post('remark', null); // 默认在线支付
			$yohoCoin = $this->post('yohoCoin', 1);
			$result = CartModel::orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $yohoCoin);
		}

		if (empty($result)) {
			echo ' ';
		} else {
			// 提交成功清除Cookie
			$this->setCookie('orderInfo', null);

			$this->echoJson($result);
		}
	}
xuqi authored
291
}