|
|
|
@ -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;
|
|
|
|
|
}
|
|
|
|
@ -120,20 +130,24 @@ class FinanceController extends BaseController
|
|
|
|
|
$income = $model->field("sum(if(pay_time < $thisDay, if(selle_ratio > 0, pay_amount * selle_ratio, 0), 0)) as history_income,
|
|
|
|
|
sum(if(pay_time >= $thisMonth, if(selle_ratio > 0, pay_amount * selle_ratio, 0), 0)) as this_month_income,
|
|
|
|
|
sum(if((pay_time >= $yesterday and pay_time < $thisDay), if(selle_ratio > 0, pay_amount * selle_ratio, 0), 0)) as yesterday_income,
|
|
|
|
|
sum(if(pay_time < $thisDay, if(selle_status = 0, pay_amount * selle_ratio, 0), 0)) as balance,
|
|
|
|
|
sum(if(selle_status = 0, pay_amount, 0)) as not_withdrawn_amount")
|
|
|
|
|
sum(if(pay_time < $thisDay, if(selle_status = 0, pay_amount * selle_ratio, 0), 0)) as balance")
|
|
|
|
|
->where($map)
|
|
|
|
|
->find();
|
|
|
|
|
|
|
|
|
|
foreach ($income as &$value) {
|
|
|
|
|
$value = bcdiv($value, 100, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$withdrawMap['promote_id'] = $this->loginPromote['id'];
|
|
|
|
|
$withdrawMap['status'] = ['neq', 2];
|
|
|
|
|
$withdrawMap['status'] = 2;
|
|
|
|
|
|
|
|
|
|
//已提现总额
|
|
|
|
|
$income['withdrawn_amount'] = M('withdraw', 'tab_')->field('sum(sum_money) as withdrawn_amount')->where($withdrawMap)->find()['withdrawn_amount'];
|
|
|
|
|
|
|
|
|
|
foreach ($income as &$value) {
|
|
|
|
|
$value = bcdiv($value, 100, 2);
|
|
|
|
|
}
|
|
|
|
|
$withdrawMap['status'] = ['in', [-1, 0, 1]];
|
|
|
|
|
$notWithdrawnAmount = M('withdraw', 'tab_')->field('sum(sum_money) as withdrawn_amount')->where($withdrawMap)->find()['withdrawn_amount'];
|
|
|
|
|
$income['withdrawn_amount'] = $income['withdrawn_amount'] ?? '0.00';
|
|
|
|
|
$notWithdrawnAmount = $notWithdrawnAmount ?? 0;
|
|
|
|
|
$income['not_withdrawn_amount'] = bcadd($this->getSumAmountBySettlementType(), $notWithdrawnAmount, 2);
|
|
|
|
|
|
|
|
|
|
$withdrawMap['status'] = ['not in', [-2, -1]];
|
|
|
|
|
$withdrawns = M('withdraw', 'tab_')->field('settlement_begin_time, settlement_end_time')
|
|
|
|
@ -191,6 +205,122 @@ class FinanceController extends BaseController
|
|
|
|
|
$this->display();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getSumAmountBySettlementType()
|
|
|
|
|
{
|
|
|
|
|
$withdrawModel = new WithdrawModel();
|
|
|
|
|
$balance = 0;
|
|
|
|
|
|
|
|
|
|
if ($this->loginPromote['settlement_type'] == 2) {
|
|
|
|
|
$settlementType = 2;
|
|
|
|
|
} else {
|
|
|
|
|
$map['pay_status'] = 1;
|
|
|
|
|
$map['selle_status'] = 0;
|
|
|
|
|
$balance = M('spend', 'tab_')->field('sum(pay_amount * selle_ratio) as balance')->where($map)->find()['balance'];
|
|
|
|
|
$balance = $balance ? bcdiv($balance , 100, 2) : 0;
|
|
|
|
|
$settlementType = 3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$months = $this->getDayList(strtotime('2019-09'), strtotime(date('Y-m')), 2);
|
|
|
|
|
$promote = $this->loginPromote;
|
|
|
|
|
|
|
|
|
|
if ($settlementType == 2) {
|
|
|
|
|
$fun = 'getMonthAmount';
|
|
|
|
|
} else {
|
|
|
|
|
$fun = 'getRecoupAmount';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($months) {
|
|
|
|
|
foreach ($months as $month) {
|
|
|
|
|
$data['begin_time'] = strtotime($month);
|
|
|
|
|
$data['end_time'] = strtotime('+1 month', $data['begin_time']) - 1;
|
|
|
|
|
$balance = bcadd($balance, $withdrawModel->$fun($promote, $data), 2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $balance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|