'') "; } $orderby=empty($orderby)!=false ? "" : $orderby; If (strrpos($orderby," desc")>1){ $orderbydesc=""; $descTXT="↓"; }else{ $orderbydesc=" desc"; $descTXT="↑"; } If ($orderby=="") { $orderby="OA_DepartmentID,OA_User_ID"; $descTXT="↓"; } if ($OrdDateType=="0" and $OrdDateStart=="" and $OrdDateEnd=="") {$OrdDateType=4;} $SqlOrdDateType=empty($SqlOrdDateType)!=false ? "" : $SqlOrdDateType; $OAOccupationSQL=empty($OAOccupation)!=false ? "" : " and EntourageID in (".$OAOccupation.") "; $StaffScoreSum=0; $StaffScoreSum_Bad=0; $StaffScoreSum_Other=0; //汇总查询 $sql="select StaffScoreSum=count(DispatchOrdID) from (select DispatchOrdID from DispatchOrd_Entourage,DispatchOrd,ServiceOrder where ServiceOrdID=ServiceOrdIDDt and DispatchOrdID=DispatchOrdIDDt and (Guest_PointE<>'0' or RV_PointE<>'0') and DispatchOrdState in (4,5,6,7,8,9) and EntourageState<>4".$OAOccupationSQL." and ServiceOrdVisit_time ".$SqlOrdDateType." and DispatchOrdClass in ('".$OrdClassListSql."') GROUP BY DispatchOrdID) as aa"; //echo $sql;exit; $data = sqlsrv_query($conn,$sql); if($data == true){ while($rs = sqlsrv_fetch_array( $data, SQLSRV_FETCH_ASSOC) ) { $StaffScoreSum = $rs['StaffScoreSum']; } } $sql="select StaffScoreSum_Bad=count(DispatchOrdID) from (select DispatchOrdID from DispatchOrd_Entourage,DispatchOrd,ServiceOrder where ServiceOrdID=ServiceOrdIDDt and DispatchOrdID=DispatchOrdIDDt and (Guest_PointE like '%1%' or Guest_PointE like '%2%' or RV_PointE like '%1%' or RV_PointE like '%2%') and DispatchOrdState in (4,5,6,7,8,9) and EntourageState<>4".$OAOccupationSQL." and (ServiceOrdVisit_time ".$SqlOrdDateType." or Guest_Time ".$SqlOrdDateType.") and DispatchOrdClass in ('".$OrdClassListSql."') GROUP BY DispatchOrdID) as aa"; //echo $sql;exit; $data = sqlsrv_query($conn,$sql); if($data == true){ while($rs = sqlsrv_fetch_array( $data, SQLSRV_FETCH_ASSOC) ) { $StaffScoreSum_Bad = $rs['StaffScoreSum_Bad']; } } $sql="select StaffScoreSum_Other=count(DispatchOrdID) from (select DispatchOrdID from DispatchOrd_Entourage,DispatchOrd,ServiceOrder where DispatchOrdID=DispatchOrdIDDt and ServiceOrdID=ServiceOrdIDDt and Guest_PointE='0' and RV_PointE='0' and ServiceOrdVisit<>'' and DispatchOrdState in (4,5,6,7,8,9) and EntourageState<>4".$OAOccupationSQL." and ServiceOrdVisit_time ".$SqlOrdDateType." and DispatchOrdClass in ('".$OrdClassListSql."') GROUP BY DispatchOrdID) as aa"; //echo $sql;exit; $data = sqlsrv_query($conn,$sql); if($data == true){ while($rs = sqlsrv_fetch_array( $data, SQLSRV_FETCH_ASSOC) ) { $StaffScoreSum_Other = $rs['StaffScoreSum_Other']; } } //查询开始 $sql="select OA_User_ID,OA_Name,DispatchOrdID,ServiceOrdID,DispatchOrdNo=DispatchOrdClass+convert(nvarchar(10),year(DispatchOrd_NS_Time))+right('0'+convert(nvarchar(10),month(DispatchOrd_NS_Time)),2)+right('0'+convert(nvarchar(10),day(DispatchOrd_NS_Time)),2)+'-'+right('00'+convert(nvarchar(10),DispatchOrdNo),3),ServiceOrdType,DispatchOrd_NS_Time=convert(char,DispatchOrd_NS_Time,120),Guest_Point_1,Guest_Point_2,Guest_Point_3,Guest_PointE,Guest_Impression,Guest_Evaluate,Guest_Reward,Guest_openid,Guest_Time=convert(char,Guest_Time,120),ServiceOrdReturnChannel,ServiceOrdVisit,ServiceOrdVisit_time=convert(char,ServiceOrdVisit_time,120),RV_Point_1,RV_Point_2,RV_Point_3,RV_PointE,ServiceOrdPtOutHosp=(select vtext from dictionary where vType=1 and vtitle='HospName' and vID=ServiceOrdPtOutHosp),ServiceOrdPtInHosp=(select vtext from dictionary where vType=1 and vtitle='HospName' and vID=ServiceOrdPtInHosp) from DispatchOrd_Entourage,DispatchOrd,OA_User,ServiceOrder where OA_User_ID=EntourageOAid and ServiceOrdID=ServiceOrdIDDt and DispatchOrdID=DispatchOrdIDDt and (Guest_Point_1>0 or Guest_Point_2>0 or Guest_Point_3>0 or Guest_PointE<>'0' or RV_Point_1>0 or RV_Point_2>0 or RV_Point_3>0 or RV_PointE<>'0' or ServiceOrdVisit<>'') and DispatchOrdState in (4,5,6,7,8,9) and EntourageState<>4".$OAOccupationSQL." and (ServiceOrdVisit_time ".$SqlOrdDateType." or Guest_Time ".$SqlOrdDateType.")".$searchSql." and ServiceOrdClass in ('".$OrdClassListSql."') order by OA_User_ID,DispatchOrd_NS_Time"; //echo $sql;exit; $data = sqlsrv_query($conn,$sql); if($data == true){ $FormArray=array(); //表头 $FormArray[0]=array("单号","部门","员工姓名","转出医院","转入医院","服务评价","评价内容","获知渠道","打赏","订单时间","评价时间","openid","评价来源"); $FormArrayX=count($FormArray[0]); if (sqlsrv_rows_affected($data)==0) { $SystemMessageType=2; $SystemMessageTXT="数据库中相关无数据!"; $y=0; } else { $i=1; while($rs = sqlsrv_fetch_array( $data, SQLSRV_FETCH_ASSOC) ) { //读取数据 $OA_User_ID = $rs['OA_User_ID']; $OA_Name = $rs['OA_Name']; $DispatchOrdID = $rs['DispatchOrdID']; $ServiceOrdID = $rs['ServiceOrdID']; $DispatchOrdNo = $rs['DispatchOrdNo']; $DispatchOrd_NS_Time= $rs['DispatchOrd_NS_Time']; $ServiceOrdType = $rs['ServiceOrdType']; $Guest_Point_1 = $rs['Guest_Point_1']; $Guest_Point_2 = $rs['Guest_Point_2']; $Guest_Point_3 = $rs['Guest_Point_3']; $Guest_PointE = $rs['Guest_PointE']; //客户微信评分(2020.12.22) $Guest_Impression = $rs['Guest_Impression']; $Guest_Evaluate = $rs['Guest_Evaluate']; $RV_Point_1 = $rs['RV_Point_1']; $RV_Point_2 = $rs['RV_Point_2']; $RV_Point_3 = $rs['RV_Point_3']; $RV_PointE = $rs['RV_PointE']; //电话回访评分(2020.12.22) $ReturnChannel = $rs['ServiceOrdReturnChannel']; $ServiceOrdVisit = $rs['ServiceOrdVisit']; $ServiceOrdVisit = str_replace(PHP_EOL, '', $ServiceOrdVisit); if (mb_strlen($ServiceOrdVisit)>20 and $is_CSV!=1) $ServiceOrdVisit=mb_substr($ServiceOrdVisit,0,20) . '...'; $ServiceOrdVisit_time=$rs['ServiceOrdVisit_time']; $Guest_Reward = $rs['Guest_Reward']; $Guest_openid = $rs['Guest_openid']; $Guest_Time = $rs['Guest_Time']; $ServiceOrdPtOutHosp= $rs['ServiceOrdPtOutHosp']; $ServiceOrdPtInHosp = $rs['ServiceOrdPtInHosp']; if ($Guest_Point_1+$Guest_Point_2+$Guest_Point_3==15) {$Guest_PointE=",9";} if ($RV_Point_1+$RV_Point_2+$RV_Point_3==15) {$RV_PointE=",8";} //读取数据--End //写入数组 $FormArray[$i][0]="".$DispatchOrdNo.""; $FormArray[$i][1]=OAUser($OA_User_ID,"DepartmentName"); $FormArray[$i][2]=$OA_Name; $FormArray[$i][3]=$ServiceOrdPtOutHosp; $FormArray[$i][4]=$ServiceOrdPtInHosp; if ($Guest_Point_1>0 or !empty($Guest_PointE)) { if (empty($Guest_PointE)){ $FormArray[$i][5]=$Guest_Point_1."/".$Guest_Point_2."/1".$Guest_Point_3; }else{ $FormArray[$i][5]=Guest_PointEA($Guest_PointE); } $FormArray[$i][6]=$Guest_Evaluate.$ServiceOrdVisit; $FormArray[$i][10]=date("Y-m-d",strtotime($Guest_Time)); if ($Guest_openid!="") { $FormArray[$i][12]="客户微信"; }else{ $FormArray[$i][12]="客户短信"; } }else{ if (empty($RV_PointE) and empty($ServiceOrdVisit)){ $FormArray[$i][5]=$RV_Point_1."/".$RV_Point_2."/".$RV_Point_3; }else{ $FormArray[$i][5]=Guest_PointEA($RV_PointE); } if (empty($FormArray[$i][5])) {$FormArray[$i][5]='其它';} $FormArray[$i][6]=$Guest_Evaluate.$ServiceOrdVisit; $FormArray[$i][10]=date("Y-m-d",strtotime($ServiceOrdVisit_time)); $FormArray[$i][12]="客服调查"; } $FormArray[$i][7]=$ReturnChannel; $FormArray[$i][8]=round($Guest_Reward,0); $FormArray[$i][9]=date("Y-m-d",strtotime($DispatchOrd_NS_Time)); $FormArray[$i][11]=$Guest_openid; $i++; } } } if ($is_CSV==2) { echo json_encode($FormArray); } //echo print_r($FormArray); //exit; ?>