diff --git a/library/LibModels/Wap/Home/CartData.php b/library/LibModels/Wap/Home/CartData.php index 61d2c60..c1f3b10 100644 --- a/library/LibModels/Wap/Home/CartData.php +++ b/library/LibModels/Wap/Home/CartData.php @@ -27,176 +27,176 @@ class CartData * @param null|int $promotionId 促销id,默认null(加价购有关) * @param null|int $uid 用户UID,可以不传 * @param string $shoppingKey 未登录用户唯一识别码,可以不传 - * @return array 加入购物车接口返回的数据 - */ - public static function addToCart($productSku, $buyNumber, $goodsType, $isEdit = 0, $promotionId = null, $uid = null, $shoppingKey = null) - { - $param = Yohobuy::param(); - $param['method'] = 'app.Shopping.add'; - $param['product_sku'] = $productSku; - $param['buy_number'] = $buyNumber; - $param['goods_type'] = $goodsType; - $param['edit_product_sku'] = $isEdit; - $param['selected'] = 'Y'; - $param['promotion_id'] = $promotionId; - - if ($uid !== null) { - $param['uid'] = $uid; - } - if ($shoppingKey !== null) { - $param['shoppingKey'] = $shoppingKey; - } - $param['client_secret'] = Sign::getSign($param); - - return Yohobuy::get(Yohobuy::API_URL, $param); - } - - /** - * 购物车商品选择与取消接口 - * - * @param int $uid 用户ID - * @param string $sku 商品sku列表 - * @param string $shoppingKey 未登录用户唯一识别码 - * @return array 购物车接口返回的数据 - */ - public static function selectGoods($uid, $sku, $shoppingKey) - { - $param = Yohobuy::param(); - $param['method'] = 'app.Shopping.selected'; - $param['product_sku_list'] = $sku; - - if (!empty($uid)) { - $param['uid'] = $uid; - } - if (!empty($shoppingKey)) { - $param['shopping_key'] = $shoppingKey; - } - - $param['client_secret'] = Sign::getSign($param); - - return Yohobuy::get(Yohobuy::API_URL, $param); - } - - /** - * 购物车数据 - * - * @param int $uid 用户ID - * @param string $shoppingKey 未登录用户唯一识别码 - * @return array 购物车接口返回的数据 - */ - public static function cartData($uid, $shoppingKey) - { - $param = Yohobuy::param(); - $param['method'] = 'app.Shopping.cart'; - - if (!empty($uid)) { - $param['uid'] = $uid; - } - if (!empty($shoppingKey)) { - $param['shopping_key'] = $shoppingKey; - } - - $param['client_secret'] = Sign::getSign($param); - - return Yohobuy::get(Yohobuy::API_URL, $param); - } - - /** - * 移出购物车 - * - * @param int $uid 用户ID - * @param string $sku 商品sku列表 - * @param string $shoppingKey 未登录用户唯一识别码 - * @return array 接口返回的数据 - */ - public static function removeFromCart($uid, $sku, $shoppingKey) - { - $param = Yohobuy::param(); - $param['method'] = 'app.Shopping.remove'; - $param['product_sku_list'] = $sku; - - if (!empty($uid)) { - $param['uid'] = $uid; - } - if (!empty($shoppingKey)) { - $param['shopping_key'] = $shoppingKey; - } - - $param['client_secret'] = Sign::getSign($param); - - return Yohobuy::get(Yohobuy::API_URL, $param); - } - - /** - * 移入收藏夹 - * - * @param int $uid 用户ID - * @param string $sku 商品sku列表 - * @return array 接口返回的数据 - */ - public static function addToFav($uid, $sku) - { - $param = Yohobuy::param(); - $param['method'] = 'app.Shopping.addfavorite'; - $param['product_sku_list'] = $sku; - $param['uid'] = $uid; - $param['client_secret'] = Sign::getSign($param); - - return Yohobuy::get(Yohobuy::API_URL, $param); - } - - /** - * 获取购物车商品数据 - * - * @param int $uid 用户ID - * @param int $skn 商品skn - * @return array 接口返回的数据 - */ - public static function cartProductData($uid, $skn) - { - $param = Yohobuy::param(); - $param['method'] = 'app.product.data'; - $param['product_skn'] = $skn; - $param['showcomment'] = 'N'; - $param['uid'] = $uid; - $param['client_secret'] = Sign::getSign($param); - - return Yohobuy::get(Yohobuy::API_URL, $param); - } - - /** - * 获取加价购商品数据 - * - * @param int $skn 商品skn - * @param int $promotionId 加价购商品促销ID - * @return array 接口返回的数据 - */ - public static function giftProductData($skn, $promotionId) - { - $param = Yohobuy::param(); - $param['method'] = 'app.product.gift'; - $param['product_skn'] = $skn; - $param['promotion_id'] = $promotionId; - $param['client_secret'] = Sign::getSign($param); - - return Yohobuy::get(Yohobuy::API_URL, $param); - } - - /** - * 增减购物车商品数量 - * - * @param int $uid 用户ID - * @param string $sku 商品SKU - * @param int $increaseNum 增加的数目 - * @param int $decreaseNum 减少的数目 - * @param string $shoppingKey 未登录用户唯一识别码 - * @return array 接口返回的数据 - */ - public static function modifyProductNum($uid, $sku, $increaseNum, $decreaseNum, $shoppingKey) - { - $param = Yohobuy::param(); - $param['method'] = 'app.Shopping.increase'; - $param['product_sku'] = $sku; + * @return array 加入购物车接口返回的数据 + */ + public static function addToCart($productSku, $buyNumber, $goodsType, $isEdit = 0, $promotionId = null, $uid = null, $shoppingKey = null) + { + $param = Yohobuy::param(); + $param['method'] = 'app.Shopping.add'; + $param['product_sku'] = $productSku; + $param['buy_number'] = $buyNumber; + $param['goods_type'] = $goodsType; + $param['edit_product_sku'] = $isEdit; + $param['selected'] = 'Y'; + $param['promotion_id'] = $promotionId; + + if (!empty($uid)) { + $param['uid'] = $uid; + } + if ($shoppingKey !== null) { + $param['shopping_key'] = $shoppingKey; + } + $param['client_secret'] = Sign::getSign($param); + + return Yohobuy::get(Yohobuy::API_URL, $param); + } + + /** + * 购物车商品选择与取消接口 + * + * @param int $uid 用户ID + * @param string $sku 商品sku列表 + * @param string $shoppingKey 未登录用户唯一识别码 + * @return array 购物车接口返回的数据 + */ + public static function selectGoods($uid, $sku, $shoppingKey) + { + $param = Yohobuy::param(); + $param['method'] = 'app.Shopping.selected'; + $param['product_sku_list'] = $sku; + + if (!empty($uid)) { + $param['uid'] = $uid; + } + if (!empty($shoppingKey)) { + $param['shopping_key'] = $shoppingKey; + } + + $param['client_secret'] = Sign::getSign($param); + + return Yohobuy::get(Yohobuy::API_URL, $param); + } + + /** + * 购物车数据 + * + * @param int $uid 用户ID + * @param string $shoppingKey 未登录用户唯一识别码 + * @return array 购物车接口返回的数据 + */ + public static function cartData($uid, $shoppingKey) + { + $param = Yohobuy::param(); + $param['method'] = 'app.Shopping.cart'; + + if (!empty($uid)) { + $param['uid'] = $uid; + } + if (!empty($shoppingKey)) { + $param['shopping_key'] = $shoppingKey; + } + + $param['client_secret'] = Sign::getSign($param); + + return Yohobuy::get(Yohobuy::API_URL, $param); + } + + /** + * 移出购物车 + * + * @param int $uid 用户ID + * @param string $sku 商品sku列表 + * @param string $shoppingKey 未登录用户唯一识别码 + * @return array 接口返回的数据 + */ + public static function removeFromCart($uid, $sku, $shoppingKey) + { + $param = Yohobuy::param(); + $param['method'] = 'app.Shopping.remove'; + $param['product_sku_list'] = $sku; + + if (!empty($uid)) { + $param['uid'] = $uid; + } + if (!empty($shoppingKey)) { + $param['shopping_key'] = $shoppingKey; + } + + $param['client_secret'] = Sign::getSign($param); + + return Yohobuy::get(Yohobuy::API_URL, $param); + } + + /** + * 移入收藏夹 + * + * @param int $uid 用户ID + * @param string $sku 商品sku列表 + * @return array 接口返回的数据 + */ + public static function addToFav($uid, $sku) + { + $param = Yohobuy::param(); + $param['method'] = 'app.Shopping.addfavorite'; + $param['product_sku_list'] = $sku; + $param['uid'] = $uid; + $param['client_secret'] = Sign::getSign($param); + + return Yohobuy::get(Yohobuy::API_URL, $param); + } + + /** + * 获取购物车商品数据 + * + * @param int $uid 用户ID + * @param int $skn 商品skn + * @return array 接口返回的数据 + */ + public static function cartProductData($uid, $skn) + { + $param = Yohobuy::param(); + $param['method'] = 'app.product.data'; + $param['product_skn'] = $skn; + $param['showcomment'] = 'N'; + $param['uid'] = $uid; + $param['client_secret'] = Sign::getSign($param); + + return Yohobuy::get(Yohobuy::API_URL, $param); + } + + /** + * 获取加价购商品数据 + * + * @param int $skn 商品skn + * @param int $promotionId 加价购商品促销ID + * @return array 接口返回的数据 + */ + public static function giftProductData($skn, $promotionId) + { + $param = Yohobuy::param(); + $param['method'] = 'app.product.gift'; + $param['product_skn'] = $skn; + $param['promotion_id'] = $promotionId; + $param['client_secret'] = Sign::getSign($param); + + return Yohobuy::get(Yohobuy::API_URL, $param); + } + + /** + * 增减购物车商品数量 + * + * @param int $uid 用户ID + * @param string $sku 商品SKU + * @param int $increaseNum 增加的数目 + * @param int $decreaseNum 减少的数目 + * @param string $shoppingKey 未登录用户唯一识别码 + * @return array 接口返回的数据 + */ + public static function modifyProductNum($uid, $sku, $increaseNum, $decreaseNum, $shoppingKey) + { + $param = Yohobuy::param(); + $param['method'] = 'app.Shopping.increase'; + $param['product_sku'] = $sku; if (!empty($increaseNum)) { $param['increase_number'] = $increaseNum; diff --git a/library/Plugin/Helpers.php b/library/Plugin/Helpers.php index 3c0afac..002dc69 100644 --- a/library/Plugin/Helpers.php +++ b/library/Plugin/Helpers.php @@ -570,6 +570,7 @@ class Helpers $oneGoods = array(); foreach ($cartGoods as $key => $value) { + $oneGoods = array(); $oneGoods['id'] = $value['product_sku']; $oneGoods['skn'] = $value['product_skn']; $oneGoods['name'] = $value['product_name']; diff --git a/template/m.yohobuy.com/actions/cart/index/gift-advance.phtml b/template/m.yohobuy.com/actions/cart/index/gift-advance.phtml index 35a64a8..9b9bb26 100644 --- a/template/m.yohobuy.com/actions/cart/index/gift-advance.phtml +++ b/template/m.yohobuy.com/actions/cart/index/gift-advance.phtml @@ -3,7 +3,7 @@ {{#if advanceBuyPage}} {{# advanceBuy}} <div class="advance-block" data-promotion-id="{{promotionId}}"> - <p class="title">{{title}}</p> + <p class="title">{{promotionTitle}}</p> {{#goods}} {{> cart/gift-advance-good}} {{/goods}} diff --git a/template/m.yohobuy.com/actions/cart/index/order-ensure.phtml b/template/m.yohobuy.com/actions/cart/index/order-ensure.phtml index 4dbf1ff..d337acd 100644 --- a/template/m.yohobuy.com/actions/cart/index/order-ensure.phtml +++ b/template/m.yohobuy.com/actions/cart/index/order-ensure.phtml @@ -70,10 +70,17 @@ {{#if yohoCoin}} <span class="desc">可抵¥{{yohoCoin}}</span> + {{#if useYohoCoin}} <span class="coin-check"> <em>- ¥ {{yohoCoin}}</em> <i class="iconfont checkbox icon-cb-checked"></i> </span> + {{else}} + <span class="coin-check"> + <em style="display: none;">- ¥ {{yohoCoin}}</em> + <i class="iconfont checkbox icon-checkbox"></i> + </span> + {{/if}} {{^}} <span class="not-used coin-check"> 无YOHO币可用 diff --git a/yohobuy/m.yohobuy.com/application/models/Index/Cart.php b/yohobuy/m.yohobuy.com/application/models/Index/Cart.php index e1c8485..acb34d8 100644 --- a/yohobuy/m.yohobuy.com/application/models/Index/Cart.php +++ b/yohobuy/m.yohobuy.com/application/models/Index/Cart.php @@ -415,6 +415,7 @@ class CartModel $oneGoods['gift'] = true; } elseif ($single['goods_type'] == 'price_gift') { $oneGoods['advanceBuy'] = true; + $oneGoods['price'] = Helpers::transPrice($single['sale_price']); } $result['goods'][] = $oneGoods; @@ -440,7 +441,8 @@ class CartModel } // 有货币 - $result['yohoCoin'] = (isset($orderCompute['use_yoho_coin']) && !empty($orderCompute['use_yoho_coin'])) ? $orderCompute['use_yoho_coin'] : $payReturn['yoho_coin']; + $result['yohoCoin'] = $payReturn['yoho_coin']; + $result['useYohoCoin'] = isset($orderCompute['use_yoho_coin']) ? $orderCompute['use_yoho_coin'] : $payReturn['yoho_coin']; // 订单数据 if (isset($payReturn['shopping_cart_data']) && !empty($payReturn['shopping_cart_data'])) { @@ -662,16 +664,9 @@ class CartModel $colorNum += $one['storage_number']; $sizeStorageStr .= $one['storage_number'] . '/'; - $sizeList[$val['color_id']][] = $oneSize; + $sizeList[$val['product_skc']][] = $oneSize; - $colorStorageGroup[$one['size_name']][$val['color_name']] = $one['storage_number']; - } - - // 统计尺码对应的各个颜色的库存量 - foreach ($sizes as $colorId => $sizeArr) { - foreach ($sizeArr as $key => $value) { - $sizeList[$colorId][$key]['colorNumStr'] = implode('/', array_values($colorStorageGroup[ $sizeArr['name'] ]) ); - } + $colorStorageGroup[$val['product_skc']][$one['size_name']] = $one['storage_number']; } // 颜色 @@ -695,9 +690,24 @@ class CartModel $totalStorageNum += $colorNum; } + // 遍历所有尺码,统计出该尺码的每个颜色的库存量,没有时添0,不能空着,因为JS中需要判断 + foreach ($sizeList as $skc => $sizeArr) { + foreach ($sizeArr as $key => $value) { + $sizeStorageStr = ''; + foreach ($colorStorageGroup as $colorArr) { + if (isset($colorArr[ $value['name'] ])) { + $sizeStorageStr .= $colorArr[ $value['name'] ] . '/'; + } else { + $sizeStorageStr .= '0/'; + } + } + $sizeList[$skc][$key]['colorNumStr'] = rtrim($sizeStorageStr, '/'); + } + } + // 格式化尺码对应的各个颜色分组 foreach ($colors as $color) { - $sizes[]['size'] = $sizeList[$color['id']]; + $sizes[]['size'] = $sizeList[$color['skcId']]; } $data['thumbs'] = $thumbImageList; diff --git a/yohobuy/m.yohobuy.com/application/modules/Cart/controllers/Index.php b/yohobuy/m.yohobuy.com/application/modules/Cart/controllers/Index.php index 12950fb..2f57cb2 100644 --- a/yohobuy/m.yohobuy.com/application/modules/Cart/controllers/Index.php +++ b/yohobuy/m.yohobuy.com/application/modules/Cart/controllers/Index.php @@ -36,7 +36,7 @@ class IndexController extends AbstractAction public function indexAction() { $this->setTitle('购物车'); - $this->setNavHeader('购物车'); + $this->setNavHeader('购物车', true, ''); $shoppingKey = Helpers::getShoppingKeyByCookie(); $uid = $this->getUid(true); @@ -275,14 +275,20 @@ class IndexController extends AbstractAction $this->setNavHeader('确认订单', Helpers::url('/cart/index/index'), false); // 不显示右上角home按钮 // 购物车商品为空跳转到购物车页面 + $cartType = $this->get('cartType', 'ordinary'); + $cartKey = 'commonCart'; + if ($cartType === 'advance') { + $cartKey = 'preSellCart'; + } + $shoppingKey = Helpers::getShoppingKeyByCookie(); $uid = $this->getUid(true); $cartGoods = CartModel::getCartData($uid, $shoppingKey); - if (empty($cartGoods) || isset($cartGoods['isEmptyCart'])) { + if (isset($cartGoods['isEmptyCart']) || empty($cartGoods[$cartKey])) { $this->go(Helpers::url('/cart/index/index')); } - $cartType = $this->get('cartType', 'ordinary'); + $cookieData = $this->getCookie('order-info', null); $uid = $this->getUid(true); $data = array( @@ -451,7 +457,7 @@ class IndexController extends AbstractAction // 设置加入购物车凭证到客户端浏览器 if (!$shoppingKey && isset($result['data']['shopping_key'])) { - $this->setCookie('_spk', $result['data']['shopping_key']); + $this->setCookie('_Spk', $result['data']['shopping_key']); } }