coupon.html 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. {extend name="base"/}
  2. {block name="resources"}
  3. <style>
  4. /* 提示弹出框 */
  5. .card-common:first-of-type{margin-top: 0;}
  6. .layui-card-body{display: flex;padding-bottom: 0 !important;padding-right: 50px !important;padding-left: 50px !important;flex-wrap: wrap;}
  7. .layui-card-body .content{width: 33.3%;display: flex;flex-direction: column;margin-bottom: 30px;justify-content: center;}
  8. .layui-card-body .content .title{color: #909399;font-size: 14px;}
  9. .layui-card-body .money{color: #303133;font-size: 26px;margin-top: 10px;max-width: 250px;}
  10. .layui-card-body .bottom-title{color: #909399;font-size: 14px;margin-top: 5px;}
  11. .table-bottom .layui-table-page {position: inherit;text-align: right}
  12. .table-tab .layui-tab-content{margin-bottom: 0;}
  13. .screen {margin-top: 15px}
  14. .table-title {cursor: pointer}
  15. .layui-layout-admin.admin-style-2 .table-tab .layui-tab-title {margin-bottom: 15px;}
  16. .layui-layout-admin.admin-style-2 .layui-form-item .layui-input-inline{background-color: #fff;}
  17. </style>
  18. {/block}
  19. {block name="main"}
  20. <div class="layui-card card-common card-brief">
  21. <div class="layui-card-header">
  22. <div>
  23. <span class="card-title">优惠券概况</span>
  24. </div>
  25. </div>
  26. <div class="layui-card-body">
  27. <div class="content">
  28. <p class="title">累计发放</p>
  29. <p class="money">{$total_count}</p>
  30. </div>
  31. <div class="content">
  32. <p class="title">已使用</p>
  33. <p class="money">{$used_count}</p>
  34. </div>
  35. <div class="content">
  36. <p class="title">待使用</p>
  37. <p class="money">{$not_used_count}</p>
  38. </div>
  39. </div>
  40. </div>
  41. <div class="screen layui-collapse" lay-filter="selection_panel">
  42. <div class="layui-colla-item">
  43. <form class="layui-colla-content layui-form layui-show">
  44. <div class="layui-form-item">
  45. <div class="layui-inline">
  46. <label class="layui-form-label">昵称/手机号:</label>
  47. <div class="layui-input-inline">
  48. <input type="text" name="search_text" placeholder="请输入会员昵称/手机号" autocomplete="off" class="layui-input">
  49. </div>
  50. </div>
  51. <div class="layui-inline">
  52. <label class="layui-form-label">获取方式:</label>
  53. <div class="layui-input-inline">
  54. <select name="get_type">
  55. <option value="">全部</option>
  56. {foreach $get_type as $k => $val}
  57. <option value="{$k}">{$val}</option>
  58. {/foreach}
  59. </select>
  60. </div>
  61. </div>
  62. </div>
  63. <div class="layui-form-item">
  64. <div class="layui-inline">
  65. <label class="layui-form-label">领取时间:</label>
  66. <div class="layui-input-inline">
  67. <input type="text" class="layui-input" name="start_time" placeholder="开始时间" id="start_time" readonly>
  68. <i class=" iconrili iconfont calendar"></i>
  69. </div>
  70. <div class="layui-form-mid">-</div>
  71. <div class="layui-input-inline">
  72. <input type="text" class="layui-input" name="end_time" placeholder="结束时间" id="end_time" readonly>
  73. <i class=" iconrili iconfont calendar"></i>
  74. </div>
  75. <button class="layui-btn layui-btn-primary date-picker-btn date-picker-btn-seven" onclick="datePick(7, this);return false;">近7天</button>
  76. <button class="layui-btn layui-btn-primary date-picker-btn date-picker-btn-thirty" onclick="datePick(30, this);return false;">近30天</button>
  77. </div>
  78. </div>
  79. <div class="form-row">
  80. <button class="layui-btn" lay-submit="" id="search" lay-filter="search">筛选</button>
  81. </div>
  82. </form>
  83. </div>
  84. </div>
  85. <div class="layui-tab table-tab" lay-filter="coupon_tab">
  86. <ul class="layui-tab-title">
  87. <li class="layui-this" lay-id="">全部</li>
  88. <li lay-id="1">已领取</li>
  89. <li lay-id="2">已使用</li>
  90. <li lay-id="3">已过期</li>
  91. </ul>
  92. <div class="layui-tab-content">
  93. <!-- 列表 -->
  94. <table id="coupon" lay-filter="coupon"></table>
  95. </div>
  96. </div>
  97. {/block}
  98. {block name="script"}
  99. <script type="text/html" id="memberInfo">
  100. <div class='table-title'>
  101. <div class='title-pic'>
  102. <img layer-src src="{{ns.img(d.headimg)}}" onerror="this.src = '{:img('public/static/img/default_img/head.png')}' ">
  103. </div>
  104. <div class='title-content' onclick="location.href = ns.url('shop/member/editmember?member_id={{d.member_id}}')">
  105. <p class="layui-elip">{{d.nickname}}</p>
  106. <p class="layui-elip">{{d.mobile}}</p>
  107. </div>
  108. </div>
  109. </script>
  110. <script type="text/html" id="operation">
  111. <div class="table-btn" align="right">
  112. {{# if(d.state == 1){ }}
  113. <a class="layui-btn" lay-event="recovery">回收</a>
  114. {{# } }}
  115. </div>
  116. </script>
  117. <script type="text/html" id="toolbarOperation">
  118. <button class="layui-btn layui-btn-primary" lay-event="recovery">批量回收</button>
  119. </script>
  120. <script type="text/html" id="batchOperation">
  121. <button class="layui-btn layui-btn-primary" lay-event="recovery">批量回收</button>
  122. </script>
  123. <script>
  124. var form, laydate, element, getType = {:json_encode($get_type)};
  125. layui.use(['laydate','form', 'element'], function(){
  126. form = layui.form;
  127. laydate = layui.laydate;
  128. element = layui.element;
  129. element.on('tab(coupon_tab)', function(){
  130. table.reload({
  131. page: {curr: 1},
  132. where: {'state': this.getAttribute('lay-id')},
  133. })
  134. });
  135. form.on('submit(search)', function(data) {
  136. if ($('#start_time').val() != '' && $('#end_time').val() != '' && (new Date($('#end_time').val()).getTime() <= new Date($('#start_time').val()).getTime() )) {
  137. layer.msg('结束时间不能小于开始时间');
  138. return false;
  139. }
  140. data.field.state = this.getAttribute('lay-id');
  141. table.reload({
  142. page: {
  143. curr: 1
  144. },
  145. where: data.field
  146. });
  147. return false;
  148. });
  149. laydate.render({
  150. elem: '#start_time',
  151. type: 'datetime',
  152. max: 0,
  153. change: function(value, date, endDate){
  154. $(".date-picker-btn").removeClass("selected");
  155. }
  156. });
  157. laydate.render({
  158. elem: '#end_time',
  159. type: 'datetime',
  160. max: 0,
  161. change: function(value, date, endDate){
  162. $(".date-picker-btn").removeClass("selected");
  163. }
  164. });
  165. table = new Table({
  166. elem: '#coupon',
  167. url: ns.url("shop/memberaccount/coupon"),
  168. cols: [
  169. [{
  170. type: 'checkbox',
  171. width: '3%',
  172. unresize: 'false'
  173. },{
  174. templet: '#memberInfo',
  175. title: '会员信息',
  176. width: '20%',
  177. unresize: 'false'
  178. }, {
  179. field: 'coupon_name',
  180. title: '优惠券',
  181. width: '10%',
  182. unresize: 'false',
  183. templet: function(data) {
  184. return `<a href="`+ ns.url('coupon://shop/coupon/detail', {coupon_type_id: data.coupon_type_id }) +`" target="_blank" class="text-color">`+ data.coupon_name +`</a>`;
  185. }
  186. }, {
  187. title: '类型',
  188. width: '10%',
  189. unresize: 'false',
  190. templet: function (data) {
  191. return data.type == 'reward' ? '满减券' : '折扣券';
  192. }
  193. }, {
  194. title: '获取方式',
  195. width: '10%',
  196. unresize: 'false',
  197. templet: function(data) {
  198. return getType[data.get_type] ? getType[data.get_type] : '';
  199. }
  200. }, {
  201. title: '状态',
  202. width: '12%',
  203. unresize: 'false',
  204. templet: function (data) {
  205. var str = '';
  206. switch (data.state) {
  207. case 1:
  208. str = '已领取';
  209. break;
  210. case 2:
  211. str = '已使用';
  212. break;
  213. case 3:
  214. str = '已过期';
  215. break;
  216. }
  217. return str;
  218. }
  219. }, {
  220. title: '领取时间',
  221. width: '15%',
  222. unresize: 'false',
  223. templet: function(data) {
  224. return ns.time_to_date(data.fetch_time);
  225. }
  226. }, {
  227. title: '使用时间',
  228. width: '15%',
  229. templet: function(data) {
  230. return data.use_time ? ns.time_to_date(data.use_time) : '';
  231. }
  232. },
  233. {
  234. title: '操作',
  235. width: '5%',
  236. templet: '#operation'
  237. }
  238. ]
  239. ],
  240. parseData: function(data){
  241. data.data.list = data.data.list.map(function (item) {
  242. item.LAY_DISABLED = item.state != 1;
  243. return item;
  244. })
  245. return {
  246. "code": data.code,
  247. "msg": data.message,
  248. "count": data.data.count,
  249. "data": data.data.list
  250. };
  251. },
  252. toolbar: '#toolbarOperation',
  253. bottomToolbar: "#batchOperation"
  254. });
  255. table.tool(function(obj) {
  256. var data = obj.data;
  257. switch (obj.event) {
  258. case 'recovery': //编辑
  259. recoveryCoupon([{coupon_type_id: data.coupon_type_id, coupon_id: data.coupon_id}]);
  260. break;
  261. }
  262. })
  263. /**
  264. * 批量操作
  265. */
  266. table.bottomToolbar(function(obj) {
  267. if (obj.data.length < 1) {
  268. layer.msg('请选择要操作的数据');
  269. return;
  270. }
  271. switch (obj.event) {
  272. case "recovery":
  273. var id_array = new Array();
  274. for (i in obj.data) id_array.push({coupon_type_id: obj.data[i].coupon_type_id, coupon_id: obj.data[i].coupon_id});
  275. recoveryCoupon(id_array);
  276. break;
  277. }
  278. });
  279. /**
  280. * 批量操作
  281. */
  282. table.toolbar(function(obj) {
  283. if (obj.data.length < 1) {
  284. layer.msg('请选择要操作的数据');
  285. return;
  286. }
  287. switch (obj.event) {
  288. case "recovery":
  289. var id_array = new Array();
  290. for (i in obj.data) id_array.push({coupon_type_id: obj.data[i].coupon_type_id, coupon_id: obj.data[i].coupon_id});
  291. recoveryCoupon(id_array);
  292. break;
  293. }
  294. });
  295. });
  296. function recoveryCoupon(data) {
  297. layer.confirm('回收将会收回会员领取的待使用的优惠券,已使用的将无法回收,确定要回收所选优惠券吗?', function() {
  298. $.ajax({
  299. url: ns.url("coupon://shop/coupon/recoverycoupon"),
  300. data: {
  301. coupon_list: JSON.stringify(data)
  302. },
  303. dataType: 'JSON',
  304. type: 'POST',
  305. success: function(res) {
  306. layer.msg(res.message);
  307. if (res.code == 0) {
  308. table.reload();
  309. }
  310. }
  311. });
  312. })
  313. }
  314. /**
  315. * 七天时间
  316. */
  317. function datePick(date_num,event_obj){
  318. $(".date-picker-btn").removeClass("selected");
  319. $(event_obj).addClass('selected');
  320. // alert(new Date().format("yyyy-MM-dd hh:mm"));
  321. var now_date = new Date();
  322. Date.prototype.Format = function (fmt,date_num) { //author: meizz
  323. this.setDate(this.getDate()-date_num);
  324. var o = {
  325. "M+": this.getMonth() + 1, //月份
  326. "d+": this.getDate(), //日
  327. "H+": this.getHours(), //小时
  328. "m+": this.getMinutes(), //分
  329. "s+": this.getSeconds(), //秒
  330. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  331. "S": this.getMilliseconds() //毫秒
  332. };
  333. if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  334. for (var k in o)
  335. if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  336. return fmt;
  337. };
  338. // var now_time = new Date().Format("yyyy-MM-dd HH:mm:ss",0);//当前日期
  339. var now_time = new Date().Format("yyyy-MM-dd 23:59:59",0);//当前日期
  340. var before_time = new Date().Format("yyyy-MM-dd 00:00:00",date_num-1);//前几天日期
  341. $("input[name=start_time]").val(before_time,0);
  342. $("input[name=end_time]").val(now_time,date_num-1);
  343. }
  344. </script>
  345. {/block}