首页 > Web开发 > 详细

php 访问用友u8数据

时间:2018-04-10 18:27:05      阅读:441      评论:0      收藏:0      [点我收藏+]
<?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数据

原文:https://www.cnblogs.com/houdj/p/8781068.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!