当前位置: 首页 > 工具软件 > ipos > 使用案例 >

通达OA对接IPOS促销方案

柴俊捷
2023-12-01

通达OA提交流程IPOS自动生成对应的促销单据

通过OA流程触发器调用PHP文件执行对应的功能

<script>  
    jQuery.ajaxSetup({  
        type:"POST",  
        dataType:"json",  
        async:false,  
        cache:false  
    });   
      
    function chkSubIsOver_before_callBack_<?php echo $PRCS_KEY_ID;?>(){  
        var run_id=jQuery("input[name='run_id']:eq(0)").val();      //获取流水号  
        var flow_id=jQuery("input[name='flow_id']:eq(0)").val();    //获取流程ID号  
        //获取表单内控件值  如果需要对表单某个数据做较验,可以使用以下部份        
      //  var myform=jQuery(window.frames["work_form_data"].document).find("form[name='form1'");  
       // var val=myform.find(":input[name='DATA_2']").val(); 
    }  
</script> 

<?php
include_once ("inc/auth.inc.php");  
ob_end_clean();  
include_once ("../plugin.inc.php"); 
require_once('/../conn/config_109_ipos.php');  //加载数据库文件	
$RUN_DATA = getRunData($RUN_ID);
//var_dump($RUN_DATA);
//获取表格变量
$hd_name=$RUN_DATA['申请店铺'].$RUN_DATA['申请活动名称'].$RUN_DATA['活动方案'];
$hd_starttime=strtotime($RUN_DATA['活动开始日期']);
$hd_stoptime=strtotime($RUN_DATA['活动结束日期']);
if($hd_stoptime<$hd_starttime){
	echo "<script language=\"JavaScript\">\r\n";
	echo " alert(\"结束日期小于开始日期,程序无法继续!\");\r\n";
	echo " history.back();\r\n";
	echo "</script>";
	exit;
}
$hd_fangan=$RUN_DATA['活动方案'];
$id=$RUN_ID;	//流程ID
$hostname = gethostbyaddr("127.0.0.1");   //机器号
$today = date("Y-m-d H:m:s");
$sprq= strtotime ('now');   //审批日期
$name=$_SESSION["LOGIN_USER_NAME"];   //取当前登录用户名
$sddm=$RUN_DATA['商店代码'];
$sdmc=$RUN_DATA['申请店铺'];
//判断是否已经生成过了
$sql_pd="select * from ipos_kbcxd where bz like '%{$id}%'";
$result_pd=mysql_query($sql_pd,$link_ipos);
$row_pd=mysql_fetch_array($result_pd);
if(empty($row_pd)){

//取系统单据号
$sql_djbh="select djbh from ipos_kbcxd ORDER BY djbh desc limit 1";
$result_djbh=mysql_query($sql_djbh,$link_ipos);
$row_djbh=mysql_fetch_array($result_djbh);
$num=str_replace('kbcx','',$row_djbh['djbh'])+1; 
switch(strlen($num)){
	case 5:
	$djbh="kbcx0".$num;
	break;
	case 6:
	$djbh="kbcx".$num;
	break;
}
//echo $djbh;

//取主表系统ID号
$sql_id="select id from ipos_kbcxd ORDER BY id desc limit 1";
$result_id=mysql_query($sql_id,$link_ipos);
$row_id=mysql_fetch_array($result_id);
$num_id=str_replace('kbcx','',$row_id['id'])+2;

//插入促销方案主表ipos_kbcxd 
$sql_zb="INSERT INTO ipos_kbcxd (id,tn_id, djbh, ydjh, rq, org_id, orgdm, orgmc, hdmc, rq_1, rq_2, cxlx, mrz, fjcx, cxdx, tjkz, kbsl, kbfs, zpsl, sdkz, tm_1, tm_2, cxrkz, cxr, sp, spr, sprq, zz, zzr, zzrq, zzbz, zdr, zdrq, xgr, xgrq, bz, row_no, alterdate, lastchanged, level, jsxz, html, mgzd, tjcx, dj, sp_sku, level_0, jfbl_jc, yxzkq, cxzk_yx, wkzk_yx, sydx, fjrl, ckjtype, tzspcx, bcyzddz, kltz, xebcycx, yxthh, mgzdspsz, mgzdspjg, cxhdz_id, viphyj, zdxycx, jtvip, fjzk_kxh, fjzk, mrzk, hgtj, hgtj1, hgtj2, hgje, icrm_is_fetch) 
VALUES ('{$num_id}','0', '{$djbh}', '', '{$sprq}', '1', NULL, NULL, '{$hd_name}', '{$hd_starttime}', '{$hd_stoptime}', '0', '1.0000', '1', '0', '0', '1', '0', '1', '0', '0', '0', '0', '', '1', '{$name}', '{$sprq}', '0', NULL, NULL, '1', '{$name}', '{$sprq}', '{$name}', '{$sprq}', '流水号:{$id}', NULL, NULL, '{$today}', NULL, '1', '', '0', '0', '1', '0', '0', '0', '0', '0', '0', '1,2', '0', '0', '0', '1', '0', '1', '1', '0', '0.0000', '7', '0', '1', '0', '0', '0', '1', '0', '0', '0', '0', '1')";
$result_zb=mysql_query($sql_zb,$link_ipos);
//echo $sql_zb;
//插入促销方案商品主表ipos_kbcxdsp
$sql_spid="select id from ipos_kbcxdsp ORDER BY id desc limit 1";
$result_spid=mysql_query($sql_spid,$link_ipos);
$row_spid=mysql_fetch_array($result_spid);
$num_spid=$row_spid['id']+1;
$sql_sp1="INSERT INTO ipos_kbcxdsp (Id, pid, tn_id, xh, spjs, spms, jtsp, sptj, dj, zk, bz, row_no, alterdate, lastchanged, lx, lwsp) VALUES ('{$num_spid}', '{$num_id}', '0', '0', '商品类别[[000]-主打]', '', '0', 'sx2_id in (1)', '0.00', '1.0000', '', NULL, NULL, '{$today}', '0', '0')";
$num_spid++;
$sql_sp2="INSERT INTO ipos_kbcxdsp (Id, pid, tn_id, xh, spjs, spms, jtsp, sptj, dj, zk, bz, row_no, alterdate, lastchanged, lx, lwsp) VALUES ('{$num_spid}', '{$num_id}', '0', '0', '商品类别[[1]-非主打]', '', '0', 'sx2_id in (2)', '0.00', '1.0000', '', NULL, NULL, '{$today}', '0', '0')";
$result_sp1=mysql_query($sql_sp1,$link_ipos);
$result_sp2=mysql_query($sql_sp2,$link_ipos);

//插入促销方案店铺主表ipos_kbcxdzd
$sql_zdid="select id from ipos_kbcxdzd ORDER BY id desc limit 1";
$result_zdid=mysql_query($sql_zdid,$link_ipos);
$row_zdid=mysql_fetch_array($result_zdid);
$num_zdid=$row_zdid['id']+1;
$sql_zd="INSERT INTO ipos_kbcxdzd (Id, pid, tn_id, zdjs, jtzd, zdtj, zbje, lastchanged) VALUES ('{$num_zdid}', '{$num_id}', NULL, '{$sddm}', '1', NULL, '0.00', '{$today}')";
$result_zd=mysql_query($sql_zd,$link_ipos);

//插入促销方案店铺明细表ipos_kbcxdzdmx
$sql_zdmxid="select id from ipos_kbcxdzdmx ORDER BY id desc limit 1";  //取明细表ID
$result_zdmxid=mysql_query($sql_zdmxid,$link_ipos);
$row_zdmxid=mysql_fetch_array($result_zdmxid);
$num_zdmxid=$row_zdmxid['id']+1;

$sql_zdmxid1="select id from ipos_kbcxdzd where pid='{$num_id}'";  //取终端表ID
$result_zdmxid1=mysql_query($sql_zdmxid1,$link_ipos);
$row_zdmxid1=mysql_fetch_array($result_zdmxid1);
$num_zdmxid1=$row_zdmxid1['id'];


$sql_zdmxid2="select id,khmc from com_base_kehu where khdm='{$sddm}'";  //取终端ID
$result_zdmxid2=mysql_query($sql_zdmxid2,$link_ipos);
$row_zdmxid2=mysql_fetch_array($result_zdmxid2);
$num_zdmxid2=$row_zdmxid2['id'];


$sql_zdmx="INSERT INTO ipos_kbcxdzdmx (Id, pid, tn_id, zd_id, zddm, zdmc, zbje, lastchanged) VALUES ('{$num_zdmxid}', '{$num_zdmxid1}', '0', '{$row_zdmxid2['id']}', '{$sddm}', '{$row_zdmxid2['khmc']}', '0.00', '{$today}')";
$result_zdmxid2=mysql_query($sql_zdmx,$link_ipos);


//插入促销方案结算表ipos_kbcxdjs
$sql_jsid="select id from ipos_kbcxdjs ORDER BY id desc limit 1";
$result_jsid=mysql_query($sql_jsid,$link_ipos);
$row_jsid=mysql_fetch_array($result_jsid);
$num_jsid=$row_jsid['id'];
$a=array('1','2','5','6','997','1000','1007'); //结算方式列表
for($x=0;$x<count($a);$x++){
	$num_jsid++;
	$sql_js="INSERT INTO ipos_kbcxdjs (Id, pid, tn_id, js_id, bz, lastchanged) VALUES ('{$num_jsid}', '{$num_id}', '0', '{$a[$x]}', '', '{$today}')";
	$result_js=mysql_query($sql_js,$link_ipos);	
}


//插入促销方案VIp主表ipos_kbcxdvp
$sql_vpid="select id from ipos_kbcxdvp ORDER BY id desc limit 1";
$result_vpid=mysql_query($sql_vpid,$link_ipos);
$row_vpid=mysql_fetch_array($result_vpid);
$num_vpid=$row_vpid['id'];

$sql_vp1="INSERT INTO ipos_kbcxdvp (Id, pid, tn_id, lb_id, zk, jfbl, bz, row_no, alterdate, lastchanged) VALUES ('{$num_vpid}', '{$num_id}', '0', '1', '1.0000', '1.00', '', NULL, NULL, '{$today}')";
$result_vp1=mysql_query($sql_vp1,$link_ipos);

$num_vpid++;
$sql_vp2="INSERT INTO ipos_kbcxdvp (Id, pid, tn_id, lb_id, zk, jfbl, bz, row_no, alterdate, lastchanged) VALUES ('{$num_vpid}', '{$num_id}', '0', '3', '1.0000', '1.00', '', NULL, NULL, '{$today}')";

$result_vp2=mysql_query($sql_vp2,$link_ipos);

//插入促销方案折扣表ipos_kbcxdfj
/*分5种方案 
1、1件9折2件85折
2、全场2件8折
3、1件9折2件85折3件8折
4、全场85折
5、全场2件85折
*/
$sql_fjid="select id from ipos_kbcxdfj ORDER BY id desc limit 1";
$result_fjid=mysql_query($sql_fjid,$link_ipos);
$row_fjid=mysql_fetch_array($result_fjid);
$num_fjid=$row_fjid['id'];

switch($hd_fangan){
	case '1件9折2件85折':
		$sql_1="INSERT INTO ipos.ipos_kbcxdfj (pid, tn_id, sl, zk, bz, row_no, alterdate, lastchanged, je) VALUES ( '{$num_id}', '0', '2', '0.8500', '', NULL, NULL, '{$today}', '0.00')";
		$num_fjid++;
		$sql_2="INSERT INTO ipos.ipos_kbcxdfj (pid, tn_id, sl, zk, bz, row_no, alterdate, lastchanged, je) VALUES ( '{$num_id}', '0', '1', '0.9000', '', NULL, NULL, '{$today}', '0.00')";
		$result_sql_1=mysql_query($sql_1,$link_ipos);
		$result_sql_2=mysql_query($sql_2,$link_ipos);		
		break;
		
	case '全场2件8折':
		$sql_3="INSERT INTO ipos.ipos_kbcxdfj ( pid, tn_id, sl, zk, bz, row_no, alterdate, lastchanged, je) VALUES ('{$num_id}', '0', '2', '0.8000', '', NULL, NULL, '{$today}', '0.00')";
		$result_sql_3=mysql_query($sql_3,$link_ipos);
		echo $sql_3;
		break;
	case '1件9折2件85折3件8折':
		$sql_4="INSERT INTO ipos.ipos_kbcxdfj (pid, tn_id, sl, zk, bz, row_no, alterdate, lastchanged, je) VALUES ( '{$num_id}', '0', '1', '0.9000', '', NULL, NULL, '{$today}', '0.00')";
			$num_fjid++;
		$sql_5="INSERT INTO ipos.ipos_kbcxdfj (pid, tn_id, sl, zk, bz, row_no, alterdate, lastchanged, je) VALUES ( '{$num_id}', '0', '2', '0.8500', '', NULL, NULL, '{$today}', '0.00')";
			$num_fjid++;
		$sql_6="INSERT INTO ipos.ipos_kbcxdfj (pid, tn_id, sl, zk, bz, row_no, alterdate, lastchanged, je) VALUES ( '{$num_id}', '0', '3', '0.8000', '', NULL, NULL, '{$today}', '0.00')";
		$result_sql_4=mysql_query($sql_4,$link_ipos);
		$result_sql_5=mysql_query($sql_5,$link_ipos);
		$result_sql_6=mysql_query($sql_6,$link_ipos);
		break;
	case '全场85折':
		$sql_7="INSERT INTO ipos.ipos_kbcxdfj (pid, tn_id, sl, zk, bz, row_no, alterdate, lastchanged, je) VALUES ( '{$num_id}', '0', '1', '0.8500', '', NULL, NULL, '{$today}', '0.00')";
		$result_sql_7=mysql_query($sql_7,$link_ipos);
		break;
	case '全场2件85折':
		$sql_8="INSERT INTO ipos.ipos_kbcxdfj (pid, tn_id, sl, zk, bz, row_no, alterdate, lastchanged, je) VALUES ( '{$num_id}', '0', '2', '0.8500', '', NULL, NULL, '{$today}', '0.00')";
		$result_sql_8=mysql_query($sql_8,$link_ipos);
		break;
}
echo '<br>促销单号:'.$djbh.'已生成!';
}else{
	echo "<br>此流程已经生成过促销方案,本次不在重复生成!";
	
}




?>

 类似资料: