@ -2,7 +2,9 @@
namespace Admin\Controller;
use Home\Controller\FileController;
use User\Api\UserApi as UserApi;
use Admin\Model\WithdrawModel;
/**
* 推广查询控制器
@ -10,164 +12,511 @@ use User\Api\UserApi as UserApi;
*/
class QueryController extends ThinkController
{
public function settlement($p = 0)
//生成提现单号
public function produceWithdrawNumber()
{
$prefix = 'WD_';
$number = '';
while (true) {
$randomNum = rand(10, 99);
$number = $prefix . time() . $randomNum;
$map['widthdraw_number'] = $number;
$res = M('withdraw', 'tab_')->where($map)->getField('id');
if (!$res) {
break;
}
}
return $number;
}
public function settlement($p = 0)
{
$settlementType = intval(I('settlement_type', 0));
$settlementTypeList = WithdrawModel::$settlementTypeList;
$page = intval(I('p', 1)); //默认显示第一页数据
$row = intval(I('row', 10));
$group = I('group', 1);
$this->assign('group', $group);
if (isset($_REQUEST['total_status'])) {
unset($_REQUEST['total_status']);
}
$this->m_title = '推广结算';
$this->assign('commonset', M('Kuaijieicon')->where(['url' => 'Query/settlement', 'status' => 1])->find());
$this->assign('is_admin', is_administrator());
$promoteId = I('promote_id', 0);
if ($group == 1) {
if ($_REQUEST['unum'] == 2) {
$order = 'unum';
$order_type = SORT_ASC;
} else if ($_REQUEST['unum'] == 1) {
$order = 'unum';
$order_type = SORT_DESC;
}
if ($_REQUEST['spay_amount'] == 2) {
$order = 'spay_amount';
$order_type = SORT_ASC;
} else if ($_REQUEST['spay_amount'] == 1) {
$order = 'spay_amount';
$order_type = SORT_DESC;
}
$model = array(
'title' => '渠道结算',
'template_list' => 'settlement',
'order' => $order,
'order_type' => $order_type//0倒序 1 正序
);
$start = $_REQUEST['timestart'];
$end = $_REQUEST['timeend'];
if (I('group') != '') {
if ($start == '' || $end == '' & & $_REQUEST['promote_account'] == '') {
$this->error('结算周期、所属渠道不能为空!', '', 1);
unset($settlementTypeList[WithdrawModel::SETTLEMENT_TYPE_OTHER]);
$time = I('time', '');
if (empty($promoteId) || empty($settlementType) || empty($time)) {
$this->assign('settlementTypeList', $settlementTypeList);
$this->display();
} else {
$promoteIds = M('promote', 'tab_')->where(['chain' => ['like', "/{$promoteId}/%"]])->getField('id', true);
$promoteIds[] = $promoteId;
if ($settlementType == 1) {
$time = explode(' 至 ', $time);
if (count($time) != 2) {
$this->display();die;
}
$beginTime = strtotime($time[0]);
$endTime = strtotime($time[1]) + 3600 * 24 - 1;
} else {
$beginTime = strtotime($time);
$endTime = strtotime('+1 month', $beginTime) - 1;
}
if ($start == '' || $end == '') {
$this->error('请选择结算周期!', '', 1);
$promote = M('promote', 'tab_')->find($promoteId);
if (empty($promote) || $promote['level'] != 1 || empty($promote['settlement_type'])) {
$this->error('网络异常');
}
if ($_REQUEST['promote_account'] == '') {
$this->error('请选择渠道!', '', 1);
if ($promote['settlement_type'] == 1) {
unset($settlementTypeList[WithdrawModel::SETTLEMENT_TYPE_MONTH]);
} else {
unset($settlementTypeList[WithdrawModel::SETTLEMENT_TYPE_WEEK]);
unset($settlementTypeList[WithdrawModel::SETTLEMENT_TYPE_RECOUP]);
}
if ($settlementType == 3) {
$withdrawMap['promote_id'] = $promoteId;
$withdrawMap['status'] = ['neq', -2];
$withdrawMap['settlement_begin_time'] = $beginTime;
$withdrawMap['settlement_end_time'] = $endTime;
$withdraw = D('withdraw')->where($withdrawMap)->find();
if (!empty($withdraw)) {
$this->assign('settlementTypeList', $settlementTypeList);
$this->display();die;
}
} else {
$spendMap['tab_spend.selle_status'] = 0;
}
$sortBy = I('sort_by', '');
$sortColumn = I('sort_column', '');
$order = 'day';
$orderType = 'desc';
if (in_array($sortColumn, ['user_num', 'sum_amount'])) {
$order = $sortColumn;
}
if ($sortBy == 1) {
$orderType = 'desc';
} elseif ($sortBy == 2) {
$orderType = 'asc';
}
}
$smap['tab_spend.pay_status'] = 1;
//判断是否结算绑币
if ($_REQUEST['bind_coin'] == 0) {
$smap['tab_spend.pay_way'] = array('neq', -1);
}
$this->meta_title = '渠道结算列表';
$this->assign('setdate', date("Y-m-d", strtotime("-1 day")));
$this->assign('is_admin', is_administrator());
if ($start & & $end) {
if ((strtotime($end) + 24 * 60 * 60 - 1) < strtotime ( $ start ) ) {
$this->error('时间选择不正确!', U('Query/settlement'), '');
$spendMap['tab_spend.pay_status'] = 1;
$spendMap['tab_spend.pay_time'] = ['between', [$beginTime, $endTime]];
$spendMap['tab_spend.promote_id'] = ['in', $promoteIds];
$spendField = "tab_spend.game_id, tab_spend.game_name, sum(tab_spend.pay_amount) as sum_amount, tab_spend.selle_ratio, sum(if(tab_spend.selle_ratio > 0, tab_spend.pay_amount * tab_spend.selle_ratio, 0)) as settlement_amount, FROM_UNIXTIME(tab_spend.`pay_time`, '%Y-%m-%d') as day";
$userMap['tab_user.promote_id'] = ['in', $promoteIds];
$userMap['_string'] = 'tab_user.promote_id = tab_spend.promote_id';
$userField = M('user', 'tab_')->field('count(tab_user.id) as user_num')
->where($userMap)
->buildSql();
$field = "{$spendField}, {$userField} as user_num";
$query = M('spend', 'tab_')->field($field)
->where($spendMap)
->group('tab_spend.selle_ratio, tab_spend.game_id, day')
->order("{$order} {$orderType}");
if(I('export', 0) != 1){
$query->page($page, $row);
}
$umap['register_time'] = array('BETWEEN', array(strtotime($start), strtotime($end) + 24 * 60 * 60 - 1));
if (isset($_REQUEST['game_name']) & & $_REQUEST['game_name'] != '') {
$umap['fgame_id'] = get_game_id($_REQUEST['game_name']);
$smap['tab_spend.game_id'] = get_game_id($_REQUEST['game_name']);
$records = M()->table($query->buildSql())
->alias('record')
->select();
if(I('export', 0) != 1){
$countQuery = M('spend', 'tab_')->field($spendField)
->where($spendMap)
->group('tab_spend.selle_ratio, tab_spend.game_id, day')
->buildSql();
$count = M()->table($countQuery)
->alias('tab_spend')
->count();
$page = set_pagination($count, $row);
}
if (isset($_REQUEST['promote_account']) & & $_REQUEST['promote_account'] != '') {
$allid = get_subordinate_promote_($_REQUEST['promote_account']);
$allid[] = $_REQUEST['promote_account'];
$umap['tab_user.promote_account'] = array('in', $allid);
$smap['tab_spend.promote_account'] = array('in', $allid);
if (!empty($records)) {
foreach ($records as & $record) {
$record['promote_account'] = $promote['account'] ?? '未知';
$record['settlement_amount'] = bcdiv($record['settlement_amount'], 100, 2);
}
}
if ($settlementType != 3) {
$totalField = 'sum(if(tab_spend.selle_ratio > 0, tab_spend.pay_amount * tab_spend.selle_ratio, 0)) as settlement_amount';
$zTotal = null_to_0(M('spend', 'tab_')->field($totalField)->where($spendMap)->find()['settlement_amount']);//累计
$zTotal = bcdiv($zTotal, 100 ,2);
} else {
$this->error('未选择渠道!', '', 1);
$spendMap['game_id'] = 157;
$totalField = 'sum(tab_spend.pay_amount) as sum_amount';
$zTotal = null_to_0(M('spend', 'tab_')->field($totalField)->where($spendMap)->find()['sum_amount']);//累计
}
$umap['is_check'] = 1;
$umap['settle_check'] = 0;
$smap['pay_time'] = array('BETWEEN', array(strtotime($start), strtotime($end) + 24 * 60 * 60 - 1));
$smap['is_check'] = 1;
$smap['settle_check'] = 0;
//为数据权限添加
setPowerPromoteIds($umap, 'tab_user.promote_id');
setPowerPromoteIds($smap, 'tab_spend.promote_id');
$map['umap'] = $umap;
$map['smap'] = $smap;
$user = A('Settlement', 'Event');
if(I('export', 0) == 1) {
$data = [];
foreach ($records as $value) {
$data[] = [
'day' => $value['day'],
'promote_account' => $value['promote_account'],
'game_name' => $value['game_name'],
'sum_amount' => $value['sum_amount'],
'user_num' => $value['user_num'],
'type' => 'CPS',
'selle_ratio' => $value['selle_ratio'] . '%',
'settlement_amount' => $value['settlement_amount'],
];
}
$field = [
'day' => '日期',
'promote_account' => '会长账号',
'game_name' => '游戏名称',
'sum_amount' => '总充值',
'user_num' => '总注册',
'type' => '结算模式',
'selle_ratio' => '分成比例',
'settlement_amount' => '结算金额',
];
data2csv($data,"推广结算", $field);
exit;
}
$user->settlement($model, $p, $map);
} else {
if($page) {
$this->assign('_page', $page);
}
$this->assign('settlementTypeList', $settlementTypeList);
$this->assign('records', $records);
$this->assign('zTotal', $zTotal);
$this->assign('commonset', M('Kuaijieicon')->where(['url' => 'Query/settlement', 'status' => 1])->find());
$this->m_title = '推广结算';
$this->display();
}
}
if ($group == 2) {
if (isset($_REQUEST['stimestart']) & & isset($_REQUEST['stimeend'])) {
$map['create_time'] = array('BETWEEN', array(strtotime($_REQUEST['stimestart']), strtotime($_REQUEST['stimeend']) + 24 * 60 * 60 - 1));
} elseif (isset($_REQUEST['stimestart'])) {
$map['create_time'] = array('BETWEEN', array(strtotime($_REQUEST['stimestart']), time()));
} elseif (isset($_REQUEST['stimeend'])) {
$map['create_time'] = array('LT', (strtotime($_REQUEST['stimeend']) + 24 * 60 * 60 - 1));
} elseif ($group == 2) {
$map['_string'] = '1 = 1';
$createTime = strtotime(I('create_time', ''));
$withdrawNumber = I('widthdraw_number', '');
$status = intval(I('status', ''));
$opType = intval(I('op_type', 0));
if ($createTime) {
$createTimeEnd = $createTime + 3600 * 24 - 1;
$map['create_time'] = ['between', [$createTime, $createTimeEnd]];
}
if (isset($_REQUEST['timestart']) & & isset($_REQUEST['timeend'])) {
$map['starttime'] = ['GT', strtotime($_REQUEST['timestart'])];
$map['endtime'] = ['LT', strtotime($_REQUEST['timeend']) + 24 * 60 * 60];
} elseif (isset($_REQUEST['timestart'])) {
$map['starttime'] = ['GT', strtotime($_REQUEST['timestart'])];
} elseif (isset($_REQUEST['timeend'])) {
$map['endtime'] = ['LT', strtotime($_REQUEST['timeend']) + 24 * 60 * 60];
if ($promoteId) {
$map['promote_id'] = $promoteId;
}
if (isset($_REQUEST['game_name'])) {
if ($_REQUEST['game_name'] == '全部') {
unset($_REQUEST['game_name']);
} else {
$map['game_name'] = $_REQUEST['game_name'];
if ($withdrawNumber) {
$map['widthdraw_number'] = ['like', "{$withdrawNumber}%"];
}
if (isset($_REQUEST['status'])) {
$map['status'] = $status;
}
if ($opType) {
$map['op_type'] = $opType;
}
if ($settlementType) {
$map['settlement_type'] = $settlementType;
}
$query = M('withdraw', 'tab_')->field('id, promote_account, widthdraw_number, sum_money, op_id, op_type, last_op_id, last_op_type, settlement_begin_time, settlement_end_time, create_time, status, respond, settlement_type')
->where($map)
->order('create_time desc');
if(I('export', 0) != 1){
$query->page($page, $row);
}
$records = $query->select();
if(I('export', 0) != 1){
$count = M('withdraw', 'tab_')->field('id, promote_account, widthdraw_number, sum_money, op_id, op_type, last_op_id, last_op_type, settlement_begin_time, settlement_end_time, create_time, status, respond')
->where($map)
->count();
}
if (!empty($records)) {
foreach ($records as & $record) {
$record['settlement_begin_time'] = $record['settlement_begin_time'] ? date('Y-m-d H:i:s', $record['settlement_begin_time']) : '--';
$record['settlement_end_time'] = date('Y-m-d H:i:s', $record['settlement_end_time']);
$record['create_time'] = date('Y-m-d H:i:s', $record['create_time']);
$record['status_text'] = promoteWithdrawStatus($record['status']);
if ($record['status'] == -2) {
$record['status_text'] = '< span style = "color: #999;" > ' . $record['status_text'] . '< / span > ';
}
$record['op_id_text'] = $this->getOpTypeText($record['op_type'], $record['op_id']);
$record['last_op_id_text'] = $this->getOpTypeText($record['last_op_type'], $record['last_op_id']);
$record['op_type_text'] = getPromoteWithdrawOpType($record['op_type']);
$record['last_op_type_text'] = getPromoteWithdrawOpType($record['last_op_type']);
$record['settlement_type_text'] = getPromoteWithdrawSettlementType($record['settlement_type']);
}
}
if (isset($_REQUEST['promote_account'])) {
if ($_REQUEST['promote_account'] == '全部') {
unset($_REQUEST['promote_account']);
} else {
$map['promote_account'] = $_REQUEST['promote_account'];
if(I('export', 0) == 1) {
$data = [];
foreach ($records as $value) {
$data[] = [
'promote_account' => $value['promote_account'],
'widthdraw_number' => $value['widthdraw_number'],
'sum_money' => $value['sum_money'],
'op_id_text' => $value['op_id_text'],
'op_type_text' => $value['op_type_text'],
'last_op_id_text' => $value['last_op_id_text'],
'last_op_type_text' => $value['last_op_type_text'],
'settlement_type_text' => $value['settlement_type_text'],
'settlement_begin_time' => $value['settlement_begin_time'],
'settlement_end_time' => $value['settlement_end_time'],
'create_time' => $value['create_time'],
'status_text' => promoteWithdrawStatus($value['status']),
'respond' => $value['respond'],
];
}
$field = [
'promote_account' => '推广员账号',
'widthdraw_number' => '结算单号',
'sum_money' => '结算金额',
'op_id_text' => '操作人',
'op_type_text' => '操作人类型',
'last_op_id_text' => '最后操作人',
'last_op_type_text' => '最后操作人类型',
'settlement_type_text' => '提现模式',
'settlement_begin_time' => '结算开始时间',
'settlement_end_time' => '结算截止时间',
'create_time' => '提现时间',
'status_text' => '提现状态',
'respond' => '说明',
];
data2csv($data,"推广结算", $field);
exit;
}
if (!empty($_REQUEST['settlement_number'])) {
$map['settlement_number'] = $_REQUEST['settlement_number'];
$page = set_pagination($count, $row);
if($page) {
$this->assign('_page', $page);
}
$this->assign('settlementTypeList', $settlementTypeList);
$this->assign('records', $records);
$this->display();
}
}
$map['developers'] = 0;
private function getOpTypeText($type, $id)
{
switch ($type) {
case 1:
return get_promote_name($id);
break;
case 2:
return getAdminNickname($id);
break;
default:
return '自动';
break;
}
}
$model = array(
'm_name' => 'settlement',
'fields' => array(
'settlement_number',
'starttime', 'endtime',
'promote_id', 'promote_account',
'sum(total_money) as total_money',
'sum(total_number) as total_number',
'sum(sum_money) as sum_money',
'bind_coin_status',
'create_time'),
'group' => 'promote_id,starttime,endtime,create_time,bind_coin_status',
'order' => 'create_time desc ',
'title' => '结算账单',
'template_list' => 'settlement',
);
//为数据权限添加
setPowerPromoteIds($map);
$map1 = $map;
public function settlementWithdraw()
{
$promoteId = intval(I('promote_id', 0));
$settlementType = intval(I('settlement_type', 0));
$time = I('time', '');
if (empty($promoteId)) {
$data['status'] = 0;
$data['msg'] = '请选择会长账号';
$this->ajaxReturn($data);
}
if (empty($settlementType)) {
$data['status'] = 0;
$data['msg'] = '请选择提现模式';
$this->ajaxReturn($data);
}
if (empty($time)) {
$data['status'] = 0;
$data['msg'] = '请选择充值时间';
$this->ajaxReturn($data);
}
$ztotal = null_to_0(D('settlement')->where($map1)->sum('sum_money*10000') / 10000);
$this->assign('ztotal', $ztotal);
$ttotal = null_to_0(D('settlement')->where('create_time' . total(1))->sum('sum_money*10000') / 10000);
$this->assign('ttotal', $ttotal);
$ytotal = null_to_0(D('settlement')->where('create_time' . total(5))->sum('sum_money*10000') / 10000);
$this->assign('ytotal', $ytotal);
$user = A('Bill', 'Event');
$promote = M('promote', 'tab_')->find($promoteId);
if (empty($promote)) {
$data['status'] = 0;
$data['msg'] = '数据异常';
$this->ajaxReturn($data);
}
if ($promote['level'] != 1) {
$data['status'] = 0;
$data['msg'] = '非会长账号,无法执行此操作';
$this->ajaxReturn($data);
}
if ($promote['ver_status'] != 1) {
$data['status'] = 0;
$data['msg'] = '该会长未通过资质认证审核,暂时无法提现';
$this->ajaxReturn($data);
}
if ($promote['settlement_type'] == 1) {
if (!in_array($settlementType, [1, 3])) {
$data['status'] = 0;
$data['msg'] = '参数异常';
$this->ajaxReturn($data);
}
} else {
if ($settlementType != 2) {
$data['status'] = 0;
$data['msg'] = '参数异常';
$this->ajaxReturn($data);
}
}
$user->money_list($model, $p, $map);
if ($settlementType == 1) {
$time = explode(' 至 ', $time);
if (count($time) != 2) {
$data['status'] = 0;
$data['msg'] = '参数异常';
$this->ajaxReturn($data);
}
$beginTime = strtotime($time[0]);
$endTime = strtotime($time[1]) + 3600 * 24 - 1;
} else {
$beginTime = strtotime($time);
$endTime = strtotime('+1 month', $beginTime) - 1;
}
$withdrawModel = new WithdrawModel();
$data['begin_time'] = $beginTime;
$data['end_time'] = $endTime;
$data['op_id'] = is_login();
$data['op_type'] = 2;
switch ($settlementType) {
case 1:
$result = $withdrawModel->promoteWithdrawWeeklyByPromote($promote, false, $data);
break;
case 2:
$result = $withdrawModel->promoteWithdrawPerMonthByPromote($promote, false, $data);
break;
case 3:
$result = $withdrawModel->promoteWithdrawRecoupByPromote($promote, $data);
break;
}
$data = [];
$data['status'] = 0;
switch ($result) {
case -4:
case -3:
$data['msg'] = '无可补点订单';
break;
case -2:
if ($settlementType == 3) {
$data['msg'] = '无可补点订单';
} else {
$data['msg'] = '累计结算低于100元, 无法提现! ';
}
break;
case -1:
case 0:
$data['msg'] = '操作失败';
break;
case 1:
$data['status'] = 1;
$data['msg'] = '操作成功';
break;
}
$this->ajaxReturn($data);
}
public function renewReview()
{
$id = intval(I('id', 0));
$data = M('withdraw', 'tab_')->find($id);
if (empty($data) || $data['status'] != -1) {
$data['status'] = 0;
$data['msg'] = '数据异常';
$this->ajaxReturn($data);
}
$save['id'] = $id;
$save['status'] = 0;
$save['last_up_update_time'] = time();
$save['last_op_id'] = is_login();
$save['last_op_type'] = 2;
$res = M('withdraw', 'tab_')->save($save);
if ($res === false) {
$data['status'] = 0;
$data['msg'] = '提交失败';
} else {
$data['status'] = 1;
$data['msg'] = '提交成功';
}
$this->ajaxReturn($data);
}
public function cancelWithdraw()
{
$id = intval(I('id', 0));
$data = M('withdraw', 'tab_')->find($id);
if (empty($data) || !in_array($data['status'], [-1, 0])) {
$data['status'] = 0;
$data['msg'] = '数据异常';
$this->ajaxReturn($data);
}
$time = time();
$data['status'] = 1;
$data['msg'] = '撤销成功';
$withdrawSave['id'] = $id;
$withdrawSave['status'] = -2;
$withdrawSave['last_up_update_time'] = $time;
$withdrawSave['last_op_id'] = is_login();
$withdrawSave['last_op_type'] = 2;
if ($data['settlement_type'] == 3) {
$withdrawRes = M('withdraw', 'tab_')->save($withdrawSave);
if ($withdrawRes === false) {
$data['status'] = 0;
$data['msg'] = '撤销失败';
$this->ajaxReturn($data);
}
} else {
$spendMap['withdraw_id'] = $id;
$spendIds = M('Spend', 'tab_')->where($spendMap)->getField('id', true);
if (empty($spendIds)) {
$data['status'] = 0;
$data['msg'] = '数据异常';
$this->ajaxReturn($data);
}
$spendIds = implode(',', $spendIds);
$withdrawSave['spend_ids'] = $spendIds;
M('withdraw', 'tab_')->startTrans();//开启事物
$withdrawRes = M('withdraw', 'tab_')->save($withdrawSave);
if ($withdrawRes === false) {
M('withdraw', 'tab_')->rollback();//事物回滚
$data['status'] = 0;
$data['msg'] = '撤销失败';
$this->ajaxReturn($data);
}
$spendSave['selle_status'] = 0;
$spendSave['withdraw_id'] = 0;
$spendRes = M('spend', 'tab_')->where($spendMap)->save($spendSave);
if ($spendRes === false) {
M('withdraw', 'tab_')->rollback();//事物回滚
$data['status'] = 0;
$data['msg'] = '撤销失败';
} else {
M('withdraw', 'tab_')->commit();//事物提交
}
}
$this->ajaxReturn($data);
}
public function downloadProve()
{
$id = intval(I('id', 0));
if ($id) {
$withdraw = M('withdraw', 'tab_')->find($id);
if (empty($withdraw) || $withdraw['status'] != 2 || !$withdraw['transfer_proof']) {
$this->error('网络异常');
}
$file = new FileController();
$file->download($withdraw['transfer_proof']);
} else {
$this->error('参数异常');
}
}
public function cpsettlement($p = 0)
@ -655,6 +1004,8 @@ class QueryController extends ThinkController
public function withdraw()
{
$page = I('p', 1);
$map['_string'] = '1=1';
$adminid = C('USER_ADMINISTRATOR');//获取超管id
$adminmobile = M('UcenterMember')->field('mobile')->find($adminid);
$this->assign('adminmobile', $adminmobile['mobile']);
@ -664,6 +1015,12 @@ class QueryController extends ThinkController
if (isset($_REQUEST['ti_status'])) {
$map['status'] = $_REQUEST['ti_status'];
}
if (isset($_REQUEST['op_type'])) {
$map['op_type'] = $_REQUEST['op_type'];
}
if (isset($_REQUEST['settlement_type'])) {
$map['settlement_type'] = $_REQUEST['settlement_type'];
}
if (isset($_REQUEST['promote_account'])) {
if ($_REQUEST['promote_account'] == '全部') {
unset($_REQUEST['promote_account']);
@ -672,7 +1029,6 @@ class QueryController extends ThinkController
}
} else {
$map['promote_id'] = array('gt', 0);
}
$order = 'create_time desc';
@ -686,6 +1042,58 @@ class QueryController extends ThinkController
}
}
}
if (I('export', 0) == 1) {
$records = D('withdraw')->field('widthdraw_number, sum_money, promote_account, op_id, op_type, last_op_id, last_op_type, settlement_type, settlement_begin_time, settlement_end_time, create_time, status, respond, audit_time')
->where($map)
->order($order)
->select();
if (!empty($records)) {
$data = [];
foreach ($records as $record) {
$record['op_id_text'] = $this->getOpTypeText($record['op_type'], $record['op_id']);
$record['last_op_id_text'] = $this->getOpTypeText($record['last_op_type'], $record['last_op_id']);
$record['op_type_text'] = getPromoteWithdrawOpType($record['op_type']);
$record['last_op_type_text'] = getPromoteWithdrawOpType($record['last_op_type']);
$record['settlement_type_text'] = getPromoteWithdrawSettlementType($record['settlement_type']);
$data[] = [
'widthdraw_number' => $record['widthdraw_number'],
'sum_money' => $record['sum_money'],
'promote_account' => $record['promote_account'],
'op_id_text' => $this->getOpTypeText($record['op_type'], $record['op_id']),
'last_op_id_text' => $this->getOpTypeText($record['last_op_type'], $record['last_op_id']),
'op_type_text' => getPromoteWithdrawOpType($record['op_type']),
'last_op_type_text' => getPromoteWithdrawOpType($record['last_op_type']),
'settlement_type_text' => getPromoteWithdrawSettlementType($record['settlement_type']),
'settlement_begin_time' => $record['settlement_begin_time'] ? date('Y-m-d H:i:s', $record['settlement_begin_time']) : '--',
'settlement_end_time' => date('Y-m-d H:i:s', $record['settlement_end_time']),
'create_time' => date('Y-m-d H:i:s', $record['create_time']),
'status_text' => promoteWithdrawStatus($record['status']),
'respond' => $record['respond'],
'audit_time' => $record['audit_time'] ? date('Y-m-d H:i:s', $record['audit_time']) : '--',
];
}
$field = [
'widthdraw_number' => '结算单号',
'sum_money' => '结算金额',
'promote_account' => '推广员账号',
'op_id_text' => '操作人',
'op_type_text' => '操作人类型',
'last_op_id_text' => '最后操作人',
'last_op_type_text' => '最后操作人类型',
'settlement_type_text' => '提现模式',
'settlement_begin_time' => '结算开始时间',
'settlement_end_time' => '结算截止时间',
'create_time' => '申请时间',
'status_text' => '提现状态',
'respond' => '说明',
'audit_time' => '审核时间',
];
data2csv($data,"推广结算", $field);
exit;
}
}
$model = array(
'm_name' => 'withdraw',
'order' => $order,
@ -710,8 +1118,43 @@ class QueryController extends ThinkController
//为数据权限添加
setPowerPromoteIds($map);
$this->assign('is_admin', is_administrator());
$user->money_list($model, $p, $map);
$user->money_list($model, $page, $map);
}
public function getWithdraw()
{
$promoteId = intval(I('post.promote_id', 0));
$beginTime = I('post.begin_time', '');
$endTime = I('post.end_time', '');
$msg = '';
if (empty($promoteId) || empty($beginTime) || empty($endTime)) {
$this->ajaxReturn(['msg' => $msg]);
}
$beginTime = strtotime($beginTime);
$endTime = strtotime($endTime) + 3600 * 24 - 1;
$map['promote_id'] = $promoteId;
$map['settlement_end_time'] = ['between', [$beginTime, $endTime]];
$map['status'] = ['neq', -2];
$withdraws = D('withdraw')->field('id, settlement_begin_time, settlement_end_time')
->where($map)
->select();
if (!empty($withdraws)) {
foreach ($withdraws as $withdraw) {
$settlementEndTime = date('Y-m-d', $withdraw['settlement_end_time'] + 1);
if ($withdraw['settlement_begin_time'] > 0) {
$settlementBeginTime = date('Y-m-d', $withdraw['settlement_begin_time']);
$msg .= "{$settlementBeginTime}至{$settlementEndTime}之间的订单已经提现;";
} else {
$msg .= "{$settlementEndTime}之前的订单已经提现;";
}
$msg .= '< br > ';
}
}
$this->ajaxReturn(['msg' => $msg]);
}
public function set_withdraw_status()
@ -901,36 +1344,28 @@ class QueryController extends ThinkController
public function withdrawDetails($id)
{
$page = intval(I('p', 1));
$row = intval(I('row', 10));
$id = intval($id);
$map['withdraw_id'] = $id;
$model = M('Spend', 'tab_');
$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('id');
//提现状态
$withdrawStatus = M('withdraw', 'tab_')
->where(array('id' => $id))
->getField('status');
$withdrawStatus = \Home\Controller\FinanceController::$withdrawStatus[$withdrawStatus];
foreach ($data as & $list) {
$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']);
$withdrawId = intval($id);
$withdraw = D('withdraw')->find($withdrawId);
$records = [];
if (!empty($withdraw) & & !empty($withdraw['game_ratio'])) {
$gameRatios = json_decode($withdraw['game_ratio'], true);
foreach ($gameRatios as $gameId => $gameRatio) {
$gameName = D('game')->where(array('id' => $gameId))->getField('game_name');
foreach ($gameRatio as $list) {
$records[] = [
'settlement_time' => "{$list['begin_time']} - {$list['end_time']}",
'game_name' => $gameName ?? '未知',
'sum_amount' => $list['sum_amount'],
'default_ratio' => $list['default_ratio'] ? $list['default_ratio'] . '%' : '未知',
'ratio' => $list['selle_ratio'] . '%',
'settlement_amount' => bcdiv(bcmul($list['sum_amount'], $list['selle_ratio'], 2), 100, 2),
];
}
}
}
$page = set_pagination($count, $row);
if ($page) {
$this->assign('_page', $page);
}
$this->assign('listData', $data);
$this->assign('withdrawStatus', $withdrawStatus);
$this->assign('settlementType', $withdraw['settlement_type']);
$this->assign('records', $records);
$this->display();
}
@ -1001,7 +1436,6 @@ class QueryController extends ThinkController
}
}
public function marketList($p=1) {
$page = intval($p);
@ -1175,4 +1609,53 @@ class QueryController extends ThinkController
}
public function getPromoteSettlementType()
{
$promoteId = intval(I('post.promote_id', 0));
$settlementType = [];
if ($promoteId > 0) {
$promote = D('promote')->field('level, settlement_type')->where(array('id' => $promoteId))->find();
if (empty($promote) || $promote['level'] != 1 || empty($promote['settlement_type'])) {
$settlementType = [];
} else {
$settlementType = WithdrawModel::$settlementTypeList;
unset($settlementType[WithdrawModel::SETTLEMENT_TYPE_OTHER]);
if ($promote['settlement_type'] == 1) {
unset($settlementType[WithdrawModel::SETTLEMENT_TYPE_MONTH]);
} else {
unset($settlementType[WithdrawModel::SETTLEMENT_TYPE_WEEK]);
unset($settlementType[WithdrawModel::SETTLEMENT_TYPE_RECOUP]);
}
}
}
$this->ajaxReturn(['settlement_type' => $settlementType]);
}
public function getAmountBySettlementType()
{
$withdrawModel = new WithdrawModel();
$promoteId = intval(I('promote_id', 0));
$settlementType = intval(I('settlement_type', 0));
$time = I('time', '');
if (empty($promoteId) || !in_array($settlementType, [2, 3])) {
$this->ajaxReturn(['balance' => 0]);
}
$promote = M('promote', 'tab_')->find($promoteId);
if (empty($promote) || $promote['level'] != 1 || $promote['ver_status'] != 1 || empty($time)) {
$this->ajaxReturn(['balance' => 0]);
}
$data['begin_time'] = strtotime($time);
$data['end_time'] = strtotime('+1 month', $data['begin_time']) - 1;
if ($settlementType == 2) {
$balance = $withdrawModel->getMonthAmount($promote, $data);
} else {
$balance = $withdrawModel->getRecoupAmount($promote, $data);
}
$this->ajaxReturn(['balance' => $balance]);
}
}