游戏折扣
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="请输入首充折扣"> 折
|
||||
<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="请输入次充折扣"> 折
|
||||
<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,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…
Reference in New Issue