CartData.php 8.21 KB
<?php

namespace LibModels\Wap\Home;

use Api\Sign;
use Api\Yohobuy;

/**
 * 购物车的数据模型
 *
 * @name CartData
 * @package LibModels/Wap/Home
 * @copyright yoho.inc
 * @version 1.0 (2015-11-09 13:58:27)
 * @author Gtskk <tttt6399998@126.com>
 */
class CartData
{

    /**
     * 加入购物车接口
     *
     * @param int $productSku 商品SKU
     * @param int $buyNumber 购买数量
     * @param int $goodsType 商品类型,0表示普通商品,1表示加价购商品
     * @param int $isEdit 是否是编辑商品SKU,0表示不是编辑
     * @param null|int $promotionId 促销id,默认null(加价购有关)
     * @param null|int $uid 用户UID,可以不传
     * @param string $shoppingKey 购物的凭证
     * @return array 加入购物车接口返回的数据
     */
    public static function addToCart($productSku, $buyNumber, $goodsType, $isEdit = 0, $promotionId = null, $uid = null, $shoppingKey = '')
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.Shopping.add';
        $param['product_sku'] = $productSku;
        $param['buy_number'] = $buyNumber;
        $param['goods_type'] = $goodsType;
        $param['edit_product_sku'] = $isEdit;
        $param['selected'] = 'Y';
        $param['promotion_id'] = $promotionId;
        $param['shopping_key'] = $shoppingKey;

        if (!empty($uid)) {
            $param['uid'] = $uid;
        }
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(Yohobuy::API_URL, $param);
    }

    /**
     * 购物车数据
     *
     * @param int $uid 用户ID
     * @param string $shoppingKey 未登录用户唯一识别码
     * @return array 购物车接口返回的数据
     */
    public static function cartData($uid, $shoppingKey)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.Shopping.cart';

        if (!empty($uid)) {
            $param['uid'] = $uid;
        }
        if (!empty($shoppingKey)) {
            $param['shopping_key'] = $shoppingKey;
        }

        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(Yohobuy::API_URL, $param);
    }

    /**
     * 移出购物车
     *
     * @param int $uid 用户ID
     * @param string $sku 商品sku列表
     * @param string $shoppingKey 未登录用户唯一识别码
     * @return array 接口返回的数据
     */
    public static function removeFromCart($uid, $sku, $shoppingKey)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.Shopping.remove';
        $param['product_sku_list'] = $sku;

        if (!empty($uid)) {
            $param['uid'] = $uid;
        }
        if (!empty($shoppingKey)) {
            $param['shopping_key'] = $shoppingKey;
        }

        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(Yohobuy::API_URL, $param);
    }

    /**
     * 移入收藏夹
     *
     * @param int $uid 用户ID
     * @param string $sku 商品sku列表
     * @return array 接口返回的数据
     */
    public static function addToFav($uid, $sku)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.Shopping.addfavorite';
        $param['product_sku_list'] = $sku;
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(Yohobuy::API_URL, $param);
    }

    /**
     * 获取购物车商品数据
     *
     * @param int $uid 用户ID
     * @param int $skn 商品skn
     * @return array 接口返回的数据
     */
    public static function cartProductData($uid, $skn)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.product.data';
        $param['product_skn'] = $skn;
        $param['showcomment'] = 'N';
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(Yohobuy::API_URL, $param);
    }

    /**
     * 获取加价购商品数据
     *
     * @param int $skn 商品skn
     * @param int $promotionId 加价购商品促销ID
     * @return array 接口返回的数据
     */
    public static function giftProductData($skn, $promotionId)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.product.gift';
        $param['product_skn'] = $skn;
        $param['promotion_id'] = $promotionId;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(Yohobuy::API_URL, $param);
    }

    /**
     * 修改购物车商品数据
     *
     * @param int $uid 用户ID
     * @param string $swapData 商品数据
     * @param string $shoppingKey 未登录用户唯一识别码
     * @return array 接口返回的数据
     */
    public static function modifyCartProduct($uid, $swapData, $shoppingKey)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.Shopping.swap';
        $param['swap_data'] = $swapData;

        if (!empty($uid)) {
            $param['uid'] = $uid;
        }
        if ($shoppingKey !== null) {
            $param['shopping_key'] = $shoppingKey;
        }

        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(Yohobuy::API_URL, $param);
    }

    /**
     * 购物车结算
     *
     * @param int $uid 用户ID
     * @param string $cartType 购物车类型,ordinary表示普通购物车
     * @return array 接口返回的数据
     */
    public static function cartPay($uid, $cartType)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.Shopping.payment';
        $param['cart_type'] = $cartType;
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(Yohobuy::API_URL, $param);
    }

    /**
     * 购物车结算--支付方式和配送方式选择
     *
     * @param int $uid 用户ID
     * @param string $cartType 购物车类型,ordinary表示普通购物车
     * @param string $deliveryWay 配送方式,1表示普通快递,2表示顺丰速运
     * @param string $paymentType 支付方式,1表示在线支付,2表示货到付款
     * @param string $yohoCoin 使用的YOHO币数量,默认为null表示不适用
     * @return array 接口返回的数据
     */
    public static function paymentTypeAndDelivery($uid, $cartType, $deliveryWay, $paymentType, $yohoCoin = null)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.Shopping.compute';
        $param['cart_type'] = $cartType;
        $param['delivery_way'] = $deliveryWay;
        $param['payment_type'] = $paymentType;
        if ($yohoCoin !== null) {
            $param['use_yoho_coin'] = $yohoCoin;
        }

        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(Yohobuy::API_URL, $param);
    }

    /**
     * 购物车结算--使用优惠券
     *
     * @param int $uid 用户ID
     * @param string $couponCode 优惠券代码
     * @return array 接口返回的数据
     */
    public static function getCoupon($uid, $couponCode)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.Shopping.useCoupon';
        $param['coupon_code'] = $couponCode;
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(Yohobuy::API_URL, $param);
    }

    /**
     * 购物车结算--提交结算信息
     *
     * @param int $uid 用户ID
     * @param string $couponCode 优惠券代码
     * @return array 接口返回的数据
     */
    public static function orderSub($uid, $addressId, $cartType, $deliveryTime, $deliveryWay, $invoiceTitle, $invoiceId, $paymentId, $paymentType, $remark, $yohoCoin)
    {
        $param = Yohobuy::param();
        $param['method'] = 'app.Shopping.submit';
        $param['addressId'] = $addressId;
        $param['cart_type'] = $cartType;
        $param['delivery_time'] = $deliveryTime;
        $param['delivery_way'] = $deliveryWay;
        $param['invoices_title'] = $invoiceTitle;
        $param['invoices_type_id'] = $invoiceId;
        $param['payment_id'] = $paymentId;
        $param['payment_type'] = $paymentType;
        $param['remark'] = $remark;
        $param['use_yoho_coin'] = $yohoCoin;
        $param['uid'] = $uid;
        $param['client_secret'] = Sign::getSign($param);

        return Yohobuy::get(Yohobuy::API_URL, $param);
    }

}