Authored by 郭成尧

'为你优选搞定'

... ... @@ -16,7 +16,7 @@ use Configs\ChannelConfig;
/**
* 购物车相关的模板数据模型
*
*
* @name CartModel
* @package Shopping
* @copyright yoho.inc
... ... @@ -30,7 +30,7 @@ class CartModel
/**
* 获取我的购物车数据
*
*
* @param int $uid 当前登录用户ID
* @param string $shoppingKey 购物车在浏览器的唯一识别码
* @param mixed $cartDelList 删除的商品列表
... ... @@ -39,7 +39,7 @@ class CartModel
public static function myCartData($uid, $shoppingKey, $cartDelList)
{
$result = array();
// 存放分析用的数据
$analysisData = array('ipinyou' => '');
... ... @@ -59,7 +59,7 @@ class CartModel
$result['isEmpty'] = true;
$result['guangUrl'] = Helpers::url('', null, 'list');
$result['viewOrderUrl'] = Helpers::url('/home/orders', array('t' => time()));
UdpLog::info('【购物车】校验参数传递auth','uid:'.$uid.'shoppingKey:'.$shoppingKey);
UdpLog::info('【购物车】校验参数传递auth', 'uid:' . $uid . 'shoppingKey:' . $shoppingKey);
break;
}
... ... @@ -107,16 +107,14 @@ class CartModel
$result['productAllA'] = Helpers::transPrice($advanceCartData['shopping_cart_data']['last_order_amount']);
// 获赠YOHO币个数
$result['getYoho'] = $advanceCartData['shopping_cart_data']['gain_yoho_coin'];
}
// 普通的
} // 普通的
elseif ($ordinaryCount !== 0 && $advanceCount === 0) {
//$result['productAmmount'] = Helpers::transPrice($ordinaryCartData['shopping_cart_data']['order_amount']);
$result['productAmmount'] = self::genProductAmount($ordinaryCartData['shopping_cart_data']['promotion_formula_list'], $ordinaryCartData['shopping_cart_data']['order_amount']);
$result['activeSale'] = Helpers::transPrice($ordinaryCartData['shopping_cart_data']['discount_amount']);
$result['productAllA'] = Helpers::transPrice($ordinaryCartData['shopping_cart_data']['last_order_amount']);
$result['getYoho'] = $ordinaryCartData['shopping_cart_data']['gain_yoho_coin'];
}
// 所有的
} // 所有的
else {
$result['productAmmount'] = Helpers::transPrice($ordinaryCartData['shopping_cart_data']['order_amount'] + $advanceCartData['shopping_cart_data']['order_amount']);
$result['activeSale'] = Helpers::transPrice($ordinaryCartData['shopping_cart_data']['discount_amount'] + $advanceCartData['shopping_cart_data']['discount_amount']);
... ... @@ -185,8 +183,7 @@ class CartModel
// 普通的
if (!empty($ordinaryCartData['promotion_info'])) {
$result['salesPromotion'] = self::buildPromotionData($ordinaryCartData['promotion_info']);
}
// 预售的
} // 预售的
elseif (!empty($advanceCartData['promotion_info'])) {
//$result['salesPromotion'] = array_merge($result['salesPromotion'], self::buildPromotionData($advanceCartData['promotion_info']));
$result['salesPromotion'] = self::buildPromotionData($advanceCartData['promotion_info']);
... ... @@ -196,9 +193,9 @@ class CartModel
$advanceCartData = array();
$ordinaryCartData = array();
$cartData = array();
} while (false);
// 增加第三方分析用的数据
$result['ids'] = empty($analysisData['ids']) ? '' : implode(',', $analysisData['ids']);
$result['ipinyou'] = empty($analysisData['ipinyou']) ? '' : $analysisData['ipinyou'];
... ... @@ -227,8 +224,8 @@ class CartModel
$addCart = CartData::addToCart($productSku, $buyNumber, $goodsType, $isEdit, $promotionId, $uid, $shoppingKey);
if ($addCart && isset($addCart['code'])) {
$result = $addCart;
}else{
UdpLog::info('【购物车】校验参数传递auth','productSku:'.$productSku.'buyNumber:'.$buyNumber.'goodsType:'.$goodsType,'isEdit:'.$isEdit.'promotionId:'.$promotionId.'uid:'.$uid.'shoppingKey:'.$shoppingKey);
} else {
UdpLog::info('【购物车】校验参数传递auth', 'productSku:' . $productSku . 'buyNumber:' . $buyNumber . 'goodsType:' . $goodsType, 'isEdit:' . $isEdit . 'promotionId:' . $promotionId . 'uid:' . $uid . 'shoppingKey:' . $shoppingKey);
}
return $result;
... ... @@ -249,7 +246,7 @@ class CartModel
do {
if (empty($skuList)) {
UdpLog::info('【购物车】校验参数传递auth','skuList:'.$skuList);
UdpLog::info('【购物车】校验参数传递auth', 'skuList:' . $skuList);
break;
}
... ... @@ -257,8 +254,8 @@ class CartModel
if ($select && isset($select['code'])) {
$result['code'] = $select['code'];
$result['message'] = $select['message'];
}else{
UdpLog::info('【购物车】校验参数传递auth','uid:'.$uid.'skuList:'.$skuList.'shoppingKey:'.$shoppingKey.'hasPromotion:'.$hasPromotion);
} else {
UdpLog::info('【购物车】校验参数传递auth', 'uid:' . $uid . 'skuList:' . $skuList . 'shoppingKey:' . $shoppingKey . 'hasPromotion:' . $hasPromotion);
}
} while (false);
... ... @@ -281,7 +278,7 @@ class CartModel
do {
if (empty($skuList)) {
UdpLog::info('【购物车】校验参数传递auth','skuList:'.$skuList);
UdpLog::info('【购物车】校验参数传递auth', 'skuList:' . $skuList);
break;
}
... ... @@ -292,8 +289,8 @@ class CartModel
if (isset($remove['data']['goods_count'])) {
$result['total_goods_num'] = $remove['data']['goods_count'];
}
}else{
UdpLog::info('【购物车】校验参数传递auth','uid:'.$uid.'skuList:'.$skuList.'shoppingKey:'.$shoppingKey.'hasPromotion:'.$hasPromotion);
} else {
UdpLog::info('【购物车】校验参数传递auth', 'uid:' . $uid . 'skuList:' . $skuList . 'shoppingKey:' . $shoppingKey . 'hasPromotion:' . $hasPromotion);
}
} while (false);
... ... @@ -321,7 +318,7 @@ class CartModel
}
if (empty($skuList)) {
UdpLog::info('【购物车】校验参数传递auth','skuList:'.$skuList);
UdpLog::info('【购物车】校验参数传递auth', 'skuList:' . $skuList);
break;
}
... ... @@ -329,8 +326,8 @@ class CartModel
if ($add && isset($add['code'])) {
$result['code'] = $add['code'];
$result['message'] = $add['message'];
}else{
UdpLog::info('【购物车】校验参数传递auth','uid:'.$uid.'skuList:'.$skuList.'hasPromotion:'.$hasPromotion);
} else {
UdpLog::info('【购物车】校验参数传递auth', 'uid:' . $uid . 'skuList:' . $skuList . 'hasPromotion:' . $hasPromotion);
}
} while (false);
... ... @@ -353,7 +350,7 @@ class CartModel
do {
if (empty($sku)) {
UdpLog::info('【购物车】校验参数传递auth','sku:'.$sku);
UdpLog::info('【购物车】校验参数传递auth', 'sku:' . $sku);
break;
}
... ... @@ -361,8 +358,8 @@ class CartModel
if ($modify && isset($modify['code'])) {
$result['code'] = $modify['code'];
$result['message'] = $modify['message'];
}else{
UdpLog::info('【购物车】校验参数传递auth','uid:'.$uid.'sku:'.$sku,'increaseNum:'.$increaseNum.'decreaseNum:'.$decreaseNum.'shoppingKey:'.$shoppingKey);
} else {
UdpLog::info('【购物车】校验参数传递auth', 'uid:' . $uid . 'sku:' . $sku, 'increaseNum:' . $increaseNum . 'decreaseNum:' . $decreaseNum . 'shoppingKey:' . $shoppingKey);
}
} while (false);
... ... @@ -371,7 +368,7 @@ class CartModel
/**
* 获取凑单商品
*
*
* @param int $page 分页页码
* @return array
*/
... ... @@ -422,10 +419,15 @@ class CartModel
/**
* 获取为你优选商品 待处理
*
* @param $channel
* @param $uid
* @param $udid
* @param $rec_pos
* @param $limit
* @param int $page 分页页码
* @return array
*/
public static function getRecommendProduct($page)
public static function getRecommendProduct($channel, $uid, $udid, $page)
{
$result = array('code' => 200, 'message' => '', 'data' => array('header' => '为你优选', 'hasPrev' => false, 'hasNext' => false, 'item' => array()));
... ... @@ -434,8 +436,8 @@ class CartModel
break;
}
$together = CartData::togetherProduct($page);
if (empty($together['data']['goods'])) {
$together = UserData::newPreference($channel, $uid, $udid, '100003', 30);
if (empty($together['data']['product_list'])) {
break;
}
... ... @@ -443,20 +445,54 @@ class CartModel
$result['data']['hasPrev'] = true;
$build = array();
foreach ($together['data']['goods'] as $value) {
$build = array();
$build['id'] = $value['id'];
$build['skn'] = $value['product_skn'];
$build['href'] = $value['url'];
$build['title'] = $value['product_name'];
$build['img'] = Helpers::getImageUrl($value['default_pic'], 100, 100);
$build['alt'] = $value['product_name'];
$build['price'] = $value['price']['sales_price'];
if ($value['price']['sales_price'] !== $value['price']['market_price']) {
$build['marketPrice'] = $value['price']['market_price'];
}
$begin = 0;
$end = 0;
switch ($page) {
case 1:
$begin = 0;
$end = 5;
break;
case 2:
$begin = 6;
$end = 11;
break;
case 3:
$begin = 12;
$end = 17;
break;
case 4:
$begin = 18;
$end = 23;
break;
case 5:
$begin = 18;
$end = 23;
break;
case 6:
$begin = 24;
$end = 30;
break;
default:
$begin = 0;
$end = 5;
break;
}
foreach ($together['data']['product_list'] as $key => $value) {
if ($key >= $begin && $key <= $end) {
$build = array();
$build['id'] = $value['product_id'];
$build['skn'] = $value['product_skn'];
$build['href'] = Helpers::getUrlBySkc($value['product_id'], $value['goods_list'][0]['product_skc'], $value['cn_alphabet']);;
$build['title'] = $value['product_name'];
$build['img'] = Helpers::getImageUrl($value['default_images'], 100, 100);
$build['alt'] = $value['product_name'];
$build['price'] = $value['price']['sales_price'];
if ($value['price']['sales_price'] !== $value['price']['market_price']) {
$build['marketPrice'] = $value['price']['market_price'];
}
$result['data']['item'][] = $build;
$result['data']['item'][] = $build;
}
}
// 当数据量不足6个时,判定为没有下一页
... ... @@ -471,7 +507,7 @@ class CartModel
/**
* 获取最近浏览商品
*
*
* @param int $page 分页页码
* @return array
*/
... ... @@ -486,7 +522,7 @@ class CartModel
$browse = CartData::browseRecord($uid, $udid, $page, 6);
if (empty($browse['data']['product_list'])) {
UdpLog::info('【购物车】校验参数传递auth','uid:'.$uid.'udid'.$udid.'page'.$page);
UdpLog::info('【购物车】校验参数传递auth', 'uid:' . $uid . 'udid' . $udid . 'page' . $page);
break;
}
... ... @@ -526,7 +562,7 @@ class CartModel
/**
* 基于本地浏览器Cookie的指定浏览记录
*
*
* @param int $page 页码
* @param int $limit 限制数
* @return array
... ... @@ -642,8 +678,7 @@ class CartModel
if ($value['payment_type'] == 1 && $value['is_support'] === 'Y') {
$result['onlinePay']['checked'] = $isDefault ? true : false;
$result['onlinePay']['paymentId'] = $value['payment_id'];
}
// 货到付款
} // 货到付款
elseif ($value['payment_type'] == 2 && $value['is_support'] === 'Y') {
$result['deliveryPay']['checked'] = $isDefault ? true : false;
$result['deliveryPay']['paymentId'] = $value['payment_id'];
... ... @@ -656,9 +691,9 @@ class CartModel
}
}
// tar add 1605061351 货到付款提示信息处理
if(isset($pay['data']['payment_way'])){
if (isset($pay['data']['payment_way'])) {
foreach ($pay['data']['payment_way'] as $item) {
if($item['payment_type'] === 2){
if ($item['payment_type'] === 2) {
$result['paymentInCashInfo'] = $item['is_support_message'];
}
}
... ... @@ -825,8 +860,7 @@ class CartModel
//JIT拆单需求 package
$result['packages'] = self::getPackageInfo($pay['data']['shopping_cart_data']);
}
while (false);
} while (false);
return $result;
}
... ... @@ -844,17 +878,17 @@ class CartModel
if ($isMulti) {
$packageList = $cartInfo['package_list'];
foreach ($packageList as $pk => $pv) {
$pIndex = $pk+1;
$packages[$pk]['title'] = ($pv['supplier_id'] == 0) ? '包裹'.$pIndex.':总仓发货' : '包裹'.$pIndex.':异地调拨'; //仓库
$pIndex = $pk + 1;
$packages[$pk]['title'] = ($pv['supplier_id'] == 0) ? '包裹' . $pIndex . ':总仓发货' : '包裹' . $pIndex . ':异地调拨'; //仓库
$goodList = $pv['goods_list'];
foreach ($goodList as $glk => $glv) {
$packages[$pk]['goodlist'][$glk]['src'] = Images::getImageUrl($glv['goods_images'], 90, 90);
$tagInfo= isset(ChannelConfig::$orderTagArr[$glv['goods_type']])?ChannelConfig::$orderTagArr[$glv['goods_type']]:'';
$packages[$pk]['goodlist'][$glk]['goodsType'] =!empty($tagInfo['name'])?$tagInfo['name']:false;
$packages[$pk]['goodlist'][$glk]['classname'] =!empty($tagInfo['classname'])?$tagInfo['classname']:false;
$tagInfo = isset(ChannelConfig::$orderTagArr[$glv['goods_type']]) ? ChannelConfig::$orderTagArr[$glv['goods_type']] : '';
$packages[$pk]['goodlist'][$glk]['goodsType'] = !empty($tagInfo['name']) ? $tagInfo['name'] : false;
$packages[$pk]['goodlist'][$glk]['classname'] = !empty($tagInfo['classname']) ? $tagInfo['classname'] : false;
$packages[$pk]['goodlist'][$glk]['link'] = 'javascript:void(0)';
}
$packages[$pk]['fee'] = ($pv['shopping_cost']=='0.00')?false:$pv['shopping_cost'];
$packages[$pk]['fee'] = ($pv['shopping_cost'] == '0.00') ? false : $pv['shopping_cost'];
$packages[$pk]['orign'] = $pv['shopping_orig_cost'];
$packages[$pk]['count'] = $pv['shopping_cut_cost'];
}
... ... @@ -875,7 +909,7 @@ class CartModel
* @param int $redEnvelopes 红包
* @return array 接口返回的数据
*/
public static function orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode,$promotionCode,$yohoCoin, $redEnvelopes)
public static function orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $promotionCode, $yohoCoin, $redEnvelopes)
{
$result = array('code' => 400, 'message' => self::ERROR_400_MESSAGE, 'data' => array());
... ... @@ -883,7 +917,7 @@ class CartModel
if (!empty($yohoCoin)) {
$yohoCoin = intval($yohoCoin) / 100;
}
$compute = CartData::orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode,$promotionCode,$yohoCoin, $redEnvelopes);
$compute = CartData::orderCompute($uid, $cartType, $deliveryWay, $paymentType, $couponCode, $promotionCode, $yohoCoin, $redEnvelopes);
if ($compute && isset($compute['code'])) {
/* 商品价格明细 */
if (!empty($compute['data']['promotion_formula_list'])) {
... ... @@ -945,25 +979,25 @@ class CartModel
* @param int $redEnvelopes 红包
* @return array 接口返回的数据
*/
public static function orderSub($uid, $addressId, $cartType, $deliveryTimeId, $deliveryWayId, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode,$promotionCode, $yohoCoin, $isPreContact, $isPrintPrice, $redEnvelopes)
public static function orderSub($uid, $addressId, $cartType, $deliveryTimeId, $deliveryWayId, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $promotionCode, $yohoCoin, $isPreContact, $isPrintPrice, $redEnvelopes)
{
$result = array('code' => 400, 'message' => self::ERROR_400_MESSAGE);
do {
if (empty($addressId)) {
UdpLog::info('【结算信息】配送地址参数校验','addressId为空');
UdpLog::info('【结算信息】配送地址参数校验', 'addressId为空');
$result['code'] = 401;
$result['message'] = '配送地址不能为空';
break;
}
if (empty($deliveryTimeId)) {
UdpLog::info('【结算信息】配送时间参数校验','deliveryTime为空');
UdpLog::info('【结算信息】配送时间参数校验', 'deliveryTime为空');
$result['code'] = 402;
$result['message'] = '请选择配送时间';
break;
}
if (empty($deliveryWayId)) {
UdpLog::info('【结算信息】配送方式参数校验','deliveryWay为空');
UdpLog::info('【结算信息】配送方式参数校验', 'deliveryWay为空');
$result['code'] = 403;
$result['message'] = '请选择配送方式';
break;
... ... @@ -986,7 +1020,7 @@ class CartModel
$userAgent = isset($unionInfo['client_id']) ? 'YOHO!Buy/3.8.2.259(Model/PC;Channel/' . $unionInfo['client_id'] . ';uid/' . $uid . ')' : null;
}
$orderSubRes = CartData::orderSub($uid, $addressId, $cartType, $deliveryTimeId, $deliveryWayId, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode,$promotionCode,$yohoCoin, $isPreContact, $isPrintPrice,$unionKey,$userAgent, $redEnvelopes);
$orderSubRes = CartData::orderSub($uid, $addressId, $cartType, $deliveryTimeId, $deliveryWayId, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $couponCode, $promotionCode, $yohoCoin, $isPreContact, $isPrintPrice, $unionKey, $userAgent, $redEnvelopes);
if ($orderSubRes && isset($orderSubRes['code'])) {
$result = $orderSubRes;
}
... ... @@ -997,7 +1031,7 @@ class CartModel
/**
* 用户的收货地址列表
*
*
* @param int $uid 用户ID
* @return array
*/
... ... @@ -1048,7 +1082,7 @@ class CartModel
/**
* 设置默认的收货地址
*
*
* @param int $uid 用户ID
* @param int $addressId 地址ID
* @return array
... ... @@ -1066,7 +1100,7 @@ class CartModel
/**
* 删除收货地址
*
*
* @param int $uid 用户ID
* @param int $addressId 地址ID
* @return array
... ... @@ -1179,8 +1213,7 @@ class CartModel
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
if (empty($result)) {
$result = Cache::get($key, 'slave');
}
// 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
} // 接口调用正常,数据封装完成, 则设置一级(master)和二级(slave)数据缓存
else {
Cache::set($key, $result, 3600); // 缓存1小时
}
... ... @@ -1191,7 +1224,7 @@ class CartModel
/**
* 获取用户的优惠券列表
*
*
* @param int $uid 用户ID
* @param int $valid 控制是否返回已失效的券, 为true时不返回, false时返回
* @return array
... ... @@ -1208,7 +1241,7 @@ class CartModel
/* 调用接口, 获取优惠券 */
$couponList = CartData::getListCoupon($uid);
$build = array();
//不可用优惠券
if (isset($couponList['data']['unusable_coupons'])) {
foreach ($couponList['data']['unusable_coupons'] as $value) {
... ... @@ -1237,7 +1270,7 @@ class CartModel
/**
* 检查用户是否收藏这一批商品
*
*
* @param int $uid 用户ID
* @param array $skuList 商品SKU列表
* @return array
... ... @@ -1267,7 +1300,7 @@ class CartModel
/**
* 获取购物车总数
*
*
* @param int $uid 用户ID
* @param string $shoppingKey 客户端购物标识
* @return array
... ... @@ -1279,7 +1312,7 @@ class CartModel
/**
* 追加商品
*
*
* @param array $source
* @param array $data
* @param int $index
... ... @@ -1297,7 +1330,7 @@ class CartModel
/**
* 获取商品总价
*
*
* @param array $promotionList 短语信息
* @param int $default 默认值
* @return float
... ... @@ -1323,7 +1356,7 @@ class CartModel
/**
* 构建促销短语数据
*
*
* @param array $promotionInfo 促销信息
* @return array
*/
... ...
... ... @@ -183,8 +183,12 @@ class IndexController extends WebAction
$result = array('code' => 200, 'data' => array(), 'message' => '为你优选');
if ($this->isAjax()) {
$channel = Helpers::getChannelNameByCookie();
$uid = $this->auditJumpLogin(true, Helpers::url('/home'));
$udid = $uid . $this->getUdid();
$page = $this->get('page', 1);
$result = CartModel::getRecommendProduct($page);
$result = CartModel::getRecommendProduct($channel, $uid, $udid, $page);
}
$this->echoJson($result);
... ... @@ -198,7 +202,8 @@ class IndexController extends WebAction
$result = array('code' => 200, 'data' => array(), 'message' => '浏览记录');
// 按照产品把明扬的指示,去掉最近浏览记录
$this->echoJson($result); exit();
$this->echoJson($result);
exit();
do {
if (!$this->isAjax()) {
... ... @@ -219,8 +224,7 @@ class IndexController extends WebAction
}
$sknList = explode(',', rawurldecode($sknList));
$result = CartModel::getNamedBrowseProduct($page, 6, $sknList);
}
while (false);
} while (false);
$this->echoJson($result);
}
... ... @@ -468,17 +472,16 @@ class IndexController extends WebAction
// 调用下单接口
$result = CartModel::orderSub($uid, $addressId, $cartType, $deliveryTimeId, $deliveryWayId, $invoiceTitle, $invoiceId,
$paymentId, $paymentType, $remark, $couponCode, $promotionCode, $yohoCoin, $isPreContact, $isPrintPrice, $redEnvelopes);
$paymentId, $paymentType, $remark, $couponCode, $promotionCode, $yohoCoin, $isPreContact, $isPrintPrice, $redEnvelopes);
// 判断是否下单成功
if (empty($result['data']['order_code'])) {
UdpLog::info('【结算信息】判断是否下单成功','order_code'.$result['data']['order_code']);
UdpLog::info('【结算信息】判断是否下单成功', 'order_code' . $result['data']['order_code']);
break;
}
// 跳转到支付的URL链接
$result['data']['payUrl'] = Helpers::url('/shopping/pay', array('ordercode' => $result['data']['order_code']));
}
while (false);
} while (false);
$this->echoJson($result);
}
... ... @@ -536,10 +539,10 @@ class IndexController extends WebAction
$uid = $this->getUid();
$vipLevel = -1;
$data = array();
if(!empty($this->_vip)) {
if (!empty($this->_vip)) {
$vipLevel = Helpers::getVipLevel($this->_vip);
}
if(!empty($productId)) {
if (!empty($productId)) {
$data = Product\ItemModel::getCartProductInfo($productId, $uid, $vipLevel);
}
$this->_view->display('goods-detail', $data);
... ...