在使用工作流和通达自带CRM中,发现工作流与CRM数据,只有单向查询(工作流查看CRM数据,反之不行)。实际工作中需要执行流程时,顺带写入合同信息至CRM中,来实现两个模块的双向通讯。目前通过通达oa工作流的触发器插件,在工作流程数据在执行过程中,写入CRM客户管理系统中。

通过工作流表单数据,来关联CRM中合同信息和甲方信息。数据写入在crm合同数据表中。省去了在CRM中新建合同的过程。

工作流表单中的数据选择控件




未加入数据重复的判断,和工作流提醒。待后续考虑。代码如下:

<?php
 /**
 * Created by PhpStorm.
 * User: benqing
 * Date: 2019/1/10
 * Time: 16:29
 */
include_once( "inc/auth.inc.php" );
include_once( "/general/workflow/plugin/plugin.inc.php" );
$RUN_DATA = getRunData($RUN_ID);
\\获取工作流表单数据
$contract_name=$RUN_DATA['项目名称-承揽表'];
$account_id_text=$RUN_DATA['甲方名称-承揽表'];
$contract_category=$RUN_DATA['工程类别-承揽表'];
$charge_preson_text=$RUN_DATA['部门委托项目负责人-承揽表']; 
$prjsn=$RUN_DATA['项目编号-承揽表'];
$createtime=time();
$contract_code = Date("YmdHis");
$create_man=$_SESSION["LOGIN_BYNAME"];
$create_man_text=$_SESSION["LOGIN_USER_NAME"];
$userid=$_SESSION["LOGIN_UID"];
$userdepid=$_SESSION["LOGIN_DEPT_ID"];
$userdep=$_SESSION["LOGIN_DEPT_ID_JUNIOR"];
\\反查crm和user表,获取用户ID
$qid="SELECT  * FROM  `crm_account` WHERE  `deleted` =0 AND  `account_name` = '$account_id_text'";
$account=exequery(TD::conn(),$qid);
$account=mysql_fetch_assoc($account);
$account_id=$account['id'];

$quid = "SELECT USER_ID from USER where USER_NAME='$charge_preson_text'";
$uid= exequery(TD::conn(),$quid); 
$uid=mysql_fetch_assoc($uid);
$charge_preson=$uid['USER_ID'];


\\写入CRM数据库
$query2 = "INSERT INTO `crm_contract` (create_time,update_time,create_man,create_man_text,update_man,update_man_text,owner,owner_dept,create_dept,deleted,contract_name,account_id,account_id_text,contract_code,contract_category,signing_date,begin_time,contract_status,charge_preson,charge_preson_text,field3) 
               VALUES ('$createtime','$createtime','$userid','$create_man_text','$userid','$create_man_text','$userid','$userdepid','$userdepid','0','$contract_name','$account_id','$account_id_text','$contract_code','$contract_category','$createtime','$createtime','STATUS_NAME_10000','$charge_preson','$charge_preson_text','$prjsn')";
exequery(TD::conn(),$query2);

?>
 

下一步,视需求考虑重复数据的update问题。

UPDATE `TD_OA`.`crm_contract` SET `contract_name` = ‘项目名称项目名称项目名称测试11’,
`contract_category` = ‘类别策略111’ WHERE `crm_contract`.`id` =18 LIMIT 1 ;