"审核拒绝", "0"=>"未申请开票", "1"=>"申请开票", "2"=>"审核同意", "3"=>"已开票", "4"=>"上传收款凭证", "5"=>"已到账" ]; public function lists() { $is_export= false; if (isset($_REQUEST['export']) && $_REQUEST['export']==1){ $is_export = true; } $page = intval(I('get.p', 0)); $page = $page ? $page : 1; //默认显示第一页数据 $row = intval(I('row', 0)); $row = empty($row) ? 10 : $row;//每页条数 $map = []; if (isset($_REQUEST['time_start']) && isset($_REQUEST['time_end'])) { $time_start = strtotime($_REQUEST['time_start']); $time_end = strtotime($_REQUEST['time_end'])+ 86399; $map["_string"] = "(begintime BETWEEN {$time_start} AND {$time_end}) OR (endtime BETWEEN {$time_start} AND {$time_end})"; } elseif (isset($_REQUEST['time_start'])) { $time_start = strtotime($_REQUEST['time_start']); $map["_string"] = "(begintime >= {$time_start} ) OR (endtime >= {$time_start})"; } elseif (isset($_REQUEST['time_end'])) { $time_end = strtotime($_REQUEST['time_end'])+ 86399; $map["_string"] = "(begintime <= {$time_end} ) OR (endtime <= {$time_end})"; } if (isset($_REQUEST['time_start2']) && isset($_REQUEST['time_end2'])) { $map['create_time'] = ['between', [strtotime($_REQUEST['time_start2']), strtotime($_REQUEST['time_end2']) + 86399]]; } elseif (isset($_REQUEST['time_start2'])) { $map['create_time'] = ['EGT', strtotime($_REQUEST['time_start2'])]; } elseif (isset($_REQUEST['time_end2'])) { $map['create_time'] = ['ELT', strtotime($_REQUEST['time_end2']) + 86399]; } if ($_REQUEST['verify_status']) { $map['verify_status'] = $_REQUEST['verify_status']; } if ($_REQUEST['channel_id']) { $map['channel_id'] = $_REQUEST['channel_id']; } $typeflag = false; if (isset($_REQUEST['withdraw_type'])) { if($_REQUEST['withdraw_type'] == 1){ $typeflag = 1;//月结 $map["withdraw_type"] = 1; }else{ $typeflag = 2;//周结 $map["withdraw_type"] = ["in",[0,2]]; } } if (isset($_REQUEST['withdraw_type2'])) { if($_REQUEST['withdraw_type2'] == 2){ if($typeflag == 1){ //月结的补点找不到 $map['withdraw_type'] = 999; }else{ //周结的补点就是补点 $map['withdraw_type'] = 2; } }else{ if($typeflag == 1){//月结的正常=月结 $map['withdraw_type'] = 1; }elseif($typeflag == 2){//周结的正常=周结 $map['withdraw_type'] = 0; }else{//没选的正常是 非补点 $map['withdraw_type'] = ["in",[0,1]]; } } } $data = M("aggregate_statement","tab_") ->where($map) ->order("create_time Desc")->page($page,$row)->select(); foreach($data as $key => $value) { $data[$key]['verify_status_str'] = $this->verify_status[$value['verify_status']]; $data[$key]['create_time'] = date('Y-m-d H:i:s',$value['create_time']); $data[$key]['begintime'] = date('Y-m-d',$value['begintime']); $data[$key]['endtime'] = date('Y-m-d',$value['endtime']); $data[$key]['withdraw_type_1'] = ($value['withdraw_type'] == 1 ? "月结" :"周结"); $data[$key]['withdraw_type_2'] = ($value['withdraw_type'] == 2 ? "补点" :"正常结算"); } $count = M("aggregate_statement","tab_")->field("count(id) count,SUM(ratio_money) ratio_money")->where($map)->find(); //分页 $parameter['p'] = $page; $parameter['row'] = $row; $page = set_pagination($count['count'], $row, $parameter); if ($page) { $this->assign('_page', $page); } $this->assign('data',$data); $this->assign('total',$count['ratio_money']); $this->assign('channel',$this->getAggChannel()); $this->assign('verify_status',$this->verify_status); $this->display(); } //获取所有下游渠道 public function getAggChannel() { return M("aggregate_statement","tab_")->field("channel_id,channel_name")->group("channel_id")->select(); } //申请开票 public function createStatement(){ if (isset($_REQUEST['id'])){ $id = $_REQUEST['id']; }else{ $this->error("参数错误"); } $info = M("aggregate_statement","tab_")->field("statement_info,pay_money,ratio_money")->where("id={$id}")->find(); $statement_info = json_decode($info['statement_info'],true); $this->assign('data',$statement_info); $this->assign('data_count',["pay_money"=>$info['pay_money'],"ratio_money"=>$info['ratio_money']]); $this->assign('id',$id); $this->display(); } public function doAddStatement(){ $first_partner_type = $_REQUEST['first_partner_type']; $second_party_info = $_REQUEST['second_party_info']; $statement_info = $_REQUEST['statement_info']; $admininfo = $_SESSION['onethink_admin']['user_auth']; $data_count = $_REQUEST['statement_count']; if(!isset($_REQUEST['statement_id'])){ $this->error("参数错误"); } //拼凑数据 $adddata = array( "pay_money"=>$data_count['pay_money'], "ratio_money"=>$data_count['ratio_money'], "pay_type"=>$_REQUEST['statement_type'] == 0 ? 1 :0, "first_party_info"=>json_encode($_REQUEST['first_party_info'],JSON_UNESCAPED_UNICODE), "second_party_info"=>json_encode($_REQUEST['second_party_info'],JSON_UNESCAPED_UNICODE), "statement_info"=>json_encode($statement_info,JSON_UNESCAPED_UNICODE), "admin_name"=>$admininfo['username'], "admin_id"=>$admininfo['uid'], "verify_status"=>1, "create_time"=>time() ); $id = $_REQUEST['statement_id']; $res = M("aggregate_statement","tab_")->where("id = '{$id}'")->save($adddata); if($res !== false){ $this->ajaxReturn(array("success"=>"ok","code"=>0)); }else{ $this->ajaxReturn(array("error"=>"database error","code"=>2000)); } } //获取公司信息 public function getCompanyList() { $id = $_REQUEST['id']; $cpCompany = M("aggregate_statement","tab_")->field("id,second_party_info")->where("id={$id}")->find(); $data = array(); $data['ptCompany']= M("CompanyInfo","tab_")->field('id,partner')->select(); $data['cpCompany']= [[ "id"=> $cpCompany['id'], "partner"=>json_decode($cpCompany['second_party_info'],true)['partner'] ]]; $this->ajaxReturn(array("success"=>$data,"code"=>2000)); } public function getCpCompanyInfo() { $CompanyId = $_REQUEST['company_id']; $company_type = $_REQUEST['company_type']; if($company_type == 'pt'){ $info = M("CompanyInfo","tab_")->field("id,partner,link_man,link_phone,address,company_tax_no,payee_name,bank_account,opening_bank")->where("id = '{$CompanyId}'")->find(); }else{ $cpCompany = M("aggregate_statement","tab_")->field("id,second_party_info")->where("id={$CompanyId}")->find(); $info = json_decode($cpCompany['second_party_info'],true); } $info['invoice_item'] = "信息技术服务费"; $info['invoice_type'] = "增值税专用发票"; if(empty($info)){ $this->ajaxReturn(array("error"=>"no find","code"=>2000)); }else{ $this->ajaxReturn(array("success"=>$info,"code"=>0)); } } public function editStatement(){ if(!isset($_REQUEST['id'])) $this->error("参数错误"); $id = $_REQUEST['id']; $dbres = M("aggregate_statement","tab_")->where("id = '{$id}'")->find(); $first_party_info = json_decode($dbres['first_party_info'],true); $second_party_info = json_decode($dbres['second_party_info'],true); $statement_info = json_decode($dbres['statement_info'],true); // if($dbres['company_name'] == $first_party_info['partner']){ // $first_partner_type=0; // }else{ // $first_partner_type=1; // } // $fine = array_pop($statement_info); $senddata = array( // "first_partner_type"=>1, "statement_id"=>$dbres['id'], "first_part_company"=>$first_party_info['partner'], "second_part_company"=>$second_party_info['partner'], "statement_type"=>$dbres['pay_type'] == 0 ? 1 :0, "first_party_info"=>$first_party_info, "second_party_info"=>$second_party_info, "statement_info"=>$statement_info, "statement_count"=>array("pay_money"=>$dbres['pay_money'],"ratio_money"=>$dbres['ratio_money']) ); $this->assign("data",$senddata); if($dbres['pay_type'] == 0){ $this->assign("company",$second_party_info['partner']); }else{ $this->assign("company",$first_party_info['partner']); } $this->assign("company_id",$dbres['company_id']); $this->assign("company_name",$dbres['company_name']); $this->assign("id",$dbres['id']); $this->display(); } //查看发票信息 public function viewStatement(){ if(!isset($_REQUEST['id'])) $this->error("参数错误"); $id = $_REQUEST['id']; $dbres = M("aggregate_statement","tab_")->where("id = '{$id}'")->find(); $first_party_info = json_decode($dbres['first_party_info'],true); $second_party_info = json_decode($dbres['second_party_info'],true); $statement_info = json_decode($dbres['statement_info'],true); if($dbres['pay_type'] == 0){ $company = $second_party_info['partner']; $pyinfo = $second_party_info; }else{ $company = $first_party_info['partner']; $pyinfo = $first_party_info; } $senddata = array( "company"=>$company, "payinfo"=>$pyinfo, "first_part_company"=>$first_party_info['partner'], "second_part_company"=>$second_party_info['partner'], "statement_type"=>$dbres['pay_type'], "first_party_info"=>$first_party_info, "second_party_info"=>$second_party_info, "statement_info"=>$statement_info, "statement_count"=>array("pay_money"=>$dbres['pay_money'],"ratio_money"=>$dbres['ratio_money'],"big_ratio_money"=>convertAmountToCn($dbres['ratio_money'])) ); $this->assign("data",$senddata); $this->display(); } //导出 public function export() { if(!isset($_REQUEST['id'])) $this->error("参数错误"); $id = $_REQUEST['id']; $data = M("aggregate_statement","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);//结算记录 //收款方 $big_pay_money = convertAmountToCn($data['ratio_money']);//大写 $data['receive_company'] = $data['pay_type'] ? $data['first_party_info'] : $data['second_party_info']; $data['pay_company'] = $data['pay_type'] ? $data['second_party_info'] : $data['first_party_info']; $this->excelDownStreamTemplate($data,$big_pay_money); } public function excelDownStreamTemplate($data,$big_all_sum_money) { header("Content-type: text/html; charset=utf-8"); error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '
'); date_default_timezone_set('Europe/London'); Vendor("PHPExcel.PHPExcel"); $objPHPExcel = new \PHPExcel(); $objReader = \PHPExcel_IOFactory::createReader('Excel5'); //设置模板文件 $objPHPExcel = $objReader->load("Public/Admin/excel/aggregate_stream.xls"); $statement_begin_time = date('Y.m.d', $data['begintime']);//对账开始时间 $statement_end_time = date('Y.m.d',$data['endtime']);//对账截止时间 $objPHPExcel->getActiveSheet()->setCellValue('A1', "《 {$data['channel_name']} 》结算单 ({$statement_begin_time}-{$statement_end_time})"); if ($data['withdraw_type'] == '2') { $objPHPExcel->getActiveSheet()->setCellValue('D2','补点比例'); } $line = 3; foreach ($data['statement_info'] as $key => $value) { $objPHPExcel->getActiveSheet()->insertNewRowBefore($line,1); $objPHPExcel->getActiveSheet()->removeConditionalStyles(); $objPHPExcel->getActiveSheet()->setCellValue('A'.$line, $value['begintime'] . '-' . $value['endtime']); $product_name = $value['game_name']; $objPHPExcel->getActiveSheet()->setCellValue('D'.$line, $value['ratio'] . '%'); $objPHPExcel->getActiveSheet()->setCellValue('E'.$line, $value['fax_ratio'] . '%'); $objPHPExcel->getActiveSheet()->setCellValue('C'.$line, $value['money']); $objPHPExcel->getActiveSheet()->setCellValue('B'.$line, $product_name); $objPHPExcel->getActiveSheet()->setCellValue('F'.$line, $value['ratio_money']); $objPHPExcel->getActiveSheet()->getStyle('A'.$line)->getFont()->setBold(false); $objPHPExcel->getActiveSheet()->getStyle('B'.$line)->getFont()->setBold(false); $objPHPExcel->getActiveSheet()->getStyle('C'.$line)->getFont()->setBold(false); $objPHPExcel->getActiveSheet()->getStyle('D'.$line)->getFont()->setBold(false); $objPHPExcel->getActiveSheet()->getStyle('E'.$line)->getFont()->setBold(false); $objPHPExcel->getActiveSheet()->getStyle('F'.$line)->getFont()->setBold(false); $line++; } $objPHPExcel->getActiveSheet()->setCellValue('C'.($line), $data['pay_money']);//合计-平台总额 $objPHPExcel->getActiveSheet()->setCellValue('F'.($line), $data['ratio_money']);//合计-结算金额 $objPHPExcel->getActiveSheet()->setCellValue('B'.($line+1), $big_all_sum_money);//大写支付结算金额 //甲方信息 $objPHPExcel->getActiveSheet()->setCellValue('B'.($line+3), $data['first_party_info']['partner']);//甲方 $objPHPExcel->getActiveSheet()->setCellValue('B'.($line+4), $data['first_party_info']['link_man']);//联系人 $objPHPExcel->getActiveSheet()->setCellValue('B'.($line+5), $data['first_party_info']['link_phone']);//联系电话 $objPHPExcel->getActiveSheet()->setCellValue('B'.($line+6), $data['second_party_info']['invoice_item']);//开票项目 $objPHPExcel->getActiveSheet()->setCellValue('B'.($line+7), $data['second_party_info']['invoice_type']);//发票类型 //乙方信息 $objPHPExcel->getActiveSheet()->setCellValue('E'.($line+3), $data['second_party_info']['partner']);//乙方 $objPHPExcel->getActiveSheet()->setCellValue('E'.($line+4), $data['second_party_info']['link_man']);//联系人 $objPHPExcel->getActiveSheet()->setCellValue('E'.($line+5), $data['second_party_info']['link_phone']);//联系电话 $objPHPExcel->getActiveSheet()->setCellValue('E'.($line+6), $data['second_party_info']['address']);//邮寄地址 // $objPHPExcel->getActiveSheet()->setCellValue('E'.($line+8), $value['pay_amount']);//请汇入此账号 $objPHPExcel->getActiveSheet()->setCellValue('E'.($line+8), $data['second_party_info']['payee_name']);//户名 $objPHPExcel->getActiveSheet()->setCellValue('E'.($line+9), $data['second_party_info']['bank_account']);//银行账号 $objPHPExcel->getActiveSheet()->setCellValue('E'.($line+10), $data['second_party_info']['opening_bank']);//开户行 if($data['withdraw_type'] == 1){ $m = date('Y.m', $data['begintime']); $fileName = "{$data['second_party_info']['partner']}&{$data['first_party_info']['partner']}-对账单{$m}"; }else{ $fileName = "{$data['second_party_info']['partner']}&{$data['first_party_info']['partner']}-对账单{$statement_begin_time}-{$statement_end_time}"; } ob_end_clean();//清除缓冲区,避免乱码 header('pragma:public'); header('Content-type:application/vnd.ms-excel;charset=utf-8;name="' . $fileName .'".xls'); header("Content-Disposition:attachment;filename={$fileName}.xls");//attachment新窗口打印inline本窗口打印 $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); $objWriter->save('php://output'); } }