@ -54,13 +54,13 @@ class CompanyStatementController extends ThinkController
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})";
$map["_string"] = "( ( statement_begin_time BETWEEN {$time_start} AND {$time_end}) OR (statement_end_time BETWEEN {$time_start} AND {$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})";
$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})";
$map["_string"] = "( ( statement_begin_time < = {$time_end} ) OR (statement_end_time < = {$time_end}) )";
}
if (isset($_REQUEST['time_start2']) & & isset($_REQUEST['time_end2'])) {
@ -80,6 +80,12 @@ class CompanyStatementController extends ThinkController
$typeflag = 2;//周结
$map["withdraw_type"] = ["in",[0,2]];
}
if($_REQUEST['withdraw_type'] == 3){
$typeflag = 3;//特殊补点
$map["withdraw_type"] = 3;
}
}
if (isset($_REQUEST['withdraw_type2'])) {
if($_REQUEST['withdraw_type2'] == 2){
@ -97,6 +103,22 @@ class CompanyStatementController extends ThinkController
$map['withdraw_type'] = ["in",[0,1]];
}
}
if($_REQUEST['withdraw_type2'] == 3){
if ($typeflag == 3 || !$typeflag) {
$map["withdraw_type"] = 3;
} else {
$map["withdraw_type"] = 999; //两者不一搜索为空
}
} else {
if($typeflag == 3) {
$map["withdraw_type"] = 999; //两者不一搜索为空
}
}
}
//其他
if(isset($_REQUEST['company_type'])){
@ -122,12 +144,14 @@ class CompanyStatementController extends ThinkController
if(isset($_REQUEST['confirm_status'])){
$map['confirm_status'] = $_REQUEST['confirm_status'];
}
// dd($map);
// $this->checkListOrCountAuthRestMap($map);//导出权限
//条件end
$data = M("company_statement","tab_")
->field("id,withdraw_type,company_name,company_belong,statement_begin_time,statement_end_time,statement_money,platform_amount,verify_status,verify_log,confirm_status,confirm_log,op_time,remark")
->where($map)
->order("FIELD(verify_status,0,1,-1,2,3,-2,-3),id desc")->page($page,$row)->select();
->order("statement_begin_time desc,id desc")->page($page,$row)->select();
foreach($data as $k => & $v) {
$v['statement_begin_time'] = date('Y.m.d',$v['statement_begin_time']);
@ -138,8 +162,8 @@ class CompanyStatementController extends ThinkController
$v["valid"] = "{$v['statement_begin_time']}-{$v['statement_end_time']}";
$v['withdraw_type_1'] = ($v['withdraw_type'] == 1 ? "月结" : ($v['withdraw_type'] == 3 ?"特殊补点 " : "周结"));
$v['withdraw_type_2'] = ($v['withdraw_type'] == 2 ? "补点" :"正常结算");
$v['withdraw_type_1'] = ($v['withdraw_type'] == 1 ? "月结" : ($v['withdraw_type'] == 3 ?"其他 " : "周结"));
$v['withdraw_type_2'] = ($v['withdraw_type'] == 2 ? "补点" : ($v['withdraw_type'] == 3 ?"特殊补点" : "正常结算") );
$v['verify_log'] = json_decode($v['verify_log'], true);
$v['confirm_log'] = json_decode($v['confirm_log'], true);
@ -348,7 +372,16 @@ class CompanyStatementController extends ThinkController
public function delStatement(){
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
$ids = $_REQUEST['ids'];
$dbres = $this->DBModel->where("id in ({$ids}) and verify_status = 0")->delete();
// $dbres = $this->DBModel->where("id in ({$ids}) and verify_status = 0")->delete();
$dbres = $this->DBModel->where("id in ({$ids})")->select();
foreach ($dbres as $key=>$value) {
if($value['withdraw_type'] !=3) {
$this->DBModel->where("id = {$value['id']} and verify_status = 0")->delete();
} else {
$this->DBModel->where("id = {$value['id']} and verify_status != 2")->delete();
}
}
addOperationLog(['op_type'=>2,'key'=>$ids,"op_name"=>"删除结算单",'url'=>U('lists')]);
$this->ajaxReturn(array(
'status' => 1,
@ -423,7 +456,8 @@ class CompanyStatementController extends ThinkController
{
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
$ids = $_REQUEST['ids'];
$dbres = $this->DBModel->field("id,verify_status,verify_log")->where("id in ({$ids})")->select();
$dbres = $this->DBModel->field("id,verify_status,verify_log,withdraw_type")->where("id in ({$ids})")->select();
foreach($dbres as $k=>& $v){
// if(in_array($v['verify_status'],[3,4])) continue; //合作方确认后不进行重算
//重算
@ -443,10 +477,12 @@ class CompanyStatementController extends ThinkController
//导出
public function export()
{
if(!isset($_REQUEST['id'])) $this->error("参数错误");
$id = $_REQUEST['id'];
$data = M("CompanyStatement","tab_")->where(['id' => $id])->find();
$data['first_party_info'] = json_decode($data['first_party_info'], 1);//甲方
$data['second_party_info'] = json_decode($data['second_party_info'], 1);//乙方
$data['statement_info'] = json_decode($data['statement_info'], 1);//结算记录
@ -481,7 +517,33 @@ class CompanyStatementController extends ThinkController
} else {
//下游
// if($dbres["company_type"] == 1){
if ($data['withdraw_type'] == 3 & & $data['company_type'] == 2) {
$dbres = M("CompanyStatement","tab_")->where(['id' => $id])->find();
if($dbres['pay_type'] == 2){
//乙方收款
$dbres['company_info'] = $dbres['second_party_info'];
}else{
$dbres['company_info'] = $dbres['first_party_info'];
}
unset($dbres['second_party_info']);
unset($dbres['first_party_info']);
$dbres=[$dbres];
$this->assign("title","下游个人特殊补点");
$this->exportSpecialComplement($dbres,1);
} else if ($data['withdraw_type'] == 3 & & $data['company_type'] != 2){
excelSpecialComplementEmplate($data, $all_sum_money, $all_pay_amount, $big_all_sum_money);
}
else {
excelDownStreamTemplate($data, $all_sum_money, $all_pay_amount, $big_all_sum_money);
}
// }else{
// $data['statement_begin_time'] = date('Ymd',$data['statement_begin_time']);
// $data['statement_end_time'] = date('Ymd',$data['statement_end_time']);
@ -492,6 +554,105 @@ class CompanyStatementController extends ThinkController
// }
}
}
public function exportSpecialComplement(& $infolist,$is_export) {
$line = 1;
$count = [];
//获取对接人
foreach($infolist as $k=>& $v){
$infolist[$k]['reward'] = 0;
$infolist[$k]['fine'] = 0;
$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']);
$v['company_info']['nickname'] = $v['statement_info'][0]['real_name'];
if (isset($v['company_info']['company_type'])) {
if($v['company_info']['company_type'] == 1) {
$v['company_info']['company_type_str'] = '公司';
} elseif($v['company_info']['company_type'] == 2){
$v['company_info']['company_type_str'] = '个人';
}
}
if (isset($v['company_info']['company_belong'])) {
$v['company_info']['company_belong_str'] = getCompanyBlong($v['company_info']['company_belong']);
}
if (isset($v['company_info']['develop_type'])) {
$v['company_info']['company_relation_str'] = getCompanyRelation($v['company_info']['develop_type']);
}
$cline = $line+1;
if($is_export){
$v['statement_money'] = "=ROUND(";
}
$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(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}),2)";
} else {
$val['sum_money'] = "=ROUND(K{$line}*(M{$line}),2)";
}
// $val['sum_money'] = "=J{$line}*(K{$line}+L{$line})";
$v['statement_money'] .= "N{$line}+";
}else{
$count['platform_amount'] += $val['pay_amount'];
$count['sum_money'] += $val['sum_money'];
}
}
// if($is_export){
// //J3*(K3+L3)+M3-N3
// if($va['statement_type'] > 0){ //罚款服务器费用
// $va['sum_money'] = "=J{$line}";
// }else{
// $va['sum_money'] = "=J{$line}*(K{$line}+L{$line})+M{$line}-N{$line}";
// }
// }else{
// $count['platform_amount'] += $va['pay_amount'];
// $count['sum_money'] += $va['sum_money'];
// }
}
$v['row'] = $row;
if($is_export){
if($v['withdraw_type'] != 3) {
$v['statement_money'] .="N{$cline}-O{$cline},2)";
} else {
$v['statement_money'] = substr($v['statement_money'],0,strlen($v['statement_money'])-1).",2)";
}
// dump($v['statement_money']);die();
}
}
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/viewPuPool");
}
//汇总
public function pool()
{
@ -559,16 +720,17 @@ class CompanyStatementController extends ThinkController
}
foreach ($dbres as $k=>$v) {
if($v['verify_status'] != 1) continue;
if($v['company_belong'] == 9){
//上游
$this->setDf($datas['up'],$v);
} elseif($v['withdraw_type'] == 3& & $v['company_type']==1){
$this->setDf($datas['complement_down'],$v);
} elseif($v['withdraw_type'] == 3& & $v['company_type']==2){
$this->setDf($datas['complement_user'],$v);
} else {
$this->setDf($datas['down'],$v);
if($v['verify_status'] == 1 || $v['verify_status'] == -2){
if($v['company_belong'] == 9){
//上游
$this->setDf($datas['up'],$v);
} elseif($v['withdraw_type'] == 3& & $v['company_type']==1){
$this->setDf($datas['complement_down'],$v);
} elseif($v['withdraw_type'] == 3& & $v['company_type']==2){
$this->setDf($datas['complement_user'],$v);
} else {
$this->setDf($datas['down'],$v);
}
}
}
@ -619,7 +781,7 @@ class CompanyStatementController extends ThinkController
M("company_lack_statement_info","tab_")->where("id in ({$v['del_lack_ids']})")->save(["is_pool"=>1]);
}
//修改结算单规则
$this->updatePoolVerifyStatus($v['statement_ids'],1, 2,"pool",$v['statement_num']);
$this->updatePoolVerifyStatus($v['statement_ids'],2,"pool",$v['statement_num']);
}
$this->ajaxReturn(array(
'status' => 1,
@ -627,10 +789,10 @@ class CompanyStatementController extends ThinkController
));
}
//结算单规则
protected function updatePoolVerifyStatus($ids,$old_status,$ change_status,$op_pre,$num){
protected function updatePoolVerifyStatus($ids,$change_status,$op_pre,$num){
$dbres = $this->DBModel->field("id,verify_status,verify_log")->where("id in ({$ids})")->select();
foreach($dbres as $k=>& $v){
if($v['verify_status'] != $old_status) continue;
// 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");
@ -993,24 +1155,41 @@ class CompanyStatementController extends ThinkController
foreach ($check_add as $key => $value) {
if ($value['statement_end_time'] >= $start_time & & $value['statement_end_time']< =$end_time
||$value['statement_begin_time']>=$start_time & & $value['statement_begin_time']< =$end_time
||$value['statement_begin_time']>=$start_time & & $value['statement_end_time'] < = $end_time)
{
$statementInfo = json_decode($value['statement_info'],true);;
if ($value['company_type'] == 2) {
$statementInfo = $statementInfo['game_list'];
// if ($value['statement_end_time'] >= $start_time & & $value['statement_end_time']< =$end_time
// ||$value['statement_begin_time']>=$start_time & & $value['statement_begin_time']< =$end_time
// ||$value['statement_begin_time']< =$start_time & & $value['statement_end_time'] >= $end_time)
// {
$statementInfo = json_decode($value['statement_info'],true);;
if ($value['company_type'] == 2) {
foreach ($statementInfo as $sk => $sv) {
$statementInfos = $sv['game_list'];
foreach ($statementInfos as $k => $v) {
if (strtotime(str_replace('.','-',$v['statement_end_time'])) >= $start_time & & strtotime(str_replace('.','-',$v['statement_end_time']))< =$end_time
||strtotime(str_replace('.','-',$v['statement_begin_time']))>=$start_time & & strtotime(str_replace('.','-',$v['statement_begin_time']))< =$end_time
||strtotime(str_replace('.','-',$v['statement_begin_time']))< =$start_time & & strtotime(str_replace('.','-',$v['statement_end_time'])) >= $end_time) {
if (in_array($v['relation_game_id'], $relation_game_data)) {
$this->ajaxReturn(['status' => 0, 'data' => [], 'msg' => "《{$v['game_name']}》在日期:{$_REQUEST['time_start']}-{$_REQUEST['time_end']}有结算过的部分,请重新选择"]);
}
}
}
}
} else {
foreach ($statementInfo as $k => $v) {
if (in_array($v['relation_game_id'],$relation_game_data)) {
$this->ajaxReturn(['status'=>0,'data'=>[],'msg'=>"《{$v['game_name']}》在日期:{$_REQUEST['time_start']}-{$_REQUEST['time_end']}有结算过的部分,请重新选择"]);
if (strtotime(str_replace('.','-',$v['statement_end_time'])) >= $start_time & & strtotime(str_replace('.','-',$v['statement_end_time']))< =$end_time
||strtotime(str_replace('.','-',$v['statement_begin_time']))>=$start_time & & strtotime(str_replace('.','-',$v['statement_begin_time']))< =$end_time
||strtotime(str_replace('.','-',$v['statement_begin_time']))< =$start_time & & strtotime(str_replace('.','-',$v['statement_end_time'])) >= $end_time) {
if (in_array($v['relation_game_id'], $relation_game_data)) {
$this->ajaxReturn(['status' => 0, 'data' => [], 'msg' => "《{$v['game_name']}》在日期:{$_REQUEST['time_start']}-{$_REQUEST['time_end']}有结算过的部分,请重新选择"]);
}
}
}
}
// }
}
@ -1029,7 +1208,7 @@ class CompanyStatementController extends ThinkController
$radioMap['_string'] = "start_time < {$end_time}";
}
$map['tab_spend.pay_status'] = 1;
$map['pay_way'] = ['egt',1 ];
// $map['pay_way'] = ['egt',0 ];
$data = M("spend","tab_")
->field("pay_amount,relation_game_id,relation_game_name,payed_time")
@ -1079,81 +1258,92 @@ class CompanyStatementController extends ThinkController
->where(['relation_game_id'=>['in',$rvalue]])
->find();
$handleData[$_REQUEST['company_id']]['company_id'] = $_REQUEST['company_id'];
$handleData[$_REQUEST['company_id']]['company_name'] = $companyData['company_name'];
$handleData[$_REQUEST['company_id']]['begin_time'][] = strtotime(I('time_start'));
$handleData[$_REQUEST['company_id']]['end_time'][] = strtotime(I('time_end')) + 86399;
$handleData[$_REQUEST['company_id']]['relation_game_id'][] = $rvalue;
$handleData[$_REQUEST['company_id']]['relation_game_name'][] = $game_name['relation_game_name'];
$handleData[$_REQUEST['company_id']]['ratio'][] = $handleRadioMould[$rvalue]['ratio']?$handleRadioMould[$rvalue]['ratio']:0;
$handleData[$_REQUEST['company_id']]['turnover_ratio'][] = $handleRadioMould[$rvalue]['turnover_ratio'];
$handleData[$_REQUEST['company_id']]['company_id'] = $_REQUEST['company_id'];
$handleData[$_REQUEST['company_id']]['company_name'] = $companyData['company_name'];
$handleData[$_REQUEST['company_id']]['begin_time'][] = strtotime(I('time_start'));
$handleData[$_REQUEST['company_id']]['end_time'][] = strtotime(I('time_end')) + 86399;
$handleData[$_REQUEST['company_id']]['relation_game_id'][] = $rvalue;
$handleData[$_REQUEST['company_id']]['relation_game_name'][] = $game_name['relation_game_name'];
$handleData[$_REQUEST['company_id']]['ratio'][] = $handleRadioMould[$rvalue]['ratio']?$handleRadioMould[$rvalue]['ratio']:0;
$handleData[$_REQUEST['company_id']]['turnover_ratio'][] = $handleRadioMould[$rvalue]['turnover_ratio'];
}
}
foreach ($radioData as $key => $value) {
foreach ($relation_game_data as $rk => $rv) {
unset($radioMap['tab_company_game_ratio.relation_game_id']);
$radioMap['tab_company_game_ratio.relation_game_id'] = $rv;
$radioGameRatios = M("company_game_ratio","tab_")
->field("tab_company_game_ratio.*,game.relation_game_name")
->join("left join ({$game_data}) game on tab_company_game_ratio.relation_game_id=game.relation_game_id")
->where($radioMap)
->order("begin_time ASC")
->select();
if (strtotime(I('time_start')) < = $value['begin_time']) {
$handleData[$_REQUEST['company_id']]['begin_time'][] = $value['begin_time'];
} else {
$handleData[$_REQUEST['company_id']]['begin_time'][] = strtotime(I('time_start'));
}
if (strtotime(I('time_end')) > $value['end_time'] & & $value['end_time']!=0) {
$handleData[$_REQUEST['company_id']]['end_time'][] = $value['end_time'];
} else {
$handleData[$_REQUEST['company_id']]['end_time'][] = strtotime(I('time_end')) + 86399;
}
$handleData[$_REQUEST['company_id']]['company_id'] = $_REQUEST['company_id'];
$handleData[$_REQUEST['company_id']]['company_name'] = $companyData['company_name'];
$handleData[$_REQUEST['company_id']]['relation_game_id'][] = $value['relation_game_id'];
$handleData[$_REQUEST['company_id']]['relation_game_name'][] = $value['relation_game_name'];
$handleData[$_REQUEST['company_id']]['ratio'][] = $value['ratio'];
$handleData[$_REQUEST['company_id']]['turnover_ratio'][] = $value['turnover_ratio'];
$num++;
//如果结算时间小于比例开始时间
if ($key == 0) {
if (strtotime(I('time_start')) < $value['begin_time']) {
$handleData[$_REQUEST['company_id']]['company_id'] = $_REQUEST['company_id'];
$handleData[$_REQUEST['company_id']]['company_name'] = $companyData['company_name'];
$handleData[$_REQUEST['company_id']]['begin_time'][] = strtotime(I('time_start'));
$handleData[$_REQUEST['company_id']]['end_time'][] = $value['begin_time']-1;
$handleData[$_REQUEST['company_id']]['relation_game_id'][] = $value['relation_game_id'];
$handleData[$_REQUEST['company_id']]['relation_game_name'][] = $value['relation_game_name'];
$handleData[$_REQUEST['company_id']]['ratio'][] = $handleRadioMould[$value['relation_game_id']]['ratio']?$handleRadioMould[$value['relation_game_id']]['ratio']:0;
$handleData[$_REQUEST['company_id']]['turnover_ratio'][] = $handleRadioMould[$value['relation_game_id']]['turnover_ratio'];
foreach ($radioGameRatios as $key => $value) {
if (strtotime(I('time_start')) < = $value['begin_time']) {
$handleData[$_REQUEST['company_id']]['begin_time'][] = $value['begin_time'];
} else {
$handleData[$_REQUEST['company_id']]['begin_time'][] = strtotime(I('time_start'));
}
}
if (strtotime(I('time_end')) > $value['end_time'] & & $value['end_time']!=0) {
$handleData[$_REQUEST['company_id']]['end_time'][] = $value['end_time'];
} else {
$handleData[$_REQUEST['company_id']]['end_time'][] = strtotime(I('time_end')) + 86399;
}
$handleData[$_REQUEST['company_id']]['company_id'] = $_REQUEST['company_id'];
$handleData[$_REQUEST['company_id']]['company_name'] = $companyData['company_name'];
$handleData[$_REQUEST['company_id']]['relation_game_id'][] = $value['relation_game_id'];
$handleData[$_REQUEST['company_id']]['relation_game_name'][] = $value['relation_game_name'];
$handleData[$_REQUEST['company_id']]['ratio'][] = $value['ratio'];
$handleData[$_REQUEST['company_id']]['turnover_ratio'][] = $value['turnover_ratio'];
$num++;
//如果结算时间小于比例开始时间
if ($key == 0) {
if (strtotime(I('time_start')) < $value['begin_time']) {
$handleData[$_REQUEST['company_id']]['company_id'] = $_REQUEST['company_id'];
$handleData[$_REQUEST['company_id']]['company_name'] = $companyData['company_name'];
$handleData[$_REQUEST['company_id']]['begin_time'][] = strtotime(I('time_start'));
$handleData[$_REQUEST['company_id']]['end_time'][] = $value['begin_time']-1;
$handleData[$_REQUEST['company_id']]['relation_game_id'][] = $value['relation_game_id'];
$handleData[$_REQUEST['company_id']]['relation_game_name'][] = $value['relation_game_name'];
$handleData[$_REQUEST['company_id']]['ratio'][] = $handleRadioMould[$value['relation_game_id']]['ratio']?$handleRadioMould[$value['relation_game_id']]['ratio']:0;
$handleData[$_REQUEST['company_id']]['turnover_ratio'][] = $handleRadioMould[$value['relation_game_id']]['turnover_ratio'];
if(!$radioData[$key+1]) {
}
}
if (strtotime(I('time_end')) > $value['end_time'] & & $value['end_time']!=0) {
$handleData[$_REQUEST['company_id']]['company_id'] = $_REQUEST['company_id'];
$handleData[$_REQUEST['company_id']]['company_name'] = $companyData['company_name'];
$handleData[$_REQUEST['company_id']]['begin_time'][] = $value['end_time'] + 1;
$handleData[$_REQUEST['company_id']]['end_time'][] = strtotime(I('time_end'))-86399;
$handleData[$_REQUEST['company_id']]['relation_game_id'][] = $value['relation_game_id'];
$handleData[$_REQUEST['company_id']]['relation_game_name'][] = $value['relation_game_name'];
$handleData[$_REQUEST['company_id']]['ratio'][] = $handleRadioMould[$value['relation_game_id']]['ratio']?$handleRadioMould[$value['relation_game_id']]['ratio']:0;
$handleData[$_REQUEST['company_id']]['turnover_ratio'][] = $handleRadioMould[$value['relation_game_id']]['turnover_ratio'];
if(!$radioData[$key+1]) {
if (strtotime(I('time_end')) > $value['end_time'] & & $value['end_time']!=0) {
$handleData[$_REQUEST['company_id']]['company_id'] = $_REQUEST['company_id'];
$handleData[$_REQUEST['company_id']]['company_name'] = $companyData['company_name'];
$handleData[$_REQUEST['company_id']]['begin_time'][] = $value['end_time'] + 1;
$handleData[$_REQUEST['company_id']]['end_time'][] = strtotime(I('time_end'))-86399;
$handleData[$_REQUEST['company_id']]['relation_game_id'][] = $value['relation_game_id'];
$handleData[$_REQUEST['company_id']]['relation_game_name'][] = $value['relation_game_name'];
$handleData[$_REQUEST['company_id']]['ratio'][] = $handleRadioMould[$value['relation_game_id']]['ratio']?$handleRadioMould[$value['relation_game_id']]['ratio']:0;
$handleData[$_REQUEST['company_id']]['turnover_ratio'][] = $handleRadioMould[$value['relation_game_id']]['turnover_ratio'];
}
}
}
//如果结算时间中有时间段间隔
if ($radioData[$key+1]) {
if ($radioData[$key+1]['begin_time'] != ($value['end_time']+1)) {
$handleData[$_REQUEST['company_id']]['company_id'] = $_REQUEST['company_id'];
$handleData[$_REQUEST['company_id']]['company_name'] = $companyData['company_name'];
$handleData[$_REQUEST['company_id']]['begin_time'][] = $value['end_time'] + 1;
$handleData[$_REQUEST['company_id']]['end_time'][] = $radioData[$key+1]['begin_time'] - 1;
$handleData[$_REQUEST['company_id']]['relation_game_id'][] = $value['relation_game_id'];
$handleData[$_REQUEST['company_id']]['relation_game_name'][] = $value['relation_game_name'];
$handleData[$_REQUEST['company_id']]['ratio'][] = $handleRadioMould[$value['relation_game_id']]['ratio']?$gameRatioMould['ratio']:0;
$handleData[$_REQUEST['company_id']]['turnover_ratio'][] = $handleRadioMould[$value['relation_game_id']]['turnover_ratio'];
//如果结算时间中有时间段间隔
if ($radioData[$key+1]) {
if ($radioData[$key+1]['begin_time'] != ($value['end_time']+1)& & $value['end_time']!=0) {
$handleData[$_REQUEST['company_id']]['company_id'] = $_REQUEST['company_id'];
$handleData[$_REQUEST['company_id']]['company_name'] = $companyData['company_name'];
$handleData[$_REQUEST['company_id']]['begin_time'][] = $value['end_time'] + 1;
$handleData[$_REQUEST['company_id']]['end_time'][] = $radioData[$key+1]['begin_time'] - 1;
$handleData[$_REQUEST['company_id']]['relation_game_id'][] = $value['relation_game_id'];
$handleData[$_REQUEST['company_id']]['relation_game_name'][] = $value['relation_game_name'];
$handleData[$_REQUEST['company_id']]['ratio'][] = $handleRadioMould[$value['relation_game_id']]['ratio']?$gameRatioMould['ratio']:0;
$handleData[$_REQUEST['company_id']]['turnover_ratio'][] = $handleRadioMould[$value['relation_game_id']]['turnover_ratio'];
}
}
}
}
// dump($handleData);die();
foreach ($handleData as $key => $value) {
$handleData[$key]['row'] = 0;
$timeArr = $value['begin_time'];
@ -1216,14 +1406,16 @@ class CompanyStatementController extends ThinkController
$statement_data = [];
M()->startTrans();
foreach ($data as $key => $value) {
$begin_time = 99999999999;
$end_time = 0;
$statement_data = [];
$company_data = M("promote_company","tab_")->where(['id'=>$value['company_id']])->find();
$company_type = M("company_relation","tab_")->where("first_company_id={$value['company_id']} or second_company_id={$value['company_id']}")->find();
$insert['is_payment'] = $company_type['is_payment'];
$insert['statement_begin_time'] = strtotime($value['statement_begin_time']);
$insert['statement_end_time'] = strtotime($value['statement_end_time']);
// $insert['statement_begin_time'] = strtotime($value['statement_begin_time']);
// $insert['statement_end_time'] = strtotime($value['statement_end_time']);
$insert['withdraw_type'] = $withdraw_type;
$insert['company_belong'] = $company_data['company_belong'];
$insert['company_name'] = $company_data['company_name'];
@ -1296,8 +1488,10 @@ class CompanyStatementController extends ThinkController
$statement_info[$k]['statement_type'] = 0;
$statement_info[$k]['fax_ratio'] = $company_data['fax_ratio'];
}
$statement_info[$k]['statement_begin_time'] = dateFormat($v['statement_begin_time']);
$statement_info[$k]['statement_end_time'] = dateFormat($v['statement_end_time']);
}
if ($company_data['company_type'] == 2) {
@ -1313,15 +1507,26 @@ class CompanyStatementController extends ThinkController
$amount_time['promote_id'] = '-1';
}
$amount_time['tab_spend.pay_status'] = 1;
$amount_time['pay_way'] = ['egt',0];
// $amount_time['pay_way'] = ['egt',0];
foreach ($statement_info as $k => $v) {
$statement_begin_time = strtotime($v['statement_begin_time']);
$statement_end_time = strtotime($v['statement_end_time'])+86399;
$statement_begin_time = strtotime(str_replace('.','-',$v['statement_begin_time']));
$statement_end_time = strtotime(str_replace('.','-',$v['statement_end_time']))+86399;
if ($statement_begin_time< $begin_time) {
$begin_time = $statement_begin_time;
}
if ($statement_end_time>$end_time) {
$end_time = $statement_end_time;
}
$amount_time['_string'] = "payed_time between {$statement_begin_time} and {$statement_end_time} and relation_game_id={$v['relation_game_id']}";
$dataAmount = M("spend","tab_")
->field("pay_amount,relation_game_id,relation_game_name,payed_time,game_type_name,substring_index(substring_index(promote.`chain`,'/',2),'/',-1) promote_id,chain,admin_id")
->field("pay_amount,relation_game_id,relation_game_name,payed_time,game_type_name,
CASE WHEN substring_index(substring_index(`chain`,'/',2),'/',-1) !='' THEN substring_index(substring_index(`chain`,'/',2),'/',-1) ELSE promote_id END promote_id,chain,admin_id")
->join("left join tab_promote promote on tab_spend.promote_id=promote.id")
->join("left join tab_game game on tab_spend.game_id=game.id")
->where($amount_time)
@ -1343,8 +1548,8 @@ class CompanyStatementController extends ThinkController
$game_list['ratio'] = $v['ratio'];
$game_list['fax_ratio'] = $company_data['fax_ratio'];
$game_list['sum_money'] = number_format( ($aval['pay_amount']*($v['increment_ratio']))/100,2,'.','') ;
$game_list['increment_ratio'] = number_format( $v['increment_ratio'],2,'.','') ;
$game_list['sum_money'] = ($aval['pay_amount']*($v['increment_ratio']))/100;
$game_list['increment_ratio'] = $v['increment_ratio'];
$game_list['statement_begin_time'] = $v['statement_begin_time'];
$game_list['statement_end_time'] = $v['statement_end_time'];
$game_list['statement_type'] = '0';
@ -1371,9 +1576,25 @@ class CompanyStatementController extends ThinkController
$insert['statement_info'] = json_encode($statement_insert);
} else {
$insert['statement_info'] = json_encode($statement_info);
foreach ($statement_info as $k => $v) {
$statement_begin_time = strtotime(str_replace('.','-',$v['statement_begin_time']));
$statement_end_time = strtotime(str_replace('.','-',$v['statement_end_time']))+86399;
if ($statement_begin_time< $begin_time) {
$begin_time = $statement_begin_time;
}
if ($statement_end_time>$end_time) {
$end_time = $statement_end_time;
}
}
}
$insert['statement_begin_time'] = $begin_time;
$insert['statement_end_time'] = $end_time;
if ($company_type['first_company_id'] == $value['company_id']) {
$insert['first_party_info'] = json_encode($proCompany_info);
$insert['second_party_info'] = json_encode($secord_info);
@ -1458,7 +1679,7 @@ class CompanyStatementController extends ThinkController
"export"=>"< a class = 'butn' id = 'export' > 批量导出< / a > ",
"updateNewStatement"=>"< a class = 'butn' id = 'updateNewStatement' style = 'background-color: green;' > 新增结算< / a > ",
"launch"=>"< a class = 'butn' id = 'launch' > 对外发起< / a > ",
"s pecialComplement"=>"< a class = 'butn' id = ' s pecialComplement'> 特殊补点< / a > ",
"viewS pecialComplement"=>"< a class = 'butn' id = ' viewS pecialComplement'> 特殊补点< / a > ",
"delStatement"=>"< a class = 'butn' id = 'delStatement' style = 'background-color: red;' > 批量删除< / a > "
];
$resarr = [];