Authored by hf

code review by fei.hong: do add criteo analysis codes

... ... @@ -682,10 +682,12 @@ class Helpers
*
* @param array $cartGoods 购物车商品列表
* @param bool $isAdvanceCart 是否是预售购物车(和上市期有关)
* @param boolean $isValid 是否是可用商品(非失效商品),默认是
* @param bool $isValid 是否是可用商品(非失效商品),默认是
* @param bool $isOffShelves 是否卖光了, 默认否
* @param array $analysis 第三方数据分析用的
* @return array 处理之后的购物车商品数据
*/
public static function formatCartGoods($cartGoods, $isAdvanceCart, $isValid = true, $isOffShelves = false)
public static function formatCartGoods($cartGoods, $isAdvanceCart, $isValid = true, $isOffShelves = false, &$analysis = array())
{
$result = array();
... ... @@ -744,6 +746,29 @@ class Helpers
elseif ($value['real_price'] == 0) {
$oneGoods['productPrice'] = self::transPrice($value['sales_price']);
$oneGoods['xForOne'] = true;
// 分析用: 商品ID列表
$analysis['ids'][] = $value['product_id'];
// 分析用: 品友
$analysis['ipinyou'] .= $value['product_id'] . ',' . $value['buy_number'] . ';';
// 分析用: CRITEO
$analysis['criteo'][] = array(
'id' => $value['product_skn'],
'quantity' => intval($value['buy_number']),
'price' => $value['last_vip_price'],
);
}
else {
// 分析用: 商品ID列表
$analysis['ids'][] = $value['product_id'];
// 分析用: 品友
$analysis['ipinyou'] .= $value['product_id'] . ',' . $value['buy_number'] . ';';
// 分析用: CRITEO
$analysis['criteo'][] = array(
'id' => $value['product_skn'],
'quantity' => intval($value['buy_number']),
'price' => $value['last_vip_price'],
);
}
// 商品类型:预售或普通
... ...
... ... @@ -341,4 +341,40 @@
<div class="loading"><span></span>请稍后...</div>
</div>
<!-- 商品详细信息窗口 -->
<script type="text/javascript">
(function (d) {
window.bd_cpro_rtid="P1fsPWc";
var s = d.createElement("script");s.type = "text/javascript";s.async = true;s.src = location.protocol + "//cpro.baidu.com/cpro/ui/rt.js";
var s0 = d.getElementsByTagName("script")[0];s0.parentNode.insertBefore(s, s0);
})(document);
</script>
<script type="text/javascript" src="http://static.criteo.net/js/ld/ld.js" async="true"></script>
<script type="text/javascript">
window.criteo_q = window.criteo_q || [];
window.criteo_q.push(
{event:"setAccount", account: 16184},
{event:"setCustomerId", id: "{{uid}}"},
{event:"setSiteType", type: "d"},
{event:"viewBasket", item: {{{cartEnsure.criteo}}} }
);
</script>
<!-- 聚效 -->
<script type="text/javascript">
var _mvq = window._mvq || [];
window._mvq = _mvq;
_mvq.push(['$setAccount', 'm-23428-1']);
_mvq.push(['$setGeneral', 'cartview', '', /*用户名*/ '', '{{uid}}']);
_mvq.push(['$logConversion']);
_mvq.push(['$addItem', '', /*商品id*/ '{{cartEnsure.ids}}', '', '']);
_mvq.push(['$logData']);
</script>
<script>
!function(w,d,e){
var _money='{{cartEnsure.ipinyouAmount}}';
var _productList='{{cartEnsure.ipinyou}}';
var b=location.href,c=d.referrer,f,s,g=d.cookie,h=g.match(/(^|;)\s*ipycookie=([^;]*)/),i=g.match(/(^|;)\s*ipysession=([^;]*)/);if (w.parent!=w){f=b;b=c;c=f;};u='//stats.ipinyou.com/cvt?a='+e('MC.Ok.7NFMIlCH_F_LE2riRlF2r_')+'&c='+e(h?h[2]:'')+'&s='+e(i?i[2].match(/jump\%3D(\d+)/)[1]:'')+'&u='+e(b)+'&r='+e(c)+'&rd='+(new Date()).getTime()+'&Money='+e(_money)+'&ProductList='+e(_productList)+'&e=';
function _(){if(!d.body){setTimeout(_(),100);}else{s= d.createElement('script');s.src = u;d.body.insertBefore(s,d.body.firstChild);}}_();
}(window,document,encodeURIComponent);
</script>
{{> layout/footer}}
\ No newline at end of file
... ...
... ... @@ -37,6 +37,9 @@ class CartModel
{
$result = array();
// 存放分析用的数据
$analysisData = array('ipinyou' => '');
do {
$result['isEmpty'] = false;
... ... @@ -121,44 +124,36 @@ class CartModel
// 普通的
if (!empty($ordinaryCartData['goods_list'])) {
$result['commonSell']['cartProductNum'] = strval($ordinaryCount);
$result['commonSell']['productItem'] = Helpers::formatCartGoods($ordinaryCartData['goods_list'], false, true);
$result['commonSell']['productItem'] = Helpers::formatCartGoods($ordinaryCartData['goods_list'], false, true, false, $analysisData);
}
// 预售的
if (!empty($advanceCartData['goods_list'])) {
$result['preSell']['cartProductNum'] = strval($advanceCount);
$result['preSell']['productItem'] = Helpers::formatCartGoods($advanceCartData['goods_list'], true, true);
$result['preSell']['productItem'] = Helpers::formatCartGoods($advanceCartData['goods_list'], true, true, false, $analysisData);
}
/* 已售磬失效 */
// 普通的
if (!$ordinarySoldOut) {
//$result['commonSell']['cartProductNum'] += count($ordinaryCartData['sold_out_goods_list']);
$result['commonSell']['productItem'] = isset($result['commonSell']['productItem'])
? self::appendProductItem($result['commonSell']['productItem'], Helpers::formatCartGoods($ordinaryCartData['sold_out_goods_list'], false, true), count($result['commonSell']['productItem']))
: Helpers::formatCartGoods($ordinaryCartData['sold_out_goods_list'], false, true);
$result['commonSell']['productItem'] = isset($result['commonSell']['productItem']) ? self::appendProductItem($result['commonSell']['productItem'], Helpers::formatCartGoods($ordinaryCartData['sold_out_goods_list'], false, true), count($result['commonSell']['productItem'])) : Helpers::formatCartGoods($ordinaryCartData['sold_out_goods_list'], false, true, false, $analysisData);
}
// 预售的
if (!$advanceSoldOut) {
//$result['preSell']['cartProductNum'] += count($advanceCartData['sold_out_goods_list']);
$result['preSell']['productItem'] = isset($result['preSell']['productItem'])
? self::appendProductItem($result['preSell']['productItem'], Helpers::formatCartGoods($advanceCartData['sold_out_goods_list'], true, true), count($result['preSell']['productItem']))
: Helpers::formatCartGoods($advanceCartData['sold_out_goods_list'], true, true);
$result['preSell']['productItem'] = isset($result['preSell']['productItem']) ? self::appendProductItem($result['preSell']['productItem'], Helpers::formatCartGoods($advanceCartData['sold_out_goods_list'], true, true), count($result['preSell']['productItem'])) : Helpers::formatCartGoods($advanceCartData['sold_out_goods_list'], true, true, false, $analysisData);
}
/* 已失效的 */
// 普通的
if (!$ordinaryOffShelves) {
//$result['commonSell']['cartProductNum'] += count($ordinaryCartData['off_shelves_goods_list']);
$result['commonSell']['productItem'] = isset($result['commonSell']['productItem'])
? self::appendProductItem($result['commonSell']['productItem'], Helpers::formatCartGoods($ordinaryCartData['off_shelves_goods_list'], false, true, true), count($result['commonSell']['productItem']))
: Helpers::formatCartGoods($ordinaryCartData['off_shelves_goods_list'], false, true, true);
$result['commonSell']['productItem'] = isset($result['commonSell']['productItem']) ? self::appendProductItem($result['commonSell']['productItem'], Helpers::formatCartGoods($ordinaryCartData['off_shelves_goods_list'], false, true, true), count($result['commonSell']['productItem'])) : Helpers::formatCartGoods($ordinaryCartData['off_shelves_goods_list'], false, true, true, $analysisData);
}
// 预售的
if (!$advanceOffShelves) {
//$result['preSell']['cartProductNum'] += count($advanceCartData['off_shelves_goods_list']);
$result['preSell']['productItem'] = isset($result['preSell']['productItem'])
? self::appendProductItem($result['preSell']['productItem'], Helpers::formatCartGoods($advanceCartData['off_shelves_goods_list'], true, true, true), count($result['preSell']['productItem']))
: Helpers::formatCartGoods($advanceCartData['off_shelves_goods_list'], true, true, true);
$result['preSell']['productItem'] = isset($result['preSell']['productItem']) ? self::appendProductItem($result['preSell']['productItem'], Helpers::formatCartGoods($advanceCartData['off_shelves_goods_list'], true, true, true), count($result['preSell']['productItem'])) : Helpers::formatCartGoods($advanceCartData['off_shelves_goods_list'], true, true, true, $analysisData);
}
/* 赠品 */
... ... @@ -168,22 +163,17 @@ class CartModel
}
// 普通的
if (!empty($ordinaryCartData['gift_list'])) {
$result['subjoinItem'] = isset($result['subjoinItem']) ? self::appendProductItem($result['subjoinItem'], Helpers::formatGiftPriceGoods($ordinaryCartData['gift_list'], true), count($result['subjoinItem']))
: Helpers::formatGiftPriceGoods($ordinaryCartData['gift_list'], true);
$result['subjoinItem'] = isset($result['subjoinItem']) ? self::appendProductItem($result['subjoinItem'], Helpers::formatGiftPriceGoods($ordinaryCartData['gift_list'], true), count($result['subjoinItem'])) : Helpers::formatGiftPriceGoods($ordinaryCartData['gift_list'], true);
}
/* 加价购 */
// 预售的
if (!empty($advanceCartData['price_gift'])) {
$result['subjoinItem'] = isset($result['subjoinItem'])
? self::appendProductItem($result['subjoinItem'], Helpers::formatGiftPriceGoods($advanceCartData['price_gift'], false), count($result['subjoinItem']))
: Helpers::formatGiftPriceGoods($advanceCartData['price_gift'], false);
$result['subjoinItem'] = isset($result['subjoinItem']) ? self::appendProductItem($result['subjoinItem'], Helpers::formatGiftPriceGoods($advanceCartData['price_gift'], false), count($result['subjoinItem'])) : Helpers::formatGiftPriceGoods($advanceCartData['price_gift'], false);
}
// 普通的
if (!empty($ordinaryCartData['price_gift'])) {
$result['subjoinItem'] = isset($result['subjoinItem'])
? self::appendProductItem($result['subjoinItem'], Helpers::formatGiftPriceGoods($ordinaryCartData['price_gift'], false), count($result['subjoinItem']))
: Helpers::formatGiftPriceGoods($ordinaryCartData['price_gift'], false);
$result['subjoinItem'] = isset($result['subjoinItem']) ? self::appendProductItem($result['subjoinItem'], Helpers::formatGiftPriceGoods($ordinaryCartData['price_gift'], false), count($result['subjoinItem'])) : Helpers::formatGiftPriceGoods($ordinaryCartData['price_gift'], false);
}
/* 促销短语 */
... ... @@ -205,6 +195,12 @@ class CartModel
} while (false);
// 增加第三方分析用的数据
$result['ids'] = empty($analysisData['ids']) ? '' : implode(',', $analysisData['ids']);
$result['ipinyou'] = empty($analysisData['ipinyou']) ? '' : $analysisData['ipinyou'];
$result['ipinyouAmount'] = isset($result['productAllA']) ? $result['productAllA'] : '0.00';
$result['criteo'] = empty($analysisData['criteo']) ? '' : json_encode($analysisData['criteo']);
return $result;
}
... ... @@ -482,7 +478,7 @@ class CartModel
foreach ($sknList as $value) {
$value = explode('-', $value);
if (isset($value[1])) {
$sknArr[ $value[0] ] = $value[1];
$sknArr[$value[0]] = $value[1];
}
}
... ... @@ -746,7 +742,6 @@ class CartModel
$isNewUser = false;
}
$result['isNewUser'] = $isNewUser ? true : false;
} while (false);
return $result;
... ... @@ -1007,7 +1002,7 @@ class CartModel
} else if (!empty($phoneNum) && !is_numeric($phoneNum)) {
$result['code'] = 406;
$result['message'] = '输入的固定电话格式不正确';
} else if ((!empty($phoneNum) && empty($phoneCode)) || (!empty($phoneCode) && empty($phoneNum)) ) {
} else if ((!empty($phoneNum) && empty($phoneCode)) || (!empty($phoneCode) && empty($phoneNum))) {
$result['code'] = 407;
$result['message'] = '输入的固定电话格式不正确';
} else {
... ... @@ -1105,7 +1100,6 @@ class CartModel
$result[] = $build;
}
$couponList = array();
} while (false);
return $result;
... ... @@ -1165,7 +1159,7 @@ class CartModel
{
foreach ($data as $value) {
$source[$index] = $value;
++ $index;
++$index;
}
return $source;
... ...
... ... @@ -35,6 +35,7 @@ class IndexController extends WebAction
$this->_view->display('cart', array(
'cartEnsurePage' => true,
'cartEnsure' => CartModel::myCartData($uid, $shoppingKey, $cartDelList),
'uid' => $uid ? $uid : '',
));
}
... ...