...
|
...
|
@@ -3,6 +3,7 @@ |
|
|
namespace Index;
|
|
|
|
|
|
use LibModels\Wap\Home\CartData;
|
|
|
use LibModels\Wap\Home\UserData;
|
|
|
use Plugin\Helpers;
|
|
|
use Plugin\Images;
|
|
|
|
...
|
...
|
@@ -18,18 +19,44 @@ class CartModel |
|
|
{
|
|
|
|
|
|
/**
|
|
|
* 加入购物车
|
|
|
*
|
|
|
* @param int $productSku 商品SKU
|
|
|
* @param int $buyNumber 购买数量
|
|
|
* @param int $goodsType 商品类型,0表示普通商品,1表示加价购商品
|
|
|
* @param int int $isEdit 是否是编辑商品SKU,0表示不是编辑
|
|
|
* @param null|int $promotionId 促销id,默认null(加价购有关)
|
|
|
* @param null|int $uid 用户UID,可以不传
|
|
|
* @return array 加入购物车接口返回的数据
|
|
|
*/
|
|
|
public static function addToCart($productSku, $buyNumber, $goodsType, $isEdit, $promotionId, $uid)
|
|
|
{
|
|
|
$result = array('code' => 400, 'message' => '出错啦~~');
|
|
|
|
|
|
$addCart = CartData::addToCart($productSku, $buyNumber, $goodsType, $isEdit, $promotionId, $uid);
|
|
|
if ($addCart && isset($addCart['code'])) {
|
|
|
$result = $addCart;
|
|
|
}
|
|
|
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param integer $uid 用户ID
|
|
|
* @param string $shoppingKey 未登录用户唯一识别码
|
|
|
* @return array|mixed 处理之后的购物车数据
|
|
|
*/
|
|
|
public static function getCartData($uid)
|
|
|
public static function getCartData($uid, $shoppingKey)
|
|
|
{
|
|
|
$result = array(
|
|
|
'cartNav' => true,
|
|
|
'showLoginInfo' => true
|
|
|
);
|
|
|
$result = array('cartNav' => true);
|
|
|
|
|
|
// 用户是否登录
|
|
|
if (empty($uid)) {
|
|
|
$result['showLoginInfo'] = true;
|
|
|
}
|
|
|
|
|
|
// 调用接口获取购物车的数据
|
|
|
$cartData = CartData::cartData($uid);
|
|
|
$cartData = CartData::cartData($uid, $shoppingKey);
|
|
|
|
|
|
// 处理普通购物车和预售购物车的数据
|
|
|
if (isset($cartData['data']) && !empty($cartData['data'])) {
|
...
|
...
|
@@ -57,16 +84,17 @@ class CartModel |
|
|
*
|
|
|
* @param int $uid 用户ID
|
|
|
* @param string $sku 商品sku列表
|
|
|
* @param string $shoppingKey 未登录用户唯一识别码
|
|
|
* @return array 接口返回的数据
|
|
|
*/
|
|
|
public static function removeFromCart($uid, $sku)
|
|
|
public static function removeFromCart($uid, $sku, $shoppingKey)
|
|
|
{
|
|
|
$result = array('code' => 400, 'message' => '出错啦~');
|
|
|
|
|
|
// 处理sku
|
|
|
$sku_list = json_encode(array($sku => 1));
|
|
|
|
|
|
$remove = CartData::removeFromCart($uid, $sku_list);
|
|
|
$remove = CartData::removeFromCart($uid, $sku_list, $shoppingKey);
|
|
|
if ($remove && isset($remove['code'])) {
|
|
|
$result['code'] = $remove['code'];
|
|
|
$result['message'] = $remove['message'];
|
...
|
...
|
@@ -86,6 +114,14 @@ class CartModel |
|
|
{
|
|
|
$result = array('code' => 400, 'message' => '出错啦~');
|
|
|
|
|
|
if (empty($uid)) {
|
|
|
$result['code'] = 300;
|
|
|
$reult['message'] = '请先登录';
|
|
|
$result['data'] = '/signin.html';
|
|
|
|
|
|
return $result;
|
|
|
}
|
|
|
|
|
|
// 处理sku
|
|
|
$sku_list = json_encode(array($sku => 1));
|
|
|
|
...
|
...
|
@@ -163,20 +199,84 @@ class CartModel |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 处理加价购商品数据
|
|
|
*
|
|
|
* @param int $skn 商品skn
|
|
|
* @param int $promotionId 加价购商品促销ID
|
|
|
* @return array
|
|
|
*/
|
|
|
public static function giftProductData($skn, $promotionId)
|
|
|
{
|
|
|
$result = array();
|
|
|
|
|
|
$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'];
|
|
|
$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
|
|
|
* @param string $param 要更改的数据
|
|
|
* @param string $shoppingKey 未登录用户唯一识别码
|
|
|
* @return array 接口返回的数据
|
|
|
*/
|
|
|
public static function modifyCartProduct($uid, $param)
|
|
|
public static function modifyCartProduct($uid, $param, $shoppingKey)
|
|
|
{
|
|
|
$result = array('code' => 400, 'message' => '出错啦~');
|
|
|
|
|
|
// 处理要更改的数据
|
|
|
$swapData = json_encode(array($param));
|
|
|
|
|
|
$modify = CartData::modifyCartProduct($uid, $swapData);
|
|
|
$modify = CartData::modifyCartProduct($uid, $swapData, $shoppingKey);
|
|
|
if ($modify && isset($modify['code'])) {
|
|
|
$result['code'] = $modify['code'];
|
|
|
$result['message'] = $modify['message'];
|
...
|
...
|
@@ -197,8 +297,102 @@ class CartModel |
|
|
$result = array();
|
|
|
|
|
|
$pay = CartData::cartPay($uid, $cartType);
|
|
|
|
|
|
if ($pay && isset($pay['code']) && $pay['code'] === 200) {
|
|
|
$result = $pay['data'];
|
|
|
$payReturn = $pay['data'];
|
|
|
$result = array();
|
|
|
|
|
|
// 收货人有关信息
|
|
|
if (isset($payReturn['delivery_address']) && !empty($payReturn['delivery_address'])) {
|
|
|
$result['name'] = $payReturn['delivery_address']['consignee'];
|
|
|
$result['phoneNum'] = $payReturn['delivery_address']['mobile'] ?: $payReturn['delivery_address']['phone'];
|
|
|
$result['address'] = $payReturn['delivery_address']['address'];
|
|
|
}
|
|
|
|
|
|
// 配送方式
|
|
|
if (isset($payReturn['delivery_way'])) {
|
|
|
$oneDeliv = array();
|
|
|
foreach ($payReturn['delivery_way'] as $val) {
|
|
|
$oneDeliv = array();
|
|
|
$oneDeliv['id'] = $val['delivery_way_id'];
|
|
|
$oneDeliv['name'] = $val['delivery_way_name'];
|
|
|
$oneDeliv['default'] = ($val['default'] === 'Y');
|
|
|
|
|
|
$result['dispatchMode'][] = $oneDeliv;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 配送时间
|
|
|
if (isset($payReturn['delivery_time'])) {
|
|
|
$oneDelivTime = array();
|
|
|
foreach ($payReturn['delivery_time'] as $one) {
|
|
|
$oneDelivTime = array();
|
|
|
$oneDelivTime['id'] = $one['delivery_time_id'];
|
|
|
$oneDelivTime['name'] = $one['delivery_time_string'];
|
|
|
$oneDelivTime['default'] = ($one['default'] === 'Y');
|
|
|
|
|
|
$result['dispatchTime'][] = $oneDelivTime;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 订单商品
|
|
|
if (isset($payReturn['goods_list'])) {
|
|
|
$oneGoods = array();
|
|
|
foreach ($payReturn['goods_list'] as $single) {
|
|
|
$oneGoods = array();
|
|
|
$oneGoods['id'] = $single['product_sku']; // TODO 未确定用哪个
|
|
|
$oneGoods['thumb'] = Images::getImageUrl($single['goods_images'], 120, 120);
|
|
|
$oneGoods['name'] = $single['product_name'];
|
|
|
$oneGoods['color'] = $single['color_name'];
|
|
|
$oneGoods['size'] = $single['size_name'];
|
|
|
$oneGoods['price'] = Helpers::transPrice($single['real_price']); // last_price有些带.00,有些不带,real_price都不带.00
|
|
|
$oneGoods['count'] = $single['buy_number'];
|
|
|
|
|
|
$result['goods'][] = $oneGoods;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 支付方式
|
|
|
if (isset($payReturn['payment_way'])) {
|
|
|
$onePay = array();
|
|
|
foreach ($payReturn['payment_way'] as $pay) {
|
|
|
$onePay = array();
|
|
|
$onePay['id'] = $pay['payment_id'];
|
|
|
$onePay['paymentType'] = $pay['payment_type'];
|
|
|
$onePay['name'] = $pay['payment_type_name'];
|
|
|
$onePay['default'] = ($pay['default'] === 'Y');
|
|
|
|
|
|
$result['paymentWay'][] = $onePay;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 有货币
|
|
|
$result['yohoCoin'] = $payReturn['yoho_coin'];
|
|
|
|
|
|
// 订单数据
|
|
|
if (isset($payReturn['shopping_cart_data']) && !empty($payReturn['shopping_cart_data'])) {
|
|
|
$result['sumPrice'] = Helpers::transPrice($payReturn['shopping_cart_data']['order_amount']);
|
|
|
$result['salePrice'] = Helpers::transPrice($payReturn['shopping_cart_data']['discount_amount']);
|
|
|
$result['price'] = Helpers::transPrice($payReturn['shopping_cart_data']['last_order_amount']);
|
|
|
$result['freight'] = Helpers::transPrice($payReturn['shopping_cart_data']['shipping_cost']);
|
|
|
}
|
|
|
|
|
|
// 发票有关数据
|
|
|
if (isset($payReturn['invoices']) && !empty($payReturn['invoices'])) {
|
|
|
$one = array();
|
|
|
foreach ($payReturn['invoices']['invoices_type_list'] as $inv) {
|
|
|
$one = array();
|
|
|
$one['id'] = $inv['invoices_type_id'];
|
|
|
$one['name'] = $inv['invoices_type_name'];
|
|
|
|
|
|
$result['invoice'][] = $one;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 优惠券数据
|
|
|
$coupons = array('notUsed' => true);
|
|
|
$coupons += UserModel::getCouponData($uid, 0, 1, true);
|
|
|
$result['coupon'] = $coupons;
|
|
|
}
|
|
|
|
|
|
return $result;
|
...
|
...
|
|