You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2813 lines
109 KiB
PHP

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace Admin\Controller;
//use Think\Controller;
/**
* 上下游结算单
* @author cz
*/
class CompanyStatementPoolController extends ThinkController
{
public $CompanyType = [
"1"=>"下游公司",
"2"=>"下游个人",
"3"=>"上游CP"
];
public $IsPayment = [
"1"=>"",
"2"=>""
];
public $WithdrawType = [
"0"=>"周结",
"1"=>"月结",
"2"=>"下游个人补点",
"3"=>"特殊补点",
"4"=>"其他"
];
public $VerifyStatus=[
"-2"=>"拒绝打款",
"-1"=>"审核拒绝",
"0"=>"未审核",
"1"=>"打款信息确认",
"2"=>"审核通过",
"3"=>"打款中",
"4"=>"打款成功",
"5"=>"无需打款",
"6"=>"初审通过",
"-3"=>"初审拒绝",
];
public $InfoVerifyStatus=[
"-1"=>"配置信息不全",
"0"=>"信息未确认",
"1"=>"允许打款",
"2"=>"线下无需打款"
];
public $PayStatus=[
"-1"=>"打款失败",
"0"=>"未打款",
"1"=>"打款成功"
];
public $admininfo;
public $DBModel;
public function _initialize()
{
$this->admininfo = $_SESSION['onethink_admin']['user_auth'];
$this->DBModel = SM("CompanyStatementPool","tab_");
parent::_initialize();
}
public function lists() {
$params = I('get.');
$page = $params['p'] ? intval($params['p']) : 1;
$row = $params['row'] ? intval($params['row']) : 10;
//权限分配
if(!IS_ROOT){
$this->OpAuthList= getModuleControllerAuth();
}
$this->assign('menubtn',$this->menuAuth());
$map = [
"_string"=>"1=1"
];
if (isset($_REQUEST['time_start']) && isset($_REQUEST['time_end'])) {
$time_start = strtotime($_REQUEST['time_start']);
$time_end = strtotime($_REQUEST['time_end'])+ 86399;
$map["_string"] = "(statement_begin_time BETWEEN {$time_start} AND {$time_end}) OR (statement_end_time BETWEEN {$time_start} AND {$time_end}) OR (statement_begin_time <= {$time_end} AND statement_end_time >= {$time_end})";
} elseif (isset($_REQUEST['time_start'])) {
$time_start = strtotime($_REQUEST['time_start']);
$map["_string"] = "(statement_begin_time >= {$time_start} ) OR (statement_end_time >= {$time_start})";
} elseif (isset($_REQUEST['time_end'])) {
$time_end = strtotime($_REQUEST['time_end'])+ 86399;
$map["_string"] = "(statement_begin_time <= {$time_end} ) OR (statement_end_time <= {$time_end})";
}
if (isset($_REQUEST['time_start2']) && isset($_REQUEST['time_end2'])) {
$map['op_time'] = ['between', [strtotime($_REQUEST['time_start2']), strtotime($_REQUEST['time_end2']) + 86399]];
} elseif (isset($_REQUEST['time_start2'])) {
$map['op_time'] = ['EGT', strtotime($_REQUEST['time_start2'])];
} elseif (isset($_REQUEST['time_end2'])) {
$map['op_time'] = ['ELT', strtotime($_REQUEST['time_end2']) + 86399];
}
//其他
if(isset($_REQUEST['company_type'])){
$map['company_type'] = $_REQUEST['company_type'];
}
if(isset($_REQUEST['verify_status'])){
$map['verify_status'] = $_REQUEST['verify_status'];
}
if(isset($_REQUEST['statement_num'])){
$map['statement_num'] = $_REQUEST['statement_num'];
}
if(isset($_REQUEST['is_payment'])){
$map['is_payment'] = $_REQUEST['is_payment'];
}
if(isset($_REQUEST['withdraw_type'])){
$map['withdraw_type'] = $_REQUEST['withdraw_type'];
}
// $this->checkListOrCountAuthRestMap($map);//导出权限
//条件end
$data = $this->DBModel
->field("*")
->where($map)
->order("id desc")
->page($page,$row)->select();
foreach($data as $k => &$v) {
$v['statement_begin_time'] = date('Y.m.d',$v['statement_begin_time']);
$v['statement_end_time'] = date('Y.m.d',$v['statement_end_time']);
$v['company_type_str'] = $this->CompanyType[$v['company_type']];
$v['is_payment_str'] = $this->IsPayment[$v['is_payment']];
// $v['can_export'] = $v['platform_amount'] == 0 ? "0" : '1';
// if($v['company_type'] == 2){
$v['can_export'] = 1;
// }
$v['op_time'] = date('Y.m.d H:i:s',$v['op_time']);
$v["valid"] = "{$v['statement_begin_time']}-{$v['statement_end_time']}";
$v['ext_file_type'] = empty($v['ext_file']) ? "" : "";
$v['withdraw_type'] = $this->WithdrawType[$v['withdraw_type']];;
$v['verify_log'] = json_decode($v['verify_log'], true);
if (isset($params['export'])) {
$symbol = "\n";
} else {
$symbol = "<br>";
}
$v["create"]= "{$v['verify_log']['create_user']} {$symbol} {$v['verify_log']['create_time']}";
if(isset($v['verify_log']['firstverify_user'])){
if($v['verify_status'] == -3){
$ts = "初审拒绝";
}else{
$ts = "初审通过";
}
$v["firstverify"]= "{$ts}({$v['verify_log']['firstverify_user']}) {$symbol} {$v['verify_log']['firstverify_time']}";
$ts = '';
}else{
$v["firstverify"] = '--';
}
if(isset($v['verify_log']['verify_user'])){
if($v['verify_status'] == -1){
$ts = "审核拒绝";
}else{
$ts = "审核通过";
}
$v["verify"]= "{$ts}({$v['verify_log']['verify_user']}) {$symbol} {$v['verify_log']['verify_time']}";
}else{
$v["verify"] = '--';
}
if(isset($v['verify_log']['payment_user'])){
if($v['verify_status'] == -2){
$ts = "拒绝打款";
}elseif($v['verify_status'] == 1){
$ts = "打款信息确认";
}elseif($v['verify_status'] == 2){
$ts = "待打款";
}elseif($v['verify_status'] == 3){
$ts = "打款中";
}elseif($v['verify_status'] == 4){
$ts="打款成功";
}elseif($v['verify_status'] == 5){
$ts="无需打款";
}
$v["payment"]= "{$ts}({$v['verify_log']['payment_user']}){$symbol} {$v['verify_log']['payment_time']}";
}else{
$v["payment"] = '--';
}
// $v['oplist'] = $this->OpAuth($v);
$v['oplist'] = $this->OpAuth($v);
}
// dump($data);die();
$count = $this->DBModel->field("count(id) count,SUM(statement_money) as statement_money,SUM(lack_statement_money) lack_statement_money")->where($map)->find();
// dd($count);
$params['p'] = $page;
$params['row'] = $row;
$page = set_pagination($count['count'], $row, $params);
if ($page) {
$this->assign('_page', $page);
}
$this->assign('data',$data);
$this->assign('count',$count);
$this->assign('CompanyType',$this->CompanyType);
$this->assign('IsPayment',$this->IsPayment);
$this->assign('VerifyStatus',$this->VerifyStatus);
$this->assign('WithdrawType',$this->WithdrawType);
$this->display();
}
//查看
public function viewPool()
{
if(!isset($_REQUEST['id'])){
$this->error('参数错误');
}
$id = $_REQUEST['id'];
$is_export= false;
if (isset($_REQUEST['export']) && $_REQUEST['export']==1){
$is_export = true;
}
//获取基本信息
$infolist = SM("company_statement_info","tab_")->field("*,'1' as st")->where("pool_id = '{$id}'")->select();
//获取母单
$pool_info = SM("company_statement_pool","tab_")
->field('statement_num,create_lack_ids,verify_status,is_payment,withdraw_type,statement_begin_time,statement_end_time,verify_log')->where("id={$id}")->find();
if(!empty($pool_info['create_lack_ids'])){
$l_ids = $pool_info['create_lack_ids'];
$lack_info = SM("company_lack_statement_info","tab_")->field("*,'0' as st")->where("id in ({$l_ids})")->select();
$infolist =array_merge($infolist,$lack_info);
}
if ($is_export) {
$symbol = "\n";
} else {
$symbol = "<br>";
}
$pool_info['verify_log'] = json_decode($pool_info['verify_log'], true);
if(isset($pool_info['verify_log']['firstverify_user'])){
if($pool_info['verify_status'] == -3){
$ts = "初审拒绝";
}else{
$ts = "初审通过";
}
$pool_info["firstverify"]= "{$ts}({$pool_info['verify_log']['firstverify_user']}) {$symbol} {$pool_info['verify_log']['firstverify_time']}";
$ts = '';
}else{
$pool_info["firstverify"] = '--';
}
if(isset($pool_info['verify_log']['verify_user'])){
if($pool_info['verify_status'] == -1){
$ts = "审核拒绝";
}else{
$ts = "审核通过";
}
$pool_info["verify"]= "{$ts}({$pool_info['verify_log']['verify_user']}) {$symbol} {$pool_info['verify_log']['verify_time']}";
}else{
$pool_info["verify"] = '--';
}
if(isset($pool_info['verify_log']['payment_user'])){
if($pool_info['verify_status'] == -2){
$ts = "拒绝打款";
}elseif($pool_info['verify_status'] == 1){
$ts = "打款信息确认";
}elseif($pool_info['verify_status'] == 2){
$ts = "待打款";
}elseif($pool_info['verify_status'] == 3){
$ts = "打款中";
}elseif($pool_info['verify_status'] == 4){
$ts="打款成功";
}elseif($pool_info['verify_status'] == 5){
$ts="无需打款";
}
$pool_info["payment"]= "{$ts}({$pool_info['verify_log']['payment_user']}){$symbol} {$pool_info['verify_log']['payment_time']}";
}else{
$pool_info["payment"] = '--';
}
// dump($pool_info);die();
$statement_num = $pool_info['statement_num'];
$this->assign("pool_data",$pool_info);
$this->assign("title",$statement_num);
$this->assign("pool_status",$pool_info['verify_status']);
$this->assign("is_payment",$pool_info['is_payment']);
$this->assign('show_verify',1);
if($infolist[0]['company_type'] == 3){
//上游
$this->viewCpPool($infolist,$is_export);
}elseif($infolist[0]['company_type'] == 1){
//下游公司
$this->viewPcPool($infolist,$is_export);
}else{
$this->viewPuPool($infolist,$is_export,$pool_info);
}
}
//查看
public function viewUnPaymentPool()
{
if(!isset($_REQUEST['id'])){
$this->error('参数错误');
}
$id = $_REQUEST['id'];
$is_export= false;
if (isset($_REQUEST['export']) && $_REQUEST['export']==1){
$is_export = true;
}
//获取基本信息
$infolist = SM("company_statement_info","tab_")->field("*,'1' as st")->where("pool_id = '{$id}' and pay_status!=1")->select();
//获取母单
$pool_info = SM("company_statement_pool","tab_")->field('statement_num,create_lack_ids,verify_status,is_payment,withdraw_type,statement_begin_time,statement_end_time')->where("id={$id}")->find();
if(!empty($pool_info['create_lack_ids'])){
$l_ids = $pool_info['create_lack_ids'];
$lack_info = SM("company_lack_statement_info","tab_")->field("*,'0' as st")->where("id in ({$l_ids})")->select();
$infolist =array_merge($infolist,$lack_info);
}
// dump($infolist);die();
$statement_num = $pool_info['statement_num'];
$this->assign("title",$statement_num);
$this->assign("pool_status",$pool_info['verify_status']);
$this->assign("is_payment",$pool_info['is_payment']);
if($infolist[0]['company_type'] == 3){
//上游
$this->viewCpPool($infolist,$is_export);
}elseif($infolist[0]['company_type'] == 1){
//下游公司
$this->viewPcPool($infolist,$is_export);
}else{
$this->viewPuPool($infolist,$is_export,$pool_info);
}
}
public function editPool() {
if(!isset($_REQUEST['id'])){
$this->error('参数错误');
}
$id = $_REQUEST['id'];
$is_export= false;
if (isset($_REQUEST['export']) && $_REQUEST['export']==1){
$is_export = true;
}
//获取基本信息
$infolist = SM("company_statement_info","tab_")->field("*,'1' as st")->where("pool_id = '{$id}'")->select();
//获取母单
$pool_info = SM("company_statement_pool","tab_")->field('statement_num,create_lack_ids,verify_status,is_payment,withdraw_type,company_type')->where("id={$id}")->find();
if(!empty($pool_info['create_lack_ids'])){
$l_ids = $pool_info['create_lack_ids'];
$lack_info = SM("company_lack_statement_info","tab_")->field("*,'0' as st")->where("id in ({$l_ids})")->select();
$infolist =array_merge($infolist,$lack_info);
}
$statement_num = $pool_info['statement_num'];
$this->assign("withdraw_type",$pool_info['withdraw_type']);
$this->assign("title",$statement_num);
$this->assign("pool_status",$pool_info['verify_status']);
$this->assign("is_payment",$pool_info['is_payment']);
if ($_REQUEST['type']) {
$this->editSpecialPuPool($infolist,$is_export);
} else {
if($pool_info['company_type'] == 2) {
$this->editPuPool($infolist,$is_export);
} elseif($pool_info['company_type'] == 1) {
$this->editPcPool($infolist, $is_export);
} elseif($pool_info['company_type'] == 3) {
$this->editCpPool($infolist, $is_export);
}
}
}
public function editPuPool(&$infolist,$is_export) {
$line = 1;
$count = [];
$week_line = 2;
//获取对接人
foreach($infolist as $k=>&$v){
$v['statement_info'] = json_decode($v['statement_info'],true);
$v['company_info'] = json_decode($v['company_info'],true);
$v['statement_begin_time'] = date('Y.m.d',$v['statement_begin_time']);
$v['statement_end_time'] = date('Y.m.d',$v['statement_end_time']);
if( isset($v['verify_status'])){
if( $v['verify_status'] ==2 ){
$v['is_payment'] = 2; //不打款
}else{
$v['is_payment'] = 1;
}
}
$cline = $line+1;
if($is_export){
$v['statement_money'] = "=ROUND(";
}
$handle_data = $this->changeDataStruct($v['statement_info'],$is_export,$week_line);
$v['statement_info'] = $handle_data;
$row = 0;
foreach($v['statement_info'] as $ke=>&$va){
$va['row'] = count($va['game_list']);
$row += count($va['game_list']);
foreach($va['game_list'] as $key=>&$val){
$line ++;
if($v['withdraw_type'] != 3) {
if (!$val['increment_ratio']) {
$val['increment_ratio'] = 0;
}
if (!$val['ratio']) {
$val['ratio'] = 0;
}
if (!$val['refund']) {
$val['refund'] = 0;
}
}
if($is_export){
if($v['withdraw_type'] != 3) {
$val['sum_money'] = "=ROUND((K{$line}-L{$line})*(M{$line}+N{$line}),2)";
} else {
$val['sum_money'] = "=ROUND(K{$line}*(M{$line}),2)";
}
$v['statement_money'] .= "N{$line}+";
}else{
$count['platform_amount'] += $val['pay_amount'];
}
}
$count['week_money'] += $va['week_amount'];
$count['sum_money'] += $va['week_amount'];
}
$v['row'] = $row;
if($is_export){
if($v['withdraw_type'] != 3) {
$v['statement_money'] .="O{$cline}-P{$cline},2)";
} else {
$v['statement_money'] = substr($v['statement_money'],0,strlen($v['statement_money'])-1).",2)";
}
}
}
if($is_export){
$count["platform_amount"] = "=ROUND(SUM(K2:K".$line."),2)";
$count["sum_money"] = "=ROUND(SUM(Q2:Q".$line."),2)";
}
$this->assign("data",$infolist);
$this->assign("count",$count);
$this->assign("is_export",$is_export);
$this->display("CompanyStatementPool/editPuPool");
}
//下游汇总结算查看
public function editPcPool(&$infolist,$is_export){
$line = 1;
$count = [];
foreach($infolist as $k=>&$v){
$v['statement_info'] = json_decode($v['statement_info'],true);
$v['company_info'] = json_decode($v['company_info'],true);
$v['statement_begin_time'] = date('Y.m.d',$v['statement_begin_time']);
$v['statement_end_time'] = date('Y.m.d',$v['statement_end_time']);
if( isset($v['verify_status'])){
if( $v['verify_status'] ==2 ){
$v['is_payment'] = 2; //不打款
}else{
$v['is_payment'] = 1;
}
}
$cline = $line+1;
$handle_data = $this->changeDataStructVc($v['statement_info'],$is_export,$cline);
$v['statement_info'] = $handle_data;
// dump($handle_data);
foreach($v['statement_info'] as $ke=>&$va){
$line ++;
if($v['withdraw_type'] != 3) {
if (isset($va['ratio'])) {
$va['increment_ratio'] = 0;
} else {
$va['ratio'] = 0;
}
}
if($is_export){
if($v['withdraw_type'] != 3) {
$va['d_statement_money'] = "=ROUND(D{$line}*(1-G{$line})*(E{$line}+F{$line}),2)";
} else {
$va['d_statement_money'] = "=ROUND(D{$line}*(F{$line}),2)";
}
}else{
if ($v['withdraw_type'] != 3) {
$va['d_statement_money'] = round(($va['pay_amount']-$va['refund'])*($va['ratio']+$va['increment_ratio'])*(100-$va['fax_ratio'])/100/100,2);
$count['platform_amount'] += $va['pay_amount'];
$count['d_statement_money'] += $va['d_statement_money'];
} else {
$va['d_statement_money'] = round((($va['pay_amount']-$va['refund'])*($va['increment_ratio']))/100,2);
$count['platform_amount'] += $va['pay_amount'];
$count['d_statement_money'] += $va['d_statement_money'];
}
}
}
$v['settlement_contact'] = $v['company_info']['link_man'];
if($is_export){
if ($v['withdraw_type'] != 3) {
$v['statement_money'] = "=ROUND(SUM(H{$cline}:H{$line})+J{$cline}-I{$cline},2)";
}
}else{
$count['fine'] += $v['fine'];
$count['reward'] += $v['reward'];
$count['statement_money'] += $v['statement_money'];
}
$v['statement_count'] = count($v['statement_info']);
if($v['statement_count'] == '0'){
$v['statement_count'] = 1;
}
}
if($is_export){
$count["platform_amount"] = "=ROUND(SUM(D2:D".$line."),2)";
$count["d_statement_money"] = "=ROUND(SUM(H2:H".$line."),2)";
$count["fine"] = "=ROUND(SUM(I2:I".$line."),2)";
$count["reward"] = "=ROUND(SUM(J2:J".$line."),2)";
$count["statement_money"] = "=ROUND(SUM(K2:K".$line."),2)";
}
$this->assign("data",$infolist);
$this->assign("count",$count);
$this->assign("is_export",$is_export);
$this->display("CompanyStatementPool/editPcPool");
}
//上游汇总查看及导出
public function editCpPool(&$infolist,$is_export)
{
$line = 2;
$count = [];
//获取平台名
$p_id = array_column($infolist,'company_id');
$map['id'] = ['in',$p_id];
$pl = M("Partner","tab_")->field("id,matche_platform")->where($map)->select();
$Partner = [];
foreach($pl as $k=>$v){
$Partner[$v['id']] = $v['matche_platform'];
}
unset($pl);
//
foreach($infolist as $k=>&$v){
$v['statement_info'] = json_decode($v['statement_info'],true);
$v['company_info'] = json_decode($v['company_info'],true);
$v['statement_begin_time'] = date('Y.m.d',$v['statement_begin_time']);
$v['statement_end_time'] = date('Y.m.d',$v['statement_end_time']);
if( isset($v['verify_status'])){
if( $v['verify_status'] ==2 ){
$v['is_payment'] = 2; //不打款
}else{
$v['is_payment'] = 1;
}
}
$cline = $line+1;
$handle_data = $this->changeDataStructCp($v['statement_info'],$is_export,$cline);
$v['statement_info'] = $handle_data;
foreach($v['statement_info'] as $ke=>&$va){
// dd($va);
$line ++;
$va['company_ratio'] = 100-$va['ratio'];
if($is_export){
$va['d_statement_money'] = "=ROUND(F{$line}*(1-I{$line})*G{$line}*(1-J{$line}),2)";//=ROUND(F3*(1-I3)*G3*(1-J3),2)
}else{
$va['d_statement_money'] = round(($va['pay_amount']-$va['refund'])*(100-$va['promote_ratio'])*$va['ratio']*(100-$va['fax_ratio'])/1000000,2);
$count['platform_amount'] += $va['pay_amount'];
$count['platform_amount2'] += $va['pay_amount'];
$count['d_statement_money'] += $va['d_statement_money'];
}
}
// $handle_data = $this->changeDataStructVc($v['statement_info'],$is_export,$cline);
// $v['statement_info'] = $handle_data;
// dump($v['statement_info']);
$v['matche_platform'] = $Partner[$v['company_id']];
if($is_export){
$v['statement_money'] = "=ROUND(SUM(K{$cline}:K{$line})+M{$cline}-L{$cline},2)";
}else{
$count['fine'] += $v['fine'];
$count['reward'] += $v['reward'];
$count['statement_money'] += $v['statement_money'];
$count['statement_money_s'] += $v['statement_money'];
}
$v['statement_count'] = count($v['statement_info']);
}
if($is_export){
$count["d_statement_money"] = "=ROUND(SUM(K3:K".$line."),2)";
$count["platform_amount"] = "=ROUND(SUM(E3:E".$line."),2)";
$count["platform_amount2"] = "=ROUND(SUM(F3:F".$line."),2)";
$count["fine"] = "=ROUND(SUM(L3:L".$line."),2)";
$count["reward"] = "=ROUND(SUM(M3:M".$line."),2)";
$count["statement_money"] = "=ROUND(SUM(N3:N".$line."),2)";
$count["statement_money_s"] = "=ROUND(SUM(N3:N".$line."),2)";
}
// dd($infolist);
$this->assign("data",$infolist);
$this->assign("count",$count);
$this->assign("is_export",$is_export);
$this->display("CompanyStatementPool/editCpPool");
}
public function editSpecialPuPool(&$infolist,$is_export) {
$line = 1;
$count = [];
$week_line = 2;
//获取对接人
foreach($infolist as $k=>&$v){
$v['statement_info'] = json_decode($v['statement_info'],true);
$v['company_info'] = json_decode($v['company_info'],true);
$v['statement_begin_time'] = date('Y.m.d',$v['statement_begin_time']);
$v['statement_end_time'] = date('Y.m.d',$v['statement_end_time']);
if( isset($v['verify_status'])){
if( $v['verify_status'] ==2 ){
$v['is_payment'] = 2; //不打款
}else{
$v['is_payment'] = 1;
}
}
$cline = $line+1;
if($is_export){
$v['statement_money'] = "=ROUND(";
}
$handle_data = $this->changeDataStruct($v['statement_info'],$is_export,$week_line);
$v['statement_info'] = $handle_data;
$row = 0;
foreach($v['statement_info'] as $ke=>&$va){
$va['row'] = count($va['game_list']);
$row += count($va['game_list']);
foreach($va['game_list'] as $key=>&$val){
$line ++;
if($v['withdraw_type'] != 3) {
// if(!$val['ratio']&&!$val['increment_ratio']) {
// if(isset($val['ratio'])){
// $val['increment_ratio'] = 0;
// }else{
// $val['ratio'] = 0;
// }
// }
if (!$val['increment_ratio']) {
$val['increment_ratio'] = 0;
}
if (!$val['ratio']) {
$val['ratio'] = 0;
}
if (!$val['refund']) {
$val['refund'] = 0;
}
// if(isset($val['ratio'])){
// $val['increment_ratio'] = 0;
// }else{
// $val['ratio'] = 0;
// }
}
if($is_export){
if($v['withdraw_type'] != 3) {
$val['sum_money'] = "=ROUND((K{$line}-L{$line})*(M{$line}+N{$line}),2)";
} else {
$val['sum_money'] = "=ROUND(K{$line}*(M{$line}),2)";
}
$v['statement_money'] .= "N{$line}+";
}else{
$count['platform_amount'] += $val['pay_amount'];
// $count['sum_money'] += $val['sum_money'];
}
}
$count['week_money'] += $va['week_amount'];
$count['sum_money'] += $va['week_amount'];
}
$v['row'] = $row;
if($is_export){
if($v['withdraw_type'] != 3) {
$v['statement_money'] .="O{$cline}-P{$cline},2)";
} else {
$v['statement_money'] = substr($v['statement_money'],0,strlen($v['statement_money'])-1).",2)";
}
}
}
if($is_export){
$count["platform_amount"] = "=ROUND(SUM(K2:K".$line."),2)";
$count["sum_money"] = "=ROUND(SUM(Q2:Q".$line."),2)";
}
// dump($infolist);
$this->assign("data",$infolist);
$this->assign("count",$count);
$this->assign("is_export",$is_export);
$this->display("CompanyStatementPool/editSpecialPuPool");
}
//个人汇总结算查看
public function viewPuPool(&$infolist,$is_export,$pool_info){
$line = 1;
$count = [
"pool_week_count"=>0,//上周数据合计
"pool_lack_count"=>0,//本周未结算流水合计
"sum_money"=>0,//打款合计
"pool_lack_count"=>0,//本周未结算流水合计
"st_lack_count"=>0,//本周暂不结算合计
"st_count"=>0,//本次应支付
'online_pay'=>0,//线上支付
'offline_pay'=>0//线下支付
];
$week_line = 2;
$pool_statement_begin_time = date('Y.m.d', $pool_info['statement_begin_time']);
$pool_statement_end_time = date('Y.m.d', $pool_info['statement_end_time']);
//获取对接人
foreach($infolist as $k=>&$v){
$v['statement_info'] = json_decode($v['statement_info'],true);
$v['company_info'] = json_decode($v['company_info'],true);
$v['statement_begin_time'] = date('Y.m.d',$v['statement_begin_time']);
$v['statement_end_time'] = date('Y.m.d',$v['statement_end_time']);
if( isset($v['verify_status'])){
if( $v['verify_status'] ==2 ){
$v['is_payment'] = 2; //不打款
}else{
$v['is_payment'] = 1;
}
}
$is_statement = $v['st'] == 1 ? true :false;
$cline = $line+1;
if($is_export){
$v['statement_money'] = "=ROUND(";
}
$handle_data = $this->changeDataStruct($v['statement_info'],$is_export,$week_line);
$v['statement_info'] = $handle_data;
$row = 0;
foreach($v['statement_info'] as $ke=>&$va){
$va['row'] = count($va['game_list']);
$row += count($va['game_list']);
foreach($va['game_list'] as $key=>&$val){
$line ++;
if($v['withdraw_type'] != 3) {
if (!$val['increment_ratio']) {
$val['increment_ratio'] = 0;
}
if (!$val['ratio']) {
$val['ratio'] = 0;
}
//上周数据合计
if($val['statement_begin_time'] == $pool_statement_begin_time && $val['statement_end_time'] == $pool_statement_end_time){
$count['pool_week_count'] += $val['pay_amount'];
if($is_export){
$this->setWeekCount($line);
}
}
//本周未结算流水合计
if(!$is_statement){
$count['pool_lack_count'] += $val['pay_amount'];
if($is_export){
$this->setlackCount($line);
}
}
}
if($is_export){
if($v['withdraw_type'] != 3) {
$val['sum_money'] = "=ROUND((K{$line}-L{$line})*(M{$line}+N{$line}),2)";
} else {
$val['sum_money'] = "=ROUND((K{$line}-L{$line})*(N{$line}),2)";
}
$v['statement_money'] .= "S{$line}+";
}else{
$count['platform_amount'] += $val['pay_amount'];
}
}
$count['week_money'] += $va['week_amount'];
$count['sum_money'] += $va['week_amount'];
}
if(!$is_statement){
$count['st_lack_count'] += $v['statement_money'];
}else{
$count['st_count'] += $v['statement_money'];
if($v['is_payment'] == 1){
//线上
$count['online_pay'] += $v['statement_money'];
}else{
$count['offline_pay'] += $v['statement_money'];
}
}
$v['row'] = $row;
if ($v['row'] == '0') {
$v['row'] = 1;
}
if($is_export){
if($v['withdraw_type'] != 3) {
$v['statement_money'] = substr($v['statement_money'],0,strlen($v['statement_money'])-1) . ",2)";
} else {
$v['statement_money'] = substr($v['statement_money'],0,strlen($v['statement_money'])-1).",2)";
}
}
}
// die();
if($is_export){
if($pool_info["withdraw_type"] != 3){
//上周数据合计
$count["pool_week_count"] = $this->setWeekCount($line,true);
$count["pool_lack_count"] = $this->setlackCount($line,true);
//本周暂不结算合计
$count["st_lack_count"] = '=ROUND(SUMIFS(T2:T'.$line.',Y2:Y'.$line.',"否"),2)';
//本次应支付
$count["st_count"] = '=ROUND(SUMIFS(T2:T'.$line.',Y2:Y'.$line.',"是"),2)';
$count["online_pay"] = '=ROUND(SUMIFS(T2:T'.$line.',Y2:Y'.$line.',"是",X2:X'.$line.',"是"),2)';
$count["offline_pay"] = '=ROUND(SUMIFS(T2:T'.$line.',Y2:Y'.$line.',"是",X2:X'.$line.',"否"),2)';
}
$count["platform_amount"] = "=ROUND(SUM(K2:K".$line."),2)";
$count["week_money"] = "=ROUND(SUM(S2:S".$line."),2)";
$count["sum_money"] = "=ROUND(SUM(T2:T".$line."),2)";
}
// die();
$this->assign("data",$infolist);
$this->assign("count",$count);
$this->assign("is_export",$is_export);
$this->assign("withdraw_type",$pool_info["withdraw_type"]);
$this->display("CompanyStatementPool/viewPuPool");
}
//导出中上周结算数据计算
protected function setWeekCount($line,$return = false)
{
global $pool_week_str,$pool_week_line;
if(empty($pool_week_str)){
$pool_week_str = "=";
$pool_week_line = 0;
}
if($pool_week_str == "="){
$pool_week_str .= "SUM(K{$line}:";
}else{
if($line - $pool_week_line > 1){
//不连续
$pool_week_str .= "K{$pool_week_line})+SUM(K{$line}:";
}
}
$pool_week_line = $line;
if($return){
$data = $pool_week_str."K{$line})";
unset($pool_week_str,$pool_week_line);
return $data;
}
}
//本周不结算
protected function setlackCount($line,$return = false)
{
global $pool_lack_str,$pool_lack_line;
if(empty($pool_lack_str)){
$pool_lack_str = "=";
$pool_lack_line = 0;
}
if($pool_lack_str == "="){
$pool_lack_str .= "SUM(K{$line}:";
}else{
if($line - $pool_lack_line > 1){
//不连续
$pool_lack_str .= "K{$pool_lack_line})+SUM(K{$line}:";
}
}
$pool_lack_line = $line;
if($return){
$data = $pool_lack_str."K{$line})";
unset($pool_lack_str,$pool_lack_line);
return $data;
}
}
//改变结构
public function changeDataStruct($statement_info = [],$is_export = 0,&$week_line = 1) {
$game_list = [];
$old_line = $week_line;
//使用时间与会长账号作为键值分离数据
foreach($statement_info as $sk=>$sv){
foreach($sv['game_list'] as $gk=>$gv){
$gv['account'] = $sv['account'];
$game_list[$gv['statement_begin_time'].'-'.$gv['statement_end_time']][$gv['account']][] = $gv;
}
}
$game_data = [];
$handle_data = [];
//处理游戏金额数据
foreach($game_list as $gk => $gv) {
foreach ($gv as $sk => $sv) {
$game_data['account'] = $sk;
$game_data['row'] = count($sv);
if ($game_data['row'] == '0') {
$game_data['row'] = 1;
}
$game_data['time_row'] = count($sv);
if ($game_data['time_row'] == '0') {
$game_data['time_row'] = 1;
}
$game_data['time'] = $gk;
$game_data['week_amount'] = 0;
//周结算金额计算
for ($i=0;;$i++) {
if ($sv[$i]['sum_money']||$sv[$i]['sum_money']=='0') {
$game_data['week_amount'] += $sv[$i]['sum_money']- $sv[$i]['withhold']+$sv[$i]['reward']-$sv[$i]['fine'];
$game_data['withhold_amount'] += $sv[$i]['withhold'];
$game_data['fine'] += $sv[$i]['fine'];
$game_data['reward'] += $sv[$i]['reward'];
} else {
break;
}
}
$game_data['game_list'] = $sv;
array_push($handle_data,$game_data);
$game_data = [];
}
}
$substract = 1;
//添加周结算金额,合并相同的结算时间
foreach($handle_data as $hk => $hv) {
if($hk > 0) {
for (;;) {
if (!$handle_data[$hk-$substract]['time']) {
$substract++;
} else {
break;
}
}
if ($hv['time'] == $handle_data[$hk-$substract]['time']) {
$handle_data[$hk-$substract]['time_row'] += $handle_data[$hk]['time_row'];
$handle_data[$hk-$substract]['week_amount'] += $handle_data[$hk]['week_amount'];
$handle_data[$hk-$substract]['withhold_amount'] += $handle_data[$hk]['withhold_amount'];
unset($handle_data[$hk]['time']);
unset($handle_data[$hk]['time_row']);
unset($handle_data[$hk]['week_amount']);
}
$substract = 1;
}
}
foreach($handle_data as $hk => $hv) {
$substract = 1;
if ($is_export) {
for (;;) {
if (!$handle_data[$hk+$substract]['time']&&$handle_data[$hk+$substract]['account']) {
// if (
// $hv['account'] == 'zj9587' ||
// $hv['account'] == 'ruiyou' || $hv['account'] == 'weicheng') {
// dump($handle_data[$hk]['time']);
// }
$week_line++;
$substract++;
} else {
break;
}
}
if (count($hv['game_list'])>1) {
$week_line += count($hv['game_list'])-1;
}
$handle_data[$hk]['week_amount'] = "=ROUND(SUM(O{$old_line}:O{$week_line})+SUM(P{$old_line}:P{$week_line})-SUM(Q{$old_line}:Q{$week_line})-SUM(R{$old_line}:R{$week_line}),2)";
if ($hk > 0) {
$handle_data[0]['week_amount'] = str_replace($old_line,$week_line,$handle_data[0]['week_amount']);
}
if (count($hv['game_list'])>1) {
$old_line += count($hv['game_list']);
} else {
$old_line++;
}
if(count($hv['game_list'])>1) {
$week_line = $old_line ;
} else {
$week_line = $old_line;
}
}
}
// dump($handle_data);
return $handle_data?$handle_data:[];
}
public function changeDataStructVc($statement_info,$is_export = 0,$cline) {
$game_list = [];
$nline = $cline;
//使用时间与会长账号作为键值分离数据
foreach($statement_info as $sk=>$sv){
$sv['time'] = $sv['statement_begin_time'].'-'.$sv['statement_end_time'];
$game_list[$sv['statement_begin_time'].'-'.$sv['statement_end_time']][] = $sv;
}
$handle_data = [];
$substract = 1;
//处理游戏金额数据
foreach($game_list as $gk => $gv) {
foreach ($gv as $lk => $lv){
if ($lk > 0) {
unset($lv['time']);
} else {
$lv['row'] = count($gv);
$lv['week_amount'] = $lv['sum_money'] - $lv['withhold'] + $lv['reward'] - $lv['fine'];
for (;;) {
if (!$gv[$lk+$substract]) {
break;
} else {
$lv['week_amount'] += $gv[$lk+$substract]['sum_money'] - $gv[$lk+$substract]['withhold'] + $gv[$lk+$substract]['reward'] - $gv[$lk+$substract]['fine'];
$substract++;
unset($gv[$lk+$substract]['time']);
}
}
$substract = 1;
}
array_push($handle_data,$lv);
}
}
foreach($handle_data as $hk => $hv) {
$substract = 1;
if ($is_export) {
if (!$hv['time']) {
continue;
}
for (;;) {
if (!$handle_data[$hk+$substract]['time']&&$handle_data[$hk+$substract]&&$hv['time']) {
$cline++;
$substract++;
} else {
break;
}
}
$handle_data[$hk]['week_amount'] = "=ROUND(SUM(J{$nline}:J{$cline})-SUM(K{$nline}:K{$cline})+SUM(L{$nline}:L{$cline})-SUM(M{$nline}:M{$cline}),2)";
$cline++;
$nline = $cline;
}
}
return $handle_data;
}
public function changeDataStructCp($statement_info,$is_export = 0,$cline) {
$game_list = [];
$nline = $cline;
//使用时间与会长账号作为键值分离数据
foreach($statement_info as $sk=>$sv){
$sv['time'] = $sv['statement_begin_time'].'-'.$sv['statement_end_time'];
$game_list[$sv['statement_begin_time'].'-'.$sv['statement_end_time']][] = $sv;
}
$handle_data = [];
$substract = 1;
//处理游戏金额数据
foreach($game_list as $gk => $gv) {
foreach ($gv as $lk => $lv){
if ($lk > 0) {
unset($lv['time']);
} else {
$lv['row'] = count($gv);
$lv['week_amount'] = $lv['sum_money'] - $lv['withhold'] + $lv['reward'] - $lv['fine'];
for (;;) {
if (!$gv[$lk+$substract]) {
break;
} else {
$lv['week_amount'] += $gv[$lk+$substract]['sum_money'] - $gv[$lk+$substract]['withhold'] + $gv[$lk+$substract]['reward'] - $gv[$lk+$substract]['fine'];
$substract++;
unset($gv[$lk+$substract]['time']);
}
}
$substract = 1;
}
array_push($handle_data,$lv);
}
}
foreach($handle_data as $hk => $hv) {
$substract = 1;
if ($is_export) {
if (!$hv['time']) {
continue;
}
for (;;) {
if (!$handle_data[$hk+$substract]['time']&&$handle_data[$hk+$substract]&&$hv['time']) {
$cline++;
$substract++;
} else {
break;
}
}
$handle_data[$hk]['week_amount'] = "=ROUND(SUM(L{$nline}:L{$cline})-SUM(M{$nline}:M{$cline})+SUM(N{$nline}:N{$cline})-SUM(O{$nline}:O{$cline}),2)";
$cline++;
$nline = $cline;
}
}
return $handle_data;
}
//下游汇总结算查看
public function viewPcPool(&$infolist,$is_export){
$line = 1;
$count = [];
// dd($infolist);
//获取对接人
// $p_id = array_column($infolist,'company_id');
// $map['id'] = ['in',$p_id];
// $pl = M("promote_company","tab_")->field("id,settlement_contact")->where($map)->select();
// $Partner = [];
// foreach($pl as $k=>$v){
// $Partner[$v['id']] = $v['settlement_contact'];
// }
// unset($pl);
foreach($infolist as $k=>&$v){
$v['statement_info'] = json_decode($v['statement_info'],true);
$v['company_info'] = json_decode($v['company_info'],true);
$v['statement_begin_time'] = date('Y.m.d',$v['statement_begin_time']);
$v['statement_end_time'] = date('Y.m.d',$v['statement_end_time']);
if( isset($v['verify_status'])){
if( $v['verify_status'] ==2 ){
$v['is_payment'] = 2; //不打款
}else{
$v['is_payment'] = 1;
}
}
$cline = $line+1;
$handle_data = $this->changeDataStructVc($v['statement_info'],$is_export,$cline);
$v['statement_info'] = $handle_data;
foreach($v['statement_info'] as $ke=>&$va){
$line ++;
if($v['withdraw_type'] != 3) {
if (isset($va['ratio'])) {
$va['increment_ratio'] = 0;
} else {
$va['ratio'] = 0;
}
}
if($is_export){
// if($v['withdraw_type'] != 3) {
// $va['d_statement_money'] = "=ROUND(E{$line}*(1-H{$line})*(F{$line}+G{$line}),2)";
// } else {
// $va['d_statement_money'] = "=ROUND(E{$line}*(G{$line}),2)";
// }
if($v['withdraw_type'] != 3) {
$va['d_statement_money'] = "=ROUND((E{$line}-F{$line})*(1-I{$line})*(H{$line}+G{$line}),2)";
} else {
$va['d_statement_money'] = "=ROUND((E{$line}-F{$line})*(1-I{$line})*(H{$line}),2)";
}
}else{
if ($v['withdraw_type'] != 3) {
$va['d_statement_money'] = round(($va['pay_amount']-$va['refund'])*($va['ratio']+$va['increment_ratio'])*(100-$va['fax_ratio'])/100/100,2);
$count['platform_amount'] += $va['pay_amount'];
$count['d_statement_money'] += $va['d_statement_money'];
} else {
$va['d_statement_money'] = round((($va['pay_amount']-$va['refund'])*($va['increment_ratio']))/100,2);
$count['platform_amount'] += $va['pay_amount'];
$count['d_statement_money'] += $va['d_statement_money'];
}
}
}
$v['settlement_contact'] = $v['company_info']['link_man'];
if($is_export){
if ($v['withdraw_type'] != 3) {
// $v['statement_money'] = "=ROUND(SUM(I{$cline}:I{$line})+K{$cline}-J{$cline},2)";
// $v['statement_money'] = "=ROUND(SUM(H{$cline}:H{$line})+J{$cline}-I{$cline},2)";
$v['statement_money'] = "=ROUND(SUM(N{$cline}:N{$line}),2)";
}
}else{
$count['fine'] += $v['fine'];
$count['reward'] += $v['reward'];
$count['statement_money'] += $v['statement_money'];
$count["statement_money_s"] += $v['statement_money'];
}
$v['statement_count'] = count($v['statement_info']);
if($v['statement_count'] == '0'){
$v['statement_count'] = 1;
}
}
if($is_export){
$count["platform_amount"] = "=ROUND(SUM(E2:E".$line."),2)";
$count["d_statement_money"] = "=ROUND(SUM(J2:J".$line."),2)";
$count["fine"] = "=ROUND(SUM(K2:K".$line."),2)";
$count["reward"] = "=ROUND(SUM(L2:L".$line."),2)";
$count["statement_money"] = "=ROUND(SUM(N2:N".$line."),2)";
$count["statement_money_s"] = "=ROUND(SUM(O2:O".$line."),2)";
}
// dd($infolist);
$this->assign("data",$infolist);
$this->assign("count",$count);
$this->assign("is_export",$is_export);
$this->display("CompanyStatementPool/viewPcPool");
}
//上游汇总查看及导出
public function viewCpPool(&$infolist,$is_export)
{
$line = 2;
$count = [];
//获取平台名
$p_id = array_column($infolist,'company_id');
$map['id'] = ['in',$p_id];
$pl = M("Partner","tab_")->field("id,matche_platform")->where($map)->select();
$Partner = [];
foreach($pl as $k=>$v){
$Partner[$v['id']] = $v['matche_platform'];
}
unset($pl);
//
foreach($infolist as $k=>&$v){
$v['statement_info'] = json_decode($v['statement_info'],true);
$v['company_info'] = json_decode($v['company_info'],true);
$v['statement_begin_time'] = date('Y.m.d',$v['statement_begin_time']);
$v['statement_end_time'] = date('Y.m.d',$v['statement_end_time']);
if( isset($v['verify_status'])){
if( $v['verify_status'] ==2 ){
$v['is_payment'] = 2; //不打款
}else{
$v['is_payment'] = 1;
}
}
$cline = $line+1;
$handle_data = $this->changeDataStructCp($v['statement_info'],$is_export,$cline);
$v['statement_info'] = $handle_data;
foreach($v['statement_info'] as $ke=>&$va){
// dd($va);
$line ++;
$va['company_ratio'] = 100-$va['ratio'];
if($is_export){
$va['d_statement_money'] = "=ROUND((F{$line}-G{$line})*(1-J{$line})*H{$line}*(1-K{$line}),2)";//=ROUND(F3*(1-I3)*G3*(1-J3),2)
}else{
$va['d_statement_money'] = round(($va['pay_amount']-$va['refund'])*(100-$va['promote_ratio'])*$va['ratio']*(100-$va['fax_ratio'])/1000000,2);
$count['platform_amount'] += $va['pay_amount'];
$count['platform_amount2'] += $va['pay_amount'];
$count['d_statement_money'] += $va['d_statement_money'];
}
}
// $handle_data = $this->changeDataStructVc($v['statement_info'],$is_export,$cline);
// $v['statement_info'] = $handle_data;
// dump($v['statement_info']);
$v['matche_platform'] = $Partner[$v['company_id']];
if($is_export){
// $v['statement_money'] = "=ROUND(SUM(K{$cline}:K{$line})+M{$cline}-L{$cline},2)";
$v['statement_money'] = "=ROUND(SUM(P{$cline}:P{$line}),2)";
}else{
$count['fine'] += $v['fine'];
$count['reward'] += $v['reward'];
$count['statement_money'] += $v['statement_money'];
$count['statement_money_s'] += $v['statement_money'];
}
$v['statement_count'] = count($v['statement_info']);
}
if($is_export){
$count["d_statement_money"] = "=ROUND(SUM(L3:L".$line."),2)";
$count["platform_amount"] = "=ROUND(SUM(E3:E".$line."),2)";
$count["platform_amount2"] = "=ROUND(SUM(F3:F".$line."),2)";
$count["fine"] = "=ROUND(SUM(M3:M".$line."),2)";
$count["reward"] = "=ROUND(SUM(N3:N".$line."),2)";
$count["statement_money"] = "=ROUND(SUM(P3:P".$line."),2)";
$count["statement_money_s"] = "=ROUND(SUM(Q3:Q".$line."),2)";
}
// dd($infolist);
$this->assign("data",$infolist);
$this->assign("count",$count);
$this->assign("is_export",$is_export);
$this->display("CompanyStatementPool/viewCpPool");
}
//审批通过
public function verifyAgree(){
$this->setVerifyStatus(6,1,"payment",false);
$this->setVerifyStatus(1,2,"verify");
}
public function verifyRefuse(){
$this->setVerifyStatus([1,6],-1,"verify");
}
//审批通过
public function firstverifyAgree(){
$this->setVerifyStatus(0,6,"firstverify");
}
public function firstverifyRefuse(){
$this->setVerifyStatus(0,-3,"firstverify");
}
//审批撤回
public function verifyReturn() {
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
$ids = $_REQUEST['ids'];
$dbres = $this->DBModel->field("id,verify_status,verify_log")->where("id in ({$ids})")->select();
if ($this->checkStatementPay($ids)) {
$this->ajaxReturn(array(
'status' => 0,
"info"=>"已有打款的详单,审批撤回失败"
));
}
foreach($dbres as $k=>&$v){
$VerifyStatus = $v['verify_status'];
if(!in_array($VerifyStatus,[-1,1,2])) continue;
$v['verify_log'] = json_decode($v['verify_log'],true);
unset($v['verify_log']['verify_user']);
unset($v['verify_log']['verify_time']);
if(isset($v['verify_log']['payment_user'])) unset($v['verify_log']['payment_user']);
if(isset($v['verify_log']['payment_time'])) unset($v['verify_log']['payment_time']);
$v['verify_log'] = json_encode($v['verify_log']);
$v['verify_status']=6;
$this->delPayInfo($v['id']);
$this->DBModel->save($v);
addOperationLog(['op_type'=>1,'key'=>$v['id'],"op_name"=>"审批撤回",'url'=>U('lists')]);
}
$this->ajaxReturn(array(
'status' => 1,
"info"=>"审批撤回成功"
));
}
public function checkStatementPay($ids) {
$dbres = $this->DBModel->field("id,verify_status,verify_log")->where("id in ({$ids})")->select();
foreach ($dbres as $k=>$v) {
if ($v['verify_status'] == 3) {
return true;
}
}
return false;
}
public function delPayInfo($id) {
$company_statement_info = SM("company_statement_info","tab_")->field("id")->where("pool_id={$id}")->select();
//有一笔单子已打款将不可撤回
foreach ($company_statement_info as $key => $value) {
if($value['pay_status'] == 1) {
return;
}
}
//线上打款审核状态撤回
SM("company_statement_info","tab_")->where("pool_id={$id}")->save(['pay_verify_status'=>0,'verify_time'=>'','verify_member_id'=>0,'pay_check'=>0,'remark'=>'']);
//线上打款支付宝状态撤回
SM("company_statement_info","tab_")->where("pool_id={$id} and verify_status != 2")->save(['verify_status'=>0]);
foreach ($company_statement_info as $key => $value) {
$is_hav = SM("pay_statement_info","tab_")->where(['statement_info_id'=>$value['id']])->find();
if ($is_hav) {
SM("pay_statement_info","tab_")->where(['statement_info_id'=>$value['id']])->delete();
}
}
}
//线下打款
public function setUlPayment()
{
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
$ids = $_REQUEST['ids'];
//修改info
$ires = SM("company_statement_info","tab_")->where("pool_id='{$ids}'")->save(['pay_type'=>3,'pay_status'=>1]);
if($ires !== false){
$this->setVerifyStatus(1,4,"payment");
}
$this->ajaxReturn(array(
'status' =>0,
"info"=>"线下打款失败"
));
}
protected function setVerifyStatus($old_status,$change_status,$op_pre,$ajaxreturn=true)
{
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
$ids = $_REQUEST['ids'];
$dbres = $this->DBModel->field("id,verify_status,verify_log")->where("id in ({$ids})")->select();
foreach($dbres as $k=>&$v){
if(is_array($old_status)){
if(!in_array($v['verify_status'],$old_status)) continue;
}else{
if($v['verify_status'] != $old_status) continue;
}
$v['verify_log'] = json_decode($v['verify_log'],true);
$v['verify_log'][$op_pre.'_user']=$this->admininfo["username"];
$v['verify_log'][$op_pre.'_time']=date("Y.m.d H:i:s");
$v['verify_log'] = json_encode($v['verify_log']);
$v['verify_status']=$change_status;
$this->DBModel->save($v);
$opname = $this->VerifyStatus[$change_status];
addOperationLog(['op_type'=>1,'key'=>$v['id'],"op_name"=>$opname,'url'=>U('lists')]);
}
if($ajaxreturn){
if ($change_status == 2) {
$this->autoSetPayment($ids);
$this->splitForPayStatementInfo();
}
$this->ajaxReturn(array(
'status' => 1,
"info"=>$opname."成功"
));
}
}
protected function setOneVerifyStatus($change_status,$op_pre,$id,$mgs = "操作")
{
$dbres = $this->DBModel->field("id,verify_status,verify_log")->where("id = {$id}")->find();
$dbres['verify_log'] = json_decode($dbres['verify_log'],true);
$dbres['verify_log'][$op_pre.'_user']=$this->admininfo["username"];
$dbres['verify_log'][$op_pre.'_time']=date("Y.m.d H:i:s");
$dbres['verify_log'] = json_encode($dbres['verify_log']);
$dbres['verify_status']=$change_status;
$this->DBModel->save($dbres);
addOperationLog(['op_type'=>1,'key'=>$id,"op_name"=>$mgs,'url'=>U('lists')]);
$this->ajaxReturn(array(
'status' => 1,
"info"=>$mgs."成功"
));
}
public function autoSetPayment($pool_id) {
$CompanyInfo = M("company_statement_info","tab_");
$pool_id = explode(',',$pool_id);
foreach ($pool_id as $pkey => $pvalue) {
$data = $CompanyInfo->where(['pool_id'=>['in',$pvalue]])->select();
foreach ($data as $key => $value) {
if($value['verify_status'] != 2) {
$CompanyInfo->where(['id'=>$value['id']])->save(['verify_status'=>1]);
}
}
}
//循环保存
// foreach($info as $k=>$v){
// $ydata = $CompanyInfo->where("id= '{$k}'")->find();
// $company_info = json_decode($ydata['company_info'],true);
// if($ydata['verify_status'] == 2){
// $company_info['payee_name'] = $v['payee_name'];
// $company_info['bank_account'] = $v['bank_account'];
// $company_info['opening_bank'] = $v['opening_bank'];
// }else{
// $company_info['ali_user'] = $v['ali_user'];
// $company_info['ali_account'] = $v['ali_account'];
// }
// $savedata = [
// "company_info"=>json_encode($company_info,JSON_UNESCAPED_UNICODE),
// "remark"=>$v['remark'],
// "id"=>$k
// ];
// if($ydata['verify_status'] != 2){
// if(empty($v['ali_user']) || empty($v['ali_account'])){
// $savedata['verify_status'] = -1;
// }else{
// $savedata['verify_status'] = 1;
// }
// }
// $CompanyInfo->save($savedata);
// }
// $verify_status = $this->DBModel->field("verify_status")->where("id = {$pool_id}")->find()['verify_status'];
// if( $verify_status == 6){
// $this->setOneVerifyStatus(1,"payment",$_REQUEST['pool_id'],$mgs = "打款信息确认");
// }else{
// $this->ajaxReturn(array(
// 'status' => 1,
// "info"=>"打款信息编辑成功"
// ));
// }
}
//打款设置
public function setPayment(){
if(!isset($_REQUEST['id'])) $this->error("参数错误");
$id = $_REQUEST['id'];
$CompanyInfo = SM("company_statement_info","tab_")
->alias('i')
->field("i.id,i.pool_id,i.company_name,i.company_info,i.statement_money,p.statement_num,i.remark,i.pay_status,p.statement_money all_money,i.verify_status")
->join("tab_company_statement_pool p ON p.id = i.pool_id")
->where("pool_id='{$id}'")
->select();
foreach($CompanyInfo as $k=>&$v){
if($v['verify_status'] == 2){
$v['is_payment'] = 2;
}else{
$v['is_payment'] = 1;
}
$v['company_info'] = json_decode($v['company_info'],true);
$v['company_info']['ali_user'] ?? '';
$v['company_info']['ali_account'] ?? '';
}
$this->assign("CompanyInfo",$CompanyInfo);
$this->assign("id",$id);
$this->display();
}
//修改打款设置
public function editPayment(){
if(!isset($_REQUEST['info'])) $this->error("参数错误");
$info = $_REQUEST['info'];
$pool_id = $_REQUEST['pool_id'];
$CompanyInfo = SM("company_statement_info","tab_");
//循环保存
foreach($info as $k=>$v){
$ydata = $CompanyInfo->where("id= '{$k}'")->find();
$company_info = json_decode($ydata['company_info'],true);
if($ydata['verify_status'] == 2){
$company_info['payee_name'] = $v['payee_name'];
$company_info['bank_account'] = $v['bank_account'];
$company_info['opening_bank'] = $v['opening_bank'];
}else{
$company_info['ali_user'] = $v['ali_user'];
$company_info['ali_account'] = $v['ali_account'];
}
$savedata = [
"company_info"=>json_encode($company_info,JSON_UNESCAPED_UNICODE),
"remark"=>$v['remark'],
"id"=>$k
];
if($ydata['verify_status'] != 2){
if(empty($v['ali_user']) || empty($v['ali_account'])){
$savedata['verify_status'] = -1;
}else{
$savedata['verify_status'] = 1;
}
}
$CompanyInfo->save($savedata);
}
$verify_status = $this->DBModel->field("verify_status")->where("id = {$pool_id}")->find()['verify_status'];
if( $verify_status == 6){
$this->setOneVerifyStatus(1,"payment",$_REQUEST['pool_id'],$mgs = "打款信息确认");
}else{
$this->ajaxReturn(array(
'status' => 1,
"info"=>"打款信息编辑成功"
));
}
}
//查看打款信息
public function viewPayment(){
if(!isset($_REQUEST['id'])) $this->error("参数错误");
$id = $_REQUEST['id'];
$CompanyInfo = SM("company_statement_info","tab_")
->alias('i')
->field("i.id,i.pool_id,i.company_name,i.company_info,i.statement_money,p.statement_num,i.remark,i.pay_status,i.verify_status,p.statement_money all_money")
->join("tab_company_statement_pool p ON p.id = i.pool_id")
->where("pool_id='{$id}'")
->select();
foreach($CompanyInfo as $k=>&$v){
$v['company_info'] = json_decode($v['company_info'],true);
$v['company_info']['ali_user'] ?? '';
$v['company_info']['ali_account'] ?? '';
if($v['verify_status'] == 2){
$v['is_payment'] = 2;
}else{
$v['is_payment'] = 1;
}
$v['verify_status_str'] = $this->PayStatus[$v['pay_status']];
if($v['verify_status'] == 1){
if($v['pay_status'] == 1){
$v['pay_type'] = $v['pay_type'] == 1 ? "提现" :"线上打款";
$v['verify_status_str'] .= ("/". $v['pay_type']);
}
}
}
$this->assign("CompanyInfo",$CompanyInfo);
$this->display();
}
//保存备注
public function saveRemark(){
if(!isset($_REQUEST['id'])) $this->error("参数错误");
$id = $_REQUEST['id'];
$remark = $_REQUEST['remark'];
$this->DBModel->where("id = '{$id}'")->save(['remark'=>$remark]);
$this->ajaxReturn(array(
'status' => 1,
'info' => "操作成功"
));
}
//上传凭证
public function uploadVoucher()
{
if(!isset($_REQUEST['id'])) $this->error("参数错误");
$id = $_REQUEST['id'];
$this->assign("id",$id);
$this->display();
}
//修改凭证
public function editVoucher()
{
if(!isset($_REQUEST['id'])) $this->error("参数错误");
$id = $_REQUEST['id'];
$info = $this->DBModel->field("id,ext_file")->where("id = '{$id}'")->find();
$this->assign("id",$id);
$this->assign("ext_file",$info['ext_file']);
$this->display();
}
//保存凭证
public function saveVoucher()
{
if(!isset($_REQUEST['id'])) $this->error("参数错误");
$id = $_REQUEST['id'];
$path = '/Uploads/';
$upload = new \Think\Upload();// 实例化上传类
$upload->maxSize = 0 ;// 设置附件上传大小
$upload->exts = array('jpg', 'gif', 'png', 'jpeg');;// 设置附件上传类型
$upload->rootPath = '.'.$path; // 设置附件上传根目录
$upload->savePath = ''; // 设置附件上传(子)目录
// 上传文件
$info = $upload->upload();
if(!$info) {// 上传错误提示错误信息
$msg = $upload->getError();
$array= array('status' => 0, 'info' => $msg);
}else{// 上传成功
//
$pf = $path.$info['file']['savepath'].$info['file']['savename'];
$save = [
"ext_file"=>$pf,
];
//获取旧值,存在删除
$info = $this->DBModel->field("id,ext_file")->where("id = '{$id}'")->find();
if(!empty($info['ext_file'])){
unlink("./".$info['ext_file']);
}
$this->DBModel->where("id = '{$id}'")->save($save);
$array=array(
'status' => 1,
"info"=>"上传成功",
"file_path"=>$pf,
);
}
$this->ajaxReturn($array);
}
//删除凭证
public function delVoucher(){
if(!isset($_REQUEST['id'])) $this->error("参数错误");
$id = $_REQUEST['id'];
$info = $this->DBModel->field("id,ext_file")->where("id = '{$id}'")->find();
if(!empty($info['ext_file'])){
unlink("./".$info['ext_file']);
}
$save = [
"ext_file"=>'',
];
$this->DBModel->where("id = '{$id}'")->save($save);
// $this->doAddOperationLog($id,"删除凭证");
$this->ajaxReturn(array(
'status' => 1,
'info' => "删除成功"
));
}
//不结算
public function cancelStatement()
{
if(!isset($_REQUEST['id'])) $this->error("参数错误");
$id = $_REQUEST['id'];
//获取结算信息
$v = SM("company_statement_info","tab_")->where("id = '{$id}'")->find();
if(empty($v)){
$this->error("请勿重复操作");
}
$pool = SM("company_statement_pool","tab_")->where("id = {$v['pool_id']}")->find();
// dump($pool);
if ($v['verify_status'] == 2) {
$is_payment = 2;
} else {
$is_payment = 1;
}
//保存未结算
$lackcompany =[
"company_id"=>$v['company_id'],
"company_type"=>$v['company_type'],
"company_name"=>$v['company_name'],
"company_info"=>$v['company_info'],
"statement_money"=>$v['statement_money'],
"pay_amount"=>$v['pay_amount'],
"platform_amount"=>$v['platform_amount'],
"fine"=>$v['fine'],
"reward"=>$v['reward'],
"statement_begin_time"=>$v['statement_begin_time'],
"statement_end_time"=>$v['statement_end_time'],
"is_payment"=>$is_payment,
"statement_pool_num"=>$pool['statement_num'],
"statement_info"=>$v['statement_info'],
"withdraw_type"=>$v['withdraw_type'],
"remark"=>$v["remark"],
];
$l_id = SM("company_lack_statement_info","tab_")->add($lackcompany);
//汇总表
$pool_data = [
"id"=>$pool['id'],
'statement_money'=>$pool['statement_money']-$v['statement_money'],
'pay_amount'=>$pool['pay_amount']-$v['pay_amount'],
'fine'=>$pool['fine']-$v['fine'],
'reward'=>$pool['reward']-$v['reward'],
'lack_statement_money'=>$pool['lack_statement_money']+$v['statement_money'],
'lack_platform_amount'=>$pool['lack_platform_amount']-0+$v['platform_amount'],
'verify_status'=>0
];
//
if(empty($pool['create_lack_ids'])){
$pool_data['create_lack_ids'] = $l_id;
}else{
$pool_data['create_lack_ids'] = $pool['create_lack_ids'].",".$l_id;
}
SM("company_statement_pool","tab_")->save($pool_data);
SM("company_statement_info","tab_")->where("id='{$id}'")->delete();
$this->ajaxReturn(array(
'status' => 1,
"info"=>"不结算成功"
));
}
//撤销汇总
public function cancelPool(){
if(!isset($_REQUEST['id'])) $this->error("参数错误");
$id = $_REQUEST['id'];
//获取基础信息
$db_res = $this->DBModel->where("id='{$id}'")->find();
$is_qz = (substr($db_res['statement_num'],0,2) == "QZ" ? true :false); //强制汇总的都允许回退
if($is_qz){
//强制汇总回退
$this->cancelQzPool($db_res);
}
$re_op = true;
$create_lack_ids = $db_res['create_lack_ids'];
if(!empty($create_lack_ids) && !$is_qz){
$clsi = SM("company_lack_statement_info","tab_")->where("is_pool = 1 and id in ({$create_lack_ids})")->find();
$re_op = true;
if(!empty($clsi)){
$re_op = false; //被引用无法重算
}
}
if($re_op){
//公司及上游回退
if($db_res['company_type'] == 2){
if($db_res['withdraw_type'] == 3) {
$this->cancelCompanyPool($db_res);//公司撤回
} else {
$this->retry($db_res); //个人重算
}
}else{
$this->cancelCompanyPool($db_res);//公司撤回
}
}
}
/**
* 重算 先全删再进行二次生成
*/
public function retry($info)
{
//执行删除
$dids = $info['del_lack_ids'];
$cids = $info['create_lack_ids'];
SM()->startTrans();
//删除info
$infores = SM("company_statement_info","tab_")->where("pool_id = {$info['id']}")->delete();
if($infores === false){
SM()->rollback();
$this->ajaxReturn(array('status' => 0,"info"=>"重算失败"));
}
//删除自己
$poolres = $this->DBModel->where("id = {$info['id']}")->delete();
if($poolres === false){
SM()->rollback();
$this->ajaxReturn(array('status' => 0,"info"=>"重算失败"));
}
//修改引用不足单
if(!empty($dids)){
$dres = SM("company_lack_statement_info","tab_")->where("id in ({$dids})")->save(['is_pool'=>0]);
if($dres === false){
SM()->rollback();
$this->ajaxReturn(array('status' => 0,"info"=>"重算失败"));
}
}
//删除创建的不足单
if(!empty($cids)){
$cres = SM("company_lack_statement_info","tab_")->where("id in ({$cids})")->delete();
if($cres === false){
SM()->rollback();
$this->ajaxReturn(array('status' => 0,"info"=>"重算失败"));
}
}
//重新计算
$stime = $info['statement_end_time']-0+1;
$type = $info['withdraw_type'];
A("CompanyStatementSet")->promoteUserPool($type,$stime,true);
SM()->commit();
$this->ajaxReturn(array(
'status' => 1,
'info' => "重算成功"
));
}
public function cancelQzPool($info){
if(!empty($info['del_lack_ids'])){
SM()->startTrans();//事务
$dbres = SM("company_lack_statement_info","tab_")->where("id in ({$info['del_lack_ids']})")->save(['is_pool'=>0]);
$poolres = $this->DBModel->where("id = {$info['id']}")->delete();
$infores = SM("company_statement_info","tab_")->where("pool_id = {$info['id']}")->delete();
if($dbres !== false && $poolres !== false && $infores !== false){
SM()->commit();
$this->ajaxReturn(array(
'status' => 1,
'info' => "撤销汇总成功"
));
}
}
SM()->rollback();
$this->ajaxReturn(array(
'status' => 0,
'info' => "撤销汇总失败"
));
}
public function cancelCompanyPool($info)
{
if(in_array($info['verify_status'],[3,4])) return;//有打款就不允许回退
$sids = $info['statement_ids'];
$dids = $info['del_lack_ids'];
$cids = $info['create_lack_ids'];
SM()->startTrans();//事务
//删除info
$infores = SM("company_statement_info","tab_")->where("pool_id = {$info['id']}")->delete();
if($infores === false){
SM()->rollback();
$this->ajaxReturn(array('status' => 0,"info"=>"撤销汇总失败"));
}
//删除自己
$poolres = $this->DBModel->where("id = {$info['id']}")->delete();
if($poolres === false){
SM()->rollback();
$this->ajaxReturn(array('status' => 0,"info"=>"撤销汇总失败"));
}
//修改结算单信息
$st_res = SM("company_statement","tab_")->field("id,verify_status,verify_log")->where("id in ({$sids})")->select();
foreach($st_res as $k=>&$v){
$v['verify_log'] = json_decode($v['verify_log'],true);
$v['verify_log']['pool_user']=$this->admininfo["username"];
$v['verify_log']['pool_time']=date("Y.m.d H:i:s");
$v['verify_log'] = json_encode($v['verify_log']);
$v['verify_status']=-2;
$stres = SM("company_statement","tab_")->save($v);
if($stres === false){
SM()->rollback();
$this->ajaxReturn(array('status' => 0,"info"=>"撤销汇总失败"));
}
}
//修改引用不足单
if(!empty($dids)){
$dres = SM("company_lack_statement_info","tab_")->where("id in ({$dids})")->save(['is_pool'=>0]);
if($dres === false){
SM()->rollback();
$this->ajaxReturn(array('status' => 0,"info"=>"撤销汇总失败"));
}
}
//删除创建的不足单
if(!empty($cids)){
$cres = SM("company_lack_statement_info","tab_")->where("id in ({$cids})")->delete();
if($cres === false){
SM()->rollback();
$this->ajaxReturn(array('status' => 0,"info"=>"撤销汇总失败"));
}
}
SM()->commit();
$this->ajaxReturn(array(
'status' => 1,
"info"=>"撤销汇总成功"
));
}
public function OpAuth($info)
{
$id = $info['id'];
$img = $info['ext_file'];
$remark = $info['remark'];
$create_lack_ids = $info['create_lack_ids'];
$is_qz = (substr($info['statement_num'],0,2) == "QZ" ? true :false); //强制汇总的都允许回退
$re_op = true;
if(!empty($create_lack_ids) && !$is_qz){
$clsi = SM("company_lack_statement_info","tab_")->where("is_pool = 1 and id in ({$create_lack_ids})")->find();
$re_op = true;
if(!empty($clsi)){
$re_op = false; //被引用无法重算
}
}
//原始列表
$opBtn = [
"viewPool"=>"<a class='confirm viewPool' data-id='{$id}'>查看</a>",
"editPool"=>"<a class='confirm editPool' data-id='{$id}'>编辑</a>",
"editSpecialPuPool"=>"<a class='confirm editSpecialPuPool' data-id='{$id}'>编辑</a>",
"addRemark"=>"<a class='confirm addRemark' data-id='{$id}'>新增备注</a>",
"editRemark"=>"<a class='confirm editRemark' data-remark='{$remark}' data-id='{$id}'>修改备注</a>",
"viewRemark"=>"<a class='confirm viewRemark' data-remark='{$remark}' data-id='{$id}'>查看备注</a>",
"uploadVoucher"=>"<a class='confirm uploadVoucher' data-id='{$id}'>上传凭证</a>",
"viewVoucher"=>"<a class='confirm viewVoucher' data-img='{$img}' data-id='{$id}'>查看凭证</a>",
"editVoucher"=>" <a class='confirm editVoucher' data-id='{$id}'>编辑凭证</a>",
"setUlPayment"=>"<a class='confirm setUlPayment' data-id='{$id}'>线下打款</a>",
"setPayment"=>"<a class='confirm setPayment' data-id='{$id}'>打款信息确认</a>",
"editPayment"=>"<a class='confirm editPayment' data-id='{$id}'>打款信息编辑</a>",
"viewPayment"=>"<a class='confirm viewPayment' data-id='{$id}'>打款详情</a>",
'reCount'=>"<a class='confirm reCount' data-id='{$id}'>重算</a>",
'cancelPool'=>"<a class='confirm cancelPool' data-id='{$id}'>撤销汇总</a>",
];
//操作对应菜单
$optist = [];
switch ($info['verify_status']) {
case '-2':
case '-1':
case '0':
$optist = ["viewPool","reCount","cancelPool"];
break;
case '1':
$optist = ["viewPool",
// "addRemark","viewRemark","editRemark",
"viewVoucher","editVoucher","uploadVoucher","editPayment","setUlPayment"];
break;
case '2':
$optist = ["viewPool",
// "addRemark","viewRemark","editRemark",
"viewVoucher","editVoucher","uploadVoucher"];
break;
case '3':
$optist = ["viewPool",
// "addRemark","viewRemark","editRemark",
"viewVoucher","editVoucher","uploadVoucher","viewPayment"];
break;
case '4':
$optist = ["viewPool",
// "addRemark","viewRemark","editRemark",
"viewVoucher","editVoucher","uploadVoucher","viewPayment"];
break;
case '5':
$optist = ["viewPool",
// "addRemark","viewRemark","editRemark",
"reCount","cancelPool"];
break;
case '6':
$optist = ["viewPool",
// "addRemark","viewRemark","editRemark",
"reCount","cancelPool"];
// ,"setPayment"];
break;
default:
break;
}
// if($info['platform_amount'] <= 0 && $info['company_type'] != 2){
// $optist = array_diff($optist, ["viewPool"]);
// }
//个人重算,上游撤销
if($re_op){
if($is_qz){
$optist = array_diff($optist, ["reCount"]);
}else{
if($info['company_type'] == 2){
$optist = array_diff($optist, ["cancelPool"]);
}else{
$optist = array_diff($optist, ["reCount"]);
}
}
}else{
$optist = array_diff($optist, ["cancelPool","reCount"]);
}
if ($info['withdraw_type'] == "特殊补点") {
$optist = array_diff($optist, ["cancelPool"]);
if ($info['verify_status'] == '0' || $info['verify_status'] == '6'|| $info['verify_status'] == '-3') {
array_push($optist,"cancelPool");
}
}
if ($info['withdraw_type'] == "特殊补点") {
$optist = array_diff($optist, ["reCount"]);
if ($info['company_type'] == 2 && $info['verify_status'] == '0') {
array_push($optist,'editSpecialPuPool');
}
}
if(($info['verify_status'] == '6' || $info['verify_status'] == '0') &&!($info['company_type'] == 2 && $info['withdraw_type'] == "特殊补点")) {
array_push($optist,"editPool");
}
if(empty($info['ext_file'])){
//未上传凭证
$optist = array_diff($optist, ["viewVoucher", "editVoucher"]);
}else{
$optist = array_diff($optist, ["uploadVoucher"]);
}
if($info['is_payment'] == 1){
$optist = array_diff($optist, ["setUlPayment"]);
}else{
$optist = array_diff($optist, ["setPayment","editPayment","viewPayment"]);
}
if(empty($info['remark'])){
//未上传备注
$optist = array_diff($optist, ["editRemark", "viewRemark"]);
}else{
$optist = array_diff($optist, ["addRemark"]);
}
//
$resarr = [];
foreach ($optist as $k => $v) {
if(IS_ROOT){
$resarr[] = $opBtn[$v];
}else{
if(in_array($v,$this->OpAuthList)){
$resarr[] = $opBtn[$v];
}
}
}
return $resarr;
}
public function menuAuth()
{
$mentBtn = [
"firstverifyAgree"=>"<a class='butn' id='firstverifyAgree'>初审通过</a>",
"firstverifyRefuse"=>"<a class='butn' id='firstverifyRefuse' style='background-color: red;'>初审拒绝</a>",
"verifyAgree"=>"<a class='butn' id='verifyAgree'>审核通过</a>",
"verifyRefuse"=>"<a class='butn' id='verifyRefuse' style='background-color: red;'>审核拒绝</a>",
"verifyReturn"=>"<a class='butn' id='verifyReturn'>审核撤回</a>",
"export"=>"<a class='butn' id='export'>导出</a>"
];
$resarr = [];
foreach ($mentBtn as $k => $v) {
if(IS_ROOT){
$resarr[] = $v;
}else{
if(in_array($k,$this->OpAuthList)){
$resarr[] = $v;
}
}
}
return $resarr;
}
//编辑个人结算单
public function editCompanyStatementPool() {
$data = $_POST;
if (!$data) {
$this->ajaxReturn(['status'=>0,'info'=>'数据错误']);
}
$ratio = $data['ratio'];
$refund = $data['refund'];
$withhold = $data['withhold'];
$increment_ratio = $data['increment_ratio'];
$sum_money = $data['sum_money'];
$st = $data['st'];
$id = $data['id'];
$remark = $data['remark'];
$amount = 0;
$statement_amount = 0;
$statement_lack_amount = 0;
$reward = 0;
$fine = 0;
$lreward = 0;
$lfine = 0;
$handledata = [];
// dump($sum_money);
// dump($ratio);
// dump($refund);
// dump($withhold);
// dump($increment_ratio);
// dump($st);
//die();
foreach ($st as $key => $value) {
$statement_info = array();
foreach($value as $akey => $aval) {
if ($st[$key][$akey] == 1) {
$model = SM("company_statement_info","tab_");
if (!$handledata[$key][1]) {
$handledata[$key][1] = 1;
} else {
continue;
}
} else {
$model = SM("company_lack_statement_info","tab_");
if (!$handledata[$key][0]) {
$handledata[$key][0] = 1;
} else {
continue;
}
}
$statement_data = $model->where(['id'=>$key])->find();
if ($statement_data['is_reward_fine_split'] == 1) {
$r_data = $model->field("fine,reward")->where(['id'=>$key])->find();
if($model == SM("company_statement_info","tab_")) {
$reward += $r_data['reward'];
$fine += $r_data['fine'];
} else {
$lreward += $r_data['reward'];
$lfine += $r_data['fine'];
}
$model->where(['id'=>$key])->save(['remark'=>$remark[$key][$st[$key][$akey]]]);
break;
}
$statement_info = json_decode($statement_data['statement_info'],true);
foreach ($statement_info as $k => $v) {
$game_list = $v['game_list'];
foreach ($game_list as $gk => $gv) {
if ($ratio[$key][$gv['game_name'].$gv['statement_begin_time'].'-'.$gv['statement_end_time'].$v['account']]) {
$statement_info[$k]['game_list'][$gk]['ratio'] = (int)$ratio[$key][$gv['game_name'].$gv['statement_begin_time'].'-'.$gv['statement_end_time'].$v['account']];
}
$statement_info[$k]['game_list'][$gk]['refund'] = $refund[$key][$gv['game_name'].$gv['statement_begin_time'].'-'.$gv['statement_end_time'].$v['account']];
// dump($gv['game_name'].$gv['statement_begin_time'].'-'.$gv['statement_end_time'].$v['account']);
// dump($withhold[$key][$gv['game_name'].$gv['statement_begin_time'].'-'.$gv['statement_end_time'].$v['account']][$gv['statement_begin_time']]);
$statement_info[$k]['game_list'][$gk]['withhold'] = $withhold[$key][$gv['game_name'].$gv['statement_begin_time'].'-'.$gv['statement_end_time'].$v['account']][$gv['statement_begin_time']];
$withhold[$key][$gv['game_name'].$gv['statement_begin_time'].'-'.$gv['statement_end_time'].$v['account']][$gv['statement_begin_time']] = 0;
$statement_info[$k]['game_list'][$gk]['increment_ratio'] = $increment_ratio[$key][$gv['game_name'].$gv['statement_begin_time'].'-'.$gv['statement_end_time'].$v['account']];
$statement_info[$k]['game_list'][$gk]['sum_money'] = $sum_money[$key][$gv['game_name'].$gv['statement_begin_time'].'-'.$gv['statement_end_time'].$v['account']];
$amount += $sum_money[$key][$gv['game_name'].$gv['statement_begin_time'].'-'.$gv['statement_end_time'].$v['account']] - $statement_info[$k]['game_list'][$gk]['withhold'];
if ($st[$key][$akey] == 1) {
$statement_amount += $sum_money[$key][$gv['game_name'].$gv['statement_begin_time'].'-'.$gv['statement_end_time'].$v['account']]-$statement_info[$k]['game_list'][$gk]['withhold'];
} else {
$statement_lack_amount += $sum_money[$key][$gv['game_name'].$gv['statement_begin_time'].'-'.$gv['statement_end_time'].$v['account']]-$statement_info[$k]['game_list'][$gk]['withhold'];
}
}
}
$statement_info_data = json_encode($statement_info);
$r_data = $model->field("fine,reward")->where(['id'=>$key])->find();
if($model == SM("company_statement_info","tab_")) {
$reward += $r_data['reward'];
$fine += $r_data['fine'];
} else {
$lreward += $r_data['reward'];
$lfine += $r_data['fine'];
}
$model->where(['id'=>$key])->save(['statement_info'=>$statement_info_data,'statement_money'=>$amount+($r_data['reward']?$r_data['reward']:0)-($r_data['fine']?$r_data['fine']:0),'pay_amount'=>$amount,'remark'=>$remark[$key][$st[$key][$akey]]]);
$amount = 0;
}
}
//die();
SM("company_statement_pool","tab_")->where(['id'=>$id])->save(['pay_amount'=>$statement_amount,'statement_money'=>$statement_amount+$reward-$fine,'lack_statement_money'=>$statement_lack_amount+$lreward-$lfine]);
$this->ajaxReturn(['status'=>1,'info'=>'保存成功']);
}
//编辑公司结算单
public function editCompanyStatementPoolPc() {
$data = $_POST;
if (!$data) {
$this->ajaxReturn(['status'=>0,'info'=>'数据错误']);
}
$ratio = $data['ratio'];
$refund = $data['refund'];
$withhold = $data['withhold'];
$increment_ratio = $data['increment_ratio'];
$sum_money = $data['sum_money'];
$st = $data['st'];
$id = $data['id'];
$remark = $data['remark'];
$amount = 0;
$statement_amount = 0;
$statement_lack_amount = 0;
$reward = 0;
$fine = 0;
$lreward = 0;
$lfine = 0;
$handledata = [];
// dump($sum_money);
// dump($ratio);
// dump($refund);
// dump($withhold);
// dump($increment_ratio);
// dump($st);
//die();
foreach ($st as $key => $value) {
$statement_info = array();
foreach($value as $akey => $aval) {
if ($st[$key][$akey] == 1) {
$model = SM("company_statement_info","tab_");
if (!$handledata[$key][1]) {
$handledata[$key][1] = 1;
} else {
continue;
}
} else {
$model = SM("company_lack_statement_info","tab_");
if (!$handledata[$key][0]) {
$handledata[$key][0] = 1;
} else {
continue;
}
}
$statement_data = $model->where(['id'=>$key])->find();
if ($statement_data['is_reward_fine_split'] == 1) {
$r_data = $model->field("fine,reward")->where(['id'=>$key])->find();
if($model == SM("company_statement_info","tab_")) {
$reward += $r_data['reward'];
$fine += $r_data['fine'];
} else {
$lreward += $r_data['reward'];
$lfine += $r_data['fine'];
}
$model->where(['id'=>$key])->save(['remark'=>$remark[$key][$st[$key][$akey]]]);
break;
}
$statement_info = json_decode($statement_data['statement_info'],true);
foreach ($statement_info as $k => $v) {
if ($ratio[$key][$v['game_name'].$v['statement_begin_time']]) {
$statement_info[$k]['ratio'] = (int)$ratio[$key][$v['game_name'].$v['statement_begin_time'].'-'.$v['statement_end_time']];
}
$statement_info[$k]['refund'] = $refund[$key][$v['game_name'].$v['statement_begin_time'].'-'.$v['statement_end_time']];
$statement_info[$k]['withhold'] = $withhold[$key][$v['game_name'].$v['statement_begin_time'].'-'.$v['statement_end_time']];
$withhold[$key][$v['game_name'].$v['statement_begin_time'].'-'.$v['statement_end_time']] = 0;
$statement_info[$k]['sum_money'] = $sum_money[$key][$v['game_name'].$v['statement_begin_time'].'-'.$v['statement_end_time']];
$amount += $sum_money[$key][$v['game_name'].$v['statement_begin_time'].'-'.$v['statement_end_time']] - $statement_info[$k]['withhold'];
if ($st[$key][$akey] == 1) {
$statement_amount += $sum_money[$key][$v['game_name'].$v['statement_begin_time'].'-'.$v['statement_end_time']]-$statement_info[$k]['withhold'];
} else {
$statement_lack_amount += $sum_money[$key][$v['game_name'].$v['statement_begin_time'].'-'.$v['statement_end_time']]-$statement_info[$k]['withhold'];
}
}
$statement_info_data = json_encode($statement_info);
$r_data = $model->field("fine,reward")->where(['id'=>$key])->find();
if($model == SM("company_statement_info","tab_")) {
$reward += $r_data['reward'];
$fine += $r_data['fine'];
} else {
$lreward += $r_data['reward'];
$lfine += $r_data['fine'];
}
$model->where(['id'=>$key])->save(['statement_info'=>$statement_info_data,'statement_money'=>$amount+($r_data['reward']?$r_data['reward']:0)-($r_data['fine']?$r_data['fine']:0),'pay_amount'=>$amount,'remark'=>$remark[$key][$st[$key][$akey]]]);
$amount = 0;
}
}
//die();
SM("company_statement_pool","tab_")->where(['id'=>$id])->save(['pay_amount'=>$statement_amount,'statement_money'=>$statement_amount+$reward-$fine,'lack_statement_money'=>$statement_lack_amount+$lreward-$lfine]);
$this->ajaxReturn(['status'=>1,'info'=>'保存成功']);
}
public function splitForPayStatementInfo() {
$ids = $_REQUEST['ids'];
$limit_amount = 50000;
$dbres = $this->DBModel->field("id,company_type")->where("id in ({$ids})")->select();
foreach($dbres as $key=>$value){
$statement_data_info = M("company_statement_info","tab_")
->where(['pool_id'=>$value['id']])
->select();
if ($value['company_type'] == 2){
//循环info汇总详单
foreach ($statement_data_info as $skey => $svalue) {
if ($svalue['verify_status'] == 1) {
$statement_info = json_decode($svalue['statement_info'], true);
$handle_data = [];
foreach ($statement_info as $k => $v) {
$game_list = $v['game_list'];
foreach ($game_list as $gk => $gv) {
//同一结算时间的汇总成一个数组
if (!$handle_data[$gv['statement_begin_time'] . '-' . $gv['statement_end_time']][$v['account']]) {
$handle_data[$gv['statement_begin_time'] . '-' . $gv['statement_end_time']][$v['account']] = ['account' => $v['account'], 'game_list' => [$gv]];
} else {
$handle_data[$gv['statement_begin_time'] . '-' . $gv['statement_end_time']][$v['account']]['game_list'][] = $gv;
}
}
}
$save = [];
$handle_statement = [];
// dump($handle_data);
//将同一时间的汇总详单记录起来
foreach ($handle_data as $hk => $hv) {
$statement_time = explode('-', $hk);
$save['statement_begin_time'] = strtotime(str_replace('.', '-', $statement_time[0]));
$save['statement_end_time'] = strtotime(str_replace('.', '-', $statement_time[1]));
$handle_statement = json_encode(array_values($hv));
$statement_money = 0;
foreach ($hv as $shk => $shv) {
$game_list = $shv['game_list'];
foreach ($game_list as $gk => $gv) {
$statement_money += $gv['sum_money']+$gv['reward']-$gv['fine']-$gv['withhold'];
}
}
if ($statement_money > $limit_amount) {
for ($amount = $statement_money; $amount > 0; $amount -= $limit_amount) {
$save['statement_info'] = $handle_statement;
$save['company_id'] = $svalue['company_id'];
$save['company_name'] = $svalue['company_name'];
$save['company_type'] = $svalue['company_type'];
$save['pay_type'] = $svalue['pay_type'];
$save['verify_status'] = $svalue['verify_status'];
$save['remark'] = $svalue['remark'];
$save['company_info'] = $svalue['company_info'];
$save['statement_num'] = "JS_" . date("YmdHis", time()) . $svalue['company_id'] . sp_random_string(5);
if ($amount > $limit_amount) {
$save['statement_money'] = $limit_amount;
} else {
$save['statement_money'] = $amount;
}
$save['final_statement_money'] = $save['statement_money'];
// $setStatementInfo = json_decode($svalue['statement_info'],true);
// foreach ($setStatementInfo as $sskey => $ssvalue) {
//
// $setStatementInfo[$sskey]['pay_amount'] = $save['statement_money']/(($ssvalue['ratio']-$ssvalue['fax_ratio'])/100);
// $setStatementInfo[$sskey]['sum_money'] = $save['statement_money'];
//
// }
//
// $save['statement_info'] = json_encode($setStatementInfo);
$save['statement_info_id'] = $svalue['id'];
$save['fine'] = $svalue['fine'];
$save['reward'] = $svalue['reward'];
$save['is_limit'] = 1;
SM("pay_statement_info", "tab_")->add($save);
}
} else {
$save['statement_info'] = $handle_statement;
$save['company_id'] = $svalue['company_id'];
$save['company_name'] = $svalue['company_name'];
$save['company_type'] = $svalue['company_type'];
$save['pay_type'] = $svalue['pay_type'];
$save['verify_status'] = $svalue['verify_status'];
$save['remark'] = $svalue['remark'];
$save['company_info'] = $svalue['company_info'];
$save['statement_num'] = "JS_" . date("YmdHis", time()) . $save['company_id'] . sp_random_string(5);
$save['statement_money'] = $statement_money;
$save['final_statement_money'] = $save['statement_money'];
$save['statement_info_id'] = $svalue['id'];
$save['fine'] = $svalue['fine'];
$save['reward'] = $svalue['reward'];
SM("pay_statement_info", "tab_")->add($save);
}
}
}
}
}
else {
foreach ($statement_data_info as $skey => $svalue) {
if ($svalue['verify_status'] == 1) {
$statement_money = $svalue['statement_money'];
if ($statement_money > $limit_amount) {
for ($amount = $statement_money; $amount > 0; $amount -= $limit_amount) {
$save['statement_begin_time'] = $svalue['statement_begin_time'];
$save['statement_end_time'] = $svalue['statement_end_time'];
$save['company_id'] = $svalue['company_id'];
$save['company_name'] = $svalue['company_name'];
$save['company_type'] = $svalue['company_type'];
$save['pay_type'] = $svalue['pay_type'];
$save['verify_status'] = $svalue['verify_status'];
$save['remark'] = $svalue['remark'];
$save['company_info'] = $svalue['company_info'];
$save['statement_num'] = "JS_" . date("YmdHis", time()) . $svalue['company_id'] . sp_random_string(5);
$save['statement_money'] = $svalue['statement_money'];
$save['is_limit'] = 1;
if ($amount > $limit_amount) {
$save['statement_money'] = $limit_amount;
} else {
$save['statement_money'] = $amount;
}
$save['final_statement_money'] = $save['statement_money'];
$setStatementInfo = json_decode($svalue['statement_info'],true);
foreach ($setStatementInfo as $sskey => $ssvalue) {
$setStatementInfo[$sskey]['pay_amount'] = $save['statement_money']/(($ssvalue['ratio']-$ssvalue['fax_ratio'])/100);
$setStatementInfo[$sskey]['sum_money'] = $save['statement_money'];
}
$save['statement_info'] = json_encode($setStatementInfo);
$save['statement_info_id'] = $svalue['id'];
$save['fine'] = $svalue['fine'];
$save['reward'] = $svalue['reward'];
SM("pay_statement_info", "tab_")->add($save);
}
} else {
$save['statement_begin_time'] = $svalue['statement_begin_time'];
$save['statement_end_time'] = $svalue['statement_end_time'];
$save['statement_info'] = $svalue['statement_info'];
$save['company_id'] = $svalue['company_id'];
$save['company_name'] = $svalue['company_name'];
$save['company_type'] = $svalue['company_type'];
$save['pay_type'] = $svalue['pay_type'];
$save['verify_status'] = $svalue['verify_status'];
$save['remark'] = $svalue['remark'];
$save['company_info'] = $svalue['company_info'];
$save['statement_num'] = "JS_" . date("YmdHis", time()) .$svalue['company_id'] . sp_random_string(5);
$save['statement_money'] = $svalue['statement_money'];
$save['final_statement_money'] = $save['statement_money'];
$save['statement_info_id'] = $svalue['id'];
$save['fine'] = $svalue['fine'];
$save['reward'] = $svalue['reward'];
SM("pay_statement_info", "tab_")->add($save);
}
}
}
}
}
}
public function splitRewardOrFailData() {
if (!$_REQUEST['id']||!isset($_REQUEST['st'])) {
$this->ajaxReturn(['msg'=>'数据传输错误','status'=>'0']);
}
$id = $_REQUEST['id'];
$st = $_REQUEST['st'];
if ($st == 1) {
$model = SM("company_statement_info","tab_");
} else {
$model = SM("company_lack_statement_info","tab_");
}
$info = $model
->where(['id'=>$id])
->find();
$statement_info = json_decode($info['statement_info'],true);
// $reward_data = [];
// $fine_data = [];
$handle_statement_data = [];
$settlementAmount = 0;
if ($info['company_type'] == 2) {
foreach ($statement_info as $key => $value) {
$game_info = $value['game_list'];
$handle_statement_data[$key]['account'] = $value['account'];
foreach ($game_info as $gkey => $gvalue) {
// $time_key = $gvalue['statement_begin_time'].$gvalue['statement_end_time'];
$handle_statement_data[$key]['game_list'][$gkey]['game_name'] = '--';
$handle_statement_data[$key]['game_list'][$gkey]['game_type_name'] = '--';
$handle_statement_data[$key]['game_list'][$gkey]['statement_begin_time'] = $gvalue['statement_begin_time'];
$handle_statement_data[$key]['game_list'][$gkey]['statement_end_time'] = $gvalue['statement_end_time'];
$handle_statement_data[$key]['game_list'][$gkey]['reward'] = $gvalue['reward'];
$handle_statement_data[$key]['game_list'][$gkey]['fine'] = $gvalue['fine'];
$handle_statement_data[$key]['game_list'][$gkey]['pay_amount'] = 0;
$handle_statement_data[$key]['game_list'][$gkey]['all_pay_amount'] = 0;
$handle_statement_data[$key]['game_list'][$gkey]['sum_money'] = 0;
$statement_info[$key]['game_list'][$gkey]['reward'] = 0;
$statement_info[$key]['game_list'][$gkey]['fine'] = 0;
$settlementAmount += $gvalue['reward']-$gvalue['fine'];
}
}
} else {
foreach ($statement_info as $key => $value) {
$handle_statement_data[$key]['game_name'] = '--';
$handle_statement_data[$key]['game_type_name'] = '--';
$handle_statement_data[$key]['statement_begin_time'] = $value['statement_begin_time'];
$handle_statement_data[$key]['statement_end_time'] = $value['statement_end_time'];
$handle_statement_data[$key]['reward'] = $value['reward'];
$handle_statement_data[$key]['fine'] = $value['fine'];
$handle_statement_data[$key]['pay_amount'] = 0;
$handle_statement_data[$key]['all_pay_amount'] = 0;
$handle_statement_data[$key]['sum_money'] = 0;
$statement_info[$key]['reward'] = 0;
$statement_info[$key]['fine'] = 0;
$settlementAmount += $value['reward']-$value['fine'];
}
}
// dump($reward_data);
// dump($fine_data);
// die();
if (!$handle_statement_data) {
$this->ajaxReturn(['msg'=>'没有奖罚数据','status'=>'0']);
}
if ($settlementAmount <= 0) {
$this->ajaxReturn(['msg'=>'奖罚结算小于等于0不分离','status'=>'0']);
}
$save['pool_id'] = $info['pool_id']?$info['pool_id']:$_REQUEST['pool_id'];
$save['company_id'] = $info['company_id'];
$save['company_type'] = $info['company_type'];
$save['company_name'] = $info['company_name'];
$save['company_info'] = $info['company_info'];
$save['statement_begin_time'] = $info['statement_begin_time'];
$save['statement_end_time'] = $info['statement_end_time'];
$save['statement_num'] = "JS_" . date("YmdHis", time()) . $info['company_id'] . sp_random_string(5);
$save['withdraw_type'] = $info['withdraw_type'];
$save['verify_status'] = $info['verify_status']?$info['verify_status']:0;
if($st!=1) {
if($info['is_payment'] == 1){
$save['verify_status'] = 0;
}else{
$save['verify_status'] = 2;
}
}
$save['statement_money'] = $settlementAmount;
$save['pay_amount'] = $settlementAmount;
$save['platform_amount'] = $settlementAmount;
$save['is_reward_fine_split'] = 1;
$handle_statement_data = json_encode($handle_statement_data);
//罚款数据
$save['statement_info'] = $handle_statement_data;
$save['reward'] = $info['reward'];
$save['fine'] = $info['fine'];
//罚款新增
SM("company_statement_info","tab_")->add($save);
$model->where(['id'=>$id])->save(['reward'=>0,'fine'=>0,'statement_info'=>json_encode($statement_info),'statement_money'=>$info['statement_money']-$settlementAmount,'pay_amount'=>$info['pay_amount']-$settlementAmount]);
$this->ajaxReturn(['msg'=>'执行成功','status'=>'1']);
}
}