Index.js 4.6 KB
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;

class IndexModel extends global.mClass {
    getPendingOrderCount($uid) {
        let options = {
            method: 'web.SpaceOrders.getPendingOrderCount',
            uid: $uid
        };
        return this.API.get('', options);
    }
    infoNum($uid, $udid) {
        let options = {
            method: 'app.home.getInfoNum',
            uid: $uid,
            udid: $udid
        };
        return this.API.get('', options);
    }
    notCommentRecordCount($uid) {
        let options = {
            method: 'show.notCommentRecordCount',
            uid: $uid
        };
        return this.API.get('', options);
    }
    getInfoNumData($uid, $udid) {
        var that = this;
        let $result = [
                {href: this.helpers.urlFormat('/home/orders'), name: '待处理订单', 'count': 0},
                {href: this.helpers.urlFormat('/home/message'), name: '未读消息', 'count': 0},
                {href: this.helpers.urlFormat('/home/comment'), name: '待评论商品', 'count': 0}
        ];
        return co(function * () {
            let $getPendingOrderCount = yield that.getPendingOrderCount($uid);// 待处理订单
            let $infoNumData = yield that.infoNum($uid, $udid); // 未读消息
            let $notCommentRecordCount = yield that.notCommentRecordCount($uid);// 待评论商品
            $result[0]['count'] = $getPendingOrderCount.data.count ? $getPendingOrderCount.data.count : 0;
            $result[1]['count'] = $infoNumData.data.inbox_total ? $infoNumData.data.inbox_total : 0;
            $result[2]['count'] = $notCommentRecordCount.data ? $notCommentRecordCount.data : 0;
            return $result;
        })();
    }
    getFooterBanner($code) {
        $code = $code || '20110609-152143';

    }

    // getBrandListUrl(){
    //     return this.SearchAPI.get('/yohosearch/brand/list.json', {},{cache:true});
    // }
    // getProductUrl($condition, $type = ''){
    //     let $orderMaps={
    //         s_t_desc:'shelve_time:desc',
    //         s_t_asc:'shelve_time:asc',
    //         s_p_asc:'sales_price:asc',
    //         s_p_desc:'sales_price:desc',
    //         p_d_desc:'discount:desc',
    //         p_d_asc:'discount:asc',
    //         skn_desc:'product_skn:desc',
    //         skn_asc:'product_skn:asc',
    //         activities_desc:'activities.order_by:desc',
    //         activities_asc:'activities.order_by:asc',
    //         s_n_asc:'sales_num:asc',
    //         s_n_desc:'sales_num:desc',
    //         activities_id_desc:'activities.activity_id:desc',
    //         activities_id_asc:'activities.activity_id:asc',
    //         brand_desc:'brand_weight:desc'
    //     }
    //     $param={
    //         status:1,
    //         sales:'Y',
    //         outlets:2,
    //         stocknumber:1,
    //         attribute_not:2
    //     };
    //     if(!$condition.order){
    //         $param.order=$orderMaps.s_t_desc;
    //     }else{
    //         $param.order=$orderMaps[$condition.order]?$orderMaps[$condition.order]:'';
    //     }
    //     if(!$condition.page){
    //         $param.page=1;
    //     }
    //     if(!$condition.viewNum){
    //         $param.viewNum=$condition.viewNum;
    //     }else if(!$condition.limit){
    //         $param.viewNum=60;
    //     }else{
    //         $param.viewNum=$condition.limit;
    //         delete $condition.limit;
    //     }
    //     if(!$condition){
    //         $param += $condition;
    //     }
    //     return this.SearchAPI.get($type, $param,{cache:true});

    // }
    // formatFavBrand($brandInfo, $i = 10){
    //     $hotBrands=[];
    //     if($brandInfo){
    //         $brandInfo.forEach(function($value){
    //            if ($value.is_hot && $value.is_hot == 'Y') {
    //                 $hotBrands.push({
    //                     'href' : Helpers::url('', '', $value['brand_domain']),
    //                     'logo' : Images::getSourceUrl($value['brand_ico'], 'brandLogo'),
    //                     'name' : $value.brand_name,
    //                 });
    //            }
    //         });
    //     }
    //     return $hotBrands;
    // }
    // homeData(){
    //     let that=this;
    //     return co(function * (){
    //         let $result = {};
    //         let $url={};
    //         $url.fav_brand =yield that.getBrandListUrl();
    //         $url.new=yield that.getProductUrl({new:'Y',viewNum:10});
    //         console.log($url);
    //         return $url;
    //         // $result.brand=$data.fav_brand&&!$data.fav_brand?
    //     }();
    // }
}
module.exports = IndexModel;