Store.php 3.42 KB
<?php

/**
 * 店铺相关接口
 * @author tongdesheng
 *
 */
class YHMApi_App_V1_Store extends YHMApi_App_V1_Base {

    /**
     * 
     * @param array $params
     * @param string $fields
     */
    public static function getListByType(array $params, $fields = '*') {
        $store_type = $params['store_type'];
        $offset = $params['offset'];
        $num = $params['num'];
        $hasgoods = 1;
        $hasstock = 1;
        $selectParams = array(
            'storetype' => $store_type,
            'viewNum' => $num,
            'page' => intval($offset / $num) + 1,
            'hasgoods' => $hasgoods,
            'hasstock' => $hasstock,
             'order_type' => 'star:desc'
        );
        if (!empty($params['uid'])) {
            $selectParams['searchuid'] = $params['uid'];
        }
            $selectParams['hasstock'] = 1;
            $selectParams['hasgoods'] = 1;
        $storeList = array();
        try {
            $storeSearch = new YHMSearch_Store();
            $storeIdList = $storeSearch->getList($selectParams);
            foreach ($storeIdList as $storeId) {
                $storeData = self::_getStoreForList($storeId);
                if (empty($storeData['newest_goods_list'])) {
                    //  		continue;
                }
                $storeList[] = $storeData;
            }
        } catch (Exception $ex) {
            return self::result(500, '搜索服务异常');
        }
        return self::result(200, "卖家列表", $storeList);
    }

    /**
     * 通过uid获取店铺id
     * @param array $params
     * @param string $fields
     */
    public static function getStoreIdByUid(array $params, $fields = '*') {
        if (empty($params['uid'])) {
            return self::result(400, 'uid不能为空');
        }
        $uid = $params['uid'];
        $store_id = YHMStore_Models_Store_Client::getStoreIdByUid($uid);
        return self::result(200, '获取成功', array('store_id' => $store_id));
    }

    /**
     * 店铺信息
     * @param array $params
     * @param string $fields
     */
    public static function info(array $params, $fields = '*') {
        if (empty($params['store_id'])) {
            return self::result(400, '店铺id不能为空');
        }
        $store_id = $params['store_id'];
        $store = YHMStore_Models_Store_Client::getById($store_id);
        //在售商品总数
        $sell_num = YHMProduct_Models_Goods_Client::getCountGoodsByStoreId($store_id);
        //已售商品总数
        $sold_num = YHMOrders_Models_Orders_Client::getCountOrderByStatus($store_id);
        //已购数量
        $buyed = YHMOrders_Models_Orders_Client::getCountBuyedByBuyerId($store['uid']);
        //是否收藏
        if (!empty($params['uid'])) {
            $favorite = YHMPassport_Models_Favorite_Store_Client::findIsFavoriteByStoreId($params['uid'], $store_id);
        }
        $is_favorite = 'N';
        if (!empty($favorite)) {
            $is_favorite = 'Y';
        }
        //需要将店铺id转化成uid
        $uid = $store['uid'];
        $storeInfo = self::_getUserInfo($uid);
        $storeInfo['sell_num'] = (isset($sell_num[0]['sell_num']))?$sell_num[0]['sell_num']:0; //在售商品
        $storeInfo['sold_num'] = ($sold_num)?$sold_num:0; //售出数量
        $storeInfo['purchased_num'] = ($buyed)?$buyed:0; //已购数量
        $storeInfo['is_favorite'] = $is_favorite;
        return self::result(200, '店铺信息', $storeInfo);
    }

}