|
|
<?php
|
|
|
|
|
|
use Action\AbstractAction;
|
|
|
use Index\CartModel;
|
|
|
use Index\UserModel;
|
|
|
use Plugin\Helpers;
|
|
|
|
|
|
/**
|
|
|
* 购物车相关的控制器
|
...
|
...
|
@@ -8,14 +11,394 @@ use Action\AbstractAction; |
|
|
* @name IndexController
|
|
|
* @package Cart
|
|
|
* @copyright yoho.inc
|
|
|
* @version 1.0 (2015-10-28 16:34:17)
|
|
|
* @author fei.hong <fei.hong@yoho.cn>
|
|
|
* @version 1.0 (2015-12-16 11:47:20)
|
|
|
* @author gtskk <iamgtskk@gmail.com>
|
|
|
*/
|
|
|
class IndexController extends AbstractAction
|
|
|
{
|
|
|
/**
|
|
|
* 通过当前用户审判是否跳到登录
|
|
|
*
|
|
|
* @param boolean $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->go(OLD_MAIN . '/cart/index/index');
|
|
|
$this->setTitle('购物车');
|
|
|
$this->setNavHeader('购物车');
|
|
|
|
|
|
$shoppingKey = Helpers::getShoppingKeyByCookie();
|
|
|
$uid = $this->getUid(true);
|
|
|
|
|
|
$data = array(
|
|
|
'shoppingCartPage' => true,
|
|
|
'shoppingCart' => CartModel::getCartData($uid, $shoppingKey)
|
|
|
);
|
|
|
|
|
|
// 渲染模板
|
|
|
$this->_view->display('index', $data);
|
|
|
}
|
|
|
/*
|
|
|
* 异步获取购物车数据
|
|
|
*/
|
|
|
public function getCartDataAction()
|
|
|
{
|
|
|
$result = array();
|
|
|
|
|
|
if ($this->isAjax()) {
|
|
|
$shoppingKey = Helpers::getShoppingKeyByCookie();
|
|
|
$uid = $this->getUid(true);
|
|
|
|
|
|
$result = CartModel::getCartData($uid, $shoppingKey);
|
|
|
}
|
|
|
|
|
|
if (empty($result)) {
|
|
|
echo ' ';
|
|
|
} else {
|
|
|
$this->echoJson($result);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 购物车商品选择与取消
|
|
|
*/
|
|
|
public function selectAction()
|
|
|
{
|
|
|
$result = array();
|
|
|
|
|
|
if ($this->isAjax()) {
|
|
|
$productId = $this->post('id', 0);
|
|
|
$uid = $this->getUid(true);
|
|
|
$shoppingKey = $this->getSession('shoppingKey');
|
|
|
$result = CartModel::selectGoods($uid, $productId, $shoppingKey);
|
|
|
}
|
|
|
|
|
|
if (empty($result)) {
|
|
|
echo ' ';
|
|
|
} else {
|
|
|
$this->echoJson($result);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 移出购物车
|
|
|
*/
|
|
|
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 giftAction()
|
|
|
{
|
|
|
$this->setTitle('赠品');
|
|
|
$this->setNavHeader('赠品');
|
|
|
|
|
|
$shoppingKey = Helpers::getShoppingKeyByCookie();
|
|
|
$uid = $this->getUid(true);
|
|
|
$cartType = $this->get('cartType', 'ordinary');
|
|
|
$data = array('shoppingCartPage' => true);
|
|
|
$data += CartModel::getCartData($uid, $shoppingKey, $cartType, true);
|
|
|
|
|
|
// 渲染模板
|
|
|
$this->_view->display('gift-advance-good', $data);
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
* 加价购页面
|
|
|
*/
|
|
|
public function advanceBuyAction()
|
|
|
{
|
|
|
$this->setTitle('加价购');
|
|
|
$this->setNavHeader('加价购');
|
|
|
|
|
|
$shoppingKey = Helpers::getShoppingKeyByCookie();
|
|
|
$uid = $this->getUid(true);
|
|
|
$cartType = $this->get('cartType', 'ordinary');
|
|
|
$data = array('shoppingCartPage' => true);
|
|
|
$data += CartModel::getCartData($uid, $shoppingKey, $cartType, false, true);
|
|
|
|
|
|
// 渲染模板
|
|
|
$this->_view->display('gift-advance-good', $data);
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
* 获取购物车商品数据
|
|
|
*/
|
|
|
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->auditJumpLogin();
|
|
|
|
|
|
$this->setTitle('购物车');
|
|
|
$this->setNavHeader('购物车');
|
|
|
|
|
|
// 购物车商品为空跳转到购物车页面
|
|
|
$shoppingKey = Helpers::getShoppingKeyByCookie();
|
|
|
$uid = $this->getUid(true);
|
|
|
$cartGoods = CartModel::getCartData($uid, $shoppingKey);
|
|
|
if (empty($cartGoods) || isset($cartGoods['isEmptyCart'])) {
|
|
|
$this->go(Helpers::url('/shoppingcart'));
|
|
|
}
|
|
|
|
|
|
$cartType = $this->get('cartType', 'ordinary');
|
|
|
$cookieData = $this->getCookie('order-info', null);
|
|
|
$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('deliveryId', 1);
|
|
|
$paymentType = $this->post('paymentTypeId', 1);
|
|
|
$couponCode = $this->post('couponCode', null);
|
|
|
$yohoCoin = $this->post('yohoCoin', 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);
|
|
|
$result = CartModel::getCouponList($uid);
|
|
|
}
|
|
|
|
|
|
if (empty($result)) {
|
|
|
echo ' ';
|
|
|
} else {
|
|
|
$this->echoJson($result);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 下单流程 选择地址
|
|
|
*/
|
|
|
public function selectAddressAction()
|
|
|
{
|
|
|
// 审判跳转登录页
|
|
|
$this->auditJumpLogin();
|
|
|
|
|
|
// 设置网站标题
|
|
|
$this->setTitle('选择地址');
|
|
|
$this->setNavHeader('选择地址', Helpers::url('/shoppingCart/orderEnsure'));
|
|
|
|
|
|
$uid = $this->getUid(true);
|
|
|
$address = UserModel::getAddressData($uid);
|
|
|
|
|
|
$this->_view->display('select-address', array(
|
|
|
'selectAddressPage' => true,
|
|
|
'pageFooter' => true,
|
|
|
'address' => $address
|
|
|
));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 下单流程 选择优惠券
|
|
|
*/
|
|
|
public function selectCouponAction()
|
|
|
{
|
|
|
// 审判跳转登录页
|
|
|
$this->auditJumpLogin();
|
|
|
|
|
|
// 设置网站标题
|
|
|
$this->setTitle('选择优惠券');
|
|
|
$this->setNavHeader('选择优惠券', Helpers::url('/shoppingCart/orderEnsure'));
|
|
|
|
|
|
$this->_view->display('select-coupon', array(
|
|
|
'selectCouponPage' => true,
|
|
|
'pageFooter' => true
|
|
|
));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 确认结算订单
|
|
|
*/
|
|
|
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('deliveryTimeId', 1); // 默认只工作日配送
|
|
|
$deliveryWay = $this->post('deliveryId', 1); // 默认普通快递
|
|
|
$invoiceTitle = $this->post('invoiceText', null);
|
|
|
$invoiceId = $this->post('invoiceType', null);
|
|
|
$paymentId = $this->post('paymentTypeId', 15);
|
|
|
$paymentType = $this->post('paymentType', 1); // 默认在线支付
|
|
|
$remark = $this->post('msg', null);
|
|
|
$couponCode = $this->post('couponCode', null);
|
|
|
$yohoCoin = $this->post('yohoCoin', 1);
|
|
|
$result = CartModel::orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $yohoCoin);
|
|
|
}
|
|
|
|
|
|
if (empty($result)) {
|
|
|
echo ' ';
|
|
|
} else {
|
|
|
// 提交成功清除Cookie
|
|
|
$this->setCookie('order-info', null);
|
|
|
|
|
|
$this->echoJson($result);
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|