Share.php 11.4 KB
<?php

/*
 * HTML5分享
 * @author elkan
 * @date 2014-9-25 10:05
 */

class ShareController extends QLib_Actions_M
{

    public function indexAction()
    {

    }

    /**
     * 店铺信息
     */
    public function storeAction()
    {
        ##########################用户信息##########################
        $store_id = $this->_get('store_id'); //用户店铺id
        if (empty($store_id)) {
            $this->helpJsRedirect('店铺id不能为空');
        }
        $store = YHMStore_Models_Store_Client::getById($store_id);
        if (empty($store)) {
            $this->helpRefresh('/index/mobile', '店铺不存在');
        }
        $baseInfo = $this->_getUserInfo($store['uid']);
        unset($baseInfo['password']);
        //星级评定结果
        $store_info = YHMStore_Models_Store_Client::getByUid($store['uid']);
        $this->_assign('store_id', $store_info['id']); //店铺id
        $star = YHMComment_Models_Comment_Client::getStarByStoreId($store_info['id']);
        $this->_assign('baseInfo', $baseInfo);
        $this->_assign('head_ico', $baseInfo['head_ico']); //头像
        $this->_assign('background_img', $baseInfo['background_img']); //背景
        $this->_assign('star', $star); //星级
        ##########################在售商品##########################
        $sell_offset = 0;
        $sell_num = 100;
        $sellingList = array();
      //  $data = YHMProduct_Models_Goods_Client::getListInStockByStoreId($store_id, $offset, $num);
        $sell_data = YHMProduct_Models_Goods_Client::getListInStockByStoreId($store_id, $sell_offset, $sell_num);
        foreach ($sell_data as $v) {
            $sell_defalut_image = YHMProduct_Models_Goodsimages_Client::getDefaultImageBySkc($v['product_skc']);
            if (empty($sell_defalut_image)) {
                $sell_defalut_image = YHMProduct_Models_Goodsimages_Client::getOneImageBySkc($v['product_skc']);
            }
            $sellingList [] = array(
                'product_skc' => $v['product_skc'],
                'goods_image' => $sell_defalut_image
            );
        }
        $this->_assign('sellingList', $sellingList); //在售商品
        ##########################已售商品##########################
        $sold_offset = 0;
        $sold_num = 100;
        $soldList = array();
        $buyGoodsList = YHMOrders_Models_Orders_Client::getBuyGoodsByStore($store_id, $sold_offset, $sold_num);
         $buyGoodsListResult = array();
        foreach ($buyGoodsList as $key => $val) {
            $goodsInfo = YHMProduct_Models_Goods_Client::getOneByProductSkc($val['product_skc']);
            $productImage = YHMProduct_Models_Goodsimages_Client::getOneImagesBySkc($val['product_skc']);
            $soldList[] = array(
                'sales_number' => (int) $val['buy_number'],
                'product_skc' => (int) $goodsInfo['product_skc'],
                'create_time' => (int) $goodsInfo['create_time'],
                'goods_image' =>$productImage,
                'is_deleted' => ($goodsInfo['status'] == 0 ? 'Y' : 'N'),
                'sale_price' => $goodsInfo['sale_price']
            );
        }
        
        
        $this->_assign('soldList', $soldList); //已售商品
    }

    /**
     * 商品详情
     */
    public function goodsinfoAction()
    {
        $skc = $this->_get('product_skc');
        if (empty($skc)) {
            $this->helpJsRedirect('商品id不能为空');
        }
        ##########################商品信息##########################
        // 商品基本信息 goods
        $goods_info = YHMProduct_Models_Goods_Client::getOneByProductSkc($skc);
        if (empty($goods_info)) {
            $this->helpRefresh('/index/mobile', '商品不存在');
        }
        // 商品描述 goods_describe
        $goods_describe = YHMProduct_Models_Goods_Client::getGoodsDescribeBySkc($skc);
        // 商品默认 goods_images
        $goods_default_image = YHMProduct_Models_Goodsimages_Client::getDefaultImageBySkc($skc);
        // 获取商品图片
        $goods_images = YHMProduct_Models_Goodsimages_Client::getByProductSkc($skc);
        // 商品品牌 brand
        $brand = YHMBrand_Models_Brand_Client::getOneById($goods_info ['brand_id']);
        // 分类 category
        $category = YHMProduct_Models_Category_Client::getOneById($goods_info ['max_category_id']);
        
         $middle_category =YHMProduct_Models_Category_Client::getOneById($goods_info['middle_category_id']);
        // 是否售馨 stock
        $stock = YHMProduct_Models_Stock_Client::getStockNumBySkc($skc);
        $is_soldout = 'N';
        if ($stock == 0) {
            $is_soldout = 'Y';
        }
        // 是否收藏商品
        if (!empty($params ['uid'])) {
            $favorite = YHMPassport_Models_Favorite_Goods_Client::findIsFavoriteBySkc($params ['uid'], $skc);
        }
        $is_favorite = 'N';
        if (!empty($favorite)) {
            $is_favorite = 'Y';
        }
        $goodsInfo = array(
            'seller_uid' => $goods_info['uid'],
            'store_id' => $goods_info['store_id'],
            'product_skc' => $skc,
            'gender' => $goods_info['gender']==3 ? '' : ($goods_info['gender']==1 ? '-BOY' : '-GIRL'),
            'goods_name' => $goods_info['goods_name'],
           'sale_price' => $goods_info['sale_price'],
            'market_price' => $goods_info['market_price'],
            'brand_id' => $goods_info['brand_id'],
            'brand_name' => $brand['brand_name'],
            'category_name' => $category['name'],
            'middle_category_name'=>$middle_category['name'],
            'max_category_id' => $goods_info['max_category_id'],
            'middle_category_id' => $goods_info['middle_category_id'],
            'small_category_id' => $goods_info['small_category_id'],
            'quality_level' => $goods_info['quality_level'],
            'describe' => $goods_describe['goods_describe'],
            'image_list' => array(),
            'is_soldout' => $is_soldout, // 是否已经售罄
            'is_favorite' => $is_favorite, // 是否已收藏
            'default_goods_image' => $goods_default_image
        );
        foreach ($goods_images as $v) {
            $goodsInfo['image_list'] [] = array(
                'id' => $v['id'],
                'image_url' => $v['image_path'],
                'image_path' => $v['image_path'],
                'is_default' => $v['is_default']
            );
        }
        $this->_assign('goodsInfo', $goodsInfo); //商品信息
        ########################用户评价##########################
        $offset = 0;
        $num = 3;
        //总留言数
        $total_num = YHMComment_Models_Comment_Client::getCountBySkc($goods_info['store_id'], $skc);
        //留言列表
        $commentlist = YHMComment_Models_Comment_Client::getListBySkc($goods_info['store_id'], $skc, $offset, $num);
        $retData = array();
        foreach ($commentlist as $id => $v) {
            //留言内容
            $contentData = YHMComment_Models_Comment_Client::getContentById($goods_info['store_id'], $v['id']);
            $oneComment = array(
                'id' => $v['id'],
                'star' => $v['star'],
                'content' => $contentData['content'],
                'comment_user_info' => self::_getUserInfo($v['uid']),
            );
            $retData[] = $oneComment;
        }
        $this->_assign('total_num', $total_num); //总留言数
        $this->_assign('comment_list', $retData); //评价列表
        ##########################卖家信息##########################
        $seller_info = self::_getUserInfo($goods_info['uid']);
        $this->_assign('seller_info', $seller_info);
        //店铺信息
        $store = YHMStore_Models_Store_Client::getById($seller_info['store_id']);
        //在售商品总数
        $sell_num = YHMProduct_Models_Goods_Client::getCountGoodsByStoreId($seller_info['store_id']);
        //售出总数
        $sold_num = YHMOrders_Models_Orders_Client::getCountOrderByStatus($seller_info['store_id']);
        //已购数量
        $buyed = YHMOrders_Models_Orders_Client::getCountBuyedByBuyerId($store['uid']);
        //是否收藏
        if (!empty($params['uid'])) {
            $favorite = YHMPassport_Models_Favorite_Store_Client::findIsFavoriteByStoreId($params['uid'], $goodsInfo['store_id']);
        }
        $is_favorite = 'N';
        if (!empty($favorite)) {
            $is_favorite = 'Y';
        }
        $store_info['store_id'] = $store['id'];
        $store_info['sell_num'] = $sell_num[0]['sell_num']; //在售商品
        $store_info['sold_num'] = $sold_num; //售出数量
        $store_info['purchased_num'] = $buyed; //已购数量
        $store_info['is_favorite'] = $is_favorite;
        $this->_assign('store_info', $store_info);
        $this->_assign('product_skc', $skc);
        $this->_headTitle($goodsInfo['goods_name'] . ' ' . $goodsInfo['brand_name'] . ' ' . $goodsInfo['category_name'] . ' - 友和市集');
    }

    /**
     * 活动信息
     */
    public function activityAction()
    {
        ##活动信息##
        $activity_id = $this->_get('activity_id');
        if (empty($activity_id)) {
            $this->helpJsRedirect('活动id不能为空');
        }
        $data = YHMSupport_Models_Activity_Client::getInfoById($activity_id);
        if (empty($data)) {
            $this->helpRefresh('/index/mobile', '活动不存在');
        }
        $actInfo = array(
            'activity_id' => $activity_id,
            'activity_banner' => 'http://yhfair.qiniudn.com/' . $data['activity_banner'],
            'activity_title' => $data['activity_name'],
            'activity_describe' => $data['activity_describe']
        );
        $this->_assign('actInfo', $actInfo);
        ##活动商品##
        $offset = 0;
        $num = 100;
        $data = YHMSupport_Models_Activity_Client::getGoodsListByActivityId($activity_id, $offset, $num);
        $activity_goods = array();
        foreach ($data as $v) {
            $activity_goods[] = self::_getGoodsForList($v['product_skc']);
        }
        $this->_assign('activity_goods', $activity_goods);
    }

    /**
     * 所有留言
     * @return type
     */
    public function commentAction()
    {
        $product_skc = $this->_get('product_skc');
        $goods_info = YHMProduct_Models_Goods_Client::getOneByProductSkc($product_skc);
        if (empty($goods_info)) {
            $this->helpRefresh('/index/mobile', '商品不存在');
        }
        //默认3条, 可分页
        $offset = 0;
        $num = 100;
        //通过skc获取商品
        $goodsInfo = YHMProduct_Models_Goods_Client::getOneByProductSkc($product_skc);
        if (empty($goodsInfo)) {
            return self::result(412, '没有找到该商品');
        }
        $store_id = $goodsInfo['store_id'];
        //留言列表
        $commentlist = YHMComment_Models_Comment_Client::getListBySkc($store_id, $product_skc, $offset, $num);
        $retData = array();
        foreach ($commentlist as $id => $v) {
            //留言内容
            $contentData = YHMComment_Models_Comment_Client::getContentById($store_id, $v['id']);
            $oneComment = array(
                'id' => $v['id'],
                'star' => $v['star'],
                'content' => $contentData['content'],
                'comment_user_info' => self::_getUserInfo($v['uid']),
            );
            $retData[] = $oneComment;
        }
        $this->_assign('product_skc', $product_skc);
        $this->_assign('comment_list', $retData);
    }
}