用友u8 php,php 访问用友u8数据

namespace app\api\controller;usethink\Controller;usethink\Db;use think\Log;/**

* desc:仓库扫码入库API*/

class Storage extendsBase

{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 functionscan_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 functionscan_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);

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值