redenvelopes-model.js 1.07 KB
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const _ = require('lodash');
const RedenvelopesApi = require('./redenvelopes-api.js');

module.exports = class extends global.yoho.BaseModel {
    constructor(ctx) {
        super(ctx);
    }

    redenvelopesList(uid) {

        let that = this;

        return co(function*() {
            let result = {};
            let redenvelopesDataModel = new RedenvelopesApi(that.ctx);
            let data = yield redenvelopesDataModel.getRedenvelopesTotal(uid);

            if (_.get(data, 'code') === 200 && _.get(data, 'data.redpacket_num')) {
                result.money = _.get(data, 'data.redpacket_num');
                result.termOfValidity = _.get(data, 'data.useable_time');
            }
            result.useRemark = '1.红包活动,全场通用(预售商品除外);<br>' +
                '2.结算时折抵现金使用,可以和优惠券叠加使用;<br>' +
                '3.限有效期内使用,过期清零';
            return {redEnvelopes: [result]};
        })();
    }

};