|
|
|
@ -34,13 +34,23 @@ class FinanceController extends BaseController
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getDayList($beginTime, $endTime)
|
|
|
|
|
private function getDayList($beginTime, $endTime, $timeType = 1)
|
|
|
|
|
{
|
|
|
|
|
$dayList = [];
|
|
|
|
|
do {
|
|
|
|
|
$dayList[] = date('Y-m-d', $beginTime);
|
|
|
|
|
$beginTime += 24 * 60 * 60;
|
|
|
|
|
} while ($beginTime < $endTime);
|
|
|
|
|
switch ($timeType) {
|
|
|
|
|
case 1:
|
|
|
|
|
do {
|
|
|
|
|
$dayList[] = date('Y-m-d', $beginTime);
|
|
|
|
|
$beginTime += 24 * 60 * 60;
|
|
|
|
|
} while ($beginTime < $endTime);
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
do {
|
|
|
|
|
$dayList[] = date('Y-m', $beginTime);
|
|
|
|
|
$beginTime = strtotime('+1 month', $beginTime);
|
|
|
|
|
} while ($beginTime < $endTime);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $dayList;
|
|
|
|
|
}
|
|
|
|
@ -139,6 +149,7 @@ class FinanceController extends BaseController
|
|
|
|
|
$income['withdrawn_amount'] = $income['withdrawn_amount'] ?? '0.00';
|
|
|
|
|
$notWithdrawnAmount = $notWithdrawnAmount ?? 0;
|
|
|
|
|
$income['not_withdrawn_amount'] = bcadd($income['not_withdrawn_amount'], $notWithdrawnAmount, 2);
|
|
|
|
|
$income['not_withdrawn_amount'] = bcadd($income['not_withdrawn_amount'], $this->getNotWithdrawnAmount(), 2);
|
|
|
|
|
|
|
|
|
|
$withdrawMap['status'] = ['not in', [-2, -1]];
|
|
|
|
|
$withdrawns = M('withdraw', 'tab_')->field('settlement_begin_time, settlement_end_time')
|
|
|
|
@ -196,6 +207,87 @@ class FinanceController extends BaseController
|
|
|
|
|
$this->display();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getNotWithdrawnAmount()
|
|
|
|
|
{
|
|
|
|
|
$thisMonth = strtotime(date('Y-m'));
|
|
|
|
|
$map['promote_id'] = $this->loginPromote['id'];
|
|
|
|
|
$map['status'] = 1;
|
|
|
|
|
$map['begin_time'] = ['elt', $thisMonth];
|
|
|
|
|
$promoteGameRatios = M('promote_game_ratio', 'tab_')->field('game_id, begin_time, end_time, ratio, turnover_ratio')
|
|
|
|
|
->where($map)
|
|
|
|
|
->select();
|
|
|
|
|
|
|
|
|
|
if (empty($promoteGameRatios)) {
|
|
|
|
|
return 0;
|
|
|
|
|
} else {
|
|
|
|
|
$income = 0;
|
|
|
|
|
$map['status'] = ['neq', -2];
|
|
|
|
|
$map['settlement_type'] = ['in', [2, 3]];
|
|
|
|
|
unset($map['begin_time']);
|
|
|
|
|
$withdrawDays = M('withdraw', 'tab_')->where($map)->getField('settlement_begin_time', true);
|
|
|
|
|
if ($withdrawDays) {
|
|
|
|
|
foreach ($withdrawDays as &$withdrawDay) {
|
|
|
|
|
$withdrawDay = date('Y-m', $withdrawDay);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$withdrawDays = [];
|
|
|
|
|
}
|
|
|
|
|
foreach ($promoteGameRatios as $promoteGameRatio) {
|
|
|
|
|
$map = [];
|
|
|
|
|
$map['game_id'] = $promoteGameRatio['game_id'];
|
|
|
|
|
$promoteGameRatio['turnover_ratio'] = json_decode($promoteGameRatio['turnover_ratio'], true);
|
|
|
|
|
$days = $this->getDayList($promoteGameRatio['begin_time'], $thisMonth, 2);
|
|
|
|
|
if ($days) {
|
|
|
|
|
foreach ($days as $day) {
|
|
|
|
|
if (!in_array($day, $withdrawDays)) {
|
|
|
|
|
$day = strtotime($day);
|
|
|
|
|
$map['pay_time'] = ['between', [$day, strtotime('+1 month', $day) - 1]];
|
|
|
|
|
$sumAmount = $this->getSumMoney($map);
|
|
|
|
|
$diffRatio = $this->getDiffRatio($sumAmount, $promoteGameRatio['ratio'], $promoteGameRatio['turnover_ratio']);
|
|
|
|
|
$income += bcmul($sumAmount, bcdiv($diffRatio, 100, 2), 2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $income;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getSumMoney($map = [])
|
|
|
|
|
{
|
|
|
|
|
$map['pay_status'] = 1;
|
|
|
|
|
|
|
|
|
|
$sumAmount = M('spend', 'tab_')->field('sum(pay_amount) as sum_amount')->where($map)->find()['sum_amount'];
|
|
|
|
|
$sumAmount = $sumAmount ?? 0;
|
|
|
|
|
return $sumAmount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getDiffRatio($sumAmount, $defaultRatio, $turnoverRatios)
|
|
|
|
|
{
|
|
|
|
|
if ($turnoverRatios) {
|
|
|
|
|
$ratio = $defaultRatio;
|
|
|
|
|
foreach ($turnoverRatios as $turnoverRatio) {
|
|
|
|
|
if (empty($turnoverRatio['instanceof']) || $turnoverRatio['instanceof'] == 1) {
|
|
|
|
|
if ($sumAmount >= $turnoverRatio['turnover']) {
|
|
|
|
|
$ratio = $turnoverRatio['ratio'];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if ($sumAmount > $turnoverRatio['turnover']) {
|
|
|
|
|
$ratio = $turnoverRatio['ratio'];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$ratio = bcsub($ratio - $defaultRatio, 2);
|
|
|
|
|
return $ratio;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//结算明细
|
|
|
|
|
public function settlementDtl()
|
|
|
|
|
{
|
|
|
|
|