php 访问用友u8数据

Posted 菜鸟

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 访问用友u8数据相关的知识,希望对你有一定的参考价值。

<?php
namespace app\api\controller;
use think\Controller;
use think\Db;
use think\Log;

/**
 * desc:仓库扫码入库API
 */
class Storage  extends Base
{
    protected static $erp;
    public function __construct()
    {
        parent::__construct();
        $dbhost =config(‘erp.dbhost‘);
        $dbuser = config(‘erp.dbuser‘); //你的mssql用户名
        $dbpass = config(‘erp.dbpass‘); //你的mssql密码
        $dbname = config(‘erp.dbname‘); //你的mssql库名
        try{
        self::$erp=odbc_connect("Driver={SQL Server};Server=$dbhost;Database=$dbname","$dbuser","$dbpass");
        }catch (\Exception $e){
            echo ‘ERP数据库连接错误,请检查数据连接‘;
            die();
        }
    }

    /*----------------------------入库扫码模块开始-------------------------------------*/
    /**
     * 列出5天内的入库单
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function scan_receipt_list(){
        $timestart = input(‘param.start‘);
        $timeend = input(‘param.end‘);
        $day=config(‘erp.getnum‘);
        $search_time_start = $timestart ? $timestart : date("Y-m-d",strtotime("-$day day"));//当天日期
        $search_time_end = $timeend ? $timeend : date("Y-m-d");//当天最晚日期
        //$map[‘insert_time‘] = array(‘between‘, [strtotime($search_time_start), strtotime($search_time_end)]);
        //按日期读取erp采购入库单列表
        $sql="select cCode from dbo.RdRecord01 where dDate>=‘$search_time_start‘ and dDate<=‘$search_time_end‘";
        $exec=odbc_exec(self::$erp,$sql);
        $list=[];
        while ($row = odbc_fetch_array($exec)){
            $list[]=$row[‘cCode‘];
        }
       // $list = Db::name(‘Test‘)->where($map)->field(‘receipt‘)->group(‘receipt‘)->select();
        if (count($list)) {
            $data[‘code‘] = 1;
            $data[‘datas‘] = $list;
            $data[‘msg‘] = ‘获取成功‘;
        }else{
            $data[‘code‘] = 0;
            $data[‘datas‘] = "";
            $data[‘msg‘] = ‘最近‘.$day.‘日暂无入库单‘;
        }
        return json($data);
    }


    /**
     * 仓管扫描入库单,列出入库产品数量
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function scan_receipt_info(){
        $receipt=input("param.receipt");
        if ($receipt != ‘‘) {
            //$list = Db::name(‘Test‘)->where(‘receipt‘, $receipt)->select();
            //根据采购入库单号 获取入库单详细
            $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++;
            }
            foreach ($list as $key=>$val){
                $tracking_code=Db::name(‘Products‘)->where(‘p_code‘,$val[‘p_code‘])->value(‘tracking_code‘);
                $count=Db::name(‘GoodsStockInfo‘)->where([‘delivery_number‘=>$val[‘receipt‘],‘p_code‘=>$val[‘p_code‘]])->count();
                $needscan=intval($val[‘p_num‘])-intval($count);
                if($count>=$val[‘p_num‘]){
                    $list[$key][‘flag‘]=1;
                    $list[$key][‘brithday‘]=$val[‘brithday‘];
                    $list[$key][‘expiration‘]=$val[‘expiration‘];
                    $list[$key][‘tracking_code‘]=$tracking_code;
                    $list[$key][‘needscan_num‘]=$needscan;
                }else{
                    $list[$key][‘flag‘]=0;
                    $list[$key][‘brithday‘]=$val[‘brithday‘];
                    $list[$key][‘expiration‘]=$val[‘expiration‘];
                    $list[$key][‘tracking_code‘]=$tracking_code;
                    $list[$key][‘needscan_num‘]=$needscan;
                }
            }
            $data[‘code‘] = 1;
            $data[‘datas‘] = $list;
            $data[‘msg‘] = ‘获取成功‘;
        }else{
            $data[‘code‘] = 0;
            $data[‘datas‘] = "";
            $data[‘msg‘] = ‘入库单号不能为空‘;
        }
//        return json($data);
        print_r($data);
    }






}

 

以上是关于php 访问用友u8数据的主要内容,如果未能解决你的问题,请参考以下文章

万物皆可集成系列:低代码释放用友U8+深度价值— 数据融合应用

万物皆可集成系列:低代码释放用友U8+深度价值— 数据融合应用

为啥用友u8把数据权限分配里面的业务对象没有部门?

用友u8只有.MDF和.ldf的情况下怎么恢复数据

用友u8只有.MDF和.ldf的情况下怎么恢复数据

用友u8.52建年度账2012 报错说年度数据已存在 SQLserver发生内部一致性错误 SQLserverDATABASE操作异常