Merge branch 'feature/yohood' of git.yoho.cn:fe/yoho-activity-platform into feature/yohood
Showing
8 changed files
with
96 additions
and
30 deletions
@@ -38,8 +38,6 @@ const couponController = { | @@ -38,8 +38,6 @@ const couponController = { | ||
38 | 38 | ||
39 | let data = await loadExcel(file.path); | 39 | let data = await loadExcel(file.path); |
40 | 40 | ||
41 | - console.log(data); | ||
42 | - | ||
43 | if (!data.length) { | 41 | if (!data.length) { |
44 | return res.json({ | 42 | return res.json({ |
45 | code: 201, | 43 | code: 201, |
@@ -116,11 +114,16 @@ const couponController = { | @@ -116,11 +114,16 @@ const couponController = { | ||
116 | async couponList(req, res) { | 114 | async couponList(req, res) { |
117 | const pageNo = req.query.pageNo || 1; | 115 | const pageNo = req.query.pageNo || 1; |
118 | const pageSize = req.query.pageSize || 20; | 116 | const pageSize = req.query.pageSize || 20; |
117 | + const status = req.query.status; | ||
119 | 118 | ||
120 | - let totalCount = await req.ctx(CouponModel).allCouponNum(); | 119 | + let totalCount = await req.ctx(CouponModel).allCouponNum(status); |
121 | 120 | ||
122 | totalCount = totalCount[0].total; | 121 | totalCount = totalCount[0].total; |
123 | - let list = await req.ctx(CouponModel).couponList({pageNo, pageSize}); | 122 | + let list = await req.ctx(CouponModel).couponList({pageNo, pageSize, status}); |
123 | + | ||
124 | + _.each(list, item => { | ||
125 | + item.createTime = timeFormat(item.createTime); | ||
126 | + }); | ||
124 | 127 | ||
125 | res.json({ | 128 | res.json({ |
126 | code: 200, | 129 | code: 200, |
@@ -13,10 +13,15 @@ class CouponModel extends global.yoho.BaseModel { | @@ -13,10 +13,15 @@ class CouponModel extends global.yoho.BaseModel { | ||
13 | super(ctx); | 13 | super(ctx); |
14 | } | 14 | } |
15 | 15 | ||
16 | - couponList({pageNo, pageSize}) { | 16 | + couponList({pageNo, pageSize, status}) { |
17 | + let str = ''; | ||
18 | + | ||
19 | + if (status === '0' || status === '1') { | ||
20 | + str = `where status = ${status}`; | ||
21 | + } | ||
17 | return mysqlCli.query( | 22 | return mysqlCli.query( |
18 | `select id, coupon_name couponName, coupon_desc couponDesc, shop_name shopName, shop_logo_url shopLogoUrl, status, type, sort , create_time createTime | 23 | `select id, coupon_name couponName, coupon_desc couponDesc, shop_name shopName, shop_logo_url shopLogoUrl, status, type, sort , create_time createTime |
19 | - from ${TABLE_COUPON} | 24 | + from ${TABLE_COUPON} ${str} |
20 | order by sort desc ,create_time desc | 25 | order by sort desc ,create_time desc |
21 | limit :start, :page;`, { | 26 | limit :start, :page;`, { |
22 | start: (pageNo - 1) * pageSize, | 27 | start: (pageNo - 1) * pageSize, |
@@ -80,22 +85,30 @@ class CouponModel extends global.yoho.BaseModel { | @@ -80,22 +85,30 @@ class CouponModel extends global.yoho.BaseModel { | ||
80 | sort: obj.sort | 85 | sort: obj.sort |
81 | }); | 86 | }); |
82 | 87 | ||
83 | - console.log(insertId); | ||
84 | - if (obj.type === 3) { | ||
85 | - await mysqlCli.insert( | 88 | + if (parseInt(obj.type) === 3) { |
89 | + let id = await mysqlCli.insert( | ||
86 | `insert into ${TABLE_COUPON_NO} (coupon_id) values (:couponId);`, | 90 | `insert into ${TABLE_COUPON_NO} (coupon_id) values (:couponId);`, |
87 | { | 91 | { |
88 | couponId: insertId, | 92 | couponId: insertId, |
89 | }); | 93 | }); |
94 | + | ||
95 | + if (!id) { | ||
96 | + return Promise.resolve({code: 204, result: false, message: '插入无码券失败'}); | ||
97 | + } | ||
90 | } | 98 | } |
91 | return Promise.resolve({code: 200, result: true}); | 99 | return Promise.resolve({code: 200, result: true}); |
92 | } | 100 | } |
93 | } | 101 | } |
94 | 102 | ||
95 | 103 | ||
96 | - allCouponNum() { | 104 | + allCouponNum(status) { |
105 | + let str = ''; | ||
106 | + | ||
107 | + if (status === '0' || status === '1') { | ||
108 | + str = `where status = ${status}`; | ||
109 | + } | ||
97 | return mysqlCli.query( | 110 | return mysqlCli.query( |
98 | - `select count(1) as total from ${TABLE_COUPON};` | 111 | + `select count(1) as total from ${TABLE_COUPON} ${str};` |
99 | ); | 112 | ); |
100 | } | 113 | } |
101 | 114 |
@@ -10,6 +10,7 @@ | @@ -10,6 +10,7 @@ | ||
10 | <input class="form-imput" type="hidden" data-type="id" id="id" value="{{id}}"> | 10 | <input class="form-imput" type="hidden" data-type="id" id="id" value="{{id}}"> |
11 | <input id="type" type="hidden" value="{{type}}"> | 11 | <input id="type" type="hidden" value="{{type}}"> |
12 | <input id="status" type="hidden" value="{{status}}"> | 12 | <input id="status" type="hidden" value="{{status}}"> |
13 | + <input id="couponDesc" type="hidden" value="{{couponDesc}}"> | ||
13 | <div class="item form-group"> | 14 | <div class="item form-group"> |
14 | <label class="control-label col-md-3 col-sm-3 col-xs-12" for="actName"> | 15 | <label class="control-label col-md-3 col-sm-3 col-xs-12" for="actName"> |
15 | 券名称<span class="required">*</span> | 16 | 券名称<span class="required">*</span> |
@@ -28,7 +29,7 @@ | @@ -28,7 +29,7 @@ | ||
28 | </div> | 29 | </div> |
29 | <div class="item form-group"> | 30 | <div class="item form-group"> |
30 | <label class="control-label col-md-3 col-sm-3 col-xs-12" for="actName"> | 31 | <label class="control-label col-md-3 col-sm-3 col-xs-12" for="actName"> |
31 | - 商家名称<span class="required">*</span> | 32 | + 商家名称<span class="required">(选填)</span> |
32 | </label> | 33 | </label> |
33 | <div class="col-md-6 col-sm-6 col-xs-12"> | 34 | <div class="col-md-6 col-sm-6 col-xs-12"> |
34 | <input class="form-control col-md-7 col-xs-12 form-imput" | 35 | <input class="form-control col-md-7 col-xs-12 form-imput" |
@@ -102,7 +103,7 @@ | @@ -102,7 +103,7 @@ | ||
102 | name="actVoteLimit" | 103 | name="actVoteLimit" |
103 | type="text" | 104 | type="text" |
104 | maxlength="10" | 105 | maxlength="10" |
105 | - value="{{sort}}"> | 106 | + value="{{sort}}"><span style="color:#d44950">备注:排序权重数大的排在前面</span> |
106 | </div> | 107 | </div> |
107 | </div> | 108 | </div> |
108 | <div class="item form-group"> | 109 | <div class="item form-group"> |
@@ -110,7 +111,7 @@ | @@ -110,7 +111,7 @@ | ||
110 | class="required">*</span> | 111 | class="required">*</span> |
111 | </label> | 112 | </label> |
112 | <div class="col-md-4 col-sm-4 col-xs-12"> | 113 | <div class="col-md-4 col-sm-4 col-xs-12"> |
113 | - <textarea class="form-control form-imput" data-type="couponDesc" rows="3" style="resize: none;height: 300px">{{couponDesc}}</textarea> | 114 | + <textarea class="form-control form-imput" data-type="couponDesc" rows="3" style="resize: none;height: 300px"></textarea> |
114 | </div> | 115 | </div> |
115 | </div> | 116 | </div> |
116 | <div class="item form-group"> | 117 | <div class="item form-group"> |
@@ -6,7 +6,16 @@ | @@ -6,7 +6,16 @@ | ||
6 | <div class="x_panel"> | 6 | <div class="x_panel"> |
7 | <div class="x_title"> | 7 | <div class="x_title"> |
8 | <a href="/admin/coupon/option" class="btn btn-primary">创建券</a> | 8 | <a href="/admin/coupon/option" class="btn btn-primary">创建券</a> |
9 | - <div class="clearfix"></div> | 9 | + <div class="btn-group" style="vertical-align: top"> |
10 | + <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
11 | + <span id="dropdown-toggle-txt">全部 </span> <span class="caret"></span> | ||
12 | + </button> | ||
13 | + <ul class="dropdown-menu"> | ||
14 | + <li data-status="1"><a href="#">已上架</a></li> | ||
15 | + <li data-status="0"><a href="#">已下架</a></li> | ||
16 | + <li><a href="#">全部</a></li> | ||
17 | + </ul> | ||
18 | + </div> | ||
10 | </div> | 19 | </div> |
11 | <div class="x_content"> | 20 | <div class="x_content"> |
12 | <div class="table-responsive"> | 21 | <div class="table-responsive"> |
@@ -15,8 +24,8 @@ | @@ -15,8 +24,8 @@ | ||
15 | <tr class="headings"> | 24 | <tr class="headings"> |
16 | <th class="column-title">ID</th> | 25 | <th class="column-title">ID</th> |
17 | <th class="column-title">券名称</th> | 26 | <th class="column-title">券名称</th> |
18 | - <th class="column-title">商铺名称</th> | ||
19 | - <th class="column-title">商铺图标</th> | 27 | + <th class="column-title">商家名称</th> |
28 | + <th class="column-title">券图标</th> | ||
20 | <th class="column-title">上下架状态</th> | 29 | <th class="column-title">上下架状态</th> |
21 | <th class="column-title">券类型</th> | 30 | <th class="column-title">券类型</th> |
22 | <th class="column-title">排序权重</th> | 31 | <th class="column-title">排序权重</th> |
@@ -48,6 +48,7 @@ const couponController = { | @@ -48,6 +48,7 @@ const couponController = { | ||
48 | }, | 48 | }, |
49 | 49 | ||
50 | async couponGet(req, res, next) { | 50 | async couponGet(req, res, next) { |
51 | + console.log(req.body); | ||
51 | if (!req.body.params.userId) { | 52 | if (!req.body.params.userId) { |
52 | return res.json({ | 53 | return res.json({ |
53 | code: 200, | 54 | code: 200, |
@@ -49,7 +49,6 @@ class CouponModel extends global.yoho.BaseModel { | @@ -49,7 +49,6 @@ class CouponModel extends global.yoho.BaseModel { | ||
49 | 49 | ||
50 | let noId = couponNolist[0].id; | 50 | let noId = couponNolist[0].id; |
51 | 51 | ||
52 | - | ||
53 | // 如果type=2(一人一码) 则修改第一张待用券码的send状态 | 52 | // 如果type=2(一人一码) 则修改第一张待用券码的send状态 |
54 | if (obj.type === 2) { | 53 | if (obj.type === 2) { |
55 | await mysqlCli.update(`UPDATE ${TABLE_COUPON_NO} SET send_flag = 1 where id = :id`, {id: noId}); | 54 | await mysqlCli.update(`UPDATE ${TABLE_COUPON_NO} SET send_flag = 1 where id = :id`, {id: noId}); |
@@ -65,7 +65,9 @@ function initUpload() { | @@ -65,7 +65,9 @@ function initUpload() { | ||
65 | function bindEditPageEvent() { | 65 | function bindEditPageEvent() { |
66 | initUpload(); | 66 | initUpload(); |
67 | 67 | ||
68 | - | 68 | + function getStrFormat(strValue) { |
69 | + return strValue.replace(/\r\n/g, '<br/>').replace(/\n/g, '<br/>').replace(/\s/g, ' '); | ||
70 | + } | ||
69 | function packInfo() { | 71 | function packInfo() { |
70 | let resData = {}; | 72 | let resData = {}; |
71 | let error; | 73 | let error; |
@@ -75,11 +77,14 @@ function bindEditPageEvent() { | @@ -75,11 +77,14 @@ function bindEditPageEvent() { | ||
75 | let val = $this.val(); | 77 | let val = $this.val(); |
76 | let data = $this.data(); | 78 | let data = $this.data(); |
77 | 79 | ||
78 | - if (!val && !error && data.type !== 'id' && data.type !== 'couponNo') { | 80 | + if (!val && !error && data.type !== 'id' && data.type !== 'couponNo' && data.type !== 'shopName') { |
79 | error = data.empty || `请填写${data.type}`; | 81 | error = data.empty || `请填写${data.type}`; |
80 | } | 82 | } |
81 | - | 83 | + if (data.type === 'couponDesc') { |
84 | + resData[data.type] = getStrFormat(val); | ||
85 | + } else { | ||
82 | resData[data.type] = val; | 86 | resData[data.type] = val; |
87 | + } | ||
83 | }); | 88 | }); |
84 | 89 | ||
85 | if (error) { | 90 | if (error) { |
@@ -109,6 +114,9 @@ function bindEditPageEvent() { | @@ -109,6 +114,9 @@ function bindEditPageEvent() { | ||
109 | }; | 114 | }; |
110 | 115 | ||
111 | } | 116 | } |
117 | + function initialStr(str) { | ||
118 | + return str.replace(new RegExp('<br/>', 'gm'), '\r\n').replace(new RegExp(' ', 'gm'), '\s'); | ||
119 | + } | ||
112 | function radioInit() { | 120 | function radioInit() { |
113 | let type = $('#type').val(); | 121 | let type = $('#type').val(); |
114 | let status = $('#status').val(); | 122 | let status = $('#status').val(); |
@@ -127,6 +135,7 @@ function bindEditPageEvent() { | @@ -127,6 +135,7 @@ function bindEditPageEvent() { | ||
127 | $('input[name=type]').each(function(index, el) { | 135 | $('input[name=type]').each(function(index, el) { |
128 | $(el).attr('disabled', true); | 136 | $(el).attr('disabled', true); |
129 | }); | 137 | }); |
138 | + $('textarea').val(initialStr($('#couponDesc').val())); | ||
130 | } | 139 | } |
131 | } | 140 | } |
132 | 141 |
@@ -34,14 +34,18 @@ function bind_table_pagination() { | @@ -34,14 +34,18 @@ function bind_table_pagination() { | ||
34 | }); | 34 | }); |
35 | } | 35 | } |
36 | }; | 36 | }; |
37 | + let statusParam = null; | ||
37 | 38 | ||
38 | const fetchRender = (pageNo, pageSize) => { | 39 | const fetchRender = (pageNo, pageSize) => { |
40 | + let param = {pageNo, pageSize}; | ||
41 | + | ||
42 | + if (statusParam != null) { | ||
43 | + param.status = statusParam; | ||
44 | + } | ||
45 | + | ||
39 | $.ajax({ | 46 | $.ajax({ |
40 | url: '/admin/api/coupon/list', | 47 | url: '/admin/api/coupon/list', |
41 | - data: { | ||
42 | - pageNo, | ||
43 | - pageSize | ||
44 | - } | 48 | + data: param |
45 | }) | 49 | }) |
46 | .then(result => { | 50 | .then(result => { |
47 | const list = result.data; | 51 | const list = result.data; |
@@ -62,9 +66,11 @@ function bind_table_pagination() { | @@ -62,9 +66,11 @@ function bind_table_pagination() { | ||
62 | } else if (item.type == 3) { | 66 | } else if (item.type == 3) { |
63 | item.typeText = '不用码'; | 67 | item.typeText = '不用码'; |
64 | } | 68 | } |
69 | + let status = item.status ? `<a class="btn btn-danger btn-status" data-id="${item.id}" data-status="0">下架</a>` : `<a class="btn btn-success btn-status" data-id="${item.id}" data-status="1">上架</a>`; | ||
70 | + | ||
65 | html += ` | 71 | html += ` |
66 | <tr class="even pointer"> | 72 | <tr class="even pointer"> |
67 | - <td class="">${item.id}</td>1 | 73 | + <td class="">${item.id}</td> |
68 | <td class="">${item.couponName}</td> | 74 | <td class="">${item.couponName}</td> |
69 | <td class="">${item.shopName}</td> | 75 | <td class="">${item.shopName}</td> |
70 | <td class=""><img src="${item.shopLogoUrl}" width="100" height="50"/></td> | 76 | <td class=""><img src="${item.shopLogoUrl}" width="100" height="50"/></td> |
@@ -76,10 +82,11 @@ function bind_table_pagination() { | @@ -76,10 +82,11 @@ function bind_table_pagination() { | ||
76 | <form id="uploadForm_${item.id}" enctype="multipart/form-data"> | 82 | <form id="uploadForm_${item.id}" enctype="multipart/form-data"> |
77 | <input id="up_excel" name="up_excel" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" style="display: inline-block; width: 80%;" type="file"> | 83 | <input id="up_excel" name="up_excel" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" style="display: inline-block; width: 80%;" type="file"> |
78 | </form> | 84 | </form> |
79 | - <button type="button" class="btn btn-danger btn-import" style="display: inline-block;" data-id="${item.id}">导入券码</button> | ||
80 | - <button class="btn btn-danger btn-export-no" data-id="${item.id}">导出券码 | 85 | + <button type="button" class="btn btn-primary btn-import" style="display: inline-block;" data-id="${item.id}">导入券码</button> |
86 | + <button class="btn btn-primary btn-export-no" data-id="${item.id}">导出领取信息 | ||
81 | </button> | 87 | </button> |
82 | - <a class="btn btn-danger btn-update" href="/admin/coupon/update?id=${item.id}">修改</a> | 88 | + <a class="btn btn-info btn-update" href="/admin/coupon/update?id=${item.id}">修改</a> |
89 | + ` + status + ` | ||
83 | <a class="btn btn-danger btn-delete" data-id="${item.id}">删除</a> | 90 | <a class="btn btn-danger btn-delete" data-id="${item.id}">删除</a> |
84 | </td> | 91 | </td> |
85 | </tr>`; | 92 | </tr>`; |
@@ -108,7 +115,6 @@ function bind_table_pagination() { | @@ -108,7 +115,6 @@ function bind_table_pagination() { | ||
108 | $('.btn-delete').click(function() { | 115 | $('.btn-delete').click(function() { |
109 | let id = $(this).attr('data-id'); | 116 | let id = $(this).attr('data-id'); |
110 | 117 | ||
111 | - console.log(id); | ||
112 | $.ajax({ | 118 | $.ajax({ |
113 | url: '/admin/api/coupon/delete?id=' + id, | 119 | url: '/admin/api/coupon/delete?id=' + id, |
114 | method: 'get', | 120 | method: 'get', |
@@ -124,9 +130,34 @@ function bind_table_pagination() { | @@ -124,9 +130,34 @@ function bind_table_pagination() { | ||
124 | } | 130 | } |
125 | }); | 131 | }); |
126 | }); | 132 | }); |
133 | + | ||
134 | + $('.btn-status').click(function() { | ||
135 | + $.ajax({ | ||
136 | + url: '/admin/api/coupon/modify', | ||
137 | + method: 'post', | ||
138 | + data: { | ||
139 | + id: $(this).attr('data-id'), | ||
140 | + status: parseInt($(this).attr('data-status')) | ||
141 | + }, | ||
142 | + success: function() { | ||
143 | + window.location.reload(); | ||
144 | + } | ||
145 | + }); | ||
146 | + }); | ||
127 | }); | 147 | }); |
128 | }; | 148 | }; |
129 | 149 | ||
150 | + $('.dropdown-menu li').click(function() { | ||
151 | + let status = $(this).attr('data-status'); | ||
152 | + | ||
153 | + if (status) { | ||
154 | + statusParam = parseInt(status); | ||
155 | + } else { | ||
156 | + statusParam = null; | ||
157 | + } | ||
158 | + $('#dropdown-toggle-txt').text($(this).text() + ' '); | ||
159 | + fetchRender(1, 20); | ||
160 | + }); | ||
130 | 161 | ||
131 | fetchRender(1, 20); | 162 | fetchRender(1, 20); |
132 | } | 163 | } |
-
Please register or login to post a comment