/*//2023年9月25日
功能:根据flow_id,或run_id,获取该流程的字段名称及其所在数据表名
返回值:$retData 例如:
array(
'sortAndDesc'=array(
'main'=>'表单名称',
'detail_816'=>'列表控件名称'
),
'sortWithTb'=>array(
'main'=>array(
'bpm_data_532',
'bpm_data_532_child'//如果表达中有多行文本框时,则有子表
),
'detail_816'=>array(
'bpm_data_532_list',//如果存在列表控件
'bpm_data_532_list_816_child'//如果列表控件中有多行文本框时,则有子表
)
),
'colAndDesc'=array(
'data_m18477'=>'申请日期',
'data_m18478'=>'备注',
'data_m18480'=>'部门',
'data_m18481'=>'备注'
),
'colInTb'=>array(
'data_m18477'=>'bpm_data_532',
'data_m18478'=>'bpm_data_532_child',
'data_m18480'=>'bpm_data_532_list',
'data_m18481'=>'bpm_data_532_list_816_child'
)
)
*/
function getColAndTbCy($run_id=''){
//流程表名前缀
$tbNamePre='bpm_data_';
$FLOW_ID=$flow_id;
$RUN_ID=$run_id;
//返回数据
$retData=array();
//SORT_ID=>表名描述 //可以根据表名描述获取对应SORT_ID
$retData['sortAndDesc']=array();
//SORT_ID=>表名数组 //可以根SORT_ID获取对应数据表名
$retData['sortWithTb']=array();
//字段名=>控件名称 //可以根据控件名获取对应字段名
$retData['colAndDesc']=array();
//字段名=>所在数据表 //可以根据字段名,获取对应的表名,然后更新该字段
$retData['colInTb']=array();
//根据RUN_ID获取FlOW_ID
$sql='select * from bpm_run where RUN_ID='.$RUN_ID.' limit 1';
$res=exequery(TD::conn(),$sql);
$row=mysqli_fetch_assoc($res);
$FLOW_ID = $row['FLOW_ID'];
$tbNamePre=$tbNamePre.$FLOW_ID;
//获取该流程的有关的数据表名
$sortIdArr=array();
$sortTypeArr=array();
$sortAndDesc=array();
$sql='select * from bpm_variable_sort where FLOW_ID='.$FLOW_ID;
$res=exequery(TD::conn(),$sql);
while ($row=mysqli_fetch_assoc($res)) {
if($row['TYPE']=='main'){
$tmpKey='main';
}else{
$tmpKey=$row['TYPE'].'_'.$row['ID'];
}
$sortAndDesc[$tmpKey]=$row['DESC'];
$sortTypeArr[$row['ID']]=$row['TYPE'];
array_push($sortIdArr,$row['ID']);
}
//获取该流程表单的字段名及对应的中文描述
$colArr=array();
$sql='select * from bpm_variable where SORT_ID in ('.implode(',',$sortIdArr).')';
$res=exequery(TD::conn(),$sql);
while ($row=mysqli_fetch_assoc($res)) {
array_push($colArr,$row);
}
//查询相关表
$colAndDesc=array();
$colInTb=array();
$sortWithTb=array();
$tmp_tb="";
foreach($colArr as $k=>$v){
$type=$sortTypeArr[$v['SORT_ID']];
if($type=='main'){
$tmpKey='main';
}else{
$tmpKey=$type.'_'.$v['SORT_ID'];
}
$colAndDesc[$v['NAME']]=$v['DESC'];
if(!isset($sortWithTb[$tmpKey])){
$sortWithTb[$tmpKey]=array();
}
if($type=='main'){ //主表
if($v['TYPE']=='text'){ //如果控件类型为text,则该字段在表xxx_child中
$tmp_tb=$tbNamePre.'_child';
}else{
$tmp_tb=$tbNamePre;
}
}else if($type=='detail'){//列表组件
if($v['TYPE']=='text'){ //如果控件类型为text,则该字段在表xxx_child中
$tmp_tb=$tbNamePre.'_list_'.$v['SORT_ID'].'_child';
}else{
$tmp_tb=$tbNamePre.'_list_'.$v['SORT_ID'];
}
}
if(!in_array($tmp_tb, $sortWithTb[$tmpKey])){
array_push($sortWithTb[$tmpKey],$tmp_tb);
sort($sortWithTb[$tmpKey]);//调整表名排序 第一个主表,第二个_child子表
}
$colInTb[$v['NAME']]=$tmp_tb;
}
$retData['sortAndDesc']=$sortAndDesc;
$retData['sortWithTb']=$sortWithTb;
$retData['colAndDesc']=$colAndDesc;
$retData['colInTb']=$colInTb;
return $retData;
}
使用说明
/*
借款单
*/
include_once "inc/auth.inc.php";
include_once "erkai/common/self_functions.php";
include_once "erkai/jindie/common/header.php";
include_once "erkai/jindie/api/PXZV_JJ.php";
include_once "erkai/jindie/api/BD_Empinfo.php";
include_once "inc/session.php";
//重复推送检查
$bok=tuiSongAgain($RUN_ID);
if($bok){
Message("提示","推送失败!同一个流程不能重复推送!
");
die();
}
$colAndTbData=getColAndTbCy($RUN_ID);
$sortAndDesc=$colAndTbData['sortAndDesc'];//表名描述
$sortWithTb=$colAndTbData['sortWithTb'];//表名数组
$colAndDesc=$colAndTbData['colAndDesc'];//字段描述
$colInTb=$colAndTbData['colInTb'];//字段所在表名
$data_m_sqr=array_search('借款人1', $colAndDesc);
$data_m_jdbm=array_search('金蝶系统部门', $colAndDesc);
$data_m_jkzlb=array_search('借款子类别', $colAndDesc);
$data_m_jdjkdx=array_search('金蝶借款对象', $colAndDesc);
$data_m_jkdx=array_search('借款对象', $colAndDesc);
$data_m_jkje=array_search('借款金额', $colAndDesc);
$data_m_dfkm=array_search('对方科目', $colAndDesc);
$data_m_djbh=array_search('单据编号', $colAndDesc);
//获取主表名及其_child子表
$tbArr=$sortWithTb['main'];
$cTbArr=count($tbArr);
if($cTbArr==1){
$sql="select * from ".$tbArr[0]." where run_id='".$RUN_ID."'";
}else if($cTbArr==2){
$sql="select * from ".$tbArr[0]." as a join ".$tbArr[1]." as b on a.run_id=b.run_id where a.run_id='".$RUN_ID."'";
}
$res=exequery(TD::conn(),$sql);
$sql_run_data=mysqli_fetch_assoc($res);