couponexchange.html 14 KB
{template 'common/header'}
<ul class="nav nav-tabs">
	<li {if $_GPC['do'] == 'couponmanage'}class="active" {/if}><a href="{php echo $this->createWeburl('couponmanage', array('op' => 'display'))}">卡券管理</a></li>
	<li {if $_GPC['do'] == 'couponexchange'}class="active"{/if}><a href="{php echo $this->createWeburl('couponexchange', array('op' => 'display'));}">卡券兑换</a></li>
	<li {if $_GPC['do'] == 'couponconsume'}class="active" {/if}><a href="{php echo $this->createWeburl('couponconsume', array('op' => 'display'))}">卡券核销</a></li>
	<li {if $_GPC['do'] == 'memberproperty'}class="active" {/if}><a href="{php echo $this->createWeburl('memberproperty', array('op' => 'display'))}">会员属性</a></li>
	<li {if $_GPC['do'] == 'couponmarket'}class="active" {/if}><a href="{php echo $this->createWeburl('couponmarket', array('op' => 'display'))}">优惠券派发</a></li>
	<li style="display:none" {if $_GPC['do'] == 'wxcardreply'}class="active"{/if}><a href="{php echo $this->createWebUrl('wxcardreply', array('op' => 'display'))}">管理微信卡券回复</a></li>
</ul>
{if $_GPC['op'] == 'display'}
<div class="main">
	<div class="page-header clearfix">
		<h4 class="pull-left">卡券兑换</h4>
		<div class="pull-right">
			<a href="{php echo $this->createWeburl('couponexchange', array('op' => 'post'))}" class="btn btn-primary we7-padding-horizontal">+添加卡券兑换</a>
		</div>
	</div>
	<div class="panel panel-info">
		<div class="panel-heading">筛选</div>
		<div class="panel-body">
			<form action="./index.php" method="get" class="form-horizontal" role="form">
				<input type="hidden" name="c" value="site" />
				<input type="hidden" name="a" value="entry" />
				<input type="hidden" name="do" value="couponexchange" />
				<input type="hidden" name="m" value="wn_storex" />
				<input type="hidden" name="op" value="display" />
				<div class="form-group">
					<label class="col-xs-12 col-sm-2 col-md-2 col-lg-2 control-label">卡券名称</label>
					<div class="col-sm-7 col-lg-8 col-xs-12">
						<input class="form-control" name="title" type="text" value="{$_GPC['title']}">
					</div>
					<div class="pull-right col-lg-2">
						<input type="submit" name="submit" class="btn btn-default" value="搜索">
						<input type="hidden" name="token" value="{$_W['token']}">
					</div>
				</div>
			</form>
		</div>
	</div>
	{if empty($list)}
	<div class="alert alert-info">
		您当前没有兑换活动
	</div>
	{else}
	<div class="panel panel-default">
		<div class="table-responsive panel-body">
			<table class="table table-hover">
				<thead class="navbar-inner">
				<tr>
					<th style="width:150px;">卡券名称</th>
					<th style="width:200px;">兑换条件</th>
					<th style="width:200px;">兑换次数</th>
					<th style="width:200px;">每人限领</th>
					<th style="width:200px;">兑换时间</th>
					<th style="width:150px;">兑换状态</th>
					<th style="width:200px;">操作</th>
				</tr>
				</thead>
				<tbody>
				{loop $list $item}
				<tr>
					<td>{$item['coupon']['title']}</td>
					<td>
						{if $item['credittype'] == 'credit1'}
						积分兑换
						{elseif $item['credittype'] == 'credit2'}
						余额兑换
						{/if}
					</td>
					<td>{$item['num']}</td>
					<td>{$item['pretotal']}</td>
					<td>{$item['starttime']} - {$item['endtime']}</td>
					<td>
						<input class="js-flag" type="checkbox" data-id="{$item['id']}" {if $item['status']}checked{/if}/>
						<script>
							require(['bootstrap.switch'],function($){
								$('.js-flag:checkbox').bootstrapSwitch({onText: '启用', offText: '关闭'});
								$('.js-flag:checkbox').on('switchChange.bootstrapSwitch', function(event, state) {
									var id = $(this).data('id');
									var ban = state ? 1 : 0;
									$.getJSON("{php echo $this->createWeburl('couponexchange', array('op' => 'change_status'))}", {id:id, status:ban}, function(data) {
										var data = eval(data.message);
									});
								});
							});
						</script>
					</td>
					<td>
						<a href="{php echo $this->createWeburl('couponexchange', array('id' => $item['id'], 'op' => 'post'))}">查看详情</a>
						<a href="{php echo $this->createWeburl('couponexchange', array('id' => $item['id'], 'op' => 'delete'))}" onclick="return confirm('确定删除卡券兑换吗?');return false;">删除</a>
					</td>
				</tr>
				{/loop}
				</tbody>
			</table>
		</div>
	</div>
	{/if}
	{$pager}
</div>
{elseif $_GPC['op'] == 'post'}
<div class="page-header clearfix">
	<h4 class="pull-left">{if !empty($_GPC['id'])}查看{else}添加{/if}兑换</h4>
	<div class="pull-right">
		<a href="{php echo $this->createWeburl('couponexchange', array('op' => 'display'));}" class="btn btn-primary we7-padding-horizontal">返回列表</a>
	</div>
</div>
<form action="{php echo $this->createWeburl('couponexchange', array('op' => 'post'))}" method="post" class="form-horizontal">
	<div class="panel panel-default">
		<div class="panel-heading">{if !empty($_GPC['id'])}查看{else}添加{/if}</div>
		<div class="panel-body">
			<div class="clearfix">
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class="text-danger">* </span> 选择卡券</label>
					<div class="col-sm-8 col-xs-12">
						{if !$id}
						<button type="button" class="btn btn-default" data-toggle="modal" data-target="#myModal" id="add_coupon">添加卡券</button>
						{/if}
						<img src="{$data['coupon']['logo_url']}" id="coupon_image" style="height: 100px;width: 240px;{if !$id}display: none;{/if}" data-id="{$data['coupon']['id']}">
						<span class="help-block" id="coupon_title">{$data['coupon']['title']}</span>
						<input type="hidden" name="coupon">
					</div>
					<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
						<div class="modal-dialog" style="width: 450px;">
							<div class="modal-content">
								<div class="modal-header">
									<h4 class="modal-title">选择卡券</h4>
								</div>
								<div class="modal-body">
									{if empty($coupons)}
									您现在没有卡券,请先<a href="{php echo $this->createWeburl('couponmanage')}">添加卡券</a>。
									{else}
									<table class="table">
										<thead style="height: 20px;">
										<th style="width: 60px">缩略图</th>
										<th style="width: 120px">卡券名称</th>
										<th style="width: 100px">类型</th>
										<th style="width: 80px">选择</th>
										</thead>
										<tbody>
										{php $types = activity_get_coupon_label();}
										{loop $coupons $coupon}
										<tr style="height: 20px;">
											{if COUPON_TYPE == WECHAT_COUPON}
											<td><img src="{php echo $coupon['logo_url']}" style="height: 10px;"></td>
											<td>{$coupon['title']}</td>
											<td>
												{$types[$coupon['type']][0]}
											</td>
											{else}
											<td><img src="{php echo $coupon['logo_url']}" style="height: 30px;"></td>
											<td>{$coupon['title']}</td>
											<td>{if $coupon['type'] == 2}代金券{else}折扣券{/if}</td>
											{/if}
											<td>
												<button type="button" class="btn btn-default coupon_check" data-src="{$coupon['logo_url']}" data-cid="{$coupon['id']}" data-title="{$coupon['title']}" {if $coupon['date_info']['time_type'] == 1}data-start="{$coupon['date_info']['time_limit_start']}" data-end="{$coupon['date_info']['time_limit_end']}"{/if} data-limit="{$coupon['get_limit']}" data-type="{$coupon['date_info']['time_type']}" data-date_limit="{$coupon['date_info']['limit']}">选择</button>
											</td>
										</tr>
										{/loop}
										</tbody>
									</table>
									{/if}
								</div>
							</div>
						</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">兑换状态</label>
					<div class="col-sm-9 col-xs-12">
						{if !$id}
						<label class="radio-inline"><input id="a" type="radio" name="status" value="1" {if $data['status'] == 1 || $data['status'] == ''}checked{/if}/>开启</label>
						<label class="radio-inline"><input id="b" type="radio" name="status" value="0" {if $data['status'] == 0 && $data['status'] != ''}checked{/if}/>关闭</label>
						<span class="help-block">此设置项设置是否开启兑换</span>
						{else}
						<label class="radio-inline">{if $data['status'] == 1}开启{else}关闭{/if}</label>
						{/if}
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">积分类型</label>
					<div class="col-sm-9 col-xs-12">
						{if !$id}
						<select name="credittype" class="form-control">
							<option value="credit1">积分</option>
							<option value="credit2">余额</option>
						</select>
						<span class="help-block">此设置项设置当前卡券兑换需要消耗的积分类型,如:金币、积分、贡献等。</span>
						{else}
						<label class="radio-inline">{if $data['credittype'] == 'credit1'}积分{else}余额{/if}</label>
						{/if}
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">积分数量</label>
					<div class="col-sm-9 col-xs-12">
						{if !$id}
						<input type="text" name="credit" value="{$data['credit']}" class="form-control"/>
						<span class="help-block">此设置项设置当前卡券兑换需要消耗的积分数量。注:所需积分(余额)必须为正整数;</span>
						{else}
						<label class="radio-inline">{$data['credit']}</label>
						{/if}
					</div>
				</div>
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label">使用期限</label>
					<div class="col-sm-9 col-xs-12">
						{if !$id}
						{php echo tpl_form_field_daterange('date', array('start' => date('Y-m-d', $data['starttime']), 'end' => date('Y-m-d', $data['endtime'])))}
						{else}
						<label class="radio-inline">{php echo date('Y-m-d', $data['starttime']);} - {php echo date('Y-m-d', $data['endtime']);}</label>
						{/if}
						<span style="display: none;" class="help-block"><span class="text-danger">注</span>:卡券有效期为<span id="start"></span> - <span id="end"></span></span>
					</div>
				</div>
				<input type="hidden" name="coupon_limit">
				<input type="hidden" name="coupon_start">
				<input type="hidden" name="coupon_end">
				<div class="form-group">
					<label class="col-xs-12 col-sm-3 col-md-2 control-label"><span class="text-danger"> </span>每人可领限制</label>
					<div class="col-sm-9 col-xs-12">
						{if !$id}
						<input type="text" name="pretotal" value="{$data['pretotal']}" class="form-control"/>
						<span class="help-block" style="display: none;"><span class="text-danger">注</span>:卡券每人领券限制为<span id="limit"></span></span>
						<span class="help-block">此设置项设置每个用户可领取此折扣券数量, 默认为1。</span>
						{else}
						<label class="radio-inline">{$data['pretotal']}</label>
						{/if}
					</div>
				</div>
			</div>
		</div>
	</div>
	<div class="form-group">
		<div class="col-sm-1 col-xs-2 col-lg-10">
			<input type="hidden" name="token" value="{$_W['token']}"/>
			<input type="hidden" name="id" value="{$_GPC['id']}"/>
			{if !$id}
			<input type="submit" id="exchange" name="submit" value="提交" class="btn btn-primary"/>
			{else}
			<a href="{php echo $this->createWeburl('couponexchange')}" class="btn btn-primary">确定</a>
			{/if}
		</div>
	</div>
</form>
<script>
	require(['bootstrap'], function($) {
		$('#coupon_image').hover(function() {
			var coupon_info = $(this);
			$.post("{php echo $this->createWeburl('couponexchange', array('op' => 'coupon_info'))}", {'id' : $(this).data('id')}, function(data) {
				var data = $.parseJSON(data);
				if (data.message.errno != 0) {
					coupon_info.popover({
						'html' : true,
						'placement' : 'right',
						'trigger':'manual',
						'content':'卡券不存在'
					});
					coupon_info.popover('show');
				} else {
					var data = data.message.message;
					var types = new Array();
					types = ['','折扣券','代金券','团购券','礼品券','优惠券'];
					var display = data.is_display == 1 ? '上架' : '下架';
					var content = '标题:'+ data.title+'<br/>';
					content += '状态:'+display+'<br/>';
					content += '类型:'+types[data.type]+'<br/>';
					if (data.description != '') {
						content += '说明:'+data.description+'<br/>';
					}
					coupon_info.popover({
						'html' : true,
						'placement' : 'right',
						'trigger':'manual',
						'content':content
					});
					coupon_info.popover('show');
				}
			});
		}, function(){
			$(this).popover('hide');
		});
	});
	$('.coupon_check').click(function() {
		$('#coupon_image').attr('src', $(this).data('src'));
		$('#coupon_title').html($(this).data('title'));
		$('#add_coupon').hide();
		$('[name="coupon"]').val($(this).data('cid'));
		$('#coupon_image').data('id', $(this).data('cid'));
		var type = $(this).data('type');
		if (type  != 2) {
			$('[name="coupon_start"]').val($(this).data('start'));
			$('#start').html($(this).data('start'));
			$('[name="coupon_end"]').val($(this).data('end'));
			$('#end').html($(this).data('end'));
		} else {
			$('#end').html("领取后"+$(this).data('date_limit')+"天");
		}
		$('#start').parent().show();
		$('#end').parent().show();
		$('[name="coupon_limit"]').val($(this).data('limit'));
		$('#limit').html($(this).data('limit'));
		$('#limit').parent().show();
		$('#coupon_image').show();
		$('#myModal').modal('hide');
	});
	$('#exchange').click(function(){
		var coupon = $('[name="coupon"]').val();
		var pretotal = $('[name="pretotal"]').val();
		var total = $('[name="total"]').val();
		var limit = $('[name="coupon_limit"]').val();
		var credit = $('[name="credit"]').val();
		if (credit != parseInt(credit) && credit != '') {
			util.message('所需积分数量请填写正整数');
			return false;
		}
		limit = parseInt(limit);
		pretotal = parseInt(pretotal);
		if (pretotal > limit && limit != 0) {
			util.message('领取限制大于卡券领取限制,请重新填写');
			return false;
		}
		if (coupon == '') {
			util.message('请选择折扣券', '', 'info');
			return false;
		}
	});
</script>
{/if}
{template 'common/footer'}