@ -119,7 +119,8 @@ 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(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")
->where($map)
->find();
@ -127,10 +128,41 @@ class FinanceController extends BaseController
$value = bcdiv($value, 100, 2);
}
$withdrawMap['promote_id'] = $this->loginPromote['id'];
$withdrawMap['status'] = ['neq', 2];
//已提现总额
$income['withdrawn_amount'] = M('withdraw', 'tab_')->field('sum(sum_money) as withdrawn_amount')->where($withdrawMap)->find()['withdrawn_amount'];
$withdrawns = M('withdraw', 'tab_')->field('settlement_begin_time, settlement_end_time')
->where($withdrawMap)
->select();
$days = [];
if (!empty($withdrawns)) {
foreach ($withdrawns as $withdrawn) {
$thisDays = [];
if (empty($withdrawn['settlement_begin_time'])) {
if ($begTime < $withdrawn['settlement_end_time']) {
if ($endTime < = $withdrawn['settlement_end_time']) {
$thisEndTime = $endTime;
} else {
$thisEndTime = $withdrawn['settlement_end_time'];
}
$thisDays = $this->getDayList($begTime, $thisEndTime);
}
} else {
$thisDays = $this->getDayList($withdrawn['settlement_begin_time'], $withdrawn['settlement_end_time']);
}
$days = array_merge($days, $thisDays);
}
}
$days = array_unique($days);
$map['pay_time'] = ['between', [$begTime, $endTime]];
$dayList = $this->getDayList($begTime, $endTime);
$data = $model->field('FROM_UNIXTIME(pay_time, "%Y-%m-%d") as day,
sum(if(selle_ratio > 0, pay_amount * selle_ratio, 0)) as income')
sum(if(selle_ratio > 0, pay_amount * selle_ratio, 0)) as income, selle_status ')
->where($map)
->group('day')
->select();
@ -140,13 +172,16 @@ class FinanceController extends BaseController
$records[] = [
'day' => $date,
'income' => bcdiv($data[$day], 100, 2),
'selle_status_text' => (in_array($day, $days) ? '已提现' : '未提现'),
'url' => U('settlementDtl', array('begtime' => $day, 'endtime' => $day))
];
}
}
$settlementCycle = ($this->loginPromote['settlement_type'] == 1 ? '周结' : '月结');
$this->assign('income', $income);
$this->assign('listData', $records);
$this->assign('settlementCycle', $settlementCycle);
$this->assign('initBegTime', $initBegTime);
$this->assign('initEndTime', $initEndTime);
$this->assign('yesterday', date('Y-m-d', $yesterday));
@ -625,45 +660,25 @@ class FinanceController extends BaseController
$this->error('参数异常');
}
$settlementBeginTime = $withdraw['settlement_begin_time'];
$settlementEndTime = $withdraw['settlement_end_time'];
$withdraw['create_time'] = date('Y-m-d H:i:s', $withdraw['create_time']);
$withdraw['settlement_end_time'] = date('Y-m-d H:i:s', $withdraw['settlement_end_time']);
$withdraw['status'] = FinanceController::$withdrawStatus[$withdraw['status']];
if (empty($withdraw['game_ratio'])) {
$map['_string'] = '1 = 2';
} else {
$gameRatios = json_decode($withdraw['game_ratio'], true);
$gameIds = array_keys($gameRatios);
$map['game_id'] = ['in', $gameIds];
$map['pay_time'] = ['between', [$settlementBeginTime, $settlementEndTime]];
}
if ($withdraw['settlement_type'] != 3) {
$map['withdraw_id'] = $withdrawId;
}
$data = M('spend', 'tab_')
->field('game_id,game_name,if(selle_ratio >= 0,selle_ratio,0) as selle_ratio,pay_way,sum(pay_amount) as pay_amount_all,sum(if(selle_ratio > 0,pay_amount * selle_ratio,0)) as income')
->where($map)
->group('game_id')
->order('game_id')
->select();
if (!empty($data)) {
foreach ($data as & $list) {
$list['income'] = '0.00';
if (isset($gameRatios[$list['game_id']])) {
foreach ($gameRatios[$list['game_id']] as $gameIncome) {
$income = bcdiv(bcmul($gameIncome['sum_amount'], $gameIncome['selle_ratio'], 2), 100, 2);
$list['income'] = bcadd($list['income'], $income, 2);
}
}
}
}
$this->assign('withdraw', $withdraw);
$this->assign('listData', $data);
$this->assign('promoteData', $this->loginPromote);
$statementMap['ext_field'] = $withdraw['widthdraw_number'];
$statementMap['statement_type'] = 1;
$statement = M('statement', 'tab_')->where($statementMap)->find();
if (empty($statement)) {
$this->error('未生成下游结算单');
}
$statement['first_party_info'] = json_decode($statement['first_party_info'], 1);//甲方
$statement['second_party_info'] = json_decode($statement['second_party_info'], 1);//乙方
$statement['statement_info'] = json_decode($statement['statement_info'], 1);//结算记录
//收款方
$statement['receive_company'] = ($statement['pay_type'] ? $statement['first_party_info']['partner'] : $statement['second_party_info']['partner']);
$all_sum_money = array_sum(array_column($statement['statement_info'], 'sum_money'));//合计平台总额
$all_pay_amount = array_sum(array_column($statement['statement_info'], 'pay_amount'));//合计结算金额
$big_all_sum_money = convertAmountToCn($statement['statement_money']);//大写
$this->assign('big_all_sum_money', $big_all_sum_money);
$this->assign('all_sum_money', $all_sum_money);
$this->assign('all_pay_amount', $all_pay_amount);
$this->assign('data', $statement);
$this->assign('meta_title', $metaTitle);
$this->assign('modelList', $modelList);
$this->display();