Authored by 李靖

二维码

... ... @@ -20,7 +20,7 @@ exports.index = (req, res, next) => {
} catch (e) {
uname = params.uname;
}
model.getQr({
req.ctx(model).getQr({
token: params.token,
}).then(result => {
params.token = result;
... ...
... ... @@ -11,7 +11,7 @@ const QRcodeModel = require('../models/qrcode');
exports.QRcode = (req, res, next) => {
let id = req.params.id || 0;
QRcodeModel.getQRcodeData(id, req.user.uid).then((result)=>{
req.ctx(QRcodeModel).getQRcodeData(id, req.user.uid).then((result)=>{
if (result) {
result.ticks = result.ticks.map(item=>{
if (+item.ticket_type === 2) {
... ...
... ... @@ -4,20 +4,28 @@ const api = global.yoho.API;
const crypto = global.yoho.crypto;
const PASSWORD = 'yoho9646yoho9646';
exports.getQr = (params) => {
let uid = '';
class qrcodeModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
getQr(params) {
let uid = '';
try {
uid = crypto.decrypt(PASSWORD, decodeURIComponent(params.token));
uid = parseInt(uid, 10);
} catch (e) {
uid = params.token;
}
try {
uid = crypto.decrypt(PASSWORD, decodeURIComponent(params.token));
uid = parseInt(uid, 10);
} catch (e) {
uid = params.token;
return api.get('', {
method: 'app.twoDimen.getCode',
uid: uid,
}).then(result => {
return (result && result.data && result.data.code) || '';
});
}
}
return api.get('', {
method: 'app.twoDimen.getCode',
uid: uid,
}).then(result => {
return (result && result.data && result.data.code) || '';
});
};
module.exports = qrcodeModel;
... ...
... ... @@ -8,18 +8,25 @@
const logger = global.yoho.logger;
var api = global.yoho.API;
exports.getQRcodeData = (id, uid) => {
return api.get('', {
method: 'app.SpaceOrders.getQrByOrderCode',
order_code: id,
uid: uid
}).then(result => {
if (result && result.code === 200) {
return result.data;
} else {
logger.error(`查看二维码ID: ${id} 接口返回数据错误`);
return false;
}
});
};
class qrcodeModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
getQRcodeData(id, uid) {
return api.get('', {
method: 'app.SpaceOrders.getQrByOrderCode',
order_code: id,
uid: uid
}).then(result => {
if (result && result.code === 200) {
return result.data;
} else {
logger.error(`查看二维码ID: ${id} 接口返回数据错误`);
return false;
}
});
}
}
module.exports = qrcodeModel;
... ...