id_owner = $result->id_owner; $rao->owner_name = $result->name; $rao->bounce_amount = $result->bounce_amount; $rao->check_amount = $result->check_amount; $rao->in_storage_count = $result->in_storage_count; $collection[] = $rao; } return $collection; } // 按条件查询 zengjun public static function getFindBy($array){ $sql = RejectedAnalyzeOwner::getQuerySQL($array); $resultSet = DB::select($sql); $list = []; foreach ($resultSet as $result) { $rao =[ 'id_owner' => $result->id_owner, 'owner_name'=> $result->name, 'bounce_amount'=>$result->bounce_amount, 'check_amount'=>$result->check_amount, 'uncheck_amount'=>$result->bounce_amount-$result->check_amount, 'in_storage_count'=>$result->in_storage_count, 'not_in_storage_count'=>$result->bounce_amount-$result->in_storage_count, ]; $list[] = $rao; } return $list; } public static function getExcelFromHead($array = null){ $arr = [[ 'id_owner'=>'货主编号', 'owner_name'=>'货主名', 'bounce_amount'=>'退件单数', 'check_amount'=>'审核单数', 'uncheck_amount'=>'未审核单数', 'in_storage_count'=>'入库单数', 'not_in_storage_count'=>'未入库单数', ]]; return $arr; } // 拼接条件 没有ids zengjun public static function getCondition($array) { $condition = ''; if (!is_null($array)) { foreach ($array as $key => $value) { if (!is_null($value)) { if ($key == 'owner_id' and $value!= '' and $value!='null' and $value!= '""') { $condition .= ' and id_owner = '; $condition .= $value; } if($key == 'ids'){ $sql=RejectedAnalyzeOwner::getSqlToIDs($value); $condition.=$sql; } if ($key == 'created_at_start' and !is_null($value) and $value!= "null" and $value!= '""') { $value = str_replace('"','',$value); $condition .= ' and created_at > "';$condition .= $value;$condition .= '"'; } if ($key == 'created_at_end' and !is_null($value) and $value!= "null" and $value!= '""') { $value = str_replace('"','',$value); $condition .= ' and created_at < "';$condition .= $value;$condition .= '"'; } } } } $condition .= ' group by id_owner'; return $condition; } public static function getSqlToIDs($ids):string { $sql = ''; if(!is_null($ids) && $ids !='' ) { $ids = str_replace('[','(',$ids); $ids = str_replace(']',')',$ids); $ids = str_replace('"','',$ids); $sql = $sql.' and id_owner in '.$ids; } return $sql; } // 返回sql zengjun public static function getQuerySQL($array= null){ $condition = RejectedAnalyzeOwner::getCondition($array);// 条件 $sql = 'select distinct rao.id_owner,owners.name,sum(bounce_amount) bounce_amount,sum(check_amount) check_amount,sum(in_storage_count) in_storage_count from'; $sql .= '('; // 退件单数 $sql .= ' select distinct id_owner,count(1) bounce_amount,0 check_amount,0 in_storage_count from rejected_bills where 1=1 '; $sql .= $condition; $sql .= ' UNION '; // 审核单数 $sql .= ' select distinct id_owner,0 bounce_amount,count(1) check_amount,0 in_storage_count from rejected_bills where is_checked = 1 '; $sql .= $condition; $sql .= ' UNION '; // 入库单数 $sql .= ' select distinct id_owner,0 bounce_amount,0 check_amount,count(1) in_storage_count from rejected_bills where is_loaded = 1 '; $sql .= $condition; $sql .= ') rao '; $sql .= ' left join owners on owners.id = rao.id_owner '; $sql .= ' group by rao.id_owner '; return $sql; } }