Authored by huangyi

领券

@@ -87,6 +87,8 @@ const couponController = { @@ -87,6 +87,8 @@ const couponController = {
87 const pageSize = req.query.pageSize || 20; 87 const pageSize = req.query.pageSize || 20;
88 88
89 let totalCount = await req.ctx(CouponModel).allCouponNum(); 89 let totalCount = await req.ctx(CouponModel).allCouponNum();
  90 +
  91 + totalCount = totalCount[0].total;
90 let list = await req.ctx(CouponModel).couponList({pageNo, pageSize}); 92 let list = await req.ctx(CouponModel).couponList({pageNo, pageSize});
91 93
92 res.json({ 94 res.json({
@@ -44,7 +44,7 @@ class CouponModel extends global.yoho.BaseModel { @@ -44,7 +44,7 @@ class CouponModel extends global.yoho.BaseModel {
44 return mysqlCli.insert(`insert into ${TABLE_COUPON_NO} (coupon_id, coupon_no) values (:couponId,:couponNo)`, arr); 44 return mysqlCli.insert(`insert into ${TABLE_COUPON_NO} (coupon_id, coupon_no) values (:couponId,:couponNo)`, arr);
45 } 45 }
46 46
47 - couponModify(obj) { 47 + async couponModify(obj) {
48 if (obj.id) { 48 if (obj.id) {
49 let sql = `UPDATE ${TABLE_COUPON} SET `; 49 let sql = `UPDATE ${TABLE_COUPON} SET `;
50 let sqlParam = {}; 50 let sqlParam = {};
@@ -68,7 +68,7 @@ class CouponModel extends global.yoho.BaseModel { @@ -68,7 +68,7 @@ class CouponModel extends global.yoho.BaseModel {
68 ); 68 );
69 } else { 69 } else {
70 70
71 - return mysqlCli.insert( 71 + return await mysqlCli.insert(
72 `insert into ${TABLE_COUPON} (coupon_name, coupon_desc, shop_name, shop_logo_url, status,type,sort) 72 `insert into ${TABLE_COUPON} (coupon_name, coupon_desc, shop_name, shop_logo_url, status,type,sort)
73 values (:couponName, :couponDesc, :shopName, :shopLogoUrl, :status, :type, :sort);`, 73 values (:couponName, :couponDesc, :shopName, :shopLogoUrl, :status, :type, :sort);`,
74 { 74 {
@@ -86,7 +86,7 @@ class CouponModel extends global.yoho.BaseModel { @@ -86,7 +86,7 @@ class CouponModel extends global.yoho.BaseModel {
86 86
87 allCouponNum() { 87 allCouponNum() {
88 return mysqlCli.query( 88 return mysqlCli.query(
89 - `select count(*) as total from ${TABLE_COUPON};` 89 + `select count(1) as total from ${TABLE_COUPON};`
90 ); 90 );
91 } 91 }
92 92
@@ -8,6 +8,8 @@ @@ -8,6 +8,8 @@
8 </div> 8 </div>
9 <form id="createForm" class="form-horizontal form-label-left"> 9 <form id="createForm" class="form-horizontal form-label-left">
10 <input class="form-imput" type="hidden" data-type="id" value="{{id}}"> 10 <input class="form-imput" type="hidden" data-type="id" value="{{id}}">
  11 + <input id="type" type="hidden" value="{{type}}">
  12 + <input id="status" type="hidden" value="{{status}}">
11 <div class="item form-group"> 13 <div class="item form-group">
12 <label class="control-label col-md-3 col-sm-3 col-xs-12" for="actName"> 14 <label class="control-label col-md-3 col-sm-3 col-xs-12" for="actName">
13 券名称<span class="required">*</span> 15 券名称<span class="required">*</span>
@@ -56,15 +58,15 @@ @@ -56,15 +58,15 @@
56 </label> 58 </label>
57 <div class="col-md-6 col-sm-6 col-xs-12"> 59 <div class="col-md-6 col-sm-6 col-xs-12">
58 <label class="control-label col-md-1"> 60 <label class="control-label col-md-1">
59 - <input type="radio" name="status" required="required"  
60 - class="form-contro col-md-7 col-xs-12" checked value="1">  
61 -  
62 - </label>  
63 - <label class="control-label col-md-1">  
64 <input type="radio" name="status" required="required" 61 <input type="radio" name="status" required="required"
65 class="form-contro col-md-7 col-xs-12" value="0"> 62 class="form-contro col-md-7 col-xs-12" value="0">
66 63
67 </label> 64 </label>
  65 + <label class="control-label col-md-1">
  66 + <input type="radio" name="status" required="required"
  67 + class="form-contro col-md-7 col-xs-12" value="1">
  68 +
  69 + </label>
68 </div> 70 </div>
69 </div> 71 </div>
70 <div class="form-group"> 72 <div class="form-group">
@@ -74,7 +76,7 @@ @@ -74,7 +76,7 @@
74 <div class="col-md-9 col-sm-9 col-xs-12"> 76 <div class="col-md-9 col-sm-9 col-xs-12">
75 <label class="control-label radi"> 77 <label class="control-label radi">
76 <input type="radio" name="type" required="required" 78 <input type="radio" name="type" required="required"
77 - class="form-contro col-md-4 col-xs-12" checked value="1"> 79 + class="form-contro col-md-4 col-xs-12" value="1">
78 通用码 80 通用码
79 </label> 81 </label>
80 <label class="control-label radi"> 82 <label class="control-label radi">
  1 +/**
  2 + * 优惠券管理controller
  3 + * @author: leo <y.huang@yoho.cn>
  4 + * @date: 08/08/2018
  5 + */
  6 +
  7 +const CouponModel = require('../models/coupon');
  8 +
  9 +const GET_SUCCESS = '获取成功';
  10 +const INVALID_PARAMS = '参数错误';
  11 +
  12 +const couponController = {
  13 +
  14 + async couponList(req, res, next) {
  15 + try {
  16 + let list = await req.ctx(CouponModel).couponList();
  17 +
  18 + res.json({
  19 + code: 200,
  20 + data: list,
  21 + message: GET_SUCCESS
  22 + });
  23 + } catch (e) {
  24 + next;
  25 + }
  26 +
  27 + },
  28 +
  29 + async couponSendFlag(req, res, next) {
  30 + if (!req.query.userId) {
  31 + return res.json({
  32 + code: 200,
  33 + message: INVALID_PARAMS
  34 + });
  35 + }
  36 +
  37 + try {
  38 + let list = await req.ctx(CouponModel).couponUserFlag(req.query.userId);
  39 +
  40 + return res.json({
  41 + code: 200,
  42 + data: list,
  43 + message: GET_SUCCESS
  44 + });
  45 + } catch (e) {
  46 + next;
  47 + }
  48 + },
  49 +
  50 + async couponGet(req, res, next) {
  51 + if (!req.body.params.userId) {
  52 + return res.json({
  53 + code: 200,
  54 + result: false,
  55 + message: INVALID_PARAMS
  56 + });
  57 + }
  58 +
  59 + try {
  60 + let result = await req.ctx(CouponModel).coouponUserGet(req.body.params);
  61 +
  62 + res.json(result);
  63 +
  64 + } catch (e) {
  65 + next;
  66 + }
  67 + },
  68 +
  69 + async couponUserOwner(req, res, next) {
  70 + if (!req.query.userId) {
  71 + return res.json({
  72 + code: 200,
  73 + result: false,
  74 + message: INVALID_PARAMS
  75 + });
  76 + }
  77 +
  78 + try {
  79 + let result = await req.ctx(CouponModel).couponUserOwner(req.query.userId);
  80 +
  81 + res.json(result);
  82 + } catch (e) {
  83 + next;
  84 + }
  85 +
  86 + }
  87 +};
  88 +
  89 +module.exports = couponController;
@@ -10,6 +10,7 @@ const wechat = require('./controllers/wechat'); @@ -10,6 +10,7 @@ const wechat = require('./controllers/wechat');
10 const prize = require('./controllers/prize'); 10 const prize = require('./controllers/prize');
11 const shoes = require('./controllers/shoes'); 11 const shoes = require('./controllers/shoes');
12 const yohood = require('./controllers/yohood'); 12 const yohood = require('./controllers/yohood');
  13 +const coupon = require('./controllers/coupon');
13 14
14 const excel = require('./controllers/excel'); 15 const excel = require('./controllers/excel');
15 const multipart = require('connect-multiparty'); 16 const multipart = require('connect-multiparty');
@@ -44,4 +45,10 @@ router.get('/yohood/getRecommend', yohood.getRecommend); @@ -44,4 +45,10 @@ router.get('/yohood/getRecommend', yohood.getRecommend);
44 router.get('/yohood/getResource', yohood.getYohoBuyResource); 45 router.get('/yohood/getResource', yohood.getYohoBuyResource);
45 router.get('/yohood/getShopProduct', yohood.getYohoBuyShopProduct); 46 router.get('/yohood/getShopProduct', yohood.getYohoBuyShopProduct);
46 47
  48 +// coupon
  49 +router.get('/coupon/getCouponList', coupon.couponList);
  50 +router.get('/coupon/getCouponSendFlags', coupon.couponSendFlag);
  51 +router.post('/coupon/couponGet', coupon.couponGet);
  52 +router.get('/coupon/couponUserOwner', coupon.couponUserOwner);
  53 +
47 module.exports = router; 54 module.exports = router;
@@ -75,7 +75,7 @@ function bindEditPageEvent() { @@ -75,7 +75,7 @@ function bindEditPageEvent() {
75 let val = $this.val(); 75 let val = $this.val();
76 let data = $this.data(); 76 let data = $this.data();
77 77
78 - if (!val && !error && data.type !== 'id') { 78 + if (!val && !error && data.type !== 'id' && data.type !== 'couponNo') {
79 error = data.empty || `请填写${data.type}`; 79 error = data.empty || `请填写${data.type}`;
80 } 80 }
81 81
@@ -83,7 +83,7 @@ function bindEditPageEvent() { @@ -83,7 +83,7 @@ function bindEditPageEvent() {
83 }); 83 });
84 84
85 if (error) { 85 if (error) {
86 - alert(error);//eslint-disable line 86 + alert(error);// eslint-disable line
87 return; 87 return;
88 } 88 }
89 89
@@ -109,8 +109,22 @@ function bindEditPageEvent() { @@ -109,8 +109,22 @@ function bindEditPageEvent() {
109 }; 109 };
110 110
111 } 111 }
112 -  
113 - 112 + function radioInit() {
  113 + let type = $('#type').val();
  114 + let status = $('#status').val();
  115 +
  116 + if (type) {
  117 + $($('input[name=type]')[parseInt(type) - 1]).attr('checked', true);
  118 + } else {
  119 + $($('input[name=type]')[0]).attr('checked', true);
  120 + }
  121 + if (status) {
  122 + $($('input[name=status]')[parseInt(status)]).attr('checked', true);
  123 + } else {
  124 + $($('input[name=status]')[0]).attr('checked', true);
  125 + }
  126 + }
  127 + radioInit();
114 $('.btn-upload-thumb').on('click', function() { 128 $('.btn-upload-thumb').on('click', function() {
115 uploadedFn = new GenUploadedFn($(this)); 129 uploadedFn = new GenUploadedFn($(this));
116 $upload[0].click(); 130 $upload[0].click();