Orders.php 3.97 KB
<?php

/**
 * Created by PhpStorm.
 * User: ziy
 * Date: 14-8-6
 * Time: 下午3:45
 */
class YHMCart_Hook_Orders
{

    /**
     * 用户uid
     * @var int
     */
    private $uid;

    /**
     *
     * @var array
     */
    private $orderData = array();

    /**
     * 获取订单数据
     * @return array
     */
    function getOrder()
    {
        return $this->orderData;
    }

    /**
     * 存储订单数据
     * @param array $orderData
     */
    function setOrder(array $orderData)
    {
        $this->orderData = $orderData;
    }

    /**
     * 设置订单数据项中得数据
     * @param $key
     * @param $val
     * @return $this
     */
    function setOrderData($key, $val)
    {
        $this->orderData[$key] = $val;
        return $this;
    }

    /**
     * 获取订单指定值
     * @param $key
     * @return string
     */
    function getOrderData($key)
    {
        if (empty($this->orderData[$key])) {
            return '';
        }
        return $this->orderData[$key];
    }

    /**
     * 设置订单商品
     * @param array $goodsData
     * @return $this
     */
    function setOrderGoods(array $goodsData)
    {
        $this->orderData['goods_list'] = $goodsData;
        return $this;
    }


    /**
     * 1、正常商品   main_goods
     * 2、赠品      gift_goods
     * 3、加价购     need_pay_gifts
     * 4、outlet   outlet_goods
     * 5、免单商品   advance_goods
     **/

    private $goodsType = array(
        'main_goods',
        'gift_goods',
        'need_pay_gifts',
        'outlet_goods',
        'advance_goods'
    );


    private $tmpGoods = array();

    /**
     * 购物车商品列表
     * @var array
     */
    private $goodsList = array();

    /**
     * 添加购物车商品
     * @param $productSku
     * @param $buyNumber
     * @param $type
     * @return $this
     * @throws Exception
     */
    function addProduct($uid, $productSku, $buyNumber, $last_price, $type)
    {
        if (!in_array($type, $this->goodsType)) {
            throw new Exception('商品类型不存在.');
        }
        $this->goodsList[$type] = array(
            $productSku => $buyNumber
        );
        $this->tmpGoods = array(
            'product_sku' => $productSku,
            'buy_number' => $buyNumber,
            'goods_type' => $type,
            'uid' => $uid,
            'last_price' => $last_price
        );
        return $this;
    }

    /**
     * 获取购物车商品
     * @param $productSku
     * @param $type
     * @return mixed
     * @throws Exception
     */
    function getProduct($productSku, $type)
    {
        if (in_array($type, $this->goodsType)) {
            throw new Exception('商品类型不存在.');
        }
        return $this->goodsList[$type][$productSku];
    }

    /**
     * 获取临时购物车商品
     * @return array
     */
    function getTmpGoods()
    {
        return $this->tmpGoods;
    }

    /**
     * 获取UID
     * @return int
     */
    function getUid()
    {
        return $this->uid;
    }

    /**
     * 设置用户UID
     * @param $uid
     * @return $this
     */
    function setUid($uid)
    {
        $this->uid = $uid;
        return $this;
    }
     /**
     * 获取订单商品信息
     * @param $productSku
     * @param $type
     * @return mixed
     * @throws Exception
     */
    function getOrderProduct($sku, $skc)
    {
       $info=array();
            //size 
         $size = YHMProduct_Models_Stock_Client::getOneBySku($skc, $sku);
         //skc基本信息
         $goods_info = YHMProduct_Models_Goods_Client::getOneByProductSkc($skc);
         
         $goods_image = YHMProduct_Models_Goodsimages_Client::getDefaultImageBySkc($skc);
         if (is_array($goods_image))
         {
             foreach ($goods_image as $k=>$v)
             {
                 $goods_image=$v;
                 continue;
             }
         }
         $goods_info['goods_images']=$goods_image;
         return  array_merge($goods_info,$size);
    }
}