@ -112,7 +112,7 @@ class CompanyStatementController extends ThinkController
if(isset($_REQUEST['verify_status'])){
$map['verify_status'] = $_REQUEST['verify_status'];
}
$this->checkListOrCountAuthRestMap($map);//导出权限
// $this->checkListOrCountAuthRestMap($map);//导出权限
//条件end
$data = M("company_statement","tab_")
->field("id,withdraw_type,company_name,company_belong,statement_begin_time,statement_end_time,statement_money,platform_amount,verify_status,verify_log,op_time,remark")
@ -704,40 +704,60 @@ class CompanyStatementController extends ThinkController
//获取要结算的公司及日期
public function getNewStatement()
{
$senddata = [];
//1.获取要计算的公司
$statement = M("company_statement","tab_")->field("count(id) count,company_id")->group("company_id")->select();
$has_company_id =implode(",",array_column($statement, 'company_id'));
if(empty($has_company_id)){
$where = "1=1";
}else{
$where = "(first_company_type > 0 AND first_company_id NOT IN ({$has_company_id}) ) OR ( second_company_type > 0 AND second_company_id NOT IN ({$has_company_id}) )";
}
$relation = M("company_relation","tab_")->field("first_company_id,first_company_type,second_company_id,second_company_type")->where($where)->select();
$senddata = [
"up_company_id"=>[],
"dowm_company_id"=>[],
];
$statement = M("company_statement","tab_")->field("count(id) count,company_id,company_belong")->group("company_id,company_belong")->select();
$up_company_id = [];
$dowm_company_id= [];
foreach($relation as $k=>$v){
foreach( $statement as $k=>$v){
if($v['company_belong'] == 9){
$up_company_id[] = $v['company_id'];
}else{
$dowm_company_id[]= $v['company_id'];
}
}
;
//获取上游
if(empty($up_company_id)){
$upwhere = "1=1";
}else{
$up_company_id =implode(",",$up_company_id);
$upwhere = "(first_company_type = 1 AND first_company_id NOT IN ({$up_company_id}) ) OR ( second_company_type = 1 AND second_company_id NOT IN ({$up_company_id}) )";
}
$uprelation = M("company_relation","tab_")->field("first_company_id,first_company_type,second_company_id,second_company_type")->where($upwhere)->select();
foreach($uprelation as $k=>$v){
if($v['first_company_type'] == 0){
if($v['second_company_type'] == 1){
$up_company_id[] = $v['second_company_id'];
}else{
$dowm_company_id[] = $v['second_company_id'];
}
$senddata["up_company_id"][] = $v['second_company_id'];
}else{
if($v['first_company_type'] == 1){
$up_company_id[] = $v['first_company_id'];
}else{
$dowm_company_id[]=$v['first_company_id'];
}
$senddata["up_company_id"][] = $v['first_company_id'];
}
}
if(count($up_company_id) < 1 & & count ( $ dowm_company_id ) < 1 ) {
$this->ajaxReturn(["error"=>'无新增关系,无需重算']);
//获取下游
if(empty($dowm_company_id)){
$downwhere = "1=1";
}else{
$dowm_company_id =implode(",",$dowm_company_id);
$downwhere = "(first_company_type = 1 AND first_company_id NOT IN ({$dowm_company_id}) ) OR ( second_company_type = 1 AND second_company_id NOT IN ({$dowm_company_id}) )";
}
$downrelation = M("company_relation","tab_")->field("first_company_id,first_company_type,second_company_id,second_company_type")->where($downwhere)->select();
foreach($downrelation as $k=>$v){
if($v['first_company_type'] == 0){
$senddata["dowm_company_id"][] = $v['second_company_id'];
}else{
$senddata["dowm_company_id"][] = $v['first_company_id'];
}
}
$senddata['up_company_id'] = implode(",",$up_company_id);
$senddata['dowm_company_id'] = implode(",",$dowm_company_id);
if(count($senddata["up_company_id"]) < 1 & & count ( $ senddata [ " dowm_company_id " ] ) < 1 ) {
$this->ajaxReturn(["error"=>'无新增关系,无需重算']);
}
$senddata['up_company_id'] = implode(",",$senddata['up_company_id']);
$senddata['dowm_company_id'] = implode(",",$senddata['dowm_company_id']);
//获取要结算的日期
$start = strtotime('-1 month');
@ -754,7 +774,6 @@ class CompanyStatementController extends ThinkController
}
$senddata['datelist'] = $datelist;
$senddata['count'] = count($datelist);
$this->ajaxReturn(["success"=>'ok',"data"=>$senddata]);
}
public function updateNewStatement()