Authored by hf

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

@@ -682,10 +682,12 @@ class Helpers @@ -682,10 +682,12 @@ class Helpers
682 * 682 *
683 * @param array $cartGoods 购物车商品列表 683 * @param array $cartGoods 购物车商品列表
684 * @param bool $isAdvanceCart 是否是预售购物车(和上市期有关) 684 * @param bool $isAdvanceCart 是否是预售购物车(和上市期有关)
685 - * @param boolean $isValid 是否是可用商品(非失效商品),默认是 685 + * @param bool $isValid 是否是可用商品(非失效商品),默认是
  686 + * @param bool $isOffShelves 是否卖光了, 默认否
  687 + * @param array $analysis 第三方数据分析用的
686 * @return array 处理之后的购物车商品数据 688 * @return array 处理之后的购物车商品数据
687 */ 689 */
688 - public static function formatCartGoods($cartGoods, $isAdvanceCart, $isValid = true, $isOffShelves = false) 690 + public static function formatCartGoods($cartGoods, $isAdvanceCart, $isValid = true, $isOffShelves = false, &$analysis = array())
689 { 691 {
690 $result = array(); 692 $result = array();
691 693
@@ -744,6 +746,29 @@ class Helpers @@ -744,6 +746,29 @@ class Helpers
744 elseif ($value['real_price'] == 0) { 746 elseif ($value['real_price'] == 0) {
745 $oneGoods['productPrice'] = self::transPrice($value['sales_price']); 747 $oneGoods['productPrice'] = self::transPrice($value['sales_price']);
746 $oneGoods['xForOne'] = true; 748 $oneGoods['xForOne'] = true;
  749 +
  750 + // 分析用: 商品ID列表
  751 + $analysis['ids'][] = $value['product_id'];
  752 + // 分析用: 品友
  753 + $analysis['ipinyou'] .= $value['product_id'] . ',' . $value['buy_number'] . ';';
  754 + // 分析用: CRITEO
  755 + $analysis['criteo'][] = array(
  756 + 'id' => $value['product_skn'],
  757 + 'quantity' => intval($value['buy_number']),
  758 + 'price' => $value['last_vip_price'],
  759 + );
  760 + }
  761 + else {
  762 + // 分析用: 商品ID列表
  763 + $analysis['ids'][] = $value['product_id'];
  764 + // 分析用: 品友
  765 + $analysis['ipinyou'] .= $value['product_id'] . ',' . $value['buy_number'] . ';';
  766 + // 分析用: CRITEO
  767 + $analysis['criteo'][] = array(
  768 + 'id' => $value['product_skn'],
  769 + 'quantity' => intval($value['buy_number']),
  770 + 'price' => $value['last_vip_price'],
  771 + );
747 } 772 }
748 773
749 // 商品类型:预售或普通 774 // 商品类型:预售或普通
@@ -341,4 +341,40 @@ @@ -341,4 +341,40 @@
341 <div class="loading"><span></span>请稍后...</div> 341 <div class="loading"><span></span>请稍后...</div>
342 </div> 342 </div>
343 <!-- 商品详细信息窗口 --> 343 <!-- 商品详细信息窗口 -->
  344 +
  345 +<script type="text/javascript">
  346 +(function (d) {
  347 +window.bd_cpro_rtid="P1fsPWc";
  348 +var s = d.createElement("script");s.type = "text/javascript";s.async = true;s.src = location.protocol + "//cpro.baidu.com/cpro/ui/rt.js";
  349 +var s0 = d.getElementsByTagName("script")[0];s0.parentNode.insertBefore(s, s0);
  350 +})(document);
  351 +</script>
  352 +<script type="text/javascript" src="http://static.criteo.net/js/ld/ld.js" async="true"></script>
  353 +<script type="text/javascript">
  354 +window.criteo_q = window.criteo_q || [];
  355 +window.criteo_q.push(
  356 +{event:"setAccount", account: 16184},
  357 +{event:"setCustomerId", id: "{{uid}}"},
  358 +{event:"setSiteType", type: "d"},
  359 +{event:"viewBasket", item: {{{cartEnsure.criteo}}} }
  360 +);
  361 +</script>
  362 +<!-- 聚效 -->
  363 +<script type="text/javascript">
  364 +var _mvq = window._mvq || [];
  365 +window._mvq = _mvq;
  366 +_mvq.push(['$setAccount', 'm-23428-1']);
  367 +_mvq.push(['$setGeneral', 'cartview', '', /*用户名*/ '', '{{uid}}']);
  368 +_mvq.push(['$logConversion']);
  369 +_mvq.push(['$addItem', '', /*商品id*/ '{{cartEnsure.ids}}', '', '']);
  370 +_mvq.push(['$logData']);
  371 +</script>
  372 +<script>
  373 +!function(w,d,e){
  374 +var _money='{{cartEnsure.ipinyouAmount}}';
  375 +var _productList='{{cartEnsure.ipinyou}}';
  376 +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=';
  377 +function _(){if(!d.body){setTimeout(_(),100);}else{s= d.createElement('script');s.src = u;d.body.insertBefore(s,d.body.firstChild);}}_();
  378 +}(window,document,encodeURIComponent);
  379 +</script>
344 {{> layout/footer}} 380 {{> layout/footer}}
@@ -37,6 +37,9 @@ class CartModel @@ -37,6 +37,9 @@ class CartModel
37 { 37 {
38 $result = array(); 38 $result = array();
39 39
  40 + // 存放分析用的数据
  41 + $analysisData = array('ipinyou' => '');
  42 +
40 do { 43 do {
41 $result['isEmpty'] = false; 44 $result['isEmpty'] = false;
42 45
@@ -121,44 +124,36 @@ class CartModel @@ -121,44 +124,36 @@ class CartModel
121 // 普通的 124 // 普通的
122 if (!empty($ordinaryCartData['goods_list'])) { 125 if (!empty($ordinaryCartData['goods_list'])) {
123 $result['commonSell']['cartProductNum'] = strval($ordinaryCount); 126 $result['commonSell']['cartProductNum'] = strval($ordinaryCount);
124 - $result['commonSell']['productItem'] = Helpers::formatCartGoods($ordinaryCartData['goods_list'], false, true); 127 + $result['commonSell']['productItem'] = Helpers::formatCartGoods($ordinaryCartData['goods_list'], false, true, false, $analysisData);
125 } 128 }
126 // 预售的 129 // 预售的
127 if (!empty($advanceCartData['goods_list'])) { 130 if (!empty($advanceCartData['goods_list'])) {
128 $result['preSell']['cartProductNum'] = strval($advanceCount); 131 $result['preSell']['cartProductNum'] = strval($advanceCount);
129 - $result['preSell']['productItem'] = Helpers::formatCartGoods($advanceCartData['goods_list'], true, true); 132 + $result['preSell']['productItem'] = Helpers::formatCartGoods($advanceCartData['goods_list'], true, true, false, $analysisData);
130 } 133 }
131 134
132 /* 已售磬失效 */ 135 /* 已售磬失效 */
133 // 普通的 136 // 普通的
134 if (!$ordinarySoldOut) { 137 if (!$ordinarySoldOut) {
135 //$result['commonSell']['cartProductNum'] += count($ordinaryCartData['sold_out_goods_list']); 138 //$result['commonSell']['cartProductNum'] += count($ordinaryCartData['sold_out_goods_list']);
136 - $result['commonSell']['productItem'] = isset($result['commonSell']['productItem'])  
137 - ? self::appendProductItem($result['commonSell']['productItem'], Helpers::formatCartGoods($ordinaryCartData['sold_out_goods_list'], false, true), count($result['commonSell']['productItem']))  
138 - : Helpers::formatCartGoods($ordinaryCartData['sold_out_goods_list'], false, true); 139 + $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);
139 } 140 }
140 // 预售的 141 // 预售的
141 if (!$advanceSoldOut) { 142 if (!$advanceSoldOut) {
142 //$result['preSell']['cartProductNum'] += count($advanceCartData['sold_out_goods_list']); 143 //$result['preSell']['cartProductNum'] += count($advanceCartData['sold_out_goods_list']);
143 - $result['preSell']['productItem'] = isset($result['preSell']['productItem'])  
144 - ? self::appendProductItem($result['preSell']['productItem'], Helpers::formatCartGoods($advanceCartData['sold_out_goods_list'], true, true), count($result['preSell']['productItem']))  
145 - : Helpers::formatCartGoods($advanceCartData['sold_out_goods_list'], true, true); 144 + $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);
146 } 145 }
147 146
148 /* 已失效的 */ 147 /* 已失效的 */
149 // 普通的 148 // 普通的
150 if (!$ordinaryOffShelves) { 149 if (!$ordinaryOffShelves) {
151 //$result['commonSell']['cartProductNum'] += count($ordinaryCartData['off_shelves_goods_list']); 150 //$result['commonSell']['cartProductNum'] += count($ordinaryCartData['off_shelves_goods_list']);
152 - $result['commonSell']['productItem'] = isset($result['commonSell']['productItem'])  
153 - ? self::appendProductItem($result['commonSell']['productItem'], Helpers::formatCartGoods($ordinaryCartData['off_shelves_goods_list'], false, true, true), count($result['commonSell']['productItem']))  
154 - : Helpers::formatCartGoods($ordinaryCartData['off_shelves_goods_list'], false, true, true); 151 + $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);
155 } 152 }
156 // 预售的 153 // 预售的
157 if (!$advanceOffShelves) { 154 if (!$advanceOffShelves) {
158 //$result['preSell']['cartProductNum'] += count($advanceCartData['off_shelves_goods_list']); 155 //$result['preSell']['cartProductNum'] += count($advanceCartData['off_shelves_goods_list']);
159 - $result['preSell']['productItem'] = isset($result['preSell']['productItem'])  
160 - ? self::appendProductItem($result['preSell']['productItem'], Helpers::formatCartGoods($advanceCartData['off_shelves_goods_list'], true, true, true), count($result['preSell']['productItem']))  
161 - : Helpers::formatCartGoods($advanceCartData['off_shelves_goods_list'], true, true, true); 156 + $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);
162 } 157 }
163 158
164 /* 赠品 */ 159 /* 赠品 */
@@ -168,22 +163,17 @@ class CartModel @@ -168,22 +163,17 @@ class CartModel
168 } 163 }
169 // 普通的 164 // 普通的
170 if (!empty($ordinaryCartData['gift_list'])) { 165 if (!empty($ordinaryCartData['gift_list'])) {
171 - $result['subjoinItem'] = isset($result['subjoinItem']) ? self::appendProductItem($result['subjoinItem'], Helpers::formatGiftPriceGoods($ordinaryCartData['gift_list'], true), count($result['subjoinItem']))  
172 - : Helpers::formatGiftPriceGoods($ordinaryCartData['gift_list'], true); 166 + $result['subjoinItem'] = isset($result['subjoinItem']) ? self::appendProductItem($result['subjoinItem'], Helpers::formatGiftPriceGoods($ordinaryCartData['gift_list'], true), count($result['subjoinItem'])) : Helpers::formatGiftPriceGoods($ordinaryCartData['gift_list'], true);
173 } 167 }
174 168
175 /* 加价购 */ 169 /* 加价购 */
176 // 预售的 170 // 预售的
177 if (!empty($advanceCartData['price_gift'])) { 171 if (!empty($advanceCartData['price_gift'])) {
178 - $result['subjoinItem'] = isset($result['subjoinItem'])  
179 - ? self::appendProductItem($result['subjoinItem'], Helpers::formatGiftPriceGoods($advanceCartData['price_gift'], false), count($result['subjoinItem']))  
180 - : Helpers::formatGiftPriceGoods($advanceCartData['price_gift'], false); 172 + $result['subjoinItem'] = isset($result['subjoinItem']) ? self::appendProductItem($result['subjoinItem'], Helpers::formatGiftPriceGoods($advanceCartData['price_gift'], false), count($result['subjoinItem'])) : Helpers::formatGiftPriceGoods($advanceCartData['price_gift'], false);
181 } 173 }
182 // 普通的 174 // 普通的
183 if (!empty($ordinaryCartData['price_gift'])) { 175 if (!empty($ordinaryCartData['price_gift'])) {
184 - $result['subjoinItem'] = isset($result['subjoinItem'])  
185 - ? self::appendProductItem($result['subjoinItem'], Helpers::formatGiftPriceGoods($ordinaryCartData['price_gift'], false), count($result['subjoinItem']))  
186 - : Helpers::formatGiftPriceGoods($ordinaryCartData['price_gift'], false); 176 + $result['subjoinItem'] = isset($result['subjoinItem']) ? self::appendProductItem($result['subjoinItem'], Helpers::formatGiftPriceGoods($ordinaryCartData['price_gift'], false), count($result['subjoinItem'])) : Helpers::formatGiftPriceGoods($ordinaryCartData['price_gift'], false);
187 } 177 }
188 178
189 /* 促销短语 */ 179 /* 促销短语 */
@@ -205,6 +195,12 @@ class CartModel @@ -205,6 +195,12 @@ class CartModel
205 195
206 } while (false); 196 } while (false);
207 197
  198 + // 增加第三方分析用的数据
  199 + $result['ids'] = empty($analysisData['ids']) ? '' : implode(',', $analysisData['ids']);
  200 + $result['ipinyou'] = empty($analysisData['ipinyou']) ? '' : $analysisData['ipinyou'];
  201 + $result['ipinyouAmount'] = isset($result['productAllA']) ? $result['productAllA'] : '0.00';
  202 + $result['criteo'] = empty($analysisData['criteo']) ? '' : json_encode($analysisData['criteo']);
  203 +
208 return $result; 204 return $result;
209 } 205 }
210 206
@@ -482,7 +478,7 @@ class CartModel @@ -482,7 +478,7 @@ class CartModel
482 foreach ($sknList as $value) { 478 foreach ($sknList as $value) {
483 $value = explode('-', $value); 479 $value = explode('-', $value);
484 if (isset($value[1])) { 480 if (isset($value[1])) {
485 - $sknArr[ $value[0] ] = $value[1]; 481 + $sknArr[$value[0]] = $value[1];
486 } 482 }
487 } 483 }
488 484
@@ -746,7 +742,6 @@ class CartModel @@ -746,7 +742,6 @@ class CartModel
746 $isNewUser = false; 742 $isNewUser = false;
747 } 743 }
748 $result['isNewUser'] = $isNewUser ? true : false; 744 $result['isNewUser'] = $isNewUser ? true : false;
749 -  
750 } while (false); 745 } while (false);
751 746
752 return $result; 747 return $result;
@@ -1007,7 +1002,7 @@ class CartModel @@ -1007,7 +1002,7 @@ class CartModel
1007 } else if (!empty($phoneNum) && !is_numeric($phoneNum)) { 1002 } else if (!empty($phoneNum) && !is_numeric($phoneNum)) {
1008 $result['code'] = 406; 1003 $result['code'] = 406;
1009 $result['message'] = '输入的固定电话格式不正确'; 1004 $result['message'] = '输入的固定电话格式不正确';
1010 - } else if ((!empty($phoneNum) && empty($phoneCode)) || (!empty($phoneCode) && empty($phoneNum)) ) { 1005 + } else if ((!empty($phoneNum) && empty($phoneCode)) || (!empty($phoneCode) && empty($phoneNum))) {
1011 $result['code'] = 407; 1006 $result['code'] = 407;
1012 $result['message'] = '输入的固定电话格式不正确'; 1007 $result['message'] = '输入的固定电话格式不正确';
1013 } else { 1008 } else {
@@ -1105,7 +1100,6 @@ class CartModel @@ -1105,7 +1100,6 @@ class CartModel
1105 $result[] = $build; 1100 $result[] = $build;
1106 } 1101 }
1107 $couponList = array(); 1102 $couponList = array();
1108 -  
1109 } while (false); 1103 } while (false);
1110 1104
1111 return $result; 1105 return $result;
@@ -1165,7 +1159,7 @@ class CartModel @@ -1165,7 +1159,7 @@ class CartModel
1165 { 1159 {
1166 foreach ($data as $value) { 1160 foreach ($data as $value) {
1167 $source[$index] = $value; 1161 $source[$index] = $value;
1168 - ++ $index; 1162 + ++$index;
1169 } 1163 }
1170 1164
1171 return $source; 1165 return $source;
@@ -35,6 +35,7 @@ class IndexController extends WebAction @@ -35,6 +35,7 @@ class IndexController extends WebAction
35 $this->_view->display('cart', array( 35 $this->_view->display('cart', array(
36 'cartEnsurePage' => true, 36 'cartEnsurePage' => true,
37 'cartEnsure' => CartModel::myCartData($uid, $shoppingKey, $cartDelList), 37 'cartEnsure' => CartModel::myCartData($uid, $shoppingKey, $cartDelList),
  38 + 'uid' => $uid ? $uid : '',
38 )); 39 ));
39 } 40 }
40 41