|
|
|
@ -97,40 +97,44 @@ class FinanceController extends BaseController
|
|
|
|
|
$endTime = strtotime($initEndTime);
|
|
|
|
|
$endTime = $endTime + 3600 * 24;
|
|
|
|
|
|
|
|
|
|
$map['chain'] = ['like', $this->loginPromote['chain'] . $this->loginPromote['id'] . '/%'];
|
|
|
|
|
$promoteIds = M('promote', 'tab_')->where($map)->getField('id', true);
|
|
|
|
|
$promoteIds[] = $this->loginPromote['id'];
|
|
|
|
|
$promoteIds = implode(',', $promoteIds);
|
|
|
|
|
|
|
|
|
|
$map = [];
|
|
|
|
|
$map['pay_status'] = 1;
|
|
|
|
|
$map['promote_id'] = ['in', $promoteIds];
|
|
|
|
|
$income = $model->field("sum(if(pay_time < $thisDay, if(selle_ratio > 0, pay_amount * selle_ratio, 0), 0)) as history_income,
|
|
|
|
|
$records = [];
|
|
|
|
|
$income = [];
|
|
|
|
|
if (intval($endTime - $begTime) / (24 * 3600) <= 31) {
|
|
|
|
|
$map['chain'] = ['like', $this->loginPromote['chain'] . $this->loginPromote['id'] . '/%'];
|
|
|
|
|
$promoteIds = M('promote', 'tab_')->where($map)->getField('id', true);
|
|
|
|
|
$promoteIds[] = $this->loginPromote['id'];
|
|
|
|
|
$promoteIds = implode(',', $promoteIds);
|
|
|
|
|
|
|
|
|
|
$map = [];
|
|
|
|
|
$map['pay_status'] = 1;
|
|
|
|
|
$map['promote_id'] = ['in', $promoteIds];
|
|
|
|
|
$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")
|
|
|
|
|
->where($map)
|
|
|
|
|
->find();
|
|
|
|
|
->where($map)
|
|
|
|
|
->find();
|
|
|
|
|
|
|
|
|
|
foreach ($income as &$value) {
|
|
|
|
|
$value = bcdiv($value, 100, 2);
|
|
|
|
|
}
|
|
|
|
|
foreach ($income as &$value) {
|
|
|
|
|
$value = bcdiv($value, 100, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$map['pay_time'] = ['between', [$begTime, $endTime]];
|
|
|
|
|
$dayList = $this->getDayList($begTime, $endTime);
|
|
|
|
|
$data = $model->field('FROM_UNIXTIME(pay_time, "%Y-%m-%d") as day,
|
|
|
|
|
$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')
|
|
|
|
|
->where($map)
|
|
|
|
|
->group('day')
|
|
|
|
|
->select();
|
|
|
|
|
$data = $this->assembleRecords($data, $dayList, 'income');
|
|
|
|
|
foreach ($dayList as $day) {
|
|
|
|
|
$date = date('Ymd', strtotime($day));
|
|
|
|
|
$records[] = [
|
|
|
|
|
'day' => $date,
|
|
|
|
|
'income' => bcdiv($data[$day], 100, 2),
|
|
|
|
|
'url' => U('settlementDtl', array('begtime' => $day, 'endtime' => $day))
|
|
|
|
|
];
|
|
|
|
|
->where($map)
|
|
|
|
|
->group('day')
|
|
|
|
|
->select();
|
|
|
|
|
$data = $this->assembleRecords($data, $dayList, 'income');
|
|
|
|
|
foreach ($dayList as $day) {
|
|
|
|
|
$date = date('Ymd', strtotime($day));
|
|
|
|
|
$records[] = [
|
|
|
|
|
'day' => $date,
|
|
|
|
|
'income' => bcdiv($data[$day], 100, 2),
|
|
|
|
|
'url' => U('settlementDtl', array('begtime' => $day, 'endtime' => $day))
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->assign('income', $income);
|
|
|
|
@ -164,6 +168,7 @@ class FinanceController extends BaseController
|
|
|
|
|
$initEndTime = empty(I('endtime')) ? $initEndTime : I('endtime');
|
|
|
|
|
$begTime = strtotime($initBegTime);
|
|
|
|
|
$endTime = strtotime($initEndTime);
|
|
|
|
|
$endTime += 3600 * 24;
|
|
|
|
|
|
|
|
|
|
$parameter['p'] = $page;
|
|
|
|
|
$parameter['row'] = $row;
|
|
|
|
@ -171,63 +176,61 @@ class FinanceController extends BaseController
|
|
|
|
|
$parameter['begtime'] = $initBegTime;
|
|
|
|
|
$parameter['endtime'] = $initEndTime;
|
|
|
|
|
|
|
|
|
|
$map['chain'] = ['like', $this->loginPromote['chain'] . $this->loginPromote['id'] . '/%'];
|
|
|
|
|
$ids = M('promote', 'tab_')->where($map)->getField('id', true);
|
|
|
|
|
$ids[] = $this->loginPromote['id'];
|
|
|
|
|
$ids = implode(',', $ids);
|
|
|
|
|
|
|
|
|
|
$map = [];
|
|
|
|
|
$map['promote_id'] = ['in', $ids];
|
|
|
|
|
if (!empty($payOrderNumber)) {
|
|
|
|
|
$map['pay_order_number'] = $payOrderNumber;
|
|
|
|
|
}
|
|
|
|
|
if (!empty($begTime) && empty($endTime)) {
|
|
|
|
|
$map['pay_time'] = ['egt', $begTime];
|
|
|
|
|
} elseif (empty($begTime) && !empty($endTime)) {
|
|
|
|
|
$map['pay_time'] = ['elt', $endTime + 86399];
|
|
|
|
|
} elseif (!empty($begTime) && !empty($endTime)) {
|
|
|
|
|
$map['pay_time'] = ['between', [$begTime, $endTime + 86399]];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$data = $model->field('pay_order_number,game_name,user_account,promote_account,pay_amount,pay_way,if(selle_ratio >= 0,selle_ratio,0) as selle_ratio,pay_time,selle_status,pay_status,withdraw_id')
|
|
|
|
|
->where($map)
|
|
|
|
|
->order('id desc')
|
|
|
|
|
->page($page, $row)
|
|
|
|
|
->select();
|
|
|
|
|
$count = $model->where($map)->count();
|
|
|
|
|
|
|
|
|
|
//提现状态
|
|
|
|
|
$withdrawIds = [0];
|
|
|
|
|
foreach ($data as $key => $value) {
|
|
|
|
|
if ($value['withdraw_id'] > 0 && !in_array($value['withdraw_id'], $withdrawIds)) {
|
|
|
|
|
$withdrawIds[] = $value['withdraw_id'];
|
|
|
|
|
$data = [];
|
|
|
|
|
$count = 0;
|
|
|
|
|
if (intval($endTime - $begTime) / (24 * 3600) <= 31) {
|
|
|
|
|
$map['chain'] = ['like', $this->loginPromote['chain'] . $this->loginPromote['id'] . '/%'];
|
|
|
|
|
$ids = M('promote', 'tab_')->where($map)->getField('id', true);
|
|
|
|
|
$ids[] = $this->loginPromote['id'];
|
|
|
|
|
$ids = implode(',', $ids);
|
|
|
|
|
|
|
|
|
|
$map = [];
|
|
|
|
|
$map['promote_id'] = ['in', $ids];
|
|
|
|
|
$map['pay_time'] = ['between', [$begTime, $endTime]];
|
|
|
|
|
if (!empty($payOrderNumber)) {
|
|
|
|
|
$map['pay_order_number'] = $payOrderNumber;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$withdrawStatus = M('withdraw', 'tab_')
|
|
|
|
|
->where(array('id' => ['in', $withdrawIds]))
|
|
|
|
|
->getField('id,status');
|
|
|
|
|
|
|
|
|
|
foreach ($data as &$list) {
|
|
|
|
|
$data = $model->field('pay_order_number,game_name,user_account,promote_account,pay_amount,pay_way,if(selle_ratio >= 0,selle_ratio,0) as selle_ratio,pay_time,selle_status,pay_status,withdraw_id')
|
|
|
|
|
->where($map)
|
|
|
|
|
->order('id desc')
|
|
|
|
|
->page($page, $row)
|
|
|
|
|
->select();
|
|
|
|
|
$count = $model->where($map)->count();
|
|
|
|
|
|
|
|
|
|
//提现状态
|
|
|
|
|
if ($list['pay_status'] == 1) {
|
|
|
|
|
switch ($list['selle_status']) {
|
|
|
|
|
case 0:
|
|
|
|
|
$list['selle_status'] = '未提现';
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
if ($list['withdraw_id'] > 0) {
|
|
|
|
|
$list['selle_status'] = FinanceController::$withdrawStatus[$withdrawStatus[$list['withdraw_id']]];
|
|
|
|
|
} else {
|
|
|
|
|
$list['selle_status'] = '';
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
$withdrawIds = [0];
|
|
|
|
|
foreach ($data as $key => $value) {
|
|
|
|
|
if ($value['withdraw_id'] > 0 && !in_array($value['withdraw_id'], $withdrawIds)) {
|
|
|
|
|
$withdrawIds[] = $value['withdraw_id'];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$list['selle_status'] = '支付失败';
|
|
|
|
|
}
|
|
|
|
|
$withdrawStatus = M('withdraw', 'tab_')
|
|
|
|
|
->where(array('id' => ['in', $withdrawIds]))
|
|
|
|
|
->getField('id,status');
|
|
|
|
|
|
|
|
|
|
$list['income'] = bcmul($list['pay_amount'], bcdiv($list['selle_ratio'], 100, 2), 2);
|
|
|
|
|
$list['pay_time'] = date('Y-m-d H:i:s', $list['pay_time']);
|
|
|
|
|
foreach ($data as &$list) {
|
|
|
|
|
//提现状态
|
|
|
|
|
if ($list['pay_status'] == 1) {
|
|
|
|
|
switch ($list['selle_status']) {
|
|
|
|
|
case 0:
|
|
|
|
|
$list['selle_status'] = '未提现';
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
if ($list['withdraw_id'] > 0) {
|
|
|
|
|
$list['selle_status'] = FinanceController::$withdrawStatus[$withdrawStatus[$list['withdraw_id']]];
|
|
|
|
|
} else {
|
|
|
|
|
$list['selle_status'] = '';
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$list['selle_status'] = '支付失败';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$list['income'] = bcmul($list['pay_amount'], bcdiv($list['selle_ratio'], 100, 2), 2);
|
|
|
|
|
$list['pay_time'] = date('Y-m-d H:i:s', $list['pay_time']);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$page = set_pagination($count, $row, $parameter);
|
|
|
|
|