...
|
...
|
@@ -24,71 +24,87 @@ class CouponModel extends global.yoho.BaseModel { |
|
|
});
|
|
|
}
|
|
|
|
|
|
couponCreate(obj) {
|
|
|
return mysqlCli.insert(
|
|
|
`insert into ${TABLE_COUPON} (coupon_name, coupon_desc, shop_name, shop_logo_url, status,type,sort)
|
|
|
values (:couponName, :couponDesc, :shopName, :shopLogoUrl, :status, :type, :sort);`,
|
|
|
{
|
|
|
couponName: obj.couponName,
|
|
|
couponDesc: obj.couponDesc,
|
|
|
shopName: obj.shopName,
|
|
|
shopLogoUrl: obj.shopLogoUrl,
|
|
|
status: obj.status,
|
|
|
type: obj.type,
|
|
|
sort: obj.sort
|
|
|
couponById(id) {
|
|
|
if (!id) {
|
|
|
return new Promise(resolve => {
|
|
|
return resolve({});
|
|
|
});
|
|
|
} else {
|
|
|
return mysqlCli.query(
|
|
|
`select id, coupon_name couponName, coupon_desc couponDesc, shop_name shopName, shop_logo_url shopLogoUrl, status, type, sort , create_time createTime
|
|
|
from ${TABLE_COUPON}
|
|
|
where id = :id`, {
|
|
|
id
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
couponUpdate(obj) {
|
|
|
let sql = `UPDATE ${TABLE_COUPON} SET `;
|
|
|
let sqlParam = {};
|
|
|
let keyArr = Object.keys(obj);
|
|
|
couponNoAdd(arr) {
|
|
|
// return mysqlCli.insert(`insert into ${TABLE_COUPON_NO} (coupon_id, coupon_no) values ?`, arr);
|
|
|
return mysqlCli.insert(`insert into ${TABLE_COUPON_NO} (coupon_id, coupon_no) values (:couponId,:couponNo)`, arr);
|
|
|
}
|
|
|
|
|
|
couponModify(obj) {
|
|
|
if (obj.id) {
|
|
|
let sql = `UPDATE ${TABLE_COUPON} SET `;
|
|
|
let sqlParam = {};
|
|
|
let keyArr = Object.keys(obj);
|
|
|
|
|
|
keyArr.map((value, index) => {
|
|
|
if (value !== 'id') {
|
|
|
let col = toLine(value);
|
|
|
keyArr.map((value, index) => {
|
|
|
if (value !== 'id') {
|
|
|
let col = toLine(value);
|
|
|
|
|
|
sql += col + ' = :' + value;
|
|
|
if (index !== (keyArr.length - 1)) {
|
|
|
sql += ',';
|
|
|
sql += col + ' = :' + value;
|
|
|
if (index !== (keyArr.length - 1)) {
|
|
|
sql += ',';
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
sqlParam[value] = obj[value];
|
|
|
});
|
|
|
sql += 'WHERE id = :id';
|
|
|
return mysqlCli.update(
|
|
|
sqlParam[value] = obj[value];
|
|
|
});
|
|
|
sql += ' WHERE id = :id';
|
|
|
return mysqlCli.update(
|
|
|
sql,
|
|
|
sqlParam
|
|
|
);
|
|
|
} else {
|
|
|
|
|
|
return mysqlCli.insert(
|
|
|
`insert into ${TABLE_COUPON} (coupon_name, coupon_desc, shop_name, shop_logo_url, status,type,sort)
|
|
|
values (:couponName, :couponDesc, :shopName, :shopLogoUrl, :status, :type, :sort);`,
|
|
|
{
|
|
|
couponName: obj.couponName,
|
|
|
couponDesc: obj.couponDesc,
|
|
|
shopName: obj.shopName,
|
|
|
shopLogoUrl: obj.shopLogoUrl,
|
|
|
status: obj.status,
|
|
|
type: obj.type,
|
|
|
sort: obj.sort
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
allCouponNum() {
|
|
|
return mysqlCli.query(
|
|
|
`select count(*) as total from ${TABLE_COUPON};`
|
|
|
);
|
|
|
}
|
|
|
|
|
|
couponNoListByCId(couponId) {
|
|
|
return mysqlCli.query(
|
|
|
`select id, coupon_id couponId,coupon_no couponNo,send_flag sendFlag,create_time createTime
|
|
|
from ${TABLE_COUPON_NO}
|
|
|
where coupon_id = :couponId `, {couponId: couponId});
|
|
|
}
|
|
|
|
|
|
couponNoListJoinUser(couponId) {
|
|
|
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
|
|
|
where coupon_id = :couponId `, {couponId: couponId});
|
|
|
on cu.coupon_id = cn.coupon_id where cn.coupon_id = :couponId`, {couponId});
|
|
|
}
|
|
|
|
|
|
couponUserListByCId(couponId) {
|
|
|
return mysqlCli.query(
|
|
|
`select id, coupon_id couponId,coupon_no_id couponNoId,user_id userId,create_time createTime
|
|
|
`select id, coupon_id couponId,coupon_no_id couponNoId,user_id userId,create_time createTime
|
|
|
from ${TABLE_COUPON_USER}
|
|
|
where coupon_id = :couponId `, {couponId: couponId});
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
module.export = CouponModel; |
|
|
module.exports = CouponModel; |
...
|
...
|
|