You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
git/scr/miniprogram-2/services/coupon/index.js

66 lines
1.9 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import { config } from '../../config/index';
/** 获取优惠券列表 */
function mockFetchCoupon(status) {
const { delay } = require('../_utils/delay');
const { getCouponList } = require('../../model/coupon');
return delay().then(() => getCouponList(status));
}
/** 获取优惠券列表 */
export function fetchCouponList(status = 'default') {
if (config.useMock) {
return mockFetchCoupon(status);
}
return new Promise((resolve) => {
resolve('real api');
});
}
/** 获取优惠券 详情 */
function mockFetchCouponDetail(id, status) {
const { delay } = require('../_utils/delay');
const { getCoupon } = require('../../model/coupon');
const { genAddressList } = require('../../model/address');
return delay().then(() => {
const result = {
detail: getCoupon(id, status),
storeInfoList: genAddressList(),
};
result.detail.useNotes = `1个订单限用1张除运费券外不能与其它类型的优惠券叠加使用运费券除外\n2.仅适用于各区域正常售卖商品,不支持团购、抢购、预售类商品`;
result.detail.storeAdapt = `商城通用`;
if (result.detail.type === 'price') {
result.detail.desc = `减免 ${result.detail.value / 100}`;
if (result.detail.base) {
result.detail.desc += `,满${result.detail.base / 100}元可用`;
}
result.detail.desc += '。';
} else if (result.detail.type === 'discount') {
result.detail.desc = `${result.detail.value}`;
if (result.detail.base) {
result.detail.desc += `,满${result.detail.base / 100}元可用`;
}
result.detail.desc += '。';
}
return result;
});
}
/** 获取优惠券 详情 */
export function fetchCouponDetail(id, status = 'default') {
if (config.useMock) {
return mockFetchCouponDetail(id, status);
}
return new Promise((resolve) => {
resolve('real api');
});
}