Index.php 3.02 KB
<?php

namespace Home;

use Home\UserModel;
use LibModels\Web\Product\BrandData;
use WebPlugin\Helpers;
use WebPlugin\HelperHome;
use WebPlugin\Images;
use Api\Yohobuy;
use LibModels\Web\Home\IndexData;
use LibModels\Web\Product\SearchData;

/**
 * 个人中心-首页相关业务逻辑处理
 */
class IndexModel
{

    /**
     * 个人中心——消息提示
     * @param type $uid
     * @param type $udid
     * @return array
     */
    public static function getInfoNumData($uid, $udid)
    {
        $result = array(
            array('href' => Helpers::url('/home/orders'), 'name' => '待处理订单', 'count' => 0),
            array('href' => Helpers::url('/home/message'), 'name' => '未读消息', 'count' => 0),
            array('href' => Helpers::url('/home/comment'), 'name' => '待评论商品', 'count' => 0),
        );
        $getPendingOrderCount = IndexData::getPendingOrderCount($uid); //待处理订单
        $infoNumData = IndexData::infoNum($uid, $udid); //未读消息
        $notCommentRecordCount = IndexData::notCommentRecordCount($uid); //待评论商品

        $result[0]['count'] = isset($getPendingOrderCount['data']['count']) ? $getPendingOrderCount['data']['count'] : 0;
        $result[1]['count'] = isset($infoNumData['data']['inbox_total']) ? $infoNumData['data']['inbox_total'] : 0;
        $result[2]['count'] = isset($notCommentRecordCount['data']) ? $notCommentRecordCount['data'] : 0;

        return $result;
    }

    /**
     * 个人中心——最新订单
     * @param type $uid
     * @return array
     */
    public static function latestOrders($uid)
    {
        $orders = OrderModel::getOrders($uid, 1, 2, 1);
        $result = array('more' => Helpers::url('/home/orders'), 'orders' => $orders);
        return $result;
    }

    /**
     * 获取个人中心数据(猜你喜欢的品牌、新品上架)
     * @return array
     */
    public static function homeData()
    {
        $result = array();
        //猜你喜欢的品牌
        $url['fav_brand'] = SearchData::getBrandListUrl();
        //新品上架
        $productParam['new'] = 'Y';
        $productParam['viewNum'] = 10;
        $url['new'] = SearchData::getProductUrl($productParam);
        //调用接口数据
        $data = Yohobuy::getMulti($url);
        //格式化数据
        $result['brand'] = isset($data['fav_brand']) && !empty($data['fav_brand']) ? HelperHome::formatFavBrand($data['fav_brand'], 6) : array();
        $result['new'] = isset($data['new']['product_list']) && !empty($data['new']['product_list']) ? HelperHome::formatNew($data['new']['product_list']) : array();
        return $result;
    }

    /**
     * 底部banner
     * @param string $code
     * @return mixed
     */
    public static function getFooterBanner($code = '20110609-152143')
    {

        $banner =  BrandData::getByNodeContent($code);
        if (isset($banner['code']) && !empty($banner['data'])) {
            return $banner['data'];
        }
    }
}