|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Admin\Controller;
|
|
|
|
|
/**
|
|
|
|
|
* 聚合下游结算
|
|
|
|
|
* @author 王贺
|
|
|
|
|
*/
|
|
|
|
|
class AggregateFinanceStatementController extends ThinkController
|
|
|
|
|
{
|
|
|
|
|
public $verify_status = [
|
|
|
|
|
"-1"=>"审核拒绝",
|
|
|
|
|
"0"=>"未申请开票",
|
|
|
|
|
"1"=>"申请开票",
|
|
|
|
|
"2"=>"审核同意",
|
|
|
|
|
"3"=>"已开票",
|
|
|
|
|
"4"=>"已上传凭证",
|
|
|
|
|
"5"=>"已到账"
|
|
|
|
|
];
|
|
|
|
|
public $admininfo;
|
|
|
|
|
public $OpAuthList=[];
|
|
|
|
|
//TODO:
|
|
|
|
|
public function _initialize()
|
|
|
|
|
{
|
|
|
|
|
$this->admininfo = $_SESSION['onethink_admin']['user_auth'];
|
|
|
|
|
parent::_initialize();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function lists() {
|
|
|
|
|
$is_export= false;
|
|
|
|
|
if (isset($_REQUEST['export']) && $_REQUEST['export']==1){
|
|
|
|
|
$is_export = true;
|
|
|
|
|
}
|
|
|
|
|
//权限
|
|
|
|
|
if(!IS_ROOT){
|
|
|
|
|
$this->getAuth();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//分页
|
|
|
|
|
$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 ? "补点" :"正常结算");
|
|
|
|
|
|
|
|
|
|
$data[$key]['oplist'] = $this->OpAuth($value);
|
|
|
|
|
}
|
|
|
|
|
$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('menubtn',$this->menuAuth());
|
|
|
|
|
$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->doAddOperationLog($id,"申请开票");
|
|
|
|
|
$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 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 = M("aggregate_statement","tab_")->field("id,verify_status,ext_field")->where("id = '{$id}'")->find();
|
|
|
|
|
$this->assign("id",$id);
|
|
|
|
|
$this->assign("ext_field",$info['ext_field']);
|
|
|
|
|
$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_field"=>$pf,
|
|
|
|
|
];
|
|
|
|
|
//获取旧值,存在删除
|
|
|
|
|
$info = M("aggregate_statement","tab_")->field("id,verify_status,ext_field")->where("id = '{$id}'")->find();
|
|
|
|
|
if(!empty($info['ext_field'])){
|
|
|
|
|
unlink("./".$info['ext_field']);
|
|
|
|
|
}
|
|
|
|
|
//如果是开票状态就改状态
|
|
|
|
|
if($info["verify_status"] == 3){
|
|
|
|
|
$save['verify_status'] = 4;
|
|
|
|
|
$save['create_time'] = time();
|
|
|
|
|
$save["admin_name"]=$this->admininfo["username"];
|
|
|
|
|
$save["admin_id"]=$this->admininfo["uid"];
|
|
|
|
|
}
|
|
|
|
|
M("aggregate_statement","tab_")->where("id = '{$id}'")->save($save);
|
|
|
|
|
$this->doAddOperationLog($id,"上传凭证");
|
|
|
|
|
$array=array(
|
|
|
|
|
'status' => 1,
|
|
|
|
|
"info"=>"上传成功",
|
|
|
|
|
"file_path"=>$pf,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
$this->ajaxReturn($array);
|
|
|
|
|
}
|
|
|
|
|
//删除凭证
|
|
|
|
|
public function delVoucher(){
|
|
|
|
|
if(!isset($_REQUEST['id'])) $this->error("参数错误");
|
|
|
|
|
$id = $_REQUEST['id'];
|
|
|
|
|
$info = M("aggregate_statement","tab_")->field("id,ext_field")->where("id = '{$id}'")->find();
|
|
|
|
|
if(!empty($info['ext_field'])){
|
|
|
|
|
unlink("./".$info['ext_field']);
|
|
|
|
|
}
|
|
|
|
|
M("aggregate_statement","tab_")->where("id = '{$id}'")->save(['ext_field'=>'']);
|
|
|
|
|
$this->doAddOperationLog($id,"删除凭证");
|
|
|
|
|
$this->ajaxReturn(array(
|
|
|
|
|
'status' => 1,
|
|
|
|
|
'info' => "删除成功"
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
//新增备注
|
|
|
|
|
public function saveRemark(){
|
|
|
|
|
if(!isset($_REQUEST['id'])) $this->error("参数错误");
|
|
|
|
|
$id = $_REQUEST['id'];
|
|
|
|
|
$remark = $_REQUEST['remark'];
|
|
|
|
|
M("aggregate_statement","tab_")->where("id = '{$id}'")->save(['remark'=>$remark]);
|
|
|
|
|
$this->doAddOperationLog($id,"新增备注");
|
|
|
|
|
$this->ajaxReturn(array(
|
|
|
|
|
'status' => 1,
|
|
|
|
|
'info' => "操作成功"
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
//审批通过
|
|
|
|
|
public function agreeApply(){
|
|
|
|
|
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
|
|
|
|
|
$ids = $_REQUEST['ids'];
|
|
|
|
|
$savedata = ["verify_status"=>2,"create_time"=>time(),"admin_name"=>$this->admininfo["username"],"admin_id"=>$this->admininfo["uid"]];
|
|
|
|
|
M("aggregate_statement","tab_")->where("id in ({$ids})")->save($savedata);
|
|
|
|
|
|
|
|
|
|
$ids = explode(",",$ids);
|
|
|
|
|
foreach($ids as $k=>$v){
|
|
|
|
|
$this->doAddOperationLog($v,"审批通过");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->ajaxReturn(array(
|
|
|
|
|
'status' => 1,
|
|
|
|
|
"info"=>"审批通过成功"
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
//审核拒绝
|
|
|
|
|
public function refuseApply(){
|
|
|
|
|
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
|
|
|
|
|
$ids = $_REQUEST['ids'];
|
|
|
|
|
$savedata = ["verify_status"=>-1,"create_time"=>time(),"admin_name"=>$this->admininfo["username"],"admin_id"=>$this->admininfo["uid"]];
|
|
|
|
|
M("aggregate_statement","tab_")->where("id in ({$ids})")->save($savedata);
|
|
|
|
|
|
|
|
|
|
$ids = explode(",",$ids);
|
|
|
|
|
foreach($ids as $k=>$v){
|
|
|
|
|
$this->doAddOperationLog($v,"审批拒绝");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->ajaxReturn(array(
|
|
|
|
|
'status' => 1,
|
|
|
|
|
"info"=>"审批拒绝成功"
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
//已开票
|
|
|
|
|
public function Invoiced(){
|
|
|
|
|
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
|
|
|
|
|
$ids = $_REQUEST['ids'];
|
|
|
|
|
$savedata = ["verify_status"=>3,"create_time"=>time(),"admin_name"=>$this->admininfo["username"],"admin_id"=>$this->admininfo["uid"]];
|
|
|
|
|
M("aggregate_statement","tab_")->where("id in ({$ids})")->save($savedata);
|
|
|
|
|
|
|
|
|
|
$ids = explode(",",$ids);
|
|
|
|
|
foreach($ids as $k=>$v){
|
|
|
|
|
$this->doAddOperationLog($v,"已开票");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->ajaxReturn(array(
|
|
|
|
|
'status' => 1,
|
|
|
|
|
"info"=>"已开票成功"
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
//已到账
|
|
|
|
|
public function Received(){
|
|
|
|
|
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
|
|
|
|
|
$ids = $_REQUEST['ids'];
|
|
|
|
|
$savedata = ["verify_status"=>5,"create_time"=>time(),"admin_name"=>$this->admininfo["username"],"admin_id"=>$this->admininfo["uid"]];
|
|
|
|
|
M("aggregate_statement","tab_")->where("id in ({$ids})")->save($savedata);
|
|
|
|
|
|
|
|
|
|
$ids = explode(",",$ids);
|
|
|
|
|
foreach($ids as $k=>$v){
|
|
|
|
|
$this->doAddOperationLog($id,"已到账");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->ajaxReturn(array(
|
|
|
|
|
'status' => 1,
|
|
|
|
|
"info"=>"已到账成功"
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
//重算金额
|
|
|
|
|
public function updateStatement()
|
|
|
|
|
{
|
|
|
|
|
if(!isset($_REQUEST['ids'])) $this->error("参数错误");
|
|
|
|
|
$ids = explode(",",$_REQUEST['ids']);
|
|
|
|
|
foreach ($ids as $k => $v) {
|
|
|
|
|
$res = A("AggregateFinanceSet")->updateAggregateFinanceData($v);
|
|
|
|
|
if(!$res){
|
|
|
|
|
$this->ajaxReturn(array(
|
|
|
|
|
'status' => 0,
|
|
|
|
|
"info"=>"重算结算金额失败"
|
|
|
|
|
));
|
|
|
|
|
}else{
|
|
|
|
|
$this->doAddOperationLog($v,"重算结算金额");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$this->ajaxReturn(array(
|
|
|
|
|
'status' => 1,
|
|
|
|
|
"info"=>"算结算金额成功"
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//撤销审核
|
|
|
|
|
public function cancelVerify(){
|
|
|
|
|
if(!isset($_REQUEST['id'])) $this->error("参数错误");
|
|
|
|
|
$id = $_REQUEST['id'];
|
|
|
|
|
$savedata = ["verify_status"=>1,"create_time"=>time(),"admin_name"=>$this->admininfo["username"],"admin_id"=>$this->admininfo["uid"]];
|
|
|
|
|
M("aggregate_statement","tab_")->where("id ='{$id}'")->save($savedata);
|
|
|
|
|
$this->doAddOperationLog($id,"撤销审核");
|
|
|
|
|
$this->ajaxReturn(array(
|
|
|
|
|
'status' => 1,
|
|
|
|
|
"info"=>"撤销审核成功"
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
//撤销申请
|
|
|
|
|
public function cancelApply(){
|
|
|
|
|
if(!isset($_REQUEST['id'])) $this->error("参数错误");
|
|
|
|
|
$id = $_REQUEST['id'];
|
|
|
|
|
$data = M("aggregate_statement","tab_")->where("id = '{$id}'")->find();
|
|
|
|
|
$savedata = ["verify_status"=>0,"create_time"=>time(),"admin_name"=>$this->admininfo["username"],"admin_id"=>$this->admininfo["uid"]];
|
|
|
|
|
$first_party_info = json_decode($data['first_party_info'], 1);
|
|
|
|
|
if($first_party_info['partner'] == $data['channel_name']){
|
|
|
|
|
$savedata['second_party_info'] = $data['first_party_info'];
|
|
|
|
|
$savedata['first_party_info'] = $data['second_party_info'];
|
|
|
|
|
$savedata['pay_type'] =0;
|
|
|
|
|
}
|
|
|
|
|
M("aggregate_statement","tab_")->where("id ='{$id}'")->save($savedata);
|
|
|
|
|
$this->doAddOperationLog($id,"撤销申请");
|
|
|
|
|
$this->ajaxReturn(array(
|
|
|
|
|
'status' => 1,
|
|
|
|
|
"info"=>"撤销申请成功"
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
//导出
|
|
|
|
|
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->doAddOperationLog($id,"导出");
|
|
|
|
|
$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 : '<br />');
|
|
|
|
|
|
|
|
|
|
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), $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');
|
|
|
|
|
}
|
|
|
|
|
//获取权限
|
|
|
|
|
public function getAuth()
|
|
|
|
|
{
|
|
|
|
|
$group = $_SESSION['onethink_admin']['user_group_id'];
|
|
|
|
|
//获取全部权限列表
|
|
|
|
|
$ruleList = M("AuthGroup")->field("rules")->where("id='{$group}'")->find()['rules'];
|
|
|
|
|
//获取所有含有规则的数据
|
|
|
|
|
$authlist = M("AuthRule")->field('name')->where("name like 'Admin/AggregateFinanceStatement%' AND id in ($ruleList)")->select();
|
|
|
|
|
$Auth = [];
|
|
|
|
|
foreach ($authlist as $k => $v) {
|
|
|
|
|
$a = str_replace("Admin/AggregateFinanceStatement/","",$v['name']);
|
|
|
|
|
$Auth[] = $a;
|
|
|
|
|
}
|
|
|
|
|
$this->OpAuthList = $Auth;
|
|
|
|
|
}
|
|
|
|
|
public function OpAuth($info)
|
|
|
|
|
{
|
|
|
|
|
$id = $info['id'];
|
|
|
|
|
$img = $info['ext_field'];
|
|
|
|
|
$remark = $info['remark'];
|
|
|
|
|
//原始列表
|
|
|
|
|
$opBtn = [
|
|
|
|
|
"viewStatement"=>"<a class='confirm viewStatement' data-id='{$id}'>查看</a>",
|
|
|
|
|
"createStatement"=>"<a class='confirm createStatement' data-id='{$id}'>申请开票</a>",
|
|
|
|
|
"editStatement"=>"<a class='confirm editStatement' 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>",
|
|
|
|
|
"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>",
|
|
|
|
|
"cancelVerify"=>"<a class='confirm cancelVerify' data-id='{$id}' style='color: red;'>撤销审核</a>",
|
|
|
|
|
"cancelApply"=>"<a class='confirm cancelApply' data-id='{$id}' style='color: red;'>撤销申请</a>",
|
|
|
|
|
];
|
|
|
|
|
//操作对应菜单
|
|
|
|
|
$optist = [];
|
|
|
|
|
switch ($info['verify_status']) {
|
|
|
|
|
case '-1':
|
|
|
|
|
$optist = ["viewStatement","cancelVerify","addRemark","viewRemark","editRemark"];
|
|
|
|
|
break;
|
|
|
|
|
case '0':
|
|
|
|
|
$optist = ["viewStatement","createStatement"];
|
|
|
|
|
break;
|
|
|
|
|
case '1':
|
|
|
|
|
$optist = ["viewStatement","editStatement","cancelApply"];
|
|
|
|
|
break;
|
|
|
|
|
case '2':
|
|
|
|
|
$optist = ["viewStatement","cancelVerify","addRemark","viewRemark","editRemark"];
|
|
|
|
|
break;
|
|
|
|
|
case '3':
|
|
|
|
|
$optist = ["viewStatement","uploadVoucher","viewVoucher","editVoucher","addRemark","viewRemark","editRemark"];
|
|
|
|
|
break;
|
|
|
|
|
case '4':
|
|
|
|
|
$optist = ["viewStatement","viewVoucher","editVoucher","addRemark","viewRemark","editRemark"];
|
|
|
|
|
break;
|
|
|
|
|
case '5':
|
|
|
|
|
$optist = ["viewStatement","uploadVoucher","viewVoucher","editVoucher","addRemark","viewRemark","editRemark"];
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
//判断凭证和备注
|
|
|
|
|
if(empty($info['ext_field'])){
|
|
|
|
|
//未上传凭证
|
|
|
|
|
$optist = array_diff($optist, ["viewVoucher", "editVoucher"]);
|
|
|
|
|
}else{
|
|
|
|
|
$optist = array_diff($optist, ["uploadVoucher"]);
|
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
$optist = ['agreeApply',"refuseApply","Invoiced","Received","updateStatement","export"];
|
|
|
|
|
$mentBtn = [
|
|
|
|
|
"agreeApply"=>"<a class='butn' id='agreeApply'>审批通过</a>",
|
|
|
|
|
"refuseApply"=>"<a class='butn' id='refuseApply' style='background-color: red;'>审批拒绝</a>",
|
|
|
|
|
"Invoiced"=>"<a class='butn' id='Invoiced'>已开票</a>",
|
|
|
|
|
"Received"=>"<a class='butn' id='Received'>已到账</a>",
|
|
|
|
|
"updateStatement"=>"<a class='butn' id='updateStatement' style='width: 150px;background-color:green;'>重算结算金额</a>",
|
|
|
|
|
"export"=>"<a class='butn' id='export'>批量导出</a>"
|
|
|
|
|
];
|
|
|
|
|
$resarr = [];
|
|
|
|
|
foreach ($optist as $k => $v) {
|
|
|
|
|
if(IS_ROOT){
|
|
|
|
|
$resarr[] = $mentBtn[$v];
|
|
|
|
|
}else{
|
|
|
|
|
if(in_array($v,$this->OpAuthList)){
|
|
|
|
|
$resarr[] = $mentBtn[$v];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $resarr;
|
|
|
|
|
}
|
|
|
|
|
//操作日志
|
|
|
|
|
public function doAddOperationLog($id,$op_name)
|
|
|
|
|
{
|
|
|
|
|
$d= M("aggregate_statement","tab_")->where("id = '{$id}'")->find();
|
|
|
|
|
$first_party_info = json_decode($d['first_party_info'],true);
|
|
|
|
|
$second_party_info = json_decode($d['second_party_info'],true);
|
|
|
|
|
|
|
|
|
|
$statement_begin_time = date('Y.m.d', $d['begintime']);//对账开始时间
|
|
|
|
|
$statement_end_time = date('Y.m.d',$d['endtime']);//对账截止时间
|
|
|
|
|
$menu = "财务-结算管理-聚合渠道结算单管理";
|
|
|
|
|
|
|
|
|
|
if($d['withdraw_type'] == 1){
|
|
|
|
|
$m = date('Y.m', $d['begintime']);
|
|
|
|
|
$key = "{$second_party_info['partner']}&{$first_party_info['partner']}【{$m} 月结】";
|
|
|
|
|
}elseif($d['withdraw_type'] == 0){
|
|
|
|
|
$key ="{$second_party_info['partner']}&{$first_party_info['partner']}【{$statement_begin_time}-{$statement_end_time} 周结 正常结算】";
|
|
|
|
|
}else{
|
|
|
|
|
$key ="{$second_party_info['partner']}&{$first_party_info['partner']}【{$statement_begin_time}-{$statement_end_time} 周结 补点】";
|
|
|
|
|
}
|
|
|
|
|
addOperationLog(['op_type'=>1,'key'=>$key,"op_name"=>$op_name,'url'=>U(CONTROLLER_NAME.'/lists',$GetData),'menu'=>$menu]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|