结算管理--更新

master
chenxiaojun 5 years ago
parent 4c42ee90e3
commit 258e10c9d1

@ -724,7 +724,7 @@ function getAllGameList($groupByRelation = false)
{
$field = 'id, game_name, relation_game_id, relation_game_name';
if ($groupByRelation) {
$games = M('game', 'tab_')->field($field)->group('relation_game_id')->select();
$games = M('game', 'tab_')->field($field)->where('id = relation_game_id')->group('relation_game_id')->select();
} else {
$games = M('game', 'tab_')->field($field)->select();
}

@ -64,7 +64,7 @@ class PromoteGameRatioController extends ThinkController
$promoteIds = array_column($promoteGameRatios, 'promote_id');
$gameIds = array_column($promoteGameRatios, 'game_id');
$promoteFiled = 'id, account, mobile_phone, create_time, status, ver_status';
$gameFiled = 'id, game_name, ratio';
$gameFiled = 'id, relation_game_name, ratio';
$promotes = M('promote', 'tab_')->where(array('id' => ['in', $promoteIds]))->getField($promoteFiled, true);
$games = M('game', 'tab_')->where(array('id' => ['in', $gameIds]))->getField($gameFiled, true);
@ -103,7 +103,7 @@ class PromoteGameRatioController extends ThinkController
$thisPromoteVerStatus = getPromoteVerStatus($promotes[$thisPromoteId]['ver_status'], 2);
}
if ($issetGame) {
$thisGameName = $games[$thisGameId]['game_name'];
$thisGameName = $games[$thisGameId]['relation_game_name'];
$thisGameRatio = $games[$thisGameId]['ratio'];
$thisGameRatio = ($thisGameRatio ?? '0.00') . '%';
}
@ -326,7 +326,7 @@ class PromoteGameRatioController extends ThinkController
$this->assign('lastRatio', $lastRatio);
}
$this->assign('gameList', getAllGameList());
$this->assign('gameList', getAllGameList(true));
$this->assign('promoteList', getPromoteByLevel(1));
$this->meta_title = $metaTitle;
$this->display();
@ -389,8 +389,11 @@ class PromoteGameRatioController extends ThinkController
$promoteIds = M('promote', 'tab_')->where($promoteMap)->getField('id', true);
$promoteIds[] = $promoteId;
$gameIds = D('game')->where(array('relation_game_id' => $promoteGameRatio['game_id']))->getField('id', true);
$gameIds = $gameIds ?? [-1];
$spendMap['promote_id'] = ['in', $promoteIds];
$spendMap['game_id'] = $promoteGameRatio['game_id'];
$spendMap['game_id'] = ['in', $gameIds];
if ($promoteGameRatio['end_time'] > 0) {
$spendMap['pay_time'] = ['between', [$promoteGameRatio['begin_time'], $promoteGameRatio['end_time'] + 3600 * 24 - 1]];
} else {

@ -268,37 +268,42 @@ class WithdrawModel extends Model{
$balance = 0;
$notInGameIds = [-1];
foreach ($promoteGameRatios as $promoteGameRatio) {
$spendWhere['game_id'] = $promoteGameRatio['game_id'];
if (!empty($promoteGameRatio['turnover_ratio']) && $promoteGameRatio['begin_time'] <= $settlementBeginTime && (empty($promoteGameRatio['end_time']) || $promoteGameRatio['end_time'] >= $settlementEndTime)) {
$notInGameIds[] = $promoteGameRatio['game_id'];
$ratio = $promoteGameRatio['ratio'];
$promoteGameRatio['turnover_ratio'] = json_decode($promoteGameRatio['turnover_ratio'], true);
$turnoverRatios = array_reverse($promoteGameRatio['turnover_ratio']);
$sumAmount = $spendModel->field("sum(pay_amount) as sum_amount")
->where($spendWhere)
->find()['sum_amount'];
$sumAmount = $sumAmount ?? 0;
foreach ($turnoverRatios as $turnoverRatio) {
if ($sumAmount >= $turnoverRatio['turnover']) {
$ratio = $turnoverRatio['ratio'];
break;
$gameIds = D('game')->where(array('relation_game_id' => $promoteGameRatio['game_id']))->getField('id', true);
if (!empty($gameIds)) {
foreach ($gameIds as $gameId) {
$spendWhere['game_id'] = $gameId;
$notInGameIds[] = $gameId;
$ratio = $promoteGameRatio['ratio'];
$promoteGameRatio['turnover_ratio'] = json_decode($promoteGameRatio['turnover_ratio'], true);
$turnoverRatios = array_reverse($promoteGameRatio['turnover_ratio']);
$sumAmount = $spendModel->field("sum(pay_amount) as sum_amount")
->where($spendWhere)
->find()['sum_amount'];
$sumAmount = $sumAmount ?? 0;
foreach ($turnoverRatios as $turnoverRatio) {
if ($sumAmount >= $turnoverRatio['turnover']) {
$ratio = $turnoverRatio['ratio'];
break;
}
}
$thisBalance = $spendModel->field("sum(pay_amount * {$ratio}) as balance")
->where($spendWhere)
->find()['balance'];
$thisBalance = $thisBalance ?? 0;
$balance = bcadd($balance, $thisBalance, 2);
$gameRatios[$gameId] = [];
$gameRatios[$gameId][] = [
'selle_ratio' => $ratio,
'default_ratio' => $promoteGameRatio['ratio'],
'sum_amount' => $sumAmount,
'begin_time' => $beginTime,
'end_time' => $endTime,
];
}
}
$thisBalance = $spendModel->field("sum(pay_amount * {$ratio}) as balance")
->where($spendWhere)
->find()['balance'];
$thisBalance = $thisBalance ?? 0;
$balance = bcadd($balance, $thisBalance, 2);
$gameRatios[$promoteGameRatio['game_id']] = [];
$gameRatios[$promoteGameRatio['game_id']][] = [
'selle_ratio' => $ratio,
'default_ratio' => $promoteGameRatio['ratio'],
'sum_amount' => $sumAmount,
'begin_time' => $beginTime,
'end_time' => $endTime,
];
}
}
@ -391,33 +396,38 @@ class WithdrawModel extends Model{
$gameRatios = [];
foreach ($promoteGameRatios as $promoteGameRatio) {
if (!empty($promoteGameRatio['turnover_ratio']) && $promoteGameRatio['begin_time'] <= $settlementBeginTime && (empty($promoteGameRatio['end_time']) || $promoteGameRatio['end_time'] >= $settlementEndTime)) {
$spendMap['game_id'] = $promoteGameRatio['game_id'];
$promoteGameRatio['turnover_ratio'] = json_decode($promoteGameRatio['turnover_ratio'], true);
$turnoverRatios = array_reverse($promoteGameRatio['turnover_ratio']);
$sumAmount = $spendModel->field("sum(pay_amount) as sum_amount")
->where($spendMap)
->find()['sum_amount'];
$sumAmount = $sumAmount ?? 0;
$ratio = 0;
foreach ($turnoverRatios as $turnoverRatio) {
if ($sumAmount >= $turnoverRatio['turnover']) {
$ratio = $turnoverRatio['ratio'];
break;
}
}
$gameIds = D('game')->where(array('relation_game_id' => $promoteGameRatio['game_id']))->getField('id', true);
if (!empty($gameIds)) {
foreach ($gameIds as $gameId) {
$spendWhere['game_id'] = $gameId;
$promoteGameRatio['turnover_ratio'] = json_decode($promoteGameRatio['turnover_ratio'], true);
$turnoverRatios = array_reverse($promoteGameRatio['turnover_ratio']);
$sumAmount = $spendModel->field("sum(pay_amount) as sum_amount")
->where($spendMap)
->find()['sum_amount'];
$sumAmount = $sumAmount ?? 0;
$ratio = 0;
foreach ($turnoverRatios as $turnoverRatio) {
if ($sumAmount >= $turnoverRatio['turnover']) {
$ratio = $turnoverRatio['ratio'];
break;
}
}
if ($ratio > 0) {
$ratio = bcsub($ratio, $promoteGameRatio['ratio'], 2);
$thisBalance = bcdiv(bcmul($sumAmount, $ratio, 2), 100, 2);
$balance = bcadd($balance, $thisBalance, 2);
$gameRatios[$promoteGameRatio['game_id']][] = [
'selle_ratio' => $ratio,
'default_ratio' => $promoteGameRatio['ratio'],
'sum_amount' => $sumAmount,
'begin_time' => date('Y-m-d', $settlementBeginTime),
'end_time' => date('Y-m-d', $settlementEndTime),
];
if ($ratio > 0) {
$ratio = bcsub($ratio, $promoteGameRatio['ratio'], 2);
$thisBalance = bcdiv(bcmul($sumAmount, $ratio, 2), 100, 2);
$balance = bcadd($balance, $thisBalance, 2);
$gameRatios[$gameId][] = [
'selle_ratio' => $ratio,
'default_ratio' => $promoteGameRatio['ratio'],
'sum_amount' => $sumAmount,
'begin_time' => date('Y-m-d', $settlementBeginTime),
'end_time' => date('Y-m-d', $settlementEndTime),
];
}
}
}
}
}
@ -477,25 +487,30 @@ class WithdrawModel extends Model{
$balance = 0;
foreach ($promoteGameRatios as $promoteGameRatio) {
if (!empty($promoteGameRatio['turnover_ratio']) && $promoteGameRatio['begin_time'] <= $settlementBeginTime && (empty($promoteGameRatio['end_time']) || $promoteGameRatio['end_time'] >= $settlementEndTime)) {
$spendMap['game_id'] = $promoteGameRatio['game_id'];
$promoteGameRatio['turnover_ratio'] = json_decode($promoteGameRatio['turnover_ratio'], true);
$turnoverRatios = array_reverse($promoteGameRatio['turnover_ratio']);
$sumAmount = $spendModel->field("sum(pay_amount) as sum_amount")
->where($spendMap)
->find()['sum_amount'];
$sumAmount = $sumAmount ?? 0;
$ratio = 0;
foreach ($turnoverRatios as $turnoverRatio) {
if ($sumAmount >= $turnoverRatio['turnover']) {
$ratio = $turnoverRatio['ratio'];
break;
}
}
$gameIds = D('game')->where(array('relation_game_id' => $promoteGameRatio['game_id']))->getField('id', true);
if (!empty($gameIds)) {
foreach ($gameIds as $gameId) {
$spendMap['game_id'] = $gameId;
$promoteGameRatio['turnover_ratio'] = json_decode($promoteGameRatio['turnover_ratio'], true);
$turnoverRatios = array_reverse($promoteGameRatio['turnover_ratio']);
$sumAmount = $spendModel->field("sum(pay_amount) as sum_amount")
->where($spendMap)
->find()['sum_amount'];
$sumAmount = $sumAmount ?? 0;
$ratio = 0;
foreach ($turnoverRatios as $turnoverRatio) {
if ($sumAmount >= $turnoverRatio['turnover']) {
$ratio = $turnoverRatio['ratio'];
break;
}
}
if ($ratio > 0) {
$ratio = bcsub($ratio, $promoteGameRatio['ratio'], 2);
$thisBalance = bcdiv(bcmul($sumAmount, $ratio, 2), 100, 2);
$balance = bcadd($balance, $thisBalance, 2);
if ($ratio > 0) {
$ratio = bcsub($ratio, $promoteGameRatio['ratio'], 2);
$thisBalance = bcdiv(bcmul($sumAmount, $ratio, 2), 100, 2);
$balance = bcadd($balance, $thisBalance, 2);
}
}
}
}
}
@ -532,28 +547,33 @@ class WithdrawModel extends Model{
$balance = 0;
$notInGameIds = [-1];
foreach ($promoteGameRatios as $promoteGameRatio) {
$spendWhere['game_id'] = $promoteGameRatio['game_id'];
if (!empty($promoteGameRatio['turnover_ratio']) && $promoteGameRatio['begin_time'] <= $settlementBeginTime && (empty($promoteGameRatio['end_time']) || $promoteGameRatio['end_time'] >= $settlementEndTime)) {
$notInGameIds[] = $promoteGameRatio['game_id'];
$ratio = $promoteGameRatio['ratio'];
$promoteGameRatio['turnover_ratio'] = json_decode($promoteGameRatio['turnover_ratio'], true);
$turnoverRatios = array_reverse($promoteGameRatio['turnover_ratio']);
$sumAmount = $spendModel->field("sum(pay_amount) as sum_amount")
->where($spendWhere)
->find()['sum_amount'];
$sumAmount = $sumAmount ?? 0;
foreach ($turnoverRatios as $turnoverRatio) {
if ($sumAmount >= $turnoverRatio['turnover']) {
$ratio = $turnoverRatio['ratio'];
break;
$gameIds = D('game')->where(array('relation_game_id' => $promoteGameRatio['game_id']))->getField('id', true);
if (!empty($gameIds)) {
foreach ($gameIds as $gameId) {
$spendWhere['game_id'] = $gameId;
$notInGameIds[] = $gameId;
$ratio = $promoteGameRatio['ratio'];
$promoteGameRatio['turnover_ratio'] = json_decode($promoteGameRatio['turnover_ratio'], true);
$turnoverRatios = array_reverse($promoteGameRatio['turnover_ratio']);
$sumAmount = $spendModel->field("sum(pay_amount) as sum_amount")
->where($spendWhere)
->find()['sum_amount'];
$sumAmount = $sumAmount ?? 0;
foreach ($turnoverRatios as $turnoverRatio) {
if ($sumAmount >= $turnoverRatio['turnover']) {
$ratio = $turnoverRatio['ratio'];
break;
}
}
$thisBalance = $spendModel->field("sum(pay_amount * {$ratio}) as balance")
->where($spendWhere)
->find()['balance'];
$thisBalance = $thisBalance ?? 0;
$balance = bcadd($balance, $thisBalance, 2);
}
}
$thisBalance = $spendModel->field("sum(pay_amount * {$ratio}) as balance")
->where($spendWhere)
->find()['balance'];
$thisBalance = $thisBalance ?? 0;
$balance = bcadd($balance, $thisBalance, 2);
}
}

@ -105,11 +105,11 @@
<option value="">游戏名称</option>
<empty name="record">
<volist name="gameList" id="vo">
<option value="{$vo.id}">{$vo.game_name}</option>
<option value="{$vo.id}">{$vo.relation_game_name}</option>
</volist>
<else/>
<volist name="gameList" id="vo">
<option value="{$vo.id}" <if condition="$vo['id'] eq $record['game_id']">selected</if> >{$vo.game_name}</option>
<option value="{$vo.id}" <if condition="$vo['id'] eq $record['game_id']">selected</if> >{$vo.relation_game_name}</option>
</volist>
</empty>
</select>

@ -1106,6 +1106,10 @@ function getGameSelleRatioByPromote($promoteId = null, $gameId = null)
$promoteId = intval($promoteId);
$gameId = intval($gameId);
$promote = M('promote', 'tab_')->find($promoteId);
$gameId = M('game', 'tab_')->where(array('id' => $gameId))->getField('relation_game_id');
if (empty($gameId)) {
return false;
}
if (empty($promote)) {
return false;

Loading…
Cancel
Save