Authored by 梁志锋

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

... ... @@ -10,9 +10,9 @@ class Helpers
/**
* 构建网站的URL
*
*
* 备注:所有的URL构建都尽量使用该方法,便于以后维护.
*
*
* @param string $uri 如 "/passport/reg/index"
* @param array $param 参数项 array(key1 => value1, key2 => value2,),默认为array()
* @param string $module 模块名 如"index"表示默认, "guang"表示逛,"list"表示商品列表,"search"表示搜索
... ... @@ -53,7 +53,7 @@ class Helpers
/**
* 根据尺寸获得图片url
*
*
* @param string $url 路径
* @param integer $width 图片宽度
* @param integer $height 图片高度
... ... @@ -67,7 +67,7 @@ class Helpers
/**
* 获取过滤APP里附加参数后的URL链接
*
*
* @param string $url 路径
* @return string 去除掉如&openby:yohobuy={"action":"go.brand"}这样的APP附加参数
*/
... ... @@ -84,7 +84,7 @@ class Helpers
/**
* 根据用户访问的COOKIE判断出性别
*
*
* @return string
*/
public static function getGenderByCookie()
... ... @@ -102,7 +102,7 @@ class Helpers
/**
* 根据用户访问的COOKIE判断出频道
*
*
* @return int
*/
public static function getChannelByCookie()
... ... @@ -124,7 +124,7 @@ class Helpers
/**
* 从用户加入购物车的COOKIE取出购物车凭证
*
*
* @return string
*/
public static function getShoppingKeyByCookie()
... ... @@ -135,7 +135,7 @@ class Helpers
/**
* 获取商品的ICON
*
*
* @param int $type
* @return array
*/
... ... @@ -195,7 +195,7 @@ class Helpers
/**
* 格式化商品信息
*
*
* @param array $productData 需要格式化的商品数据
* @param bool $showTags 控制是否显示标签
* @param bool $showNew 控制是否显示NEW图标
... ... @@ -273,7 +273,7 @@ class Helpers
/**
* 格式化资讯文章
*
*
* @param array $articleData 需要格式化的资讯数据
* @param bool $showTag 是否显示左上角标签
* @param mixed $isApp 是否显示分享,在APP客户端里嵌入需要传url链接
... ... @@ -348,7 +348,7 @@ class Helpers
/**
* 格式化广告焦点图数据
*
*
* @param array $bannerData 需要格式化的广告图数据
* @param int $width 图片的宽度
* @param int $height 图片的高度
... ... @@ -370,7 +370,7 @@ class Helpers
/**
* 生成公开的TOKEN凭证
*
*
* @param string $string 字符串
* @return string
*/
... ... @@ -381,7 +381,7 @@ class Helpers
/**
* 验证TOKEN凭证
*
*
* @param string $string 字符串
* @param string $token 公开访问TOKEN
* @return bool
... ... @@ -397,7 +397,7 @@ class Helpers
/**
* 验证手机是否合法
*
*
* @param int $mobile
* @return boolean
*/
... ... @@ -411,7 +411,7 @@ class Helpers
/**
* 验证密码是否合法
*
*
* @param int $password
* @return boolean
*/
... ... @@ -425,7 +425,7 @@ class Helpers
/**
* 验证邮箱是否合法
*
*
* @param string $email
* @return boolean
*/
... ... @@ -438,8 +438,8 @@ class Helpers
}
/**
* 验证国际手机号是否合法
*
* 验证国际手机号是否合法
*
* @param string $areaMobile
* @return boolean
*/
... ... @@ -518,7 +518,7 @@ class Helpers
/**
* 格式化订单商品
*
*
* @param array $orderGoods 订单
* @param int $count 计订单件数
* @param bool $haveLink 控制是否需要商品链接
... ... @@ -601,7 +601,7 @@ class Helpers
}
/**
* 格式化加价购商品
* 格式化加价购和赠品商品
*
* @param array $advanceGoods 加价购商品列表
* @param int $count 计商品件数
... ... @@ -615,12 +615,13 @@ class Helpers
$oneGoods = array();
foreach ($advanceGoods as $value) {
$gift = array();
$gift['promotionId'] = $value['promotion_id'];
$gift['promotionTitle'] = $value['promotion_title'];
foreach ($value['goods_list'] as $single) {
$oneGoods['id'] = $single['product_skn'];
$oneGoods['name'] = $single['product_name'];
$oneGoods['thumb'] = !empty($single['goods_images']) ? Images::getImageUrl($single['goods_images'], 120, 120) : '';
$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'];
... ... @@ -686,7 +687,7 @@ class Helpers
/**
* 获取会员的级别
*
*
* @param string $vipInfo
* @return int
*/
... ... @@ -714,9 +715,9 @@ class Helpers
/**
* 同步用户的会话
*
*
* 转向老的PHP服务器上处理, 因购物车相关的操作会依赖SESSION
*
*
* @param int $uid 用户ID
* @param string $refer 访问来源
* @param string $callback 回调方法名
... ... @@ -730,9 +731,9 @@ class Helpers
/**
* 退出清除用户的会话
*
*
* 转向老的PHP服务器上处理, 因购物车相关的操作会依赖SESSION
*
*
* @param int $uid 用户ID
* @param string $refer 访问来源
* @param string $callback 回调方法名
... ...
... ... @@ -5,25 +5,52 @@
*/
var $ = require('jquery'),
lazyLoad = require('yoho.lazyload');
lazyLoad = require('yoho.lazyload'),
Handlebars = require('yoho.handlebars'),
tip = require('../plugin/tip'),
chosePanel = require('./chose-panel');
//var chosePanel = require('./chose-panel');
var panelTmpl,
$page = $('.gift-advance-page'),
$chosePanel = $('#chose-panel');
lazyLoad($('.lazy'));
//$('.gift-advance-page').on('touchstart', '.chose', function() {
// var id = $(this).closest('.gift-advance-good').data('id');
//
// $.ajax({
// type: 'GET',
// url: '/shoppingCart/goodinfo',
// data: {
// id: id
// },
// success: function(data) {
// if (data.code === 200) {
// chosePanel.show(data.data);
// }
// }
// });
//});
\ No newline at end of file
$.get('/cart/index/giftinfoTpl', function(html) {
if (!html) {
tip.show('网络错误');
return;
}
panelTmpl = Handlebars.compile(html);
}).fail(function() {
tip.show('网络错误');
});
function getProductInfo(skn, promotionId) {
$.get('/cart/index/giftinfo', {
skn: skn,
promotionId: promotionId
}).then(function(res) {
if (!res) {
tip.show('网络错误');
return;
}
console.log(res);
if (res.code === 200) {
$chosePanel.html(panelTmpl(res.data));
chosePanel.show();
} else {
tip.show(res.message || '网络错误');
}
}).fail(function() {
tip.show('网络错误');
});
}
$page.on('touchend', '.chose', function() {
var $this = $(this),
id = $this.closest('.gift-advance-good').data('id'),
promotionId = $this.closest('.advance-block').data('promotion-id');
getProductInfo(id, promotionId);
});
... ...
... ... @@ -44,6 +44,10 @@
&:before {
content: '赠品';
display: block;
font-size: 12px;
line-height: 25rem / $pxConvertRem;
transform: scale(0.833);
}
}
... ... @@ -52,6 +56,7 @@
}
.name {
width: 440rem / $pxConvertRem;
font-size: 28rem / $pxConvertRem;
}
... ... @@ -74,8 +79,14 @@
}
.price {
margin-left: 10rem / $pxConvertRem;
font-size: 24rem / $pxConvertRem;
color: #000;
color: #f1545b;
&.market-price {
color: #999;
text-decoration: line-through;
}
}
.count {
... ... @@ -96,9 +107,9 @@
}
.title {
height: 50rem / $pxConvertRem;
line-height: 50rem / $pxConvertRem;
padding-left: 20rem / $pxConvertRem;
height: 60rem / $pxConvertRem;
line-height: 60rem / $pxConvertRem;
padding: 0 20rem / $pxConvertRem;
font-size: 24rem / $pxConvertRem;
background: #f8f8f8;
}
... ... @@ -109,4 +120,4 @@
content: '加价购';
}
}
}
\ No newline at end of file
}
... ...
... ... @@ -158,5 +158,5 @@ a {
@import "category/index";
@import "product/index";
@import "index/index";
@import "shopping-cart/index";
@import "cart/index";
@import "me/index"; //个人中心
... ...
... ... @@ -2,7 +2,7 @@
<div class="gift-advance-page yoho-page">
{{#if advanceBuyPage}}
{{# advanceBuy}}
<div class="advance-block">
<div class="advance-block" data-promotion-id="{{promotionId}}">
<p class="title">{{title}}</p>
{{#goods}}
{{> cart/gift-advance-good}}
... ... @@ -10,11 +10,11 @@
</div>
{{/ advanceBuy}}
{{else}}
{{# gift}}
{{# freebie}}
{{> cart/gift-advance-good}}
{{/ gift}}
{{/ freebie}}
{{/if}}
<div id="chose-panel"></div>
</div>
{{> layout/footer}}
... ...
... ... @@ -6,23 +6,10 @@
<div class="deps">
<p class="name row">{{name}}</p>
<p class="row">
{{#if color}}
<span class="color">
颜色:{{color}}
</span>
{{/if}}
{{#if size}}
<span class="size">
尺码:{{size}}
</span>
{{/if}}
</p>
<p class="row">
<span class="price">
¥{{price}}
</span>
<span class="price">
<span class="price market-price">
¥{{marketPrice}}
</span>
<span class="count">
... ...
... ... @@ -189,50 +189,7 @@ class CartModel
$product = CartData::cartProductData($uid, $skn);
if (isset($product['code']) && $product['code'] === 200) {
$result['code'] = 200;
$data = array();
$productData = $product['data'];
// 品牌信息
if (isset($productData['brand_info']) && !empty($productData['brand_info'])) {
$data['thumb'] = Helpers::getImageUrl($productData['brand_info']['brand_ico'], 120, 120);
}
$data['name'] = $productData['product_name'];
$data['price'] = $productData['market_price'];
$data['salePrice'] = $productData['sales_price'];
$data['storage'] = $productData['storage_sum'];
$data['num'] = $num;
// 商品选择
if (isset($productData['goods_list'])) {
$goodsList = $productData['goods_list'];
$colors = array();
$oneColor = array();
$sizes = array();
$oneSize = array();
foreach ($goodsList as $val) {
// 颜色
$oneColor = array();
$oneColor['id'] = $val['color_id'];
$oneColor['name'] = $val['color_name'];
// 尺码
foreach ($val['size_list'] as $one) {
$oneSize = array();
$oneSize['id'] = $one['size_id'];
$oneSize['name'] = $one['size_name'];
}
$sizes[] = $oneSize;
$oneColor['sizes'] = $sizes;
$colors[] = $oneColor;
}
$data['colors'] = $colors;
}
$result['data'] = $data;
$result['data'] = self::procGoodsDetail($product['data'], $num);
}
return $result;
... ... @@ -252,49 +209,7 @@ class CartModel
$product = CartData::giftProductData($skn, $promotionId);
if (isset($product['code']) && $product['code'] === 200) {
$result['code'] = 200;
$data = array();
$productData = $product['data'];
// 品牌信息
if (isset($productData['brand_info']) && !empty($productData['brand_info'])) {
$data['thumb'] = Helpers::getImageUrl($productData['brand_info']['brand_ico'], 120, 120);
}
$data['name'] = $productData['product_name'];
$data['price'] = $productData['market_price'];
$data['salePrice'] = $productData['sales_price'];
$data['storage'] = $productData['storage_sum'];
// 商品选择
if (isset($productData['goods_list'])) {
$goodsList = $productData['goods_list'];
$colors = array();
$oneColor = array();
$sizes = array();
$oneSize = array();
foreach ($goodsList as $val) {
// 颜色
$oneColor = array();
$oneColor['id'] = $val['color_id'];
$oneColor['name'] = $val['color_name'];
// 尺码
foreach ($val['size_list'] as $one) {
$oneSize = array();
$oneSize['id'] = $one['size_id'];
$oneSize['name'] = $one['size_name'];
}
$sizes[] = $oneSize;
$oneColor['sizes'] = $sizes;
$colors[] = $oneColor;
}
$data['colors'] = $colors;
}
$result['data'] = $data;
$result['data'] = self::procGoodsDetail($product['data']);
}
return $result;
... ... @@ -657,6 +572,65 @@ class CartModel
/**
* 处理购物车商品、加价购商品、赠品详情数据
*
* @param array $productData 要处理的商品数据
* @param int $num 购买数目
* @return array $data 处理之后的数据
*/
private static function procGoodsDetail($productData, $num = null)
{
$data = array();
// 品牌信息
if (isset($productData['brand_info']) && !empty($productData['brand_info'])) {
$data['thumb'] = Helpers::getImageUrl($productData['brand_info']['brand_ico'], 120, 120);
}
$data['name'] = $productData['product_name'];
$data['price'] = $productData['market_price'];
$data['salePrice'] = $productData['sales_price'];
if (isset($productData['storage_sum'])) {
$data['storage'] = $productData['storage_sum'];
}
if ($num !== null) {
$data['num'] = $num;
}
// 商品选择
if (isset($productData['goods_list'])) {
$goodsList = $productData['goods_list'];
$colors = array();
$oneColor = array();
$sizes = array();
$oneSize = array();
foreach ($goodsList as $val) {
// 颜色
$oneColor = array();
$oneColor['id'] = $val['color_id'];
$oneColor['name'] = $val['color_name'];
// 尺码
foreach ($val['size_list'] as $one) {
$oneSize = array();
$oneSize['id'] = $one['size_id'];
$oneSize['name'] = $one['size_name'];
}
$sizes[] = $oneSize;
$oneColor['sizes'] = $sizes;
$colors[] = $oneColor;
}
$data['colors'] = $colors;
}
return $data;
}
/**
* 处理不同类型的购物车数据
*
* @param array $data 不同类型购物车数据
... ...
... ... @@ -191,6 +191,16 @@ class IndexController extends AbstractAction
}
/*
* 获取购物车加价购商品数据模板
*/
public function giftinfoTplAction()
{
if ($this->isAjax()) {
echo file_get_contents($this->_view->getScriptPath() . '/../partials/cart/chose-panel.phtml');
}
}
/*
* 获取购物车加价购商品数据
*/
public function giftinfoAction()
... ...