...
|
...
|
@@ -266,122 +266,130 @@ const _getContent = (data, isApp) => { |
|
|
return result;
|
|
|
};
|
|
|
|
|
|
exports.floor = (params, isApp, appVersion) => {
|
|
|
return Promise.coroutine(function*() {
|
|
|
let result = {},
|
|
|
resource = yield api.get('', Object.assign(params, {
|
|
|
method: 'app.promotion.queryCouponCenter',
|
|
|
}));
|
|
|
class couponFloor extends global.yoho.BaseModel {
|
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
|
|
}
|
|
|
|
|
|
if (resource && resource.code === 200) {
|
|
|
result = _getContent(resource.data, isApp);
|
|
|
} else {
|
|
|
result.noData = true;
|
|
|
}
|
|
|
floor(params, isApp, appVersion) {
|
|
|
return Promise.coroutine(function*() {
|
|
|
let result = {},
|
|
|
resource = yield api.get('', Object.assign(params, {
|
|
|
method: 'app.promotion.queryCouponCenter',
|
|
|
}));
|
|
|
|
|
|
result.share = getShare(params.contentCode, '领券中心');
|
|
|
result.noLoginUrl = getNoLoginUrl(params, appVersion);
|
|
|
return result;
|
|
|
})();
|
|
|
};
|
|
|
if (resource && resource.code === 200) {
|
|
|
result = _getContent(resource.data, isApp);
|
|
|
} else {
|
|
|
result.noData = true;
|
|
|
}
|
|
|
|
|
|
exports.status = (params) => {
|
|
|
return Promise.coroutine(function*() {
|
|
|
const resource = yield api.get('', Object.assign(params, {
|
|
|
method: 'app.promotion.couponStatus'
|
|
|
}));
|
|
|
const result = {
|
|
|
code: resource.code,
|
|
|
data: []
|
|
|
};
|
|
|
result.share = getShare(params.contentCode, '领券中心');
|
|
|
result.noLoginUrl = getNoLoginUrl(params, appVersion);
|
|
|
return result;
|
|
|
})();
|
|
|
}
|
|
|
|
|
|
if (resource && resource.code === 200 && resource.data.length) {
|
|
|
resource.data.forEach(function(val) {
|
|
|
result.data.push({
|
|
|
hasNum: val.hasNum,
|
|
|
couponId: crypto.encryption('yoho9646abcdefgh', String(val.couponId)),
|
|
|
status: val.status
|
|
|
status(params) {
|
|
|
return Promise.coroutine(function*() {
|
|
|
const resource = yield api.get('', Object.assign(params, {
|
|
|
method: 'app.promotion.couponStatus'
|
|
|
}));
|
|
|
const result = {
|
|
|
code: resource.code,
|
|
|
data: []
|
|
|
};
|
|
|
|
|
|
if (resource && resource.code === 200 && resource.data.length) {
|
|
|
resource.data.forEach(function(val) {
|
|
|
result.data.push({
|
|
|
hasNum: val.hasNum,
|
|
|
couponId: crypto.encryption('yoho9646abcdefgh', String(val.couponId)),
|
|
|
status: val.status
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
return result;
|
|
|
})();
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 前端ajax领券
|
|
|
*/
|
|
|
exports.receiveCoupon = (receiveData, uid) => {
|
|
|
let returnData = {};
|
|
|
|
|
|
// 获取优惠券 ID
|
|
|
if (receiveData.couponID) {
|
|
|
receiveData.couponID = crypto.decrypt('yoho9646abcdefgh', receiveData.couponID);
|
|
|
}
|
|
|
return result;
|
|
|
})();
|
|
|
}
|
|
|
|
|
|
// 登录后调用领券接口
|
|
|
return api.get('', {
|
|
|
method: 'app.promotion.getCoupon',
|
|
|
couponId: receiveData.couponID,
|
|
|
uid: uid
|
|
|
}).then(result => {
|
|
|
switch (result.code) {
|
|
|
case 200:
|
|
|
returnData = {
|
|
|
msg: '领券成功!',
|
|
|
status: true
|
|
|
};
|
|
|
break;
|
|
|
case 401:
|
|
|
returnData = {
|
|
|
code: 401,
|
|
|
msg: '您已领取过优惠券',
|
|
|
status: false
|
|
|
};
|
|
|
break;
|
|
|
case 315:
|
|
|
returnData = {
|
|
|
code: 315,
|
|
|
msg: '优惠券已过期',
|
|
|
status: false
|
|
|
};
|
|
|
break;
|
|
|
default:
|
|
|
returnData = {
|
|
|
msg: result.message || '领券失败!',
|
|
|
status: false
|
|
|
};
|
|
|
break;
|
|
|
}
|
|
|
return returnData;
|
|
|
});
|
|
|
};
|
|
|
|
|
|
exports.couponSend = (uid, token) => {
|
|
|
let data = {
|
|
|
method: 'app.coupons.couponSend',
|
|
|
uid: uid,
|
|
|
coupon_send_token: token
|
|
|
};
|
|
|
/**
|
|
|
* 前端ajax领券
|
|
|
*/
|
|
|
receiveCoupon(receiveData, uid) {
|
|
|
let returnData = {};
|
|
|
|
|
|
if (/:/.test(token)) {
|
|
|
let [couponId, personCouponId] = token.split(':');
|
|
|
// 获取优惠券 ID
|
|
|
if (receiveData.couponID) {
|
|
|
receiveData.couponID = crypto.decrypt('yoho9646abcdefgh', receiveData.couponID);
|
|
|
}
|
|
|
|
|
|
data = {
|
|
|
// 登录后调用领券接口
|
|
|
return api.get('', {
|
|
|
method: 'app.promotion.getCoupon',
|
|
|
couponId: receiveData.couponID,
|
|
|
uid: uid
|
|
|
}).then(result => {
|
|
|
switch (result.code) {
|
|
|
case 200:
|
|
|
returnData = {
|
|
|
msg: '领券成功!',
|
|
|
status: true
|
|
|
};
|
|
|
break;
|
|
|
case 401:
|
|
|
returnData = {
|
|
|
code: 401,
|
|
|
msg: '您已领取过优惠券',
|
|
|
status: false
|
|
|
};
|
|
|
break;
|
|
|
case 315:
|
|
|
returnData = {
|
|
|
code: 315,
|
|
|
msg: '优惠券已过期',
|
|
|
status: false
|
|
|
};
|
|
|
break;
|
|
|
default:
|
|
|
returnData = {
|
|
|
msg: result.message || '领券失败!',
|
|
|
status: false
|
|
|
};
|
|
|
break;
|
|
|
}
|
|
|
return returnData;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
couponSend(uid, token) {
|
|
|
let data = {
|
|
|
method: 'app.coupons.couponSend',
|
|
|
uid: uid,
|
|
|
couponId: couponId,
|
|
|
personCouponId: personCouponId
|
|
|
coupon_send_token: token
|
|
|
};
|
|
|
}
|
|
|
|
|
|
return api.get('', data).then(result => {
|
|
|
if (/:/.test(token)) {
|
|
|
let [couponId, personCouponId] = token.split(':');
|
|
|
|
|
|
if (!result) {
|
|
|
result.code = 404;
|
|
|
result.message = '出错啦~';
|
|
|
data = {
|
|
|
method: 'app.promotion.getCoupon',
|
|
|
uid: uid,
|
|
|
couponId: couponId,
|
|
|
personCouponId: personCouponId
|
|
|
};
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
});
|
|
|
}; |
|
|
return api.get('', data).then(result => {
|
|
|
|
|
|
if (!result) {
|
|
|
result.code = 404;
|
|
|
result.message = '出错啦~';
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
module.exports = couponFloor; |
...
|
...
|
|