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.

238 lines
9.6 KiB
PHTML

5 years ago
<?php
namespace Admin\Controller;
/**
* 聚合下游结算
* @author 王贺
*/
class AggregateFinanceStatementController extends ThinkController
{
public $verify_status = [
"-1"=>"审核拒绝",
"0"=>"未申请开票",
"1"=>"申请开票",
"2"=>"审核同意",
"3"=>"已开票",
"4"=>"上传收款凭证",
"5"=>"已到账"
];
public function lists() {
5 years ago
$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 = [];
5 years ago
5 years ago
if (isset($_REQUEST['time_start']) && isset($_REQUEST['time_end'])) {
5 years ago
$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})";
5 years ago
} elseif (isset($_REQUEST['time_start'])) {
5 years ago
$time_start = strtotime($_REQUEST['time_start']);
$map["_string"] = "(begintime >= {$time_start} ) OR (endtime >= {$time_start})";
5 years ago
} elseif (isset($_REQUEST['time_end'])) {
5 years ago
$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];
5 years ago
}
5 years ago
5 years ago
if ($_REQUEST['verify_status']) {
$map['verify_status'] = $_REQUEST['verify_status'];
}
if ($_REQUEST['channel_id']) {
$map['channel_id'] = $_REQUEST['channel_id'];
}
5 years ago
$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]];
}
}
5 years ago
}
$data = M("aggregate_statement","tab_")
->where($map)
5 years ago
->order("create_time Desc")->page($page,$row)->select();
5 years ago
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']);
5 years ago
$data[$key]['withdraw_type_1'] = ($value['withdraw_type'] == 1 ? "月结" :"周结");
$data[$key]['withdraw_type_2'] = ($value['withdraw_type'] == 2 ? "补点" :"正常结算");
5 years ago
}
$count = M("aggregate_statement","tab_")->field("count(id) count,SUM(ratio_money) ratio_money")->where($map)->find();
5 years ago
5 years ago
//分页
$parameter['p'] = $page;
$parameter['row'] = $row;
$page = set_pagination($count['count'], $row, $parameter);
5 years ago
if ($page) {
$this->assign('_page', $page);
}
$this->assign('data',$data);
$this->assign('total',$count['ratio_money']);
5 years ago
$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();
}
5 years ago
//申请开票
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("参数错误");
}
5 years ago
//拼凑数据
$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()
5 years ago
);
$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();
}
5 years ago
}