| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- use Overtrue\Pinyin;
- /**
- * 中间表数据同步
- */
- class Synchronization extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**
- * 工单资料数据同步
- */
- public function WorkOrderData()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $db3 = Db::connect(config('database.db3'));
- $workOrderList = $db3->name('U8_06工单资料')
- ->where('MES接收时间',null)
- ->where('MES接收状态','0')
- ->where('U8插入类型','<>','关闭')
- ->select();
- if (empty($workOrderList)){
- $this->success('未获取新工单');
- }
- $j = $m = $n =0;
- foreach ($workOrderList as $key=>$value){
- //插入产品资料
- $productData = \db('产品_基本资料')
- ->where('产品编号',$value['成品编号'])
- ->count();
- if ($productData === 0){
- $clientCode = substr($value['成品编号'],0,5);
- $product = [
- '客户编号' => $clientCode,
- '客户名称' => $value['客户名称'],
- '产品编号' => $value['成品编号'],
- '产品名称' => $value['成品名称'],
- '计量单位' => '万张',
- '状态' => '',
- 'Mod_rq' => date('Y-m-d H:i:s',time()),
- 'UniqID' => \db('产品_基本资料')->order('UniqID desc')->value('UniqID')+1,
- ];
- if (strpos($value['成品名称'],'小盒') === false){
- $product['产品类别'] = '条盒';
- }else{
- $product['产品类别'] = '小盒';
- }
- $productSql = \db('产品_基本资料')->fetchSql(true)->insert($product);
- $productRes = \db()->query($productSql);
- if ($productRes === false){
- $n++;
- }
- }
- //插入工单资料
- if (preg_match("/[A-Za-z]/",$value['工单编号'])){
- $workcode = $value['工单编号'];
- }else{
- $workcode = 'Y'.$value['工单编号'];
- }
- $client = \db('产品_基本资料')->where('产品编号',$value['成品编号'])->field('rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称')->find();
- $data = [
- 'Gd_gdbh' => $workcode,
- '行号' => $value['行号'],
- 'Gd_客户代号' => $client['客户编号'],
- 'Gd_客户名称' => $client['客户名称'],
- 'Gd_khdh' => $value['客户编号'],
- 'Gd_khmc' => $value['客户名称'],
- '客户料号' => $value['客户料号'],
- '成品代号' => $value['成品编号'],
- '成品名称' => $value['成品名称'],
- 'Gd_cpdh' => $value['产品编号'],
- 'Gd_cpmc' => $value['产品名称'],
- '产品版本号' => $value['版本号'],
- '销售订单号' => $value['销售订单号'],
- '警语版面' => $value['警语版面'],
- '码源数量' => substr(str_replace('.','',$value['投料数量']),0,-2),
- 'Gd_desc' => $value['备注'],
- '接单日期' => $value['接单日期'],
- '开单日期' => $value['开单日期'],
- '交货日期' => $value['交货日期'],
- '订单数量' => $value['订单数量'],
- '实际投料' => $value['投料数量'],
- '产品单价' => $value['产品单价'],
- '计量单位' => '万张',
- '成本考核_胶印' => 1,
- '成本考核_凹印' => 1,
- '成本考核_丝印' => 1,
- '成本考核_模切' => 1,
- '成本考核_检验' => 1,
- 'gd_statu' => '3-计划中',
- 'Sys_id' => '[1012/开单员]',
- 'Sys_rq' => date('Y-m-d H:i:s',time()),
- 'Mod_rq' => date('Y-m-d H:i:s',time()),
- 'U8UID' => $value['U8_UID'],
- 'Uniqid' => $value['UniqId']
- ];
- $workOrderdata = \db('工单_基本资料')
- ->where('Uniqid',$value['UniqId'])
- ->count();
- if ($workOrderdata === 0){
- $addSql = \db('工单_基本资料')->fetchSql(true)->insert($data);
- $result = \db()->query($addSql);
- if ($result === false){
- $m++;
- }else{
- $sqlString = $db3->name('U8_06工单资料')
- ->where('UniqId', $value['UniqId'])
- ->fetchSql(true)
- ->update([
- 'MES接收时间' => date('Y-m-d H:i:s', time()),
- 'MES接收状态' => '1'
- ]);
- $db3->execute($sqlString);
- }
- }else{
- $updateSql = \db('工单_基本资料')->where('Uniqid',$value['UniqId'])->fetchSql(true)->update($data);
- $updateRes = \db()->query($updateSql);
- if ($updateRes === false){
- $j++;
- }else{
- $sqlString = $db3->name('U8_06工单资料')
- ->where('UniqId', $value['UniqId'])
- ->fetchSql(true)
- ->update([
- 'MES接收时间' => date('Y-m-d H:i:s', time()),
- 'MES接收状态' => '1'
- ]);
- $db3->execute($sqlString);
- }
- }
- }
- if ($j !== 0 || $m !==0 || $n !== 0){
- $this->error('工单资料同步失败');
- }else{
- $this->success('工单资料同步成功');
- }
- }
- /**
- * 工单bom资料同步
- */
- public function WorkOrderBomData()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $db3 = Db::connect(config('database.db3'));
- $BomDataList = $db3->name('U8_09工单bom')
- ->where('MES接收时间',null)
- ->where('MES接收状态','0')
- ->order('U8传递时间 desc')
- ->select();
- if (empty($BomDataList)){
- $this->success('未找到新工单BOM');
- }
- $j = $m = 0;
- foreach ($BomDataList as $key=>$value){
- $res = \db('工单_bom资料')->where('UNIQID',$value['UNIQID'])->count();
- if (preg_match("/[A-Za-z]/",$value['BOM_工单编号'])){
- $workcode = $value['BOM_工单编号'];
- }else{
- $workcode = 'Y'.$value['BOM_工单编号'];
- }
- $data = [
- 'BOM_方案' => '工单评审定案',
- 'BOM_工单编号' => $workcode,
- 'BOM_版本' => $value['BOM_版本'],
- 'BOM_工单行号' => $value['BOM_工单行号'],
- 'BOM_行号' => $value['BOM_行号'],
- 'BOM_产品编号' => $value['BOM_产品编号'],
- 'BOM_物料编码' => $value['BOM_物料编码'],
- 'BOM_物料名称' => $value['BOM_物料名称'],
- 'BOM_投料单位' => $value['BOM_投料单位'],
- 'BOM_投入数' => $value['BOM_投入数'],
- 'BOM_产出数' => $value['BOM_产出数'],
- 'BOM_产出单位' => $value['BOM_产出单位'],
- 'BOM_标准用量' => $value['BOM_标准用量'],
- 'BOM_实际用量' => $value['BOM_实际用量'],
- 'BOM_计划用量' => $value['BOM_计划用量'],
- 'BOM_核算价格' => 0,
- 'Bom_领用工序' => '01-01',
- 'BOM_备注' => $value['BOM_备注'],
- 'Mod_rq' => date('Y-m-d H:i:s',time()),
- 'U8UID' => $value['U8_UID'],
- 'UNIQID' => $value['UNIQID']
- ];
- if ($res === 0){
- $addSql = \db('工单_bom资料')->fetchSql(true)->insert($data);
- $addRes = \db()->query($addSql);
- if ($addRes === false){
- $m++;
- }else{
- $sqlString = $db3->name('U8_09工单bom')
- ->where('UniqId', $value['UNIQID'])
- ->fetchSql(true)
- ->update([
- 'MES接收时间' => date('Y-m-d H:i:s', time()),
- 'MES接收状态' => '1'
- ]);
- $db3->execute($sqlString);
- }
- }else{
- $updateSql = \db('工单_bom资料')
- ->where('UNIQID',$value['UNIQID'])
- ->fetchSql(true)
- ->update($data);
- $updateRes = \db()->query($updateSql);
- if ($updateRes === false){
- $j++;
- }else{
- $sqlString = $db3->name('U8_09工单bom')
- ->where('UniqId', $value['UNIQID'])
- ->fetchSql(true)
- ->update([
- 'MES接收时间' => date('Y-m-d H:i:s', time()),
- 'MES接收状态' => '1'
- ]);
- $db3->execute($sqlString);
- }
- }
- }
- if ($j !== 0 || $m !== 0){
- $this->error('工单BOM资料同步失败');
- }else{
- $this->success('工单BOM资料同步成功');
- }
- }
- /**
- * 存货结构数据同步
- */
- public function MaterialRequisitionData()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $db3 = \db()->connect(config('database.db3'));
- $MaterialDataList = $db3->name('U8_11存货结构')
- ->where('MES接收时间',null)
- ->where('MES接收状态','0')
- ->select();
- if (empty($MaterialDataList)){
- $this->success('未找到新的物料存货结构');
- }
- $i = 0;
- foreach ($MaterialDataList as $key=>$value){
- $data = [
- '编号' => $value['编号'],
- '名称' => $value['名称'],
- 'Sys_id' => '[272/超级用户]',
- 'Sys_rq' => date('Y-m-d H:i:s',time()),
- 'Mod_rq' => date('Y-m-d H:i:s',time()),
- 'U8UID' => $value['U8_UID'],
- 'UniqId' => $value['UniqId']
- ];
- if ($value['U8插入类型'] === '新增'){
- $sql = \db('物料_存货结构')->fetchSql(true)->insert($data);
- $res = \db()->query($sql);
- if ($res === false){
- $i++;
- }else{
- $sqlString = $db3->name('U8_11存货结构')
- ->where('UniqId', $value['UniqId'])
- ->fetchSql(true)
- ->update([
- 'MES接收时间' => date('Y-m-d H:i:s', time()),
- 'MES接收状态' => '1'
- ]);
- $db3->execute($sqlString);
- }
- }else{
- $sql = \db('物料_存货结构')
- ->fetchSql(true)
- ->where('UniqId',$value['UniqId'])
- ->update($data);
- $res = \db()->query($sql);
- if ($res === false){
- $i++;
- }else{
- $sqlString = $db3->name('U8_11存货结构')
- ->where('UniqId', $value['UniqId'])
- ->fetchSql(true)
- ->update([
- 'MES接收时间' => date('Y-m-d H:i:s', time()),
- 'MES接收状态' => '1'
- ]);
- $db3->execute($sqlString);
- }
- }
- }
- if ($i !== 0){
- $this->error('存货结构同步失败');
- }else{
- $this->success('存货结构同步成功');
- }
- }
- /**
- * 人事基本资料同步
- * @return void
- * @throws \think\Exception
- * @throws \think\db\exception\BindParamException
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function PersonnelData()
- {
- //拼音类
- $pinyin = new Pinyin\Pinyin();
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $db3 = \db()->connect(config('database.db3'));
- $PersonnelDataList = $db3->name('U8_02人事资料')
- ->where('MES接收时间',null)
- ->where('MES接收状态','0')
- ->select();
- if (empty($PersonnelDataList)){
- $this->success('未找到新的人事资料');
- }
- $i = 0;
- foreach ($PersonnelDataList as $key=>$value){
- //获取姓名首字母
- $pycode = $pinyin->abbr($value['员工姓名']);
- $nameCode = strtoupper($pycode);
- $data = [
- '工卡编号'=>'',
- '卡钟设定'=>'',
- '打卡设置'=>'',
- '员工编号'=>$value['员工编号'],
- '员工姓名'=>$value['员工姓名'],
- '性别'=>$value['性别'],
- '聘用日期'=>$value['聘用日期'],
- '转正日期'=>$value['转正日期'],
- 'U8离职日期'=>$value['离职日期'],
- 'MES离职日期'=>$value['离职日期'],
- '扣减司龄'=>0,
- '部门编码'=>$value['部门编码'],
- '所在部门'=>$value['所在部门'],
- '人员类别'=>$value['人员类别'],
- '人员性质'=>$value['人员性质'],
- '班次类型'=>'',
- '标准工时制'=>'',
- '职称职务'=>$value['职称职务'],
- '薪资级别'=>$value['级别'],
- '工资表类别'=>'',
- '基本工资'=>'',
- '绩效工资1'=>'',
- '绩效工资2'=>'',
- '技能工资'=>'',
- '岗位津贴'=>'',
- '竞业补贴'=>'',
- '专业技术津贴'=>'',
- '技工技师津贴'=>'',
- '特殊工种津贴'=>'',
- '各类奖项津贴'=>'',
- '职危津贴'=>'',
- '夜班津贴'=>'',
- '全勤津贴'=>'',
- '住房津贴'=>'',
- '高温津贴'=>'',
- '用餐津贴'=>'',
- '司龄津贴'=>'',
- '联系电话'=>$value['联系电话'],
- '合同类型'=>'',
- '合同起始日期'=>'1900-01-01 00:00:00',
- '合同终止日期'=>'1900-01-01 00:00:00',
- '合同备注'=>'',
- '出生日期'=>$value['出生日期'],
- 'pycode'=>$nameCode,
- '籍贯'=>'',
- '民族'=>'',
- '身份证号'=>$value['身份证号'],
- '证件有效日期'=>'1900-01-01 00:00:00',
- '发证机关'=>'',
- '家庭住址'=>'',
- '学历'=>'',
- '婚姻状况'=>'',
- '社保开始日期'=>'1900-01-01 00:00:00',
- '开户银行'=>$value['开户银行'],
- '开户账号'=>$value['开户账号'],
- '存折办理日期'=>'1900-01-01 00:00:00',
- '紧急电话'=>'',
- '照片ID'=>'',
- '在职状态'=>$value['在职状态'],
- 'U8在职'=>$value['在职状态'],
- '薪酬核算分组'=>'',
- '考勤类型'=>'',
- '班组代号'=>'',
- 'sys_id'=>'[272/超级用户]',
- 'sys_rq'=>date('Y-m-d H:i:s',time()),
- 'mod_rq'=>'1900-01-01 00:00:00',
- 'U8UID'=>$value['U8_UID'],
- 'UniqID'=>$value['UniqId']
- ];
- $number = \db('人事_基本资料')
- ->where('Uniqid',$value['UniqId'])
- ->count();
- if ($number === 0){
- $sql = \db('人事_基本资料')->fetchSql(true)->insert($data);
- $res = \db()->query($sql);
- if ($res === false){
- $i++;
- }else{
- $sqlString = $db3->name('U8_02人事资料')
- ->where('UniqId', $value['UniqId'])
- ->fetchSql(true)
- ->update([
- 'MES接收时间' => date('Y-m-d H:i:s', time()),
- 'MES接收状态' => '1'
- ]);
- $db3->execute($sqlString);
- }
- }else{
- $sql = \db('人事_基本资料')
- ->fetchSql(true)
- ->where('UniqId',$value['UniqId'])
- ->update($data);
- $res = \db()->query($sql);
- if ($res === false){
- $i++;
- }else{
- $sqlString = $db3->name('U8_02人事资料')
- ->where('UniqId', $value['UniqId'])
- ->fetchSql(true)
- ->update([
- 'MES接收时间' => date('Y-m-d H:i:s', time()),
- 'MES接收状态' => '1'
- ]);
- $db3->execute($sqlString);
- }
- }
- }
- if ($i !== 0){
- $this->error('人事资料同步失败');
- }else{
- $this->success('人事资料同步成功');
- }
- }
- /**
- * 人事组织结构
- * @return void
- * @throws \think\Exception
- * @throws \think\db\exception\BindParamException
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function OrganizationalStructureData()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $db3 = \db()->connect(config('database.db3'));
- $OrganizationalDataList = $db3->name('U8_01组织结构')
- ->where('MES接收时间',null)
- ->where('MES接收状态','0')
- ->select();
- if (empty($OrganizationalDataList)){
- $this->success('未找到新的组织结构');
- }
- $i = 0;
- foreach ($OrganizationalDataList as $key=>$value){
- $data = [
- '编号'=>$value['编号'],
- '名称'=>$value['名称'],
- '状态'=>$value['状态'],
- 'Sys_id'=>'[272/超级用户]',
- 'Sys_rq'=>date('Y-m-d H:i:s',time()),
- 'Mod_rq'=>'1900-01-01 00:00:00',
- 'U8UID'=>$value['U8_UID'],
- 'UNIQID'=>$value['UniqId'],
- ];
- $number = \db('人事_组织结构')
- ->where('Uniqid',$value['UniqId'])
- ->count();
- if ($number === 0){
- $sql = \db('人事_组织结构')->fetchSql(true)->insert($data);
- $res = \db()->query($sql);
- if ($res === false){
- $i++;
- }else{
- $sqlString = $db3->name('U8_01组织结构')
- ->where('UniqId', $value['UniqId'])
- ->fetchSql(true)
- ->update([
- 'MES接收时间' => date('Y-m-d H:i:s', time()),
- 'MES接收状态' => '1'
- ]);
- $db3->execute($sqlString);
- }
- }else{
- $sql = \db('人事_组织结构')
- ->fetchSql(true)
- ->where('UniqId',$value['UniqId'])
- ->update($data);
- $res = \db()->query($sql);
- if ($res === false){
- $i++;
- }else{
- $sqlString = $db3->name('U8_01组织结构')
- ->where('UniqId', $value['UniqId'])
- ->fetchSql(true)
- ->update([
- 'MES接收时间' => date('Y-m-d H:i:s', time()),
- 'MES接收状态' => '1'
- ]);
- $db3->execute($sqlString);
- }
- }
- }
- if ($i !== 0){
- $this->error('人事组织结构同步失败');
- }else{
- $this->success('人事组织结构同步成功');
- }
- }
- /**
- * 物料存货编码数据同步
- * @return void
- * @throws \think\Exception
- * @throws \think\db\exception\BindParamException
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function InventoryCodeData()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $db3 = \db()->connect(config('database.db3'));
- $OrganizationalDataList = $db3->name('U8_04物料编码')
- ->where('MES接收时间',null)
- ->where('MES接收状态','0')
- ->select();
- if (empty($OrganizationalDataList)){
- $this->success('未找到新的物料编码');
- }
- $i = 0;
- foreach ($OrganizationalDataList as $key=>$value){
- $data = [
- '物料代码'=>$value['物料代码'],
- '物料名称'=>$value['物料名称'],
- '规格'=>$value['规格'],
- '采购单位'=>$value['采购单位'],
- '领用单位'=>$value['领用单位'],
- '单位换算率'=>$value['单位换算率'],
- '单价'=>$value['单价'],
- '币种'=>$value['币种'],
- '物料备注'=>$value['物料备注'],
- '状态'=>$value['状态'],
- 'Sys_id'=>'[272/超级用户]',
- 'Sys_rq'=>date('Y-m-d H:i:s',time()),
- 'Mod_rq'=>'1900-01-01 00:00:00',
- 'U8UID'=>$value['U8_UID'],
- 'UniqId'=>$value['UniqId'],
- ];
- $number = \db('物料_存货编码')
- ->where('Uniqid',$value['UniqId'])
- ->count();
- if ($number === 0){
- $sql = \db('物料_存货编码')->fetchSql(true)->insert($data);
- $res = \db()->query($sql);
- if ($res === false){
- $i++;
- }else{
- $sqlString = $db3->name('U8_04物料编码')
- ->where('UniqId', $value['UniqId'])
- ->fetchSql(true)
- ->update([
- 'MES接收时间' => date('Y-m-d H:i:s', time()),
- 'MES接收状态' => '1'
- ]);
- $db3->execute($sqlString);
- }
- }else{
- $sql = \db('物料_存货编码')
- ->fetchSql(true)
- ->where('UniqId',$value['UniqId'])
- ->update($data);
- $res = \db()->query($sql);
- if ($res === false){
- $i++;
- }else{
- $sqlString = $db3->name('U8_04物料编码')
- ->where('UniqId', $value['UniqId'])
- ->fetchSql(true)
- ->update([
- 'MES接收时间' => date('Y-m-d H:i:s', time()),
- 'MES接收状态' => '1'
- ]);
- $db3->execute($sqlString);
- }
- }
- }
- if ($i !== 0){
- $this->error('物料编码同步失败');
- }else{
- $this->success('物料编码同步成功');
- }
- }
- /**
- * 客户供应商数据同步
- * @return void
- * @throws \think\Exception
- * @throws \think\db\exception\BindParamException
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function CustomerSupplierData()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $db3 = \db()->connect(config('database.db3'));
- $OrganizationalDataList = $db3->name('U8_03客户供应商')
- ->where('MES接收时间',null)
- ->where('MES接收状态','0')
- ->select();
- if (empty($OrganizationalDataList)){
- $this->success('未找到新的客户供应商');
- }
- $i = 0;
- foreach ($OrganizationalDataList as $key=>$value){
- $data = [
- '类型'=>$value['类型'],
- '编号'=>$value['编号'],
- '名称'=>$value['名称'],
- '简称'=>$value['简称'],
- '地址'=>$value['地址'],
- '对口部门'=>$value['对口部门'],
- '联系人'=>$value['联系人'],
- '电话'=>$value['电话'],
- '业务员'=>$value['业务员'],
- '币种'=>$value['币种'],
- 'Sys_id'=>'[272/超级用户]',
- 'Sys_rq'=>date('Y-m-d H:i:s',time()),
- 'Mod_rq'=>'1900-01-01 00:00:00',
- 'U8UID'=>$value['U8_UID'],
- 'UniqId'=>$value['UniqId'],
- ];
- $number = \db('erp_客户供应商')
- ->where('Uniqid',$value['UniqId'])
- ->count();
- if ($number === 0){
- $sql = \db('erp_客户供应商')->fetchSql(true)->insert($data);
- $res = \db()->query($sql);
- if ($res === false){
- $i++;
- }else{
- $sqlString = $db3->name('U8_03客户供应商')
- ->where('UniqId', $value['UniqId'])
- ->fetchSql(true)
- ->update([
- 'MES接收时间' => date('Y-m-d H:i:s', time()),
- 'MES接收状态' => '1'
- ]);
- $db3->execute($sqlString);
- }
- }else{
- $sql = \db('erp_客户供应商')
- ->fetchSql(true)
- ->where('UniqId',$value['UniqId'])
- ->update($data);
- $res = \db()->query($sql);
- if ($res === false){
- $i++;
- }else{
- $sqlString = $db3->name('U8_03客户供应商')
- ->where('UniqId', $value['UniqId'])
- ->fetchSql(true)
- ->update([
- 'MES接收时间' => date('Y-m-d H:i:s', time()),
- 'MES接收状态' => '1'
- ]);
- $db3->execute($sqlString);
- }
- }
- }
- if ($i !== 0){
- $this->error('客户供应商同步失败');
- }else{
- $this->success('客户供应商同步成功');
- }
- }
- /**
- * 物料领用记录数据同步
- * @return void
- * @throws \think\Exception
- * @throws \think\db\exception\BindParamException
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function ReceiptRecordData()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $db3 = \db()->connect(config('database.db3'));
- $OrganizationalDataList = $db3->name('U8_07物料领用')
- ->where('MES接收时间',null)
- ->where('MES接收状态','0')
- ->select();
- if (empty($OrganizationalDataList)){
- $this->success('未找到新的物料领用记录');
- }
- $i = 0;
- foreach ($OrganizationalDataList as $key=>$value){
- if (preg_match("/[A-Za-z]/",$value['工单编号'])){
- $workcode = $value['工单编号'];
- }else{
- $workcode = 'Y'.$value['工单编号'];
- }
- $data = [
- 'st_rq'=>$value['日期'],
- 'st_jylb'=>$value['交易类别'],
- 'st_gdbh'=>$workcode,
- '采购单号'=>$value['采购单号'],
- '供方批次'=>$value['供方批次'],
- 'st_wlbh'=>$value['物料编号'],
- 'st_sl'=>$value['领用数量'],
- 'st_dw'=>$value['领用单位'],
- '领用单价'=>$value['领用单价'],
- 'st_desc'=>$value['备注'],
- '仓库编号'=>$value['仓库编号'],
- 'st_dpt'=>$value['采购单号'],
- 'st_jtbh'=>$value['机台编号'],
- 'sys_id'=>'[272/超级用户]',
- 'sys_rq'=>date('Y-m-d H:i:s',time()),
- 'mod_rq'=>'1900-01-01 00:00:00',
- 'U8UID'=>$value['U8_UID'],
- 'Uniqid'=>$value['UniqId'],
- ];
- $number = \db('物料_收发记录')
- ->where('Uniqid',$value['UniqId'])
- ->count();
- if ($number === 0){
- $sql = \db('物料_收发记录')->fetchSql(true)->insert($data);
- $res = \db()->query($sql);
- if ($res === false){
- $i++;
- }else{
- $sqlString = $db3->name('U8_07物料领用')
- ->where('UniqId', $value['UniqId'])
- ->fetchSql(true)
- ->update([
- 'MES接收时间' => date('Y-m-d H:i:s', time()),
- 'MES接收状态' => '1'
- ]);
- $db3->execute($sqlString);
- }
- }else{
- $sql = \db('物料_收发记录')
- ->fetchSql(true)
- ->where('UniqId',$value['UniqId'])
- ->update($data);
- $res = \db()->query($sql);
- if ($res === false){
- $i++;
- }else{
- $sqlString = $db3->name('U8_07物料领用')
- ->where('UniqId', $value['UniqId'])
- ->fetchSql(true)
- ->update([
- 'MES接收时间' => date('Y-m-d H:i:s', time()),
- 'MES接收状态' => '1'
- ]);
- $db3->execute($sqlString);
- }
- }
- }
- if ($i !== 0){
- $this->error('物料领用记录同步失败');
- }else{
- $this->success('物料领用记录同步成功');
- }
- }
- /**
- * 仓库信息数据同步
- * @return void
- * @throws \think\Exception
- * @throws \think\db\exception\BindParamException
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function WarehouseInformationData()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $db3 = \db()->connect(config('database.db3'));
- $OrganizationalDataList = $db3->name('U8_12仓库信息')
- ->where('MES接收时间',null)
- ->where('MES接收状态','0')
- ->select();
- if (empty($OrganizationalDataList)){
- $this->success('未找到新的仓库信息');
- }
- $i = 0;
- foreach ($OrganizationalDataList as $key=>$value){
- $data = [
- '编号'=>$value['编号'],
- '名称'=>$value['名称'],
- 'Sys_id'=>'[272/超级用户]',
- 'Sys_rq'=>date('Y-m-d H:i:s',time()),
- 'Mod_rq'=>'1900-01-01 00:00:00',
- 'U8UID'=>$value['U8_UID'],
- 'UniqId'=>$value['UniqId'],
- ];
- $number = \db('物料_仓库信息')
- ->where('Uniqid',$value['UniqId'])
- ->count();
- if ($number === 0){
- $sql = \db('物料_仓库信息')->fetchSql(true)->insert($data);
- $res = \db()->query($sql);
- if ($res === false){
- $i++;
- }else{
- $sqlString = $db3->name('U8_12仓库信息')
- ->where('UniqId', $value['UniqId'])
- ->fetchSql(true)
- ->update([
- 'MES接收时间' => date('Y-m-d H:i:s', time()),
- 'MES接收状态' => '1'
- ]);
- $db3->execute($sqlString);
- }
- }else{
- $sql = \db('物料_仓库信息')
- ->fetchSql(true)
- ->where('UniqId',$value['UniqId'])
- ->update($data);
- $res = \db()->query($sql);
- if ($res === false){
- $i++;
- }else{
- $sqlString = $db3->name('U8_12仓库信息')
- ->where('UniqId', $value['UniqId'])
- ->fetchSql(true)
- ->update([
- 'MES接收时间' => date('Y-m-d H:i:s', time()),
- 'MES接收状态' => '1'
- ]);
- $db3->execute($sqlString);
- }
- }
- }
- if ($i !== 0){
- $this->error('仓库信息同步失败');
- }else{
- $this->success('仓库信息同步成功');
- }
- }
- /**
- * 职位编码数据同步
- * @return void
- * @throws \think\Exception
- * @throws \think\db\exception\BindParamException
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function PositionData()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- $db3 = \db()->connect(config('database.db3'));
- $OrganizationalDataList = $db3->name('U8_13职位编码')
- ->where('MES接收时间',null)
- ->where('MES接收状态','0')
- ->select();
- if (empty($OrganizationalDataList)){
- $this->success('未找到新的职位编码');
- }
- $i = 0;
- foreach ($OrganizationalDataList as $key=>$value){
- $data = [
- '职位编码'=>$value['职位编码'],
- '职位名称'=>$value['职位名称'],
- '定编人数'=>0,
- '备注说明'=>'',
- 'sys_id'=>'[272/超级用户]',
- 'sys_rq'=>date('Y-m-d H:i:s',time()),
- 'Mod_rq'=>'1900-01-01 00:00:00',
- 'U8UID'=>$value['U8_UID'],
- 'UniqID'=>$value['UniqID'],
- ];
- $number = \db('人事_职位编码')
- ->where('Uniqid',$value['UniqID'])
- ->count();
- if ($number === 0){
- $sql = \db('人事_职位编码')->fetchSql(true)->insert($data);
- $res = \db()->query($sql);
- if ($res === false){
- $i++;
- }else{
- $sqlString = $db3->name('U8_13职位编码')
- ->where('UniqID', $value['UniqID'])
- ->fetchSql(true)
- ->update([
- 'MES接收时间' => date('Y-m-d H:i:s', time()),
- 'MES接收状态' => '1'
- ]);
- $db3->execute($sqlString);
- }
- }else{
- $sql = \db('人事_职位编码')
- ->fetchSql(true)
- ->where('UniqID',$value['UniqID'])
- ->update($data);
- $res = \db()->query($sql);
- if ($res === false){
- $i++;
- }else{
- $sqlString = $db3->name('U8_13职位编码')
- ->where('UniqID', $value['UniqID'])
- ->fetchSql(true)
- ->update([
- 'MES接收时间' => date('Y-m-d H:i:s', time()),
- 'MES接收状态' => '1'
- ]);
- $db3->execute($sqlString);
- }
- }
- }
- if ($i !== 0){
- $this->error('职位编码同步失败');
- }else{
- $this->success('职位编码同步成功');
- }
- }
- /**
- * 设备产量计酬云中间表数据库同步
- * @return void
- * @throws \think\db\exception\BindParamException
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- * @throws \think\exception\PDOException
- */
- public function ProductionData()
- {
- if ($this->request->isGet() === false){
- $this->error('请求错误');
- }
- if(is_dir(ROOT_PATH.'public/'.date('Y-m-d',time())) == null)
- {
- mkdir(ROOT_PATH.'public/'.date('Y-m-d',time()),0777,true);
- }
- // $lastID = \db('设备_产量计酬')->order('UniqId desc')->value('UniqId');
- // if (empty($lastID)){
- // $lastID = 0;
- // }
- $db5 = \db()->connect(config('database.db5'));
- $where = [
- // 'sczl_rq'=>date('Y-m-d',time()),
- // 'UniqId' =>['>',$lastID]
- 'sczl_rq' => ['>=','2024-04-01']
- ];
- $productData = $db5->name('设备_产量计酬')
- ->where($where)
- ->select();
- //获取机台信息
- $machineData = \db('设备_基本资料')
- ->where('mn_设备编号','<>','')
- ->field('rtrim(设备编号) as 设备编号,rtrim(mn_设备编号) as 美浓设备编号')
- ->select();
- //获取员工资料
- $employeeData = \db('人事_基本资料')
- ->where('mn_员工编号','<>','')
- ->field('rtrim(员工编号) as 员工编号,rtrim(mn_员工编号) as 美浓员工编号')
- ->select();
- //循环判断机台、员工编号
- $j = 0;
- $data = [];
- foreach ($productData as $key=>$value){
- //判断机台编号
- foreach ($machineData as $v){
- if ($value['sczl_jtbh'] === $v['美浓设备编号']){
- $productData[$key]['sczl_jtbh'] = $v['设备编号'];
- array_push($data,$productData[$key]);
- }
- }
- }
- if (empty($data)){
- $this->error('未找到新的生产数据');
- }
- foreach ($data as $key=>$value){
- $name = [];
- //判断员工编号,如果不存在写入日志文件
- for($i=1;$i<=10;$i++){
- foreach ($employeeData as $vv){
- if ($value['sczl_bh'.$i] === $vv['美浓员工编号']){
- $data[$key]['sczl_bh'.$i] = $vv['员工编号'];
- }else{
- array_push($name,$value['sczl_bh'.$i]);
- }
- }
- }
- $name = array_unique($name);
- $filename = ROOT_PATH.'public/'.date('Y-m-d',time()).'/'.$value['sczl_jtbh'].'日志文件.txt';
- $handle = fopen($filename, 'w');
- foreach ($name as $v){
- fwrite($handle, $v);
- }
- fclose($handle);
- //修改工单编号
- if (preg_match("/[A-Za-z]/",$value['sczl_gdbh'])){
- $workcode = $value['sczl_gdbh'];
- }else{
- $workcode = 'Y'.$value['sczl_gdbh'];
- }
- $data[$key]['sczl_gdbh'] = $workcode;
- }
- //插入设备产量计酬数据
- \db()->startTrans();
- try {
- \db('设备_产量计酬')->where('sczl_rq','>=','2024-04-01 00:00:00')->delete();
- $sql = \db('设备_产量计酬')->fetchSql(true)->insertAll($data);
- $res = \db()->query($sql);
- }catch (\Exception $e){
- \db()->rollback();
- }
- $this->success('同步成功');
- }
- }
|