master
chenxiaojun 5 years ago
commit 009842c218

@ -139,14 +139,14 @@ class QueryController extends ThinkController
}
}
if ($settlementType == 3) {
if ($settlementType != 3) {
$totalField = 'sum(if(tab_spend.selle_ratio > 0, tab_spend.pay_amount * tab_spend.selle_ratio, 0)) as settlement_amount';
$zTotal = null_to_0(M('spend', 'tab_')->field($totalField)->where($spendMap)->find()['settlement_amount']);//累计
$zTotal = bcdiv($zTotal, 100 ,2);
} else {
$totalField = 'sum(tab_spend.pay_amount) as sum_amount';
$zTotal = null_to_0(M('spend', 'tab_')->field($totalField)->where($spendMap)->find()['sum_amount']);//累计
}
$zTotal = bcdiv($zTotal, 100 ,2);
if(I('export', 0) == 1) {
$data = [];
@ -1354,6 +1354,7 @@ class QueryController extends ThinkController
'settlement_time' => "{$list['begin_time']} - {$list['end_time']}",
'game_name' => $gameName ?? '未知',
'sum_amount' => $list['sum_amount'],
'default_ratio' => $list['default_ratio'] ? $list['default_ratio'] . '%' : '未知',
'ratio' => $list['selle_ratio'] . '%',
'settlement_amount' => bcdiv(bcmul($list['sum_amount'], $list['selle_ratio'], 2), 100, 2),
];
@ -1361,6 +1362,7 @@ class QueryController extends ThinkController
}
}
$this->assign('settlementType', $withdraw['settlement_type']);
$this->assign('records', $records);
$this->display();
}
@ -1562,26 +1564,30 @@ class QueryController extends ThinkController
$this->ajaxReturn(['settlement_type' => $settlementType]);
}
public function getRecoupAmount()
public function getAmountBySettlementType()
{
$withdrawModel = new WithdrawModel();
$promoteId = intval(I('promote_id', 0));
$settlementType = intval(I('settlement_type', 0));
$time = I('time', '');
if (empty($promoteId) || $settlementType != 3) {
if (empty($promoteId) || !in_array($settlementType, [2, 3])) {
$this->ajaxReturn(['balance' => 0]);
}
$promote = M('promote', 'tab_')->find($promoteId);
if (empty($promote) || $promote['level'] != 1 || $promote['ver_status'] != 1 || $promote['settlement_type'] != 1 || empty($time)) {
if (empty($promote) || $promote['level'] != 1 || $promote['ver_status'] != 1 || empty($time)) {
$this->ajaxReturn(['balance' => 0]);
}
$data['begin_time'] = strtotime($time);
$data['end_time'] = strtotime('+1 month', $data['begin_time']) - 1;
if ($settlementType == 2) {
$balance = $withdrawModel->getMonthAmount($promote, $data);
} else {
$balance = $withdrawModel->getRecoupAmount($promote, $data);
}
$this->ajaxReturn(['balance' => $balance]);
}
}

@ -294,6 +294,7 @@ class WithdrawModel extends Model{
$gameRatios[$promoteGameRatio['game_id']] = [];
$gameRatios[$promoteGameRatio['game_id']][] = [
'selle_ratio' => $ratio,
'default_ratio' => $promoteGameRatio['ratio'],
'sum_amount' => $sumAmount,
'begin_time' => $beginTime,
'end_time' => $endTime,
@ -412,6 +413,7 @@ class WithdrawModel extends Model{
$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),
@ -501,6 +503,72 @@ class WithdrawModel extends Model{
return $balance;
}
public function getMonthAmount($promote, $data = [])
{
$promoteIds = $this->getPromoteChildren($promote);
$settlementBeginTime = $data['begin_time'] ?? strtotime(date('Y-m', strtotime('-1 month', time())));
$settlementEndTime = $data['end_time'] ?? strtotime(date('Y-m')) - 1;
$spendMap['pay_status'] = 1;
$spendMap['selle_status'] = 0;
$spendMap['promote_id'] = ['in', $promoteIds];
$spendMap['pay_time'] = ['between', [$settlementBeginTime, $settlementEndTime]];
$spendWhere = $spendMap;
$spendModel = M('spend', 'tab_');
$promoteGameRatioMap['status'] = 1;
$promoteGameRatioMap['promote_id'] = $promote['id'];
$promoteGameRatios = D('promote_game_ratio')->field('game_id, ratio, turnover_ratio, begin_time, end_time')
->where($promoteGameRatioMap)
->order('update_time desc')
->select();
if (empty($promoteGameRatios)) {
$balance = $spendModel->field("sum(if(selle_ratio > 0, pay_amount * selle_ratio, 0)) as balance")
->where($spendMap)
->find()['balance'];
$balance = $balance ?? 0;
} else {
$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;
}
}
$thisBalance = $spendModel->field("sum(pay_amount * {$ratio}) as balance")
->where($spendWhere)
->find()['balance'];
$thisBalance = $thisBalance ?? 0;
$balance = bcadd($balance, $thisBalance, 2);
}
}
$spendWhere['game_id'] = ['not in', $notInGameIds];
$otherBalance = $spendModel->field("sum(if(selle_ratio > 0, pay_amount * selle_ratio, 0)) as balance")
->where($spendWhere)
->find()['balance'];
$otherBalance = $otherBalance ?? 0;
$balance = bcadd($balance, $otherBalance, 2);
}
$balance = bcdiv($balance, 100, 2);
return $balance;
}
private function getSpendMessageByGame($map)
{
$field = 'game_id, selle_ratio, sum(pay_amount) as sum_amount, pay_time';

@ -433,7 +433,9 @@
msg += "收益结算时间:" + time;
msg += "<br>";
if (settlementType == 3) {
msg += "补点金额:" + getRecoupAmount(promoteId, settlementType, time);
msg += "补点金额:" + getAmountBySettlementType(promoteId, settlementType, time) + '元';
} else if (settlementType == 2) {
msg += "实际提现金额:" + getAmountBySettlementType(promoteId, settlementType, time) + '元';
} else {
msg += "提现金额:{$zTotal}元";
}
@ -577,11 +579,11 @@
}
});
function getRecoupAmount(promoteId, settlementType, time) {
function getAmountBySettlementType(promoteId, settlementType, time) {
var balance = 0;
$.ajax({
type: 'post',
url: '{:U("getRecoupAmount")}',
url: '{:U("getAmountBySettlementType")}',
dataType: 'json',
async: false,
data: {'promote_id': promoteId, 'settlement_type': settlementType, 'time': time},

@ -35,7 +35,12 @@ body{ padding: 0px; }
<th>结算时间</th>
<th>游戏名称</th>
<th>流水总额</th>
<if condition="$settlementType eq 3">
<th>默认分成比例</th>
<th>补点分成比例</th>
<else/>
<th>分成比例</th>
</if>
<th>结算总额</th>
</tr>
</thead>
@ -47,7 +52,12 @@ body{ padding: 0px; }
<td>{$record.settlement_time}</td>
<td>{$record.game_name}</td>
<td>{$record.sum_amount}</td>
<if condition="$settlementType eq 3">
<td>{$record.default_ratio}</td>
<td>{$record.ratio}</td>
<else/>
<td>{$record.ratio}</td>
</if>
<td>{$record.settlement_amount}</td>
</tr>
</volist>

Loading…
Cancel
Save