Authored by 陈峰

Merge branch 'feature/yohood' into 'master'

Feature/yohood



See merge request !45
... ... @@ -32,10 +32,12 @@ const timeFormat = (time) => {
};
const couponController = {
async loadCouponNoList(req, res, next) {
loadCouponNoList: async function(req, res, next) {
let file = req.files.up_excel;
let id = req.body.id;
res.setTimeout(1000 * 60 * 3 + 1000);
let data = await loadExcel(file.path);
if (!data.length) {
... ... @@ -76,11 +78,8 @@ const couponController = {
}
}
for (let item of data) {
let param = {couponId: id, couponNo: item.couponNo};
await req.ctx(CouponModel).couponNoAdd(param);
}
await req.ctx(CouponModel).couponNoAdd({couponId: id, couponNos: data});
return res.json({
code: 200,
result: true,
... ... @@ -168,6 +167,8 @@ const couponController = {
downloadNoList(req, res, next) {
const couponId = req.query.id;
res.setTimeout(1000 * 60 * 3 + 1000);
if (!couponId) {
return res.json({
code: 400,
... ...
... ... @@ -44,8 +44,17 @@ class CouponModel extends global.yoho.BaseModel {
}
}
couponNoAdd(arr) {
return mysqlCli.insert(`insert into ${TABLE_COUPON_NO} (coupon_id, coupon_no) values (:couponId,:couponNo)`, arr);
couponNoAdd(obj) {
let sql = `insert into ${TABLE_COUPON_NO} (coupon_id, coupon_no) values `;
let arr = obj.couponNos;
arr.map((value, index) => {
sql += '(' + obj.couponId + ',"' + value.couponNo + '")';
if (index !== (arr.length - 1)) {
sql += ',';
}
});
return mysqlCli.insert(sql);
}
async couponModify(obj) {
... ... @@ -120,7 +129,7 @@ class CouponModel extends global.yoho.BaseModel {
return mysqlCli.query(
`select cn.coupon_id couponId,cn.coupon_no couponNo,cn.send_flag sendFlag,cu.user_id userId,cu.create_time createTime
from ${TABLE_COUPON_NO} as cn left join ${TABLE_COUPON_USER} as cu
on cu.coupon_id = cn.coupon_id where cn.coupon_id = :couponId`, {couponId});
on cu.coupon_no_id = cn.id where cn.coupon_id = :couponId`, {couponId});
}
couponUserListByCId(couponId) {
... ...
... ... @@ -25,7 +25,7 @@ class CouponModel extends global.yoho.BaseModel {
return mysqlCli.query(
`select c.id, c.coupon_name couponName, c.coupon_desc couponDesc, c.shop_logo_url shopLogoUrl,cn.coupon_no couponNo
from ${TABLE_COUPON} c ,${TABLE_COUPON_NO} cn, ${TABLE_COUPON_USER} cu where cu.user_id =:userId and cu.coupon_no_id = cn.id and c.id = cn.coupon_id
order by c.sort desc ,c.create_time desc`, {userId});
order by cu.create_time desc`, {userId});
}
async coouponUserGet(obj) {
... ...
... ... @@ -269,7 +269,14 @@ const userController = {
* @param res
*/
wechatUserCallback(req, res, next) {
let wechatUserInfo = JSON.parse(req.query.wechatUserInfo);
let wechatUserInfo;
try {
wechatUserInfo = JSON.parse(req.query.wechatUserInfo);
} catch (err) {
wechatUserInfo = {};
}
console.log('wechatUserCallBack:', wechatUserInfo);
let user_name = '',
... ... @@ -277,7 +284,7 @@ const userController = {
union_id = '';
if (wechatUserInfo) {
if (wechatUserInfo && wechatUserInfo.nickname) {
user_name = wechatUserInfo.nickname;
head_img = wechatUserInfo.headimgurl;
union_id = wechatUserInfo.unionid || wechatUserInfo.openid;
... ...