coupons.js 1.3 KB
// 优惠券 by acgpiano
'use strict';

const helpers = global.yoho.helpers;

class couponsModel extends global.yoho.BaseModel {
    constructor(ctx) {
        super(ctx);
    }

    couponData(params) {
        return this.get({data: params}).then(result => {

            if (result && result.data && result.data.couponList) {
                let status0 = params.status === 0;
                let status1 = params.status === 1;

                return result.data.couponList.map(function(elem) {
                    delete elem.id;

                    if (status0) {
                        elem.bestowLink = helpers.urlFormat('/product/index/index',
                            {
                                coupon_id: elem.couponId,
                                coupon_code: elem.couponCode,
                                title: '优惠活动商品',
                                intro_text: `以下商品可使用【${elem.couponDetailInfomation}】优惠券`
                            }
                        );
                    } else if (status1) {
                        delete elem.overState;
                        elem.employbg = true;
                    }
                    return elem;
                });
            }

            return [];
        });
    }
}

module.exports = couponsModel;