php 訪問用友u8數據
阿新 • • 發佈:2018-04-10
list bpa rod trac rom driver 數據連接 protect track
<?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數據