@ -704,40 +704,60 @@ class CompanyStatementController extends ThinkController
//获取要结算的公司及日期
//获取要结算的公司及日期
public function getNewStatement()
public function getNewStatement()
{
{
$senddata = [];
$senddata = [
//1.获取要计算的公司
"up_company_id"=>[],
$statement = M("company_statement","tab_")->field("count(id) count,company_id")->group("company_id")->select();
"dowm_company_id"=>[],
$has_company_id =implode(",",array_column($statement, 'company_id'));
];
if(empty($has_company_id)){
$statement = M("company_statement","tab_")->field("count(id) count,company_id,company_belong")->group("company_id,company_belong")->select();
$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();
$up_company_id = [];
$up_company_id = [];
$dowm_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['first_company_type'] == 0){
if($v['second_company_type'] == 1){
$senddata["up_company_id"][] = $v['second_company_id'];
$up_company_id[] = $v['second_company_id'];
}else{
$dowm_company_id[] = $v['second_company_id'];
}
}else{
}else{
if($v['first_company_type'] == 1){
$senddata["up_company_id"][] = $v['first_company_id'];
$up_company_id[] = $v['first_company_id'];
}else{
$dowm_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);
if(count($senddata["up_company_id"]) < 1 & & count ( $ senddata [ " dowm_company_id " ] ) < 1 ) {
$senddata['dowm_company_id'] = implode(",",$dowm_company_id);
$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');
$start = strtotime('-1 month');
@ -754,7 +774,6 @@ class CompanyStatementController extends ThinkController
}
}
$senddata['datelist'] = $datelist;
$senddata['datelist'] = $datelist;
$senddata['count'] = count($datelist);
$senddata['count'] = count($datelist);
$this->ajaxReturn(["success"=>'ok',"data"=>$senddata]);
$this->ajaxReturn(["success"=>'ok',"data"=>$senddata]);
}
}
public function updateNewStatement()
public function updateNewStatement()