master
ELF 4 years ago
parent 096e32d581
commit f3b323bda8

@ -196,7 +196,6 @@ class PaymentMerchantController extends ThinkController
$data = [];
$data['name'] = $name;
$data['account'] = $account;
$data['identifier'] = $identifier;
$data['type'] = 1;
$data['status'] = $status;
$data['ways'] = $waysValue;
@ -207,8 +206,10 @@ class PaymentMerchantController extends ThinkController
if ($id == 0) {
$data['create_time'] = time();
$data['channel'] = $channel;
$data['identifier'] = $paymentMerchantService->getIdentifierByConfig($config, $channel);
M('payment_merchant', 'tab_')->add($data);
} else {
$data['identifier'] = $paymentMerchantService->getIdentifierByConfig($config, $merchant['channel']);
M('payment_merchant', 'tab_')->where(['id' => $id])->save($data);
}
@ -293,11 +294,24 @@ class PaymentMerchantController extends ThinkController
}
}
private function getEffectiveTimeRange($startedAt, $endedAt)
{
$start = 0;
$end = PaymentRuleService::FOREVER_TIME;
if ($startedAt != '') {
$start = strtotime($startedAt . ' 00:00:00');
}
if ($endedAt != '') {
$end = strtotime($startedAt . ' 23:59:59');
}
return [$start, $end];
}
public function rules()
{
$page = I('p', 1);
$row = I('row', 10);
$companyBelong = I('compnay_belong', -1);
$companyBelong = I('company_belong', -1);
$companyId = I('company_id', 0);
$gameTypeId = I('game_type_id', 0);
$gameId = I('game_id', 0);
@ -329,12 +343,17 @@ class PaymentMerchantController extends ThinkController
if ($expressId != 0) {
$conditions['express_merchant_id'] = $expressId;
}
if ($startedAt != '') {
$conditions['update_time'] = ['egt', strtotime($startedAt . ' 00:00:00')];
}
if ($endedAt != '') {
$conditions['update_time'] = ['elt', strtotime($endedAt . ' 23:59:59')];
[$start, $end] = $this->getEffectiveTimeRange($startedAt, $endedAt);
// var_dump($start, $end);die();
$timeCondition = ' ((start_time >= ' . $start . ' AND start_time <= ' . $end . ') OR (start_time <= ' . $start . ' AND end_time >= ' . $end
. ') OR (end_time >= ' . $start . ' AND end_time <= ' . $end . '))';
if (isset($conditions['_string'])) {
$conditions['_string'] .= $timeCondition;
} else {
$conditions['_string'] = $timeCondition;
}
$paymentRuleService = new PaymentRuleService();
$gameService = new GameService();
@ -362,7 +381,7 @@ class PaymentMerchantController extends ThinkController
foreach ($items as $item) {
$records[] = [
'id' => $item['id'],
'company_type_name' => $companyTypes[$item['company_belong']] ?? '',
'company_type_name' => $companyTypes[$item['company_belong']] ?? '--',
'company_name' => isset($companies[$item['company_id']]) ? $companies[$item['company_id']]['company_name'] : '--',
'game_name' => isset($games[$item['game_id']]) ? $games[$item['game_id']]['name'] : '--',
'game_type_name' => isset($gameTypes[$item['game_type_id']]) ? $gameTypes[$item['game_type_id']]['type_name'] : '--',
@ -375,7 +394,6 @@ class PaymentMerchantController extends ThinkController
'effective_time_display' => $paymentRuleService->getEffectiveTimeDisplay($item)
];
}
// var_dump($records);die();
$page = set_pagination($count, $row);
if($page) {
@ -440,9 +458,16 @@ class PaymentMerchantController extends ThinkController
]);
}
$paymentRuleService = new PaymentRuleService();
foreach ($records as $record) {
$startTime = $record['start_time'] == '' ? 0 : strtotime($record['start_time'] . ' 00:00:00');
$endTime = $record['end_time'] == '' ? 0 : strtotime($record['end_time'] . ' 23:59:59');
$endTime = $record['end_time'] == '' ? PaymentRuleService::FOREVER_TIME : strtotime($record['end_time'] . ' 23:59:59');
$repeatRules = $paymentRuleService->getTimeRepeatRules($record);
if (count($repeatRules)) {
$paymentRuleService->resetTimeRules($repeatRules, $startTime, $endTime);
}
$item = [
'company_belong' => $record['company_id'] > 0 ? -1 : $record['company_belong'],
'company_id' => $record['company_id'],
@ -465,6 +490,105 @@ class PaymentMerchantController extends ThinkController
]);
}
public function editRule()
{
$id = I('id', 0);
$rule = M('payment_rule', 'tab_')->where(['id' => $id])->find();
if ($rule === null) {
$this->error('记录不存在');
}
$gameService = new GameService();
$gameTypes = $gameService->getGameTypes(null, 'id,type_name');
$games = $gameService->getBaseGames(null, 'id,name');
$companyBelongs = PromoteCompanyService::$belongs;
$companyService = new PromoteCompanyService();
$paymentMerchantService = new PaymentMerchantService();
$aliMerchants = $paymentMerchantService->getMerchantsByWay(PaymentMerchantService::WAY_ALIPAY);
$weixinMerchants = $paymentMerchantService->getMerchantsByWay(PaymentMerchantService::WAY_WEIXIN);
$expressMerchants = $paymentMerchantService->getMerchantsByWay(PaymentMerchantService::WAY_EXPRESS);
$companies = $companyService->getCompanies(null, 'id,company_name');
$rule ['start_time'] = $rule ['start_time'] == 0 ? '' : date('Y-m-d', $rule ['start_time']);
$rule ['end_time'] = $rule ['end_time'] == PaymentRuleService::FOREVER_TIME ? '' : date('Y-m-d', $rule ['end_time']);
$this->assign('aliMerchants', $aliMerchants);
$this->assign('weixinMerchants', $weixinMerchants);
$this->assign('expressMerchants', $expressMerchants);
$this->assign('record', $rule);
$this->assign('games', $games);
$this->assign('gameTypes', $gameTypes);
$this->assign('companyBelongs', $companyBelongs);
$this->assign('companies', $companies);
$this->display('ruleEditForm');
}
public function modifyRule()
{
$params = I('post.');
$id = $params['id'] ?? 0;
if ($id == 0) {
$this->ajaxReturn([
'status' => 0,
'message' => '提交数据异常'
]);
}
$rule = M('payment_rule', 'tab_')->where(['id' => $id])->find();
if ($rule === null) {
$this->ajaxReturn([
'status' => 0,
'message' => '记录不存在'
]);
}
$startTime = $params['start_time'] == '' ? 0 : strtotime($params['start_time'] . ' 00:00:00');
$endTime = $params['end_time'] == '' ? PaymentRuleService::FOREVER_TIME : strtotime($params['end_time'] . ' 23:59:59');
if (date('Ymd', $rule['start_time']) <= date('Ymd') && $startTime != $rule['start_time']) {
$this->ajaxReturn([
'status' => 0,
'message' => '原开始生效时间在今日之前,不可修改'
]);
}
if (date('Ymd', $startTime) <= date('Ymd') && $startTime != $rule['start_time']) {
$this->ajaxReturn([
'status' => 0,
'message' => '开始生效时间在今日之前,不可修改'
]);
}
if (date('Ymd', $rule['end_time']) <= date('Ymd') && $endTime != $rule['end_time']) {
$this->ajaxReturn([
'status' => 0,
'message' => '原最后生效时间在今日之前,不可修改'
]);
}
if (date('Ymd', $endTime) <= date('Ymd') && $endTime != $rule['end_time']) {
$this->ajaxReturn([
'status' => 0,
'message' => '最后生效时间在今日之前,不可修改'
]);
}
$item = [
'alipay_merchant_id' => $params['alipay_merchant_id'],
'weixin_merchant_id' => $params['weixin_merchant_id'],
'express_merchant_id' => $params['express_merchant_id'],
'start_time' => $startTime,
'end_time' => $endTime,
'update_time' => time()
];
M('payment_rule', 'tab_')->where(['id' => $id])->save($item);
$this->ajaxReturn([
'status' => 1,
'message' => '修改成功'
]);
}
public function deleteRule()
{
$id = I('id', 0);
@ -519,6 +643,29 @@ class PaymentMerchantController extends ThinkController
public function checkRules()
{
$records = I('records', []);
if (count($records) == 0) {
$this->ajaxReturn([
'status' => 0,
'message' => '未提交换绑数据'
]);
}
$isRepat = false;
$paymentRuleService = new PaymentRuleService();
foreach ($records as $record) {
$rules = $paymentRuleService->getTimeRepeatRules($record);
if (count($rules)) {
$isRepat = true;
break;
}
}
$this->ajaxReturn([
'status' => 1,
'message' => '成功',
'data' => [
'is_repeat' => $isRepat
]
]);
}
}

@ -88,12 +88,12 @@
</td>
</tr>
<tr>
<td class="l"><i class="mustmark">*</i>商户主体:</td>
<td class="r table_radio">
<input type="text" class="txt ratio" name="main_name" id="main_name" value="<?=$record?$record['main_name']:''?>" placeholder="请输入商户主体">
<span class="notice-text"></span>
</td>
</tr>
<td class="l"><i class="mustmark">*</i>商户主体:</td>
<td class="r table_radio">
<input type="text" class="txt ratio" name="main_name" id="main_name" value="<?=$record?$record['main_name']:''?>" placeholder="请输入商户主体">
<span class="notice-text"></span>
</td>
</tr>
<tr>
<td class="l"><i class="mustmark">*</i>商户账号:</td>
<td class="r table_radio">
@ -101,13 +101,6 @@
<span class="notice-text"></span>
</td>
</tr>
<tr>
<td class="l"><i class="mustmark">*</i>商户号:</td>
<td class="r table_radio">
<input type="text" class="txt ratio" name="identifier" id="identifier" value="<?=$record?$record['identifier']:''?>" placeholder="请输入商户号">
<span class="notice-text"></span>
</td>
</tr>
<tr>
<td class="l noticeinfo"><i class="mustmark">*</i>启用状态</td>
<td class="r table_radio">
@ -237,6 +230,13 @@
<input type="hidden" name="ways[]" value="2" >
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="l noticeinfo">商户号</td>
<td class="r table_radio">
<input name="config[partner]" type="text" value="<?=$config['partner'] ?? ''?>" class="">
<span class="notice-text"></span>
</td>
</tr>
<tr>
<td class="l noticeinfo">APPID</td>
<td class="r table_radio">
@ -282,6 +282,13 @@
<?php $config3 = $channelConfig[3] ?? null; ?>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="l noticeinfo">商户号</td>
<td class="r table_radio">
<input name="config[partner]" type="text" value="<?=$config['partner'] ?? ''?>" class="">
<span class="notice-text"></span>
</td>
</tr>
<tr>
<td class="l noticeinfo">上级商户号</td>
<td class="r table_radio">
@ -354,10 +361,17 @@
<div id="merchant-4">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="l noticeinfo">商户号</td>
<td class="r table_radio">
<input name="config[merno]" type="text" value="<?=$config['merno'] ?? ''?>" class="">
<span class="notice-text"></span>
</td>
</tr>
<tr>
<td class="l noticeinfo">双乾密钥key</td>
<td class="r table_radio">
<input name="config[key]" type="text" value="<?=$config['key'] ?? ''?>" class="">
<input name="config[secret]" type="text" value="<?=$config['secret'] ?? ''?>" class="">
<span class="notice-text">双乾秘钥</span>
</td>
</tr>
@ -406,10 +420,17 @@
<div id="merchant-5">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="l noticeinfo">商户号</td>
<td class="r table_radio">
<input name="config[merno]" type="text" value="<?=$config['merno'] ?? ''?>" class="">
<span class="notice-text"></span>
</td>
</tr>
<tr>
<td class="l noticeinfo">汇付宝密钥key</td>
<td class="r table_radio">
<input name="config[key]" type="text" value="<?=$config['key'] ?? ''?>" class="">
<input name="config[secret]" type="text" value="<?=$config['secret'] ?? ''?>" class="">
<span class="notice-text">汇付宝秘钥</span>
</td>
</tr>
@ -507,6 +528,7 @@ $(function(){
window.location.href = '{:U("list")}'
}, 200)
} else {
$(that).removeClass('disabled').attr('autocomplete','on').prop('disabled',false);
layer.msg(result.message)
}
});

@ -181,7 +181,7 @@
</td>
</tr>
<tr>
<td class="l">生效时间(开始):</td>
<td class="l"><i class="mustmark">*</i>生效时间(开始):</td>
<td class="r">
<input type="text" id="start_time" name="start_time" class="time" value="" autocomplete="off" placeholder="请选择生效时间(开始)" style="width: 200px"/>
</td>
@ -270,7 +270,7 @@ $(function(){
change: function() {
var companyBelong = $(this).val()
getCompaniesByBelong(companyBelong, function(companies) {
var html = '<option value="">所有推广公司</option>'
var html = '<option value="0">所有推广公司</option>'
for (var key in companies) {
html += '<option value="' +
companies[key].id +
@ -285,7 +285,7 @@ $(function(){
change: function() {
var gameTypeId = $(this).val()
getGamesByType(gameTypeId, function(games) {
var html = '<option value="">所有游戏</option>'
var html = '<option value="0">所有游戏</option>'
for (var key in games) {
html += '<option value="' +
games[key].id +
@ -402,6 +402,30 @@ $(function(){
return $("#game-select option[value=" + id + "]").html();
}
function isUniqueKeyExists(uniqueKey) {
return ($("#record-table tr[data-key=" + uniqueKey + "]").length == 0 ? false : true);
}
function getUniqueKey(data) {
var startTime = data.start_time == '' ? '0' : data.start_time.replace(/-/g, "")
var endTime = data.end_time == '' ? '0' : data.end_time.replace(/-/g, "")
return data.company_belong + '_' + data.company_id + '_' + data.game_id + '_' + data.game_type_id + '_' + startTime + '_' + endTime
}
function getTodayValue() {
var now = new Date()
var year = now.getFullYear().toString()
var month = now.getMonth() + 1
var date = now.getDate()
if (month < 10) {
month = "0" + month;
}
if (date < 10) {
date = "0" + date;
}
return parseInt(year + month + date);
}
$('#add-item').on({
click: function () {
var companySelect = $("#company-select");
@ -432,24 +456,39 @@ $(function(){
var startTime = $("#start_time").val();
var endTime = $("#end_time").val();
var items = descartes([
[companyBelongId], companyIds, [gameTypeId], gameIds
])
/* if (companyId == '') {
if (companyIds == null || companyIds.length == 0) {
return layer.msg('请选择推广公司')
}
if (promoteId == '') {
return layer.msg('请选择会长')
if (gameIds == null || gameIds.length == 0) {
return layer.msg('请选择游戏')
}
if (startTime == '') {
return layer.msg('开始生效时间必填')
}
var notValue = getTodayValue()
var startValue = parseInt(startTime.replace(/-/g, ""))
var endValue = parseInt(endTime.replace(/-/g, ""))
if (notValue >= startValue) {
return layer.msg('开始生效时间必须在今天之后')
}
if (marketId == '') {
return layer.msg('请新市场专员')
if (endTime != '') {
var endValue = parseInt(endTime.replace(/-/g, ""))
if (notValue >= endValue) {
return layer.msg('最终生效时间必须在今天之后')
}
if (startValue > endValue) {
return layer.msg('开始生效时间不能大于最终生效时间')
}
}
if (promoteIds.includes(promoteId)) {
return layer.msg('该会长已添加')
} */
var items = descartes([
[companyBelongId], companyIds, [gameTypeId], gameIds
])
var uniqueKeys = []
var records = []
for (var i in items) {
var data = {
company_belong: items[i][0],
@ -462,10 +501,21 @@ $(function(){
start_time: startTime,
end_time: endTime,
}
var html = '<tr data-post=' + JSON.stringify(data) + '><td>' + companyBelongName + '</td>' +
'<td>' + getCompanyName(items[i][1]) + '</td>' +
console.log(data)
var uniqueKey = getUniqueKey(data)
if (isUniqueKeyExists(uniqueKey)) {
return layer.msg('已经添加相同配置,请检查')
}
data.unique_key = uniqueKey
records.push(data)
}
for (var i in records) {
var data = records[i]
var html = '<tr data-post=' + JSON.stringify(data) + ' data-key="' + data.unique_key + '"><td>' + companyBelongName + '</td>' +
'<td>' + getCompanyName(data.company_id) + '</td>' +
'<td>' + gameTypeName + '</td>' +
'<td>' + getGameName(items[i][3]) + '</td>' +
'<td>' + getGameName(data.game_id) + '</td>' +
'<td>' + alipayName + '</td>' +
'<td>' + weixinName + '</td>' +
'<td>' + expressName + '</td>' +
@ -486,6 +536,45 @@ $(function(){
$('#record-table').find('tbody').children('tr').each(function() {
records.push(JSON.parse($(this).attr('data-post')))
})
if (records.length == 0) {
return layer.msg('请添加配置数据')
}
var accessStatus = true
var checkStatus = true
$.ajax({
url: '{:U("checkRules")}',
type: 'post',
dataType: 'json',
async: false,
data: {records: records},
success: function(result) {
if (result.status == 1) {
if (result.data.is_repeat) {
checkStatus = false
}
} else {
accessStatus = false
layer.msg(result.message)
}
}
})
if (!accessStatus) {
return layer.msg('验证异常')
}
if (!checkStatus) {
layer.confirm('该时间段已有相同条件设置,是否设置?', {
title: "是否设置",
btn: ['确定', '取消']
}, function () {
saveRules(records)
});
} else {
saveRules(records)
}
});
function saveRules(records) {
$.ajax({
url: '{:U("saveRule")}',
type: 'post',
@ -502,7 +591,7 @@ $(function(){
}
}
})
});
}
});
</script>
</block>

@ -109,7 +109,7 @@
<select name="company_belong" id="company-belong-select" class="select_gallery" disabled>
<option value="-1">所有公司类型</option>
<?php foreach($companyBelongs as $key => $name):?>
<option value="<?=$key?>" <?php if($record['company_belong']==$key):?>select<?php endif;?>><?=$name?></option>
<option value="<?=$key?>" <?php if($record['company_belong']==$key):?>selected<?php endif;?>><?=$name?></option>
<?php endforeach;?>
</select>
</td>
@ -120,7 +120,7 @@
<select name="company_id[]" id="company-select" class="select_gallery" style="width: 500px;" disabled>
<option value="0">所有公司</option>
<?php foreach($companies as $company):?>
<option value="<?=$company['id']?>" <?php if($record['company_id']==$company['id']):?>select<?php endif;?>><?=$company['company_name']?></option>
<option value="<?=$company['id']?>" <?php if($record['company_id']==$company['id']):?>selected<?php endif;?>><?=$company['company_name']?></option>
<?php endforeach;?>
</select>
</td>
@ -131,7 +131,7 @@
<select name="game_type_id" id="game-type-select" class="select_gallery" disabled>
<option value="0">所有游戏类型</option>
<?php foreach($gameTypes as $gameType):?>
<option value="<?=$gameType['id']?>" <?php if($record['game_type_id']==$gameType['id']):?>select<?php endif;?>><?=$gameType['type_name']?></option>
<option value="<?=$gameType['id']?>" <?php if($record['game_type_id']==$gameType['id']):?>selected<?php endif;?>><?=$gameType['type_name']?></option>
<?php endforeach;?>
</select>
</td>
@ -142,7 +142,7 @@
<select name="game_id" id="game-select" class="select_gallery" style="width: 500px;" disabled>
<option value="0">所有择游戏</option>
<?php foreach($games as $game):?>
<option value="<?=$game['id']?>" <?php if($record['game_id']==$game['id']):?>select<?php endif;?>><?=$game['name']?></option>
<option value="<?=$game['id']?>" <?php if($record['game_id']==$game['id']):?>selected<?php endif;?>><?=$game['name']?></option>
<?php endforeach;?>
</select>
</td>
@ -153,7 +153,7 @@
<select name="alipay_merchant_id" id="alipay-merchant-select" class="select_gallery">
<option value="0">跟随系统默认商户</option>
<?php foreach($aliMerchants as $merchant):?>
<option value="<?=$merchant['id']?>"><?=$merchant['name']?></option>
<option value="<?=$merchant['id']?>" <?php if($record['alipay_merchant_id']==$merchant['id']):?>selected<?php endif;?>><?=$merchant['name']?></option>
<?php endforeach;?>
</select>
</td>
@ -164,7 +164,7 @@
<select name="weixin_merchant_id" id="weixin-merchant-select" class="select_gallery">
<option value="0">跟随系统默认商户</option>
<?php foreach($weixinMerchants as $merchant):?>
<option value="<?=$merchant['id']?>"><?=$merchant['name']?></option>
<option value="<?=$merchant['id']?>" <?php if($record['weixin_merchant_id']==$merchant['id']):?>selected<?php endif;?>><?=$merchant['name']?></option>
<?php endforeach;?>
</select>
</td>
@ -175,7 +175,7 @@
<select name="express_merchant_id" id="express-merchant-select" class="select_gallery">
<option value="0">跟随系统默认商户</option>
<?php foreach($expressMerchants as $merchant):?>
<option value="<?=$merchant['id']?>"><?=$merchant['name']?></option>
<option value="<?=$merchant['id']?>" <?php if($record['express_merchant_id']==$merchant['id']):?>selected<?php endif;?>><?=$merchant['name']?></option>
<?php endforeach;?>
</select>
</td>
@ -183,18 +183,19 @@
<tr>
<td class="l">生效时间(开始):</td>
<td class="r">
<input type="text" id="start_time" name="start_time" class="time" value="" autocomplete="off" placeholder="请选择生效时间(开始)" style="width: 200px"/>
<input type="text" id="start_time" name="start_time" class="time" value="<?=$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="" autocomplete="off" placeholder="请选择生效时间(开始)" style="width: 200px"/>
<input type="text" id="end_time" name="end_time" class="time" value="<?=$record['end_time']?>" autocomplete="off" placeholder="请选择生效时间(开始)" style="width: 200px"/>
</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">
确认
@ -204,9 +205,6 @@
</a>
</div>
</form>
<div style="margin-top: 30px; height: 35px; width: 100%;">
<a class="submit_btn" href="javascript:;" id="submit" style="margin: 0px auto; margin-left: 208px; ">全部提交</a>
</div>
</div>
</div>
@ -249,7 +247,7 @@ $(function(){
change: function() {
var companyBelong = $(this).val()
getCompaniesByBelong(companyBelong, function(companies) {
var html = '<option value="">所有推广公司</option>'
var html = '<option value="0">所有推广公司</option>'
for (var key in companies) {
html += '<option value="' +
companies[key].id +
@ -264,7 +262,7 @@ $(function(){
change: function() {
var gameTypeId = $(this).val()
getGamesByType(gameTypeId, function(games) {
var html = '<option value="">所有游戏</option>'
var html = '<option value="0">所有游戏</option>'
for (var key in games) {
html += '<option value="' +
games[key].id +
@ -319,6 +317,7 @@ $(function(){
window.location.href = '{:U("rules")}'
}, 200)
} else {
$(that).removeClass('disabled').attr('autocomplete','on').prop('disabled',false);
layer.msg(result.message)
}
});

@ -65,7 +65,7 @@
</select>
</div>
<div class="input-list input-list-promote search_label_rehab">
<select id="status_select" name="status" class="select_gallery" style="width:200px;">
<select id="company_select" name="company_id" class="select_gallery" style="width:200px;">
<option value="">请选择公司</option>
<?php foreach($companies as $company):?>
<option value="<?=$company['id']?>"><?=$company['company_name']?></option>
@ -73,7 +73,7 @@
</select>
</div>
<div class="input-list input-list-promote search_label_rehab">
<select id="status_select" name="status" class="select_gallery" style="width:200px;">
<select id="game_type_select" name="game_type_id" class="select_gallery" style="width:200px;">
<option value="">请选择游戏类型</option>
<?php foreach($gameTypes as $gameType):?>
<option value="<?=$gameType['id']?>"><?=$gameType['type_name']?></option>
@ -81,7 +81,7 @@
</select>
</div>
<div class="input-list input-list-promote search_label_rehab">
<select id="status_select" name="status" class="select_gallery" style="width:200px;">
<select id="game_select" name="game_id" class="select_gallery" style="width:200px;">
<option value="">请选择游戏</option>
<?php foreach($games as $game):?>
<option value="<?=$game['id']?>"><?=$game['name']?></option>
@ -122,7 +122,7 @@
</select>
</div>
<div class="input-list">
<a class="sch-btn" href="javascript:;" id="search" url="{:U('Market/rebindRecords')}">搜索</a>
<a class="sch-btn" href="javascript:;" id="search" url="{:U('PaymentMerchant/rules')}">搜索</a>
<a class="sch-btn" style="width: 100px;" href="{:U('PaymentMerchant/addRule')}">新增配置</a>
<!-- <a class="sch-btn" href="javascript:;" id="batch-delete-btn">删除</a> -->
</div>
@ -174,7 +174,7 @@
<td>{$data.effective_time_display}</td>
<td>
<div class="partakebtn">
<a href="<?=U('edit', ['id' => $data['id']])?>">编辑</a>
<a href="<?=U('editRule', ['id' => $data['id']])?>">编辑</a>
<a class="delete-btn">删除</a>
</div>
</td>

@ -88,6 +88,29 @@ class PaymentMerchantService {
return $nameList;
}
public function getIdentifierByConfig($config, $channel)
{
$identifier = '';
switch($channel) {
case 1:
$identifier = $config['app_id'] ?? '';
break;
case 2:
$identifier = $config['partner'] ?? '';
break;
case 3:
$identifier = $config['partner'] ?? '';
break;
case 4:
$identifier = $config['merno'] ?? '';
break;
case 5:
$identifier = $config['merno'] ?? '';
break;
}
return $identifier;
}
public function setDefault($way, $merchantId)
{
$merchantBefore = $this->getDefault($way);
@ -107,6 +130,6 @@ class PaymentMerchantService {
public function getDefault($way)
{
return M('payment_merchant', 'tab_')->where(['_string' => 'is_default&' . $way . '=' . $way])->find();
return M('payment_merchant', 'tab_')->where(['_string' => 'ways&' . $way . '=' . $way . ' and is_default&' . $way . '=' . $way])->find();
}
}

@ -3,7 +3,12 @@ namespace Base\Service;
use Base\Facade\Request;
class PaymentRuleService {
class PaymentRuleService
{
/**
* @var 永久默认时间(为方便查询,设为 2100-01-01 00:00:00
*/
const FOREVER_TIME = 4102444800;
public function getRulesByIds(array $ids = null, $fields = '*')
{
@ -22,7 +27,7 @@ class PaymentRuleService {
public function getEffectiveTimeDisplay($rule)
{
$startTime = $rule['start_time'] == 0 ? null : date('Y-m-d', $rule['start_time']);
$endTime = $rule['end_time'] == 0 ? null : date('Y-m-d', $rule['end_time']);
$endTime = $rule['end_time'] == self::FOREVER_TIME ? null : date('Y-m-d', $rule['end_time']);
if ($startTime == null && $endTime == null) {
return '永久';
}
@ -36,4 +41,72 @@ class PaymentRuleService {
return $startTime . ' 至 永久';
}
}
public function getTimeRepeatCondition($startTime, $endTime)
{
return ' ((start_time >= ' . $startTime . ' AND start_time <= ' . $endTime . ') OR (start_time <= ' . $startTime . ' AND end_time >= ' . $endTime
. ') OR (end_time >= ' . $startTime . ' AND end_time <= ' . $endTime . '))';
}
public function getTimeRepeatRules($record)
{
$conditions = [
'company_belong' => $record['company_belong'],
'company_id' => $record['company_id'] ?? 0,
'game_time_id' => $record['game_time_id'],
'game_id' => $record['game_id'] ?? 0,
];
$startTime = $record['start_time'] == '' ? 0 : strtotime($record['start_time'] . ' 00:00:00');
$endTime = $record['end_time'] == '' ? PaymentRuleService::FOREVER_TIME : strtotime($record['end_time'] . ' 23:59:59');
$conditions['_string'] = $this->getTimeRepeatCondition($startTime, $endTime);
return M('payment_rule', 'tab_')->where($conditions)->order('start_time asc')->select();
}
public function resetTimeRules($repeatRules, $startTime, $endTime)
{
$length = count($repeatRules);
if ($length == 0) {
return;
}
if ($length == 1) {
$first = $repeatRules[0];
if ($startTime <= $first['start_time'] && $endTime >= $last['end_time']) {
M('payment_rule', 'tab_')->where(['id' => $first['id']])->delete();
} elseif ($endTime < $first['end_time'] && $startTime <= $first['start_time']) {
M('payment_rule', 'tab_')->where(['id' => $first['id']])->save(['start_time' => $endTime + 1, 'update_time' => time()]);
} elseif ($endTime >= $first['end_time'] && $startTime > $first['start_time']) {
M('payment_rule', 'tab_')->where(['id' => $first['id']])->save(['end_time' => $startTime - 1, 'update_time' => time()]);
} else {
$newRule = $first;
M('payment_rule', 'tab_')->where(['id' => $first['id']])->save(['end_time' => $startTime - 1, 'update_time' => time()]);
unset($newRule['id']);
unset($newRule['create_time']);
$newRule['start_time'] = $endTime + 1;
$newRule['update_time'] = time();
M('payment_rule', 'tab_')->add($newRule);
}
} else {
$first = $repeatRules[0];
$last = $repeatRules[$length - 1];
$exceptIds = [];
if ($startTime <= $first['start_time'] && $endTime >= $last['end_time']) {
} elseif ($startTime <= $first['start_time'] && $endTime < $last['end_time']) {
M('payment_rule', 'tab_')->where(['id' => $last['id']])->save(['start_time' => $endTime + 1, 'update_time' => time()]);
$exceptIds = [$last['id']];
} elseif ($startTime > $first['start_time'] && $endTime >= $last['end_time']) {
M('payment_rule', 'tab_')->where(['id' => $first['id']])->save(['end_time' => $startTime - 1, 'update_time' => time()]);
$exceptIds = [$first['id']];
} else {
M('payment_rule', 'tab_')->where(['id' => $first['id']])->save(['end_time' => $startTime - 1, 'update_time' => time()]);
M('payment_rule', 'tab_')->where(['id' => $last['id']])->save(['start_time' => $endTime + 1, 'update_time' => time()]);
$exceptIds = [$first['id'], $last['id']];
}
foreach ($repeatRules as $rule) {
if (!in_array($rule['id'], $exceptIds)) {
M('payment_rule', 'tab_')->where(['id' => $rule['id']])->delete();
}
}
}
}
}
Loading…
Cancel
Save