游戏折扣

master
ELF 3 years ago
parent 86a2b164f0
commit 10d3156c8e

@ -0,0 +1,159 @@
<?php
namespace Admin\Controller;
use Base\Service\DiscountService;
/**
* 游戏折扣
*/
class DiscountController extends ThinkController
{
public function records()
{
$page = I('p', 1);
$row = I('row', 10);
$baseGameId = I('base_game_id', 0);
$status = I('status', -1);
$where = [
'_string' => '1=1',
];
if ($baseGameId != 0) {
$where['base_game_id'] = $baseGameId;
}
if ($status != -1) {
$where['status'] = $status;
}
if (I('time_start', '') != '') {
$where['_string'] .= ' and end_time>=' . strtotime(I('time_start') . ' 00:00:00');
}
if (I('time_end', '') != '') {
$where['_string'] .= ' and start_time<=' . strtotime(I('time_end') . ' 23:59:59');
}
$query = M('game_discount', 'tab_')->where($where);
$records = [];
if (I('export', 0) == 1 || $row == 'all') {
$records = $query->order('create_time desc')->select();
} else {
$countQuery = clone $query;
$records = $query->order('create_time desc')->page($page, $row)->select();
$count = $countQuery->count();
}
$statusList = [
0 => '关闭',
1 => '开启',
];
$service = new DiscountService();
if (count($records) > 0) {
foreach ($records as $key => $record) {
$isActived = $service->isActived($record);
$records[$key]['status_text'] = $statusList[$record['status']];
$records[$key]['start_time'] = date('Y-m-d H:i:s', $record['start_time']);
$records[$key]['end_time'] = $record['end_time'] == DiscountService::FOREVER_TIME ? '永久' : date('Y-m-d H:i:s', $record['end_time']);
$records[$key]['create_time'] = date('Y-m-d H:i:s', $record['create_time']);
$records[$key]['update_time'] = date('Y-m-d H:i:s', $record['update_time']);
$records[$key]['is_actived'] = $isActived;
$records[$key]['is_actived_text'] = $isActived ? '生效中' : '未生效';
}
if (I('export', 0) == 1) {
$field = [
'base_game_name' => '游戏名称',
'start_time' => '生效时间',
'end_time' => '失效时间',
'status_text' => '状态',
'is_actived_text' => '生效状态',
'first_rate' => '首充折扣',
'second_rate' => '次充折扣',
'create_admin_username' => '添加人',
'create_time' => '添加时间',
'update_admin_username' => '修改人',
'update_time' => '修改时间',
];
addOperationLog(['op_type'=>3,'key'=>getNowDate(),'op_name'=>'导出游戏折扣记录','url'=>U('Discount/records'),'menu'=>'游戏-折扣代金券-游戏折扣-' . '导出游戏折扣记录']);
data2csv($records, '游戏折扣', $field);
exit;
}
}
$page = set_pagination($count, $row == 'all' ? 99999999 : $row);
if($page) {
$this->assign('_page', $page);
}
// $admins = M('ucenter_member', 'sys_')->field(['id', 'username'])->select();
$baseGames = M('base_game', 'tab_')->select();
// $this->assign('admins', $admins);
$this->assign('baseGames', $baseGames);
$this->assign('statusList', $statusList);
$this->assign('records', $records);
$this->display('records');
}
public function delOne()
{
$id = I('id', 0);
try {
$service = new DiscountService();
$service->delete($id);
$this->ajaxReturn([
'status' => 1,
'message' => '操作成功'
]);
} catch (\Exception $e) {
$this->ajaxReturn([
'status' => 0,
'message' => $e->getMessage()
]);
}
}
public function save()
{
$params = I('post.');
try {
$service = new DiscountService();
$service->check($params);
$service->save($params, session('user_auth'));
$this->ajaxReturn([
'status' => 1,
'message' => '操作成功'
]);
} catch (\Exception $e) {
$this->ajaxReturn([
'status' => 0,
'message' => $e->getMessage()
]);
}
}
public function addPage()
{
$this->meta_title = '新增游戏折扣';
$baseGames = M('base_game', 'tab_')->select();
$this->assign('baseGames', $baseGames);
$this->display('form');
}
public function updatePage()
{
$id = I('id', 0);
$gameDiscount = M('game_discount', 'tab_')->where(['id' => $id])->find();
if (is_null($gameDiscount)) {
return $this->error('记录不存在');
}
$this->meta_title = '修改游戏折扣';
$baseGames = M('base_game', 'tab_')->select();
$this->assign('baseGames', $baseGames);
$this->assign('record', $gameDiscount);
$this->display('form');
}
}

@ -0,0 +1,202 @@
<extend name="Public/base" />
<block name="body">
<link rel="stylesheet" href="__CSS__/select2.min.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="__CSS__/admin_table.css" media="all">
<link href="__STATIC__/icons_alibaba/iconfont.css" rel="stylesheet">
<script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
<script type="text/javascript" src="__STATIC__/provincecityarea/AreaData_min.js"></script>
<script src="__STATIC__/layer/layer.js"></script>
<script type="text/javascript" src="__JS__/select2.min.js"></script>
<style>
.tabcon1711 input.time {
width: 150px;
}
#form .txt_area {
width: 300px;
height: 150px;
}
.tabcon1711 .form_unit {
margin-left: 2px;
}
.tabcon1711 .mustmark {
margin-left:-7px;
}
.list-ratio {
display: table;
}
.list-ratio .li-ratio {
display: flex;
margin-bottom: 20px;
align-items: center;
}
.list-ratio .li-ratio .turnover, .list-ratio .li-ratio .turnover-ratio {
position: relative;
}
.list-ratio .li-ratio .turnover span, .list-ratio .li-ratio .turnover-ratio .error-message {
color: red;
position: absolute;
left: 0;
top: 30px;
white-space: nowrap;
display: none;
}
.iconfont-btn {
cursor: pointer;
}
.iconfont-style {
font-size: 18px;
color: #fff;
border-radius: 4px;
border: 0;
padding: 5px;
margin-left: 10px;
}
.iconfont-selected {
background-color: #0A9AF2;
}
.iconfont-selected:hover {
background-color: #03a9f4;
}
.iconfont-unselected {
background-color: #999;
}
.iconfont-unselected:hover {
background-color: #ababab;
}
</style>
<div class="cf main-place top_nav_list navtab_list">
<h3 class="page_title">{$meta_title}</h3>
<!-- <p class="description_text">说明:此功是创建推广员时所需填写信息</p>-->
</div>
<!-- 标签页导航 -->
<div class="tab-wrap">
<div class="tab-content tabcon1711">
<!-- 表单 -->
<form id="form" action="{:U('save')}" method="post" class="form-horizontal">
<!-- 基础文档模型 -->
<div id="tab1" class="tab-pane in tab1">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="l noticeinfo"><i class="mustmark">*</i>启用状态</td>
<td class="r table_radio">
<span class="form_radio">
<label><input type="radio" name="status" value="1" <?php if (empty($record) || $record['status'] == 1):?>checked<?php endif;?>> 开启</label>
<label><input type="radio" name="status" value="0" <?php if ($record && $record['status'] == 0):?>checked<?php endif;?>> 关闭</label>
</span>
<span class="notice-text">设置该游戏是否开启使用折扣券 公式:需支付金额 = (原价 - 平台币) * 折扣</span>
</td>
</tr>
<tr>
<td class="l"><i class="mustmark">*</i>折扣游戏:</td>
<td class="r">
<select name="base_game_id" id="base_game_id" class="select_gallery">
<option value="">请选择游戏</option>
<?php foreach($baseGames as $baseGame):?>
<option value="<?=$baseGame['id']?>" <?php if($record && $record['base_game_id'] == $baseGame['id']):?>selected<?php endif;?>><?=$baseGame['name']?></option>
<?php endforeach;?>
</select>
<span class="notice-text"></span>
</td>
</tr>
<tr>
<td class="l"><i class="mustmark">*</i>生效时间(开始):</td>
<td class="r">
<input type="text" id="start_time" name="start_time" class="time" value="<?=$record?date('Y-m-d', $record['start_time']):''?>" autocomplete="off" placeholder="请选择生效时间(开始)" style="width: 200px"/>
</td>
</tr>
<tr>
<td class="l">生效时间(结束):</td>
<td class="r">
<input type="text" id="end_time" name="end_time" class="time" value="<?=$record?date('Y-m-d', $record['end_time']):''?>" autocomplete="off" placeholder="请选择生效时间(开始)" style="width: 200px"/>
</td>
</tr>
<tr>
<td class="l">首充折扣:</td>
<td class="r table_radio">
<input type="text" class="txt ratio" style="float: none;" name="first_rate" id="first_rate" value="<?=$record?$record['first_rate']:''?>" placeholder="请输入首充折扣"> &nbsp;
<span class="notice-text" style="float: none;">首次充值使用该折扣,请输入数字,支持小数点后一位,例如: 7.8;默认为空,表示不打折</span>
</td>
</tr>
<tr>
<td class="l">次充折扣:</td>
<td class="r table_radio">
<input type="text" class="txt ratio" style="float: none;" name="second_rate" id="second_rate" value="<?=$record?$record['second_rate']:''?>" placeholder="请输入次充折扣"> &nbsp;
<span class="notice-text" style="float: none;">第二次(包含)充值以后使用该折扣,请输入数字,支持小数点后一位,例如: 7.8;默认为空,表示不打折</span>
</td>
</tr>
</tbody>
</table>
</div>
<input type="hidden" name="id" id="id" value="{$record.id}" />
<div class="form-item cf">
<button class="submit_btn mlspacing" id="submit" type="submit" target-form="form-horizontal">
确认
</button>
<a class="submit_btn " alt="返回上一页" title="返回上一页" href="javascript:window.history.back();" >
返回
</a>
</div>
</form>
</div>
</div>
<div class="common_settings">
<span class="plus_icon"><span><img src="__IMG__/zwmimages/icon_jia.png"></span></span>
<form class="addShortcutIcon">
<input type="hidden" name="title" value="{$m_title}">
<input type="hidden" name="url" value="Promote/lists/type/1">
</form>
<a class="ajax-post add-butn <notempty name='commonset'>addSIsetted</notempty>" href="javascript:;" target-form="addShortcutIcon" url="{:U('Think/addShortcutIcon')}"><img src="__IMG__/zwmimages/icon_jia.png"><span><notempty name='commonset'>已添加<else />添加至常用设置</notempty></span></a>
</div>
</block>
<block name="script">
<link href="__STATIC__/datetimepicker/css/datetimepicker.css" rel="stylesheet" type="text/css">
<php>if(C('COLOR_STYLE')=='blue_color') echo '<link href="__STATIC__/datetimepicker/css/datetimepicker_blue.css" rel="stylesheet" type="text/css">';</php>
<link href="__STATIC__/datetimepicker/css/dropdown.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="__STATIC__/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="__STATIC__/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
<script type="text/javascript">
//导航高亮
highlight_subnav("{:U('PaymentMerchant/list')}");
$(".select_gallery").select2();
$(function(){
$('.time').datetimepicker({
format: 'yyyy-mm-dd',
language: "zh-CN",
autoclose: true,
scrollMonth: false,
scrollTime: false,
scrollInput: false,
startView: 'month',
minView:'month',
maxView:'month',
});
showTab();
$('#submit').click(function (e) {
var target = $('form').get(0).action;
var query = $('form').serialize();
var that = this;
$(that).addClass('disabled').attr('autocomplete','off').prop('disabled',true);
$.post(target,query).success(function(result){
if(layer) { layer.closeAll('loading'); }
if (result.status == 1) {
layer.msg(result.message)
setTimeout(function() {
window.location.href = '{:U("records")}'
}, 200)
} else {
$(that).removeClass('disabled').attr('autocomplete','on').prop('disabled',false);
layer.msg(result.message)
}
});
});
});
</script>
</block>

@ -0,0 +1,261 @@
<extend name="Public/base"/>
<block name="css">
<link rel="stylesheet" href="__CSS__/select2.min.css" type="text/css" />
<link rel="stylesheet" href="__CSS__/promote.css" type="text/css"/>
<script src="__STATIC__/laydate/laydate.js"></script>
<link rel="stylesheet" type="text/css" href="__STATIC__/webuploader/webuploader.css" media="all">
<style>
.select2-container--default .select2-selection--single {
color: #000;
resize: none;
border-width: 1px;
border-style: solid;
border-color: #a7b5bc #ced9df #ced9df #a7b5bc;
box-shadow: 0px 3px 3px #F7F8F9 inset;height:35px;
height:28px;border-radius:3px;font-size:12px;
}
.select2-container--default .select2-selection--single .select2-selection__rendered {
line-height:35px;
line-height:28px;
}
.select2-container--default .select2-selection--single .select2-selection__arrow {
height:26px;
}
.select2-container--default .select2-search--dropdown .select2-search__field {
height:26px;line-height:26px;font-size:12px;
}
.select2-results__option[aria-selected] {font-size:12px;}
.textarea-style {
width: 200px;
height: 80px;
border-radius: 5px;
padding: 5px;
}
.mustmark {
color: #FF0000;
font-style: normal;
margin: 0 3px;
}
.butnbox {
padding: 10px 0 10px;
}
.butnbox .butnlist .butn {
display: inline-block;
width: 120px;
height: 28px;
line-height: 28px;
text-align: center;
color: #FFF;
background: #3C95C8;
border-radius: 3px;
cursor: pointer;
}
.data_list table td .status-0 {
color: #e6a23c;
}
.data_list table td .status-1 {
color: #67c23a;
}
.data_list table td .status-2 {
color: #f56c6c;
}
</style>
</block>
<block name="body">
<script type="text/javascript" src="__JS__/bootstrap.min.js"></script>
<script type="text/javascript" src="__JS__/select2.min.js"></script>
<script type="text/javascript" src="__JS__/jquery.form.js"></script>
<script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
<script src="__STATIC__/md5.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="__STATIC__/webuploader/webuploader.js"></script>
<script src="__STATIC__/layer/layer.js" type="text/javascript"></script>
<script type="text/javascript" src="__STATIC__/layer/extend/layer.ext.js"></script>
<div class="cf main-place top_nav_list navtab_list">
<h3 class="page_title">游戏折扣</h3>
</div>
<div class="cf top_nav_list" style="height: 38px;">
<!-- 高级搜索 -->
<div class="jssearch cf search_list">
<div class="input-list search-title-box">
<label>搜索:</label>
</div>
<div class="input-list input-list-promote search_label_rehab">
<select id="game_id" name="base_game_id" class="select_gallery" style="width:120px;">
<option value="0">请选择游戏</option>
<?php foreach($baseGames as $baseGame):?>
<option value="<?=$baseGame['id']?>"><?=$baseGame['name']?></option>
<?php endforeach;?>
</select>
</div>
<div class="input-list input-list-promote search_label_rehab">
<input type="text" readonly name="time_start" class="time-select" value="{:I('time_start')}"
placeholder="生效开始时间"/>
-
<div class="input-append date" id="datetimepicker" style="display:inline-block">
<input type="text" readonly name="time_end" class="time-select" value="{:I('time_end')}"
placeholder="生效结束时间"/>
<span class="add-on"><i class="icon-th"></i></span>
</div>
</div>
<div class="input-list input-list-promote search_label_rehab">
<select name="status" class="select_gallery" style="width:120px;">
<option value="-1">请选择开启状态</option>
<?php foreach($statusList as $key => $name):?>
<option value="<?=$key?>">
<?=$name?>
</option>
<?php endforeach;?>
</select>
</div>
<div class="input-list">
<a class="sch-btn" href="javascript:;" id="search" url="{:U('Discount/records')}">搜索</a>
</div>
<!-- <div class="input-list">
<a class="sch-btn" href="{:U('Export/expUser',array_merge(array('id'=>12,),I('get.')))}">导出</a>
</div> -->
</div>
</div>
<div class="butnbox">
<div class="butnlist jscheckbutn" style="margin-left: 2px">
<a class="butn" href="{:U('Discount/addPage')}">新增</a>
</div>
</div>
<!-- 数据列表 -->
<div class="data_list">
<div class="">
<table>
<!-- 表头 -->
<thead>
<tr>
<th>游戏名称</th>
<th>生效时间</th>
<th>失效时间</th>
<th>状态</th>
<th>首充折扣</th>
<th>次充折扣</th>
<th>添加人</th>
<th>添加时间</th>
<th>修改人</th>
<th>修改时间</th>
<th>操作</th>
</tr>
</thead>
<!-- 列表 -->
<tbody>
<empty name ="records">
<td colspan="99" class="text-center">aOh! 暂时还没有内容!</td>
<else />
<volist name="records" id="data">
<tr data-id="<?=$data['id']?>">
<td>{$data.base_game_name}</td>
<td>{$data.start_time}</td>
<td>{$data.end_time}</td>
<td>{$data.status_text} <?php if($data['is_actived']):?>(<span style="color: #67C23A;">生效中</span>)<?php endif;?></td>
<td>{$data.first_rate}</td>
<td>{$data.second_rate}</td>
<td>{$data.create_admin_username}</td>
<td>{$data.create_time}</td>
<td>{$data.update_admin_username}</td>
<td>{$data.update_time}</td>
<td><a href="<?=U('updatePage', ['id' => $data['id']])?>">编辑</a></td>
</tr>
</volist>
</empty>
</tbody>
</table>
</div>
</div>
<div class="page">
<a class="sch-btn export-btn"
href="{:U(CONTROLLER_NAME.'/'.ACTION_NAME,array_merge(['export'=>1],I('get.')))}" target="_blank">导出</a>
{$_page|default=''}
</div>
<div class="common_settings">
<span class="plus_icon"><span><img src="__IMG__/zwmimages/icon_jia.png"></span></span>
<form class="addShortcutIcon">
<input type="hidden" name="title" value="{$m_title}">
<input type="hidden" name="url" value="Query/withdraw">
</form>
<a class="ajax-post add-butn <notempty name='commonset'>addSIsetted</notempty>" href="javascript:;" target-form="addShortcutIcon" url="{:U('Think/addShortcutIcon')}"><img src="__IMG__/zwmimages/icon_jia.png"><span><notempty name='commonset'>已添加<else />添加至常用设置</notempty></span></a>
</div>
</block>
<block name="script">
<script src="__STATIC__/layer/layer.js" type="text/javascript"></script>
<script type="text/javascript" src="__STATIC__/layer/extend/layer.ext.js" ></script>
<script src="__STATIC__/jquery.cookie.js" charset="utf-8"></script>
<script>
<volist name=":I('get.')" id="vo">
Think.setValue('{$key}',"{$vo}");
</volist>
$(".select_gallery").select2();
</script>
<script type="text/javascript">
//导航高亮
highlight_subnav("{:U('Discount/records')}");
$(function(){
// 添加全部选项
if ('all' == "{:I('row', 0)}") {
$("#pagechange").prepend("<option value='all' selected>全部</option>");
} else {
$("#pagechange").prepend("<option value='all'>全部</option>");
}
$('.time-select').each(function(){
laydate.render({
elem: this,
type: 'date'
});
});
//搜索功能
$("#search").click(function(){
var sdate = Date.parse($("input[name='send_time_start']").val()) / 1000;
var edate = Date.parse($("input[name='send_time_end']").val()) / 1000;
if (sdate > edate) {
layer.msg('开始时间必须小于等于结束时间');
return false;
}
if ((edate - sdate) > 2592000) {
layer.msg('时间间隔不能超过31天请重新选择日期');
return false;
}
var url = $(this).attr('url');
var query = $('.jssearch').find('input').serialize();
query += "&"+$('.jssearch').find('select').serialize();
//query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
query = query.replace(/^&/g,'');
if( url.indexOf('?')>0 ){
url += '&' + query;
}else{
url += '?' + query;
}
window.location.href = url;
});
//回车自动提交
$('.jssearch').find('input').keyup(function(event){
if(event.keyCode===13){
$("#search").click();
}
});
function getIds() {
var ids = [];
$('.ids:checked').each(function() {
ids.push($(this).val());
})
return ids;
}
});
$(".export-btn").on("click",function(e){
e.preventDefault();
window.location.href=$(this).attr("href")
})
</script>
</block>

@ -0,0 +1,101 @@
<?php
namespace Base\Service;
class DiscountService
{
const FOREVER_TIME = 4102444800;
public function save($params, $admin = null)
{
$id = $params['id'] ?? 0;
$baseGame = M('base_game', 'tab_')->where(['id' => $params['base_game_id']])->find();
$data = [
'base_game_id' => $params['base_game_id'],
'base_game_name' => $baseGame['name'],
'start_time' => strtotime($params['start_time']),
'end_time' => empty($params['end_time']) ? self::FOREVER_TIME : strtotime($params['end_time']),
'first_rate' => $params['first_rate'],
'second_rate' => $params['second_rate'],
'status' => $params['status'],
];
$data['update_time'] = time();
$data['update_admin_id'] = $admin ? $admin['uid'] : 0;
$data['update_admin_username'] = $admin ? $admin['username'] : '';
if ($id > 0) {
M('game_discount', 'tab_')->where(['id' => $id])->save($data);
} else {
$data['create_time'] = time();
$data['create_admin_id'] = $admin ? $admin['uid'] : 0;
$data['create_admin_username'] = $admin ? $admin['username'] : '';
M('game_discount', 'tab_')->add($data);
}
}
public function check($params)
{
$id = $params['id'] ?? 0;
if (empty($params['base_game_id'])) {
throw new \Exception('请选择游戏');
}
if (empty($params['start_time'])) {
throw new \Exception('请选择生效时间');
}
if (empty($params['base_game_id'])) {
throw new \Exception('请选择游戏');
}
$startTime = strtotime($params['start_time'] . ' 00:00:00');
$endTime = empty($params['end_time']) ? self::FOREVER_TIME : strtotime($params['end_time'] . ' 23:59:59');
if ($endTime < $startTime) {
throw new \Exception('生效开始时间不能大于结束时间');
}
$firstRate = $params['first_rate'] ?? 0;
$secondRate = $params['second_rate'] ?? 0;
// /^[0-9]+(.[0-9]{1,2})?$/
if (!preg_match('/^[0-9]+(.[0-9]{1})?$/', $firstRate)) {
throw new \Exception('首充折扣为大于等于0的整数或者一位小数');
}
if (!preg_match('/^[0-9]+(.[0-9]{1})?$/', $secondRate)) {
throw new \Exception('次充折扣为大于等于0的整数或者一位小数');
}
if ($id > 0) {
$record = M('game_discount', 'tab_')->where(['id' => $id])->find();
if ($record['end_time'] < time()) {
throw new \Exception('生效时间已过,不可修改');
}
}
$map = [];
$map['base_game_id'] = $params['base_game_id'];
$map['_string'] = 'NOT (end_time < ' . $startTime . ' OR start_time > ' . $endTime . ')';
if ($id > 0) {
$map['_string'] .= ' and id<>' . $id;
}
$item = M('game_discount', 'tab_')->where($map)->limit(1)->find();
if ($item) {
throw new \Exception('该游戏在相同时间区间已存在打折规则');
}
}
public function delete($id)
{
M('game_discount', 'tab_')->where(['id' => $id])->delete();
}
public function isActived($record)
{
if ($record['status'] == 0) {
return false;
}
if ($record['start_time'] <= time() && $record['end_time'] >= time()) {
return true;
}
return false;
}
}

@ -0,0 +1,7 @@
<?php
namespace Base\Service;
class VoucherService
{
}
Loading…
Cancel
Save