Authored by 毕凯

Merge branch 'feature/couponCenter' into 'release/6.1'

上下文



See merge request !930
... ... @@ -14,7 +14,7 @@ exports.index = (req, res, next) => {
param.uid = uid;
}
model.floor(param, req.yoho.isApp, req.query.app_version).then(result => {
req.ctx(model).floor(param, req.yoho.isApp, req.query.app_version).then(result => {
if (!result.length) {
res.set('Cache-Control', 'no-cache');
}
... ... @@ -47,7 +47,7 @@ exports.status = (req, res, next) => {
});
}
model.status({
req.ctx(model).status({
uid: uid,
contentCode: req.query.code
}, req.yoho.isApp).then(result => {
... ... @@ -65,7 +65,7 @@ exports.receive = (req, res, next) => {
});
}
model.receiveCoupon({
req.ctx(model).receiveCoupon({
couponID: req.query.couponID
}, uid).then(result => {
res.jsonp(result);
... ... @@ -95,7 +95,7 @@ exports.couponSend = (req, res, next) => {
return res.jsonp(resultData);
}
model.couponSend(uid, token, app).then(result => {
req.ctx(model).couponSend(uid, token, app).then(result => {
res.jsonp(result);
}).catch(next);
};
... ...
... ... @@ -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;
... ...