Authored by huangyi

领券

... ... @@ -87,6 +87,8 @@ const couponController = {
const pageSize = req.query.pageSize || 20;
let totalCount = await req.ctx(CouponModel).allCouponNum();
totalCount = totalCount[0].total;
let list = await req.ctx(CouponModel).couponList({pageNo, pageSize});
res.json({
... ...
... ... @@ -44,7 +44,7 @@ class CouponModel extends global.yoho.BaseModel {
return mysqlCli.insert(`insert into ${TABLE_COUPON_NO} (coupon_id, coupon_no) values (:couponId,:couponNo)`, arr);
}
couponModify(obj) {
async couponModify(obj) {
if (obj.id) {
let sql = `UPDATE ${TABLE_COUPON} SET `;
let sqlParam = {};
... ... @@ -68,7 +68,7 @@ class CouponModel extends global.yoho.BaseModel {
);
} else {
return mysqlCli.insert(
return await 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);`,
{
... ... @@ -86,7 +86,7 @@ class CouponModel extends global.yoho.BaseModel {
allCouponNum() {
return mysqlCli.query(
`select count(*) as total from ${TABLE_COUPON};`
`select count(1) as total from ${TABLE_COUPON};`
);
}
... ...
... ... @@ -8,6 +8,8 @@
</div>
<form id="createForm" class="form-horizontal form-label-left">
<input class="form-imput" type="hidden" data-type="id" value="{{id}}">
<input id="type" type="hidden" value="{{type}}">
<input id="status" type="hidden" value="{{status}}">
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="actName">
券名称<span class="required">*</span>
... ... @@ -56,15 +58,15 @@
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<label class="control-label col-md-1">
<input type="radio" name="status" required="required"
class="form-contro col-md-7 col-xs-12" checked value="1">
</label>
<label class="control-label col-md-1">
<input type="radio" name="status" required="required"
class="form-contro col-md-7 col-xs-12" value="0">
</label>
<label class="control-label col-md-1">
<input type="radio" name="status" required="required"
class="form-contro col-md-7 col-xs-12" value="1">
</label>
</div>
</div>
<div class="form-group">
... ... @@ -74,7 +76,7 @@
<div class="col-md-9 col-sm-9 col-xs-12">
<label class="control-label radi">
<input type="radio" name="type" required="required"
class="form-contro col-md-4 col-xs-12" checked value="1">
class="form-contro col-md-4 col-xs-12" value="1">
通用码
</label>
<label class="control-label radi">
... ...
/**
* 优惠券管理controller
* @author: leo <y.huang@yoho.cn>
* @date: 08/08/2018
*/
const CouponModel = require('../models/coupon');
const GET_SUCCESS = '获取成功';
const INVALID_PARAMS = '参数错误';
const couponController = {
async couponList(req, res, next) {
try {
let list = await req.ctx(CouponModel).couponList();
res.json({
code: 200,
data: list,
message: GET_SUCCESS
});
} catch (e) {
next;
}
},
async couponSendFlag(req, res, next) {
if (!req.query.userId) {
return res.json({
code: 200,
message: INVALID_PARAMS
});
}
try {
let list = await req.ctx(CouponModel).couponUserFlag(req.query.userId);
return res.json({
code: 200,
data: list,
message: GET_SUCCESS
});
} catch (e) {
next;
}
},
async couponGet(req, res, next) {
if (!req.body.params.userId) {
return res.json({
code: 200,
result: false,
message: INVALID_PARAMS
});
}
try {
let result = await req.ctx(CouponModel).coouponUserGet(req.body.params);
res.json(result);
} catch (e) {
next;
}
},
async couponUserOwner(req, res, next) {
if (!req.query.userId) {
return res.json({
code: 200,
result: false,
message: INVALID_PARAMS
});
}
try {
let result = await req.ctx(CouponModel).couponUserOwner(req.query.userId);
res.json(result);
} catch (e) {
next;
}
}
};
module.exports = couponController;
... ...
... ... @@ -10,6 +10,7 @@ const wechat = require('./controllers/wechat');
const prize = require('./controllers/prize');
const shoes = require('./controllers/shoes');
const yohood = require('./controllers/yohood');
const coupon = require('./controllers/coupon');
const excel = require('./controllers/excel');
const multipart = require('connect-multiparty');
... ... @@ -44,4 +45,10 @@ router.get('/yohood/getRecommend', yohood.getRecommend);
router.get('/yohood/getResource', yohood.getYohoBuyResource);
router.get('/yohood/getShopProduct', yohood.getYohoBuyShopProduct);
// coupon
router.get('/coupon/getCouponList', coupon.couponList);
router.get('/coupon/getCouponSendFlags', coupon.couponSendFlag);
router.post('/coupon/couponGet', coupon.couponGet);
router.get('/coupon/couponUserOwner', coupon.couponUserOwner);
module.exports = router;
... ...
... ... @@ -75,7 +75,7 @@ function bindEditPageEvent() {
let val = $this.val();
let data = $this.data();
if (!val && !error && data.type !== 'id') {
if (!val && !error && data.type !== 'id' && data.type !== 'couponNo') {
error = data.empty || `请填写${data.type}`;
}
... ... @@ -83,7 +83,7 @@ function bindEditPageEvent() {
});
if (error) {
alert(error);//eslint-disable line
alert(error);// eslint-disable line
return;
}
... ... @@ -109,8 +109,22 @@ function bindEditPageEvent() {
};
}
function radioInit() {
let type = $('#type').val();
let status = $('#status').val();
if (type) {
$($('input[name=type]')[parseInt(type) - 1]).attr('checked', true);
} else {
$($('input[name=type]')[0]).attr('checked', true);
}
if (status) {
$($('input[name=status]')[parseInt(status)]).attr('checked', true);
} else {
$($('input[name=status]')[0]).attr('checked', true);
}
}
radioInit();
$('.btn-upload-thumb').on('click', function() {
uploadedFn = new GenUploadedFn($(this));
$upload[0].click();
... ...