|
|
|
@ -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';
|
|
|
|
|