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.

574 lines
22 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 SubCompanyStatementPoolController 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->OpWmAuth($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('wm_statement_ids,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(true) {
$this->viewWmStatement($pool_info['wm_statement_ids'],$is_export);
}
}
public function exportWmStatement($wm_statement_ids = 0) {
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 : '<br />');
Vendor("PHPExcel.PHPExcel");
$objPHPExcel = new \PHPExcel();
$objReader = \PHPExcel_IOFactory::createReader('Excel2007');
//设置模板文件
$objPHPExcel = $objReader->load("Public/Admin/excel/wmStatement.xlsx");
$data = SM("new_company_statement_info","tab_")->where(['id'=>$wm_statement_ids])->find();
$list = json_decode($data['statement_info'],true);
$statement_begin_time = date("Y-m-d",$data['statement_begin_time']);
$statement_end_time = date("Y-m-d",$data['statement_end_time']);
$amount_data['pay_amount'] = $data['pay_amount'];
$amount_data['user_newcount'] = $data['user_newcount'];
$amount_data['fax_ratio'] = $data['fax_ratio'];
$amount_data['sum_money'] = $data['sum_money'];
$first_party_info = json_decode($data['first_party_info'],true);
$second_party_info = json_decode($data['second_party_info'],true);
$objPHPExcel->getActiveSheet()->setCellValue('A1', "{$data['company_name']} 》结算单\n{$statement_begin_time}-{$statement_end_time}");
$line = 3;
foreach ($list as $key => $value) {
$objPHPExcel->getActiveSheet()->insertNewRowBefore($line,1);
$objPHPExcel->getActiveSheet()->removeConditionalStyles();
$objPHPExcel->getActiveSheet()->setCellValue('A'.$line, $value['statement_begin_time'].'-'.$value['statement_end_time']);
$objPHPExcel->getActiveSheet()->setCellValue('B'.$line, $value['game_name']);
$line++;
}
$objPHPExcel->getActiveSheet()->setCellValue('C3', $amount_data['pay_amount']);
$objPHPExcel->getActiveSheet()->setCellValue('D3', $amount_data['user_newcount']);
$objPHPExcel->getActiveSheet()->setCellValue('E3', $amount_data['fax_ratio']."%");
$objPHPExcel->getActiveSheet()->setCellValue('F3', $amount_data['sum_money']);
$tline = $line-1;
$objPHPExcel->getActiveSheet()->mergeCells("C3:C{$tline}")->mergeCells("D3:D{$tline}")->mergeCells("E3:E{$tline}")->mergeCells("F3:F{$tline}");
$objPHPExcel->getActiveSheet()->setCellValue('B'.($line), convertAmountToCn($amount_data['sum_money']));
//甲方信息
$objPHPExcel->getActiveSheet()->setCellValue('B'.($tline+3), $first_party_info['partner']);//甲方
$objPHPExcel->getActiveSheet()->setCellValue('B'.($tline+4), $first_party_info['link_man']);//联系人
$objPHPExcel->getActiveSheet()->setCellValue('B'.($tline+5), $first_party_info['link_phone']."\t");//联系电话
$objPHPExcel->getActiveSheet()->setCellValue('B'.($tline+6), $first_party_info['invoice_item']);//开票项目
$objPHPExcel->getActiveSheet()->setCellValue('B'.($tline+7), $first_party_info['invoice_type']);//发票类型
$objPHPExcel->getActiveSheet()->setCellValue('B'.($tline+8), $first_party_info['address']);//发票类型
//乙方信息
$objPHPExcel->getActiveSheet()->setCellValue('E'.($tline+3), $second_party_info['partner']);//乙方
$objPHPExcel->getActiveSheet()->setCellValue('E'.($tline+4), $second_party_info['link_man']);//联系人
$objPHPExcel->getActiveSheet()->setCellValue('E'.($tline+5), $second_party_info['phone']."\t");//联系电话
$objPHPExcel->getActiveSheet()->setCellValue('E'.($tline+6), $second_party_info['address']);//邮寄地址
if ($second_party_info['is_payment'] != 1) {
$objPHPExcel->getActiveSheet()->setCellValue('E'.($tline+8), $second_party_info['bank_address']);//户名
$objPHPExcel->getActiveSheet()->setCellValue('E'.($tline+9), $second_party_info['bank_card']."\t");//银行账号
$objPHPExcel->getActiveSheet()->setCellValue('E'.($tline+10), $second_party_info['bank_name']);//开户行
} else {
$objPHPExcel->getActiveSheet()->setCellValue('E'.($tline+8), $second_party_info['ali_user']);//户名
$objPHPExcel->getActiveSheet()->setCellValue('E'.($tline+9), $second_party_info['ali_account']."\t");//银行账号
}
$fileName = "{$data['company_name']}&{$data['my_company']}-对账单{$statement_begin_time}-{$statement_end_time}";
// dd($fileName);
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');
exit;
}
public function viewWmStatement($wm_statement_ids = '',$is_export=0) {
if (!$wm_statement_ids) {
$this->error('参数错误');
}
if ($is_export) {
$this->exportWmStatement($wm_statement_ids);
}
$data = SM("new_company_statement_info","tab_")->where(['id'=>$wm_statement_ids])->find();
$list = json_decode($data['statement_info'],true);
$statement_begin_time = date("Y-m-d",$data['statement_begin_time']);
$statement_end_time = date("Y-m-d",$data['statement_end_time']);
$amount_data['pay_amount'] = $data['pay_amount'];
$amount_data['user_newcount'] = $data['user_newcount'];
$amount_data['fax_ratio'] = $data['fax_ratio'];
$amount_data['sum_money'] = $data['sum_money'];
$first_party_info = json_decode($data['first_party_info'],true);
$second_party_info = json_decode($data['second_party_info'],true);
$this->assign("list",$list);
$this->assign("row",count($list));
$this->assign("company_name",$data['company_name']);
$this->assign("statement_begin_time",$statement_begin_time);
$this->assign("statement_end_time",$statement_end_time);
$this->assign("amount_data",$amount_data);
$this->assign("first_party_info",$first_party_info);
$this->assign("second_party_info",$second_party_info);
$this->display("poolWmStatement");
}
//撤销汇总
public function cancelPool(){
if(!isset($_REQUEST['id'])) $this->error("参数错误");
$id = $_REQUEST['id'];
//获取基础信息
$db_res = $this->DBModel->where("id='{$id}'")->find();
if (IS_SUBSITE) {
$this->cancelWmCompanyPool($db_res);
}
}
public function cancelWmCompanyPool($info)
{
if(in_array($info['verify_status'],[3,4])) return;//有打款就不允许回退
$sids = $info['statement_ids'];
$wm_statement_ids = $info['wm_statement_ids'];
SM()->startTrans();//事务
//删除info
$infores = SM("new_company_statement_info","tab_")->where(['id'=>$wm_statement_ids])->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"=>"撤销汇总失败"));
}
//修改结算单信息
$sids = array_filter(explode(",",$sids));
$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"=>"撤销汇总失败"));
}
}
SM()->commit();
$this->ajaxReturn(array(
'status' => 1,
"info"=>"撤销汇总成功"
));
}
public function OpWmAuth($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); //强制汇总的都允许回退
//原始列表
$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","cancelPool"];
break;
case '1':
$optist = ["viewPool","viewVoucher","editVoucher","uploadVoucher","editPayment","setUlPayment"];
break;
case '2':
$optist = ["viewPool","viewVoucher","editVoucher","uploadVoucher"];
break;
case '3':
$optist = ["viewPool","viewVoucher","editVoucher","uploadVoucher","viewPayment"];
break;
case '4':
$optist = ["viewPool","viewVoucher","editVoucher","uploadVoucher","viewPayment"];
break;
case '5':
$optist = ["viewPool","cancelPool"];
break;
case '6':
$optist = ["viewPool","cancelPool"];
break;
default:
break;
}
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 = [
"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;
}
}