Authored by Rock Zhang

添加购物车商品数据展示接口

... ... @@ -51,17 +51,17 @@ class CartData
}
/**
* 修改购物车商品数据
* 移入收藏夹
*
* @param int $uid 用户ID
* @param string $swapData 商品数据
* @param string $sku 商品sku列表
* @return array 接口返回的数据
*/
public static function modifyCartProduct($uid, $swapData)
public static function addToFav($uid, $sku)
{
$param = Yohobuy::param();
$param['method'] = 'app.Shopping.swap';
$param['swap_data'] = $swapData;
$param['method'] = 'app.Shopping.addfavorite';
$param['product_sku_list'] = $sku;
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
... ... @@ -69,17 +69,35 @@ class CartData
}
/**
* 移入收藏夹
* 获取购物车商品数据
*
* @param int $uid 用户ID
* @param string $sku 商品sku列表
* @param int $skn 商品skn
* @return array 接口返回的数据
*/
public static function addToFav($uid, $sku)
public static function cartProductData($uid, $skn)
{
$param = Yohobuy::param();
$param['method'] = 'app.Shopping.addfavorite';
$param['product_sku_list'] = $sku;
$param['method'] = 'app.product.data';
$param['product_skn'] = $skn;
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
* 修改购物车商品数据
*
* @param int $uid 用户ID
* @param string $swapData 商品数据
* @return array 接口返回的数据
*/
public static function modifyCartProduct($uid, $swapData)
{
$param = Yohobuy::param();
$param['method'] = 'app.Shopping.swap';
$param['swap_data'] = $swapData;
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
... ...
... ... @@ -231,54 +231,19 @@ class ShoppingCartController extends AbstractAction
public function goodinfoAction()
{
$result = array();
if ($this->isAjax()) {
$data = array(
'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/09/17/03/014cacfa5c458b9732c68adf1af15d7a45.jpg?imageMogr2/thumbnail/120x120/extent/120x120/background/d2hpdGU=/position/center/quality/90',
'name' => '黄伟文Wyman X y yohood 联名商品YYYOHOOD圆领卫衣',
'price' => 289,
'salePrice' => 241,
'colors' => array(
array(
'id' => 1,
'name' => '黄色'
),
array(
'id' => 2,
'chosed' => true,
'name' => '白色'
)
),
'sizes' => array(
array(
'id' => 1,
'name' => 'XS'
),
array(
'id' => 2,
'name' => 'S'
),
array(
'id' => 3,
'chosed' => true,
'name' => 'M'
),
array(
'id' => 4,
'name' => 'L'
),
array(
'id' => 5,
'name' => 'XL'
),
array(
'id' => 6,
'name' => 'XXL'
)
),
'num' => 1
);
$num = $this->get('buy_num', 1);
$skn = $this->get('id', 1);
$result = CartModel::cartProductData($this->_uid, $skn, $num); // 测试skn的ID为51172055
$result['num'] = $num;
}
$this->echoJson(array('code' => 200, 'data' => $data));
if (empty($result)) {
echo ' ';
} else {
$this->echoJson($result);
}
}
}
... ...
... ... @@ -3,6 +3,7 @@
namespace Index;
use LibModels\Wap\Home\CartData;
use Plugin\Helpers;
use Plugin\Images;
/**
... ... @@ -98,6 +99,70 @@ class CartModel
}
/**
* 处理购物车商品数据
*
* @param int $uid 用户ID
* @param int $skn 商品skn
* @param int $num 购买数目
* @return array 接口返回的数据
*/
public static function cartProductData($uid, $skn, $num)
{
$result = array('code' => 400, 'message' => '出错啦~');
$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;
}
return $result;
}
/**
* 修改购物车商品数据
*
* @param int $uid 用户ID
... ... @@ -135,6 +200,7 @@ class CartModel
// 购买的商品列表
foreach ($data['goods_list'] as $value) {
$oneGoods['id'] = $value['product_sku'];
$oneGoods['skn'] = $value['product_skn'];
$oneGoods['name'] = $value['product_name'];
$oneGoods['thumb'] = Images::getImageUrl($value['goods_images'], 120, 120);
$oneGoods['color'] = $value['color_name'];
... ...