php读取用友u8采购入库单列表及详细

<?php

class erpData
{
    protected static $erp;
    public function __construct()
    {
        $dbhost ="192.168.2.50";
        $dbuser = "sa"; //你的mssql用户名
        $dbpass = "sa"; //你的mssql密码
        $dbname = "UFDATA_998_2015"; //你的mssql库名
        try{
        self::$erp=odbc_connect("Driver={SQL Server};Server=$dbhost;Database=$dbname","$dbuser","$dbpass");
        }catch(Exception $e){
            echo $e->getMessage();
        }
    }

    public function get_list($search_time_start,$search_time_end){
        $sql="select cCode from dbo.RdRecord01 where cWhCode=19 and cPTCode=00 and dDate>='$search_time_start' and dDate<='$search_time_end'";
        $exec=odbc_exec(self::$erp,$sql);
        $list=[];
        while ($row = odbc_fetch_array($exec)){
            //如果发现此单中含有配赠商品,删除掉这张入库单,当前的入库单逻辑是这样的 产品采购和配赠采购不在同一个采购单
            $sql2="select cCode,cBatch as batch_number,dMadeDate as brithday,iMassDate as validity,dVDate as expiration from dbo.zpurrkdlist where cCode='$row[cCode]'";
            $exec2=odbc_exec(self::$erp,$sql2);
            $i=0;
            while ($row2 = odbc_fetch_array($exec2)){
                if($row2['batch_number']=='' || $row2['brithday']=='' || $row2['validity']=='' || $row2['expiration']==''){
                    $i++;
                }
            }
            if($i==0){
                $list[]=$row['cCode'];
            }
        }
        return $list;
    }


    public function get_info($receipt){
        $sql="select dDate,cCode as receipt,cinvname as p_name,iQuantity as p_num,cInvCode as p_code,cBatch as batch_number,dMadeDate as brithday,iMassDate as validity,dVDate as expiration from dbo.zpurrkdlist where cCode='$receipt'";
            $exec=odbc_exec(self::$erp,$sql);
            $list=[];
            $i=0;
            while ($row = odbc_fetch_array($exec)){
                $list[$i]=$row;
                $list[$i]['p_num']=(int)$row['p_num'];
                $list[$i]['p_name']=iconv('gbk','utf-8',$row['p_name']);
                $i++;
            }
            return $list;
    }

}

$erp=new erpData;
$action=$_GET['action'];
if($action=='get_list'){
    $start=$_GET['start']?$_GET['start']:'2018-01-01';
    $end=$_GET['end']?$_GET['end']:'2019-01-01';
    $result=$erp->get_list($start,$end);
}elseif($action=='get_info'){
    $receipt=$_GET['receipt'];
    $result=$erp->get_info($receipt);
}
if(count($result)){
    $data['code']=1;
    $data['data']=$result;
}else{
    $data['code']=0;
    $data['data']=$result;
}
echo  json_encode($data);


?>

 

posted on 2018-06-12 13:18  长不大的菜鸟  阅读(1428)  评论(0编辑  收藏  举报

导航