|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Admin\Controller;
|
|
|
|
/**
|
|
|
|
* 聚合下游结算
|
|
|
|
* @author 王贺
|
|
|
|
*/
|
|
|
|
class AggregateFinanceStatementController extends ThinkController
|
|
|
|
{
|
|
|
|
public $verify_status = [
|
|
|
|
"-1"=>"审核拒绝",
|
|
|
|
"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 H:i:s',$value['begintime']);
|
|
|
|
$data[$key]['endtime'] = date('Y-m-d H:i:s',$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->meta_title = '结算单管理';
|
|
|
|
$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'];
|
|
|
|
//拼凑数据
|
|
|
|
$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
|
|
|
|
);
|
|
|
|
$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));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|