Authored by 毕凯

Merge branch 'develop' of http://git.dev.yoho.cn/web/yohobuy into develop

framework @ e9d066dd
Subproject commit 75bbc3b075de19f239532f60c5995d06c5f814e2
Subproject commit e9d066dd88a8e7e37103021c427a205a5cfcdcec
... ...
... ... @@ -18,6 +18,8 @@ class CacheConfig
const KEY_ACTION_GIRLS_INDEX = 'key_action_girls_index'; // 女生首页
const KEY_ACTION_KIDS_INDEX = 'key_action_kids_index'; // 潮童首页
const KEY_ACTION_LIFESTYLE_INDEX = 'key_action_lifestyle_index'; // 创意生活首页
const KEY_ACTION_INDEX_CONFIG = 'key_action_index_config'; // 频道配置
const KEY_ACTION_BOYS_BOTTOM_BANNER = 'key_action_boys_bottom_banner'; // 男生首页底部banner
const KEY_ACTION_GRILS_BOTTOM_BANNER = 'key_action_girls_bottom_banner';// 女生首页底部banner
... ... @@ -51,6 +53,6 @@ class CacheConfig
const KEY_ACTION_GUANG_DETAIL_DATA = 'key_action_guang_detail_data'; // 逛内容详情
const KEY_ACTION_GUANG_RSS_DATA = 'key_action_guang_detail_data'; // 逛订阅内容
const KEY_ACTION_ADDRESS_LIST_DATA = 'key_action_address_list_data'; // 地址树数据
const KEY_ACTION_ADDRESS_LIST_DATA = 'key_action_address_list_data'; // 地址树数据
}
... ...
... ... @@ -77,7 +77,8 @@ class IndexData
{
$param = Yohobuy::param();
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::SERVICE_URL . 'operations/api/v5/entrance/getEntrance',$param,3600);
return Yohobuy::get(Yohobuy::SERVICE_URL . 'operations/api/v5/entrance/getEntrance', $param);
}
}
... ...
... ... @@ -624,8 +624,8 @@ class Helpers
$oneGoods['name'] = $single['product_name'];
$oneGoods['thumb'] = !empty($single['goods_images']) ? Images::getImageUrl($single['goods_images'], 120, 160) : '';
$oneGoods['appearDate'] = '12月'; // 目前app接口没有返回该数据
$oneGoods['price'] = $single['last_price'];
$oneGoods['marketPrice'] = $single['market_price'];
$oneGoods['price'] = self::transPrice($single['last_price']);
$oneGoods['marketPrice'] = self::transPrice($single['market_price']);
$oneGoods['count'] = $single['storage_number'];
$gift['goods'][] = $oneGoods;
... ...
... ... @@ -148,12 +148,14 @@ $('.cart-goods').on('touchstart', '.checkbox', function() {
}
}, function() {
var id = $this.closest('.shopping-cart-good').data('id');
var count = $this.data('count');
$.ajax({
method: 'post',
url: '/cart/index/del',
data: {
id: id
sku: id,
count: count
}
}).then(function(data) {
if (data.code === 200) {
... ... @@ -240,7 +242,7 @@ function bottomCheckBoxHandeler(isSelected, type, handlerAfterTouch) {
}
goodInfo.goods_type = type;
goodInfo.selected = isSelected ? 'Y' : 'N';
goodInfo.selected = isSelected ? 'N' : 'Y';
$goods.each(function(idx, good) {
$good = $(good);
... ... @@ -257,9 +259,8 @@ function bottomCheckBoxHandeler(isSelected, type, handlerAfterTouch) {
//是否要全选
function willBeSelected() {
function willBeSelected($this) {
var isSelected = true;
var $this = $(this);
if ($this.hasClass('icon-cb-checked')) {
isSelected = true;
... ... @@ -272,7 +273,8 @@ function willBeSelected() {
//全选按钮点击事件
$selectAllBtn.on('touchend', function() {
bottomCheckBoxHandeler(willBeSelected(), getCartType(), didUpdateAllGoodsCheckStatus);
var $this = $(this);
bottomCheckBoxHandeler(willBeSelected($this), getCartType(), didUpdateAllGoodsCheckStatus);
});
$('.down').on('touchend', function() {
... ...
... ... @@ -5,7 +5,7 @@
<div class="cart-zero">
<i class="iconfont">&#xe62c</i>
<p>您的购物车暂无商品</p>
<a href="">随便逛逛</a>
<a href="/product/new">随便逛逛</a>
</div>
{{> product/recommend-for-you}}
</div>
... ... @@ -31,7 +31,7 @@
<p class="login-info">
<span class="iconfont">&#xe628;</span>
请您先
<a class="btn btn-login">登录</a>
<a class="btn btn-login" href="{{signurl}}">登录</a>
可以同步电脑和手机中的商品
</p>
{{/if}}
... ...
... ... @@ -15,7 +15,7 @@
<li class="freebie">
<span class="iconfont">&#xe620;</span>
赠品
<a href={{url}}>
<a href="/cart/index/gift">
<span class="count">{{count}}</span>
<span class="iconfont icon-right-arrow">&#xe614;</span>
</a>
... ... @@ -25,7 +25,7 @@
<li class="advance-buy">
<span class="iconfont">&#xe61b;</span>
加价购
<a>
<a href="/cart/index/advanceBuy">
<span class="count">{{advanceBuyCount}}</span>
<span class="iconfont icon-right-arrow">&#xe614;</span>
</a>
... ...
... ... @@ -13,9 +13,9 @@
<div class="text-info">
<p class="name">{{name}}</p>
<p class="price">
<span class="sale-price{{^price}} no-price{{/price}}">¥{{salePrice}}</span>
<span class="sale-price{{^price}} no-price{{/price}}">{{salePrice}}</span>
{{#if price}}
<span class="market-price">¥{{price}}</span>
<span class="market-price">{{price}}</span>
{{/if}}
</p>
</div>
... ...
... ... @@ -51,8 +51,7 @@
{{/if}}
<span class="iconfont icon-del">&#xe621;</span>
<span class="iconfont icon-del" data-count="{{count}}">&#xe621;</span>
</p>
<p class="row">
{{#if lowStocks}}
... ...
... ... @@ -23,12 +23,14 @@ class IndexController extends AbstractAction
// 设置浏览器缓存5分钟
$this->setExpires(300);
}
$result = Index\HomeModel::getChannel();
$result['background'] = Index\HomeModel::getBgImage();
$result['channelPage'] = true;
$result['showDownloadApp'] = true;
$result['searchUrl'] = Helpers::url('', null, 'search');
$result['pageFooter'] = true;
// 渲染模板
$this->_view->display('index', $result);
}
... ...
... ... @@ -41,6 +41,8 @@ class CartModel
}
/**
* 获取购物车信息
*
* @param integer $uid 用户ID
* @param string $shoppingKey 未登录用户唯一识别码
* @param string $cartType 购物车类型
... ... @@ -54,6 +56,7 @@ class CartModel
// 用户是否登录
if (empty($uid)) {
$result['signurl'] = Helpers::url('/signin.html', array('refer' => Helpers::url('/cart/index/index')));
$result['showLoginInfo'] = true;
}
... ... @@ -63,11 +66,14 @@ class CartModel
// 处理普通购物车和预售购物车的数据
do {
if (!isset($cartData['data']) || empty($cartData['data'])) {
// $result['isEmptyCart'] = true;
break;
}
$cart = $cartData['data'];
$result['cartNav'] = true;
if ($cartType !== 'all') { // 加价购或者赠品数据
$result = self::procCartData($cart['ordinary_cart_data'], $onlyGift, $onlyAdvanceBuy);
break;
... ... @@ -93,6 +99,31 @@ class CartModel
}
/**
* 获取购物车商品数目
*
* @param integer $uid 用户ID
* @param string $shoppingKey 未登录用户唯一识别码
* @return array|mixed 购物车商品数目
*/
public static function getCartCount($uid, $shoppingKey)
{
$result = array(
'code' => 200,
'data' => array(
'cart_goods_count' => 0
)
);
$carData = self::getCartData($uid, $shoppingKey);
if (isset($carData['commonGoodsCount'])) {
$result['data']['cart_goods_count'] = $carData['commonGoodsCount'] + $carData['presellGoodsCount'];
}
return $result;
}
/**
* 购物车商品选择与取消接口返回的数据处理
*
* @param int $uid 用户ID
... ... @@ -123,16 +154,17 @@ class CartModel
* 移出购物车
*
* @param int $uid 用户ID
* @param string $sku 商品sku列表
* @param string $sku 商品sku
* @param string $count 要删除的数目
* @param string $shoppingKey 未登录用户唯一识别码
* @return array 接口返回的数据
*/
public static function removeFromCart($uid, $sku, $shoppingKey)
public static function removeFromCart($uid, $sku, $count, $shoppingKey)
{
$result = array('code' => 400, 'message' => '出错啦~');
// 处理sku
$sku_list = json_encode(array($sku => 1));
$sku_list = json_encode(array($sku => $count));
$remove = CartData::removeFromCart($uid, $sku_list, $shoppingKey);
if ($remove && isset($remove['code'])) {
... ... @@ -485,10 +517,18 @@ class CartModel
{
$result = array('code' => 400, 'message' => '出错啦~');
$coupon = CartData::searchCoupon($uid, $couponCode);
if ($coupon && isset($coupon['code'])) {
$result = $coupon;
}
do {
if (empty($couponCode)) {
$result['code'] = 401;
$result['message'] = '优惠券代码为空';
break;
}
$coupon = CartData::searchCoupon($uid, $couponCode);
if ($coupon && isset($coupon['code'])) {
$result = $coupon;
}
}while(0);
return $result;
}
... ... @@ -583,8 +623,8 @@ class CartModel
$data = array();
$data['name'] = $productData['product_name'];
$data['price'] = Helpers::transPrice($productData['market_price']);
$data['salePrice'] = Helpers::transPrice($productData['sales_price']);
$data['price'] = $productData['format_market_price'];
$data['salePrice'] = $productData['format_sales_price'];
if (isset($productData['storage_sum'])) {
$data['storage'] = $productData['storage_sum'];
... ...
... ... @@ -20,6 +20,7 @@ use Configs\CacheConfig;
class HomeModel
{
/* 频道选择页取背景图片的位置码 */
const CODE_BG = '7ba9118028f9b22090b57341487567eb';
/* 男生楼层资源的位置码 */
... ... @@ -70,7 +71,8 @@ class HomeModel
/**
* 设置选择的频道保存到浏览器COOKIE
*
* (已废弃,改成JS设置)
*
* @param string $cookie
* @return void
*/
... ... @@ -99,10 +101,10 @@ class HomeModel
// 调用接口获取数据
$banner = IndexData::getBannerStart(self::CODE_BG);
if (isset($banner['code']) && $banner['code'] == 200 && !empty($banner['data'])) {
$imgArr = $banner['data'][0]['data'];
if (isset($banner['data'][0]['data']['list'])) {
$imgArr = $banner['data'][0]['data']['list'];
}
$imgArr = $banner['data'][0]['data'];
if (isset($banner['data'][0]['data']['list'])) {
$imgArr = $banner['data'][0]['data']['list'];
}
$result = Helpers::getImageUrl($imgArr[0]['src'], 640, 800, 2);
}
... ... @@ -128,7 +130,7 @@ class HomeModel
public static function getBottomBanner($channel)
{
$result = false;
if($channel == 2) {
if ($channel == 2) {
$resource = self::CODE_NAME_GIRLS_BOTTOM_BANNER;
$cache = CacheConfig::KEY_ACTION_GRILS_BOTTOM_BANNER;
} else {
... ... @@ -324,45 +326,65 @@ class HomeModel
*
* @return array
*/
public static function getChannel(){
public static function getChannel()
{
$result = array();
$result['showYohood'] = false;
$data = IndexData::channelData();
if (USE_CACHE) {
$key = CacheConfig::KEY_ACTION_INDEX_CONFIG;
// 先尝试获取一级缓存(master), 有数据则直接返回.
$result = Cache::get($key, 'master');
if (!empty($result)) {
return $result;
}
}
$channelList = array();
if(isset($data['data']['list'])){
foreach($data['data']['list'] as $key => $value){
switch ($value['channel_id']) {
case 5:
$result['showYohood'] = true;
$result['yohoodHref'] = '/yohood';
break;
$data = IndexData::channelData();
if (!empty($data['data']['list'])) {
$build = array();
foreach ($data['data']['list'] as $value) {
$build = array();
switch (intval($value['channel_id'])) {
case 1:
$channelList[$key]['href'] = '/boys';
$channelList[$key]['title'] = '男生';
$channelList[$key]['entitle'] = 'BOYS';
$build['href'] = '/boys';
$build['title'] = '男生';
$build['entitle'] = 'BOYS';
break;
case 2:
$channelList[$key]['href'] = '/girls';
$channelList[$key]['title'] = '女生';
$channelList[$key]['entitle'] = 'GIRLS';
$build['href'] = '/girls';
$build['title'] = '女生';
$build['entitle'] = 'GIRLS';
break;
case 3:
$channelList[$key]['href'] = '/kids';
$channelList[$key]['title'] = '潮童';
$channelList[$key]['entitle'] = 'KIDS';
$build['href'] = '/kids';
$build['title'] = '潮童';
$build['entitle'] = 'KIDS';
break;
case 4:
$channelList[$key]['href'] = '/lifestyle';
$channelList[$key]['title'] = '创意生活';
$channelList[$key]['entitle'] = 'LIFESTYLE';
$build['href'] = '/lifestyle';
$build['title'] = '创意生活';
$build['entitle'] = 'LIFESTYLE';
break;
default:
case 5:
$result['showYohood'] = true;
$result['yohoodHref'] = 'http://yohood.cn';
break;
default:
continue;
}
$result['channelList'][] = $build;
}
}
if (USE_CACHE) {
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
if (empty($result)) {
$result = Cache::get($key, 'slave');
}
// 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
else {
Cache::set($key, $result);
}
$result['channelList'] = $channelList;
}
return $result;
... ...
... ... @@ -45,9 +45,11 @@ class IndexController extends AbstractAction
'shoppingCartPage' => true,
'shoppingCart' => CartModel::getCartData($uid, $shoppingKey)
);
// 渲染模板
$this->_view->display('index', $data);
}
/*
* 异步获取购物车数据
*/
... ... @@ -70,6 +72,22 @@ class IndexController extends AbstractAction
}
/**
* 异步获取购物车商品数目
*/
public function countAction()
{
$result = array();
if ($this->isAjax()) {
$uid = $this->getUid(true);
$shoppingKey = Helpers::getShoppingKeyByCookie();
$result = CartModel::getCartCount($uid, $shoppingKey);
}
$this->echoJson($result);
}
/**
* 购物车商品选择与取消
*/
public function selectAction()
... ... @@ -77,17 +95,13 @@ class IndexController extends AbstractAction
$result = array();
if ($this->isAjax()) {
$productId = $this->post('id', 0);
$productId = $this->post('skuList', 0);
$uid = $this->getUid(true);
$shoppingKey = $this->getSession('shoppingKey');
$shoppingKey = Helpers::getShoppingKeyByCookie();
$result = CartModel::selectGoods($uid, $productId, $shoppingKey);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/**
... ... @@ -98,17 +112,14 @@ class IndexController extends AbstractAction
$result = array();
if ($this->isAjax()) {
$productId = $this->post('id', 0);
$sku = $this->post('sku', 0);
$count = $this->post('count', 0);
$uid = $this->getUid(true);
$shoppingKey = $this->getSession('shoppingKey');
$result = CartModel::removeFromCart($uid, $productId, $shoppingKey);
$shoppingKey = Helpers::getShoppingKeyByCookie();
$result = CartModel::removeFromCart($uid, $sku, $count, $shoppingKey);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/**
... ... @@ -124,11 +135,7 @@ class IndexController extends AbstractAction
$result = CartModel::addToFav($uid, $productId);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/*
... ... @@ -182,11 +189,7 @@ class IndexController extends AbstractAction
$result['num'] = $num;
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/*
... ... @@ -212,11 +215,7 @@ class IndexController extends AbstractAction
$result = CartModel::giftProductData($skn, $promotionId);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/**
... ... @@ -236,11 +235,7 @@ class IndexController extends AbstractAction
$result = CartModel::modifyProductNum($uid, $sku, $increaseNum, $decreaseNum, $shoppingKey);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/**
... ... @@ -262,11 +257,7 @@ class IndexController extends AbstractAction
$result = CartModel::modifyCartProduct($uid, $params, $shoppingKey);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/**
... ... @@ -316,11 +307,7 @@ class IndexController extends AbstractAction
$result = CartModel::orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $yohoCoin);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/**
... ... @@ -331,16 +318,12 @@ class IndexController extends AbstractAction
$result = array();
if ($this->isAjax()) {
$couponCode = $this->get('couponCode', '');
$couponCode = $this->post('couponCode', '');
$uid = $this->getUid(true);
$result = CartModel::searchCoupon($uid, $couponCode);
}
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
$this->echoJson($result);
}
/**
... ... @@ -464,7 +447,7 @@ class IndexController extends AbstractAction
// 设置加入购物车凭证到客户端浏览器
if (isset($result['data']['shopping_key'])) {
$this->setCookie('_spk', $shoppingKey);
$this->setCookie('_spk', $result['data']['shopping_key']);
}
}
... ...