| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084 |
- <?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('工单编号','like','Y%')
- ->where('MES接收时间',null)
- ->where('MES接收状态','0')
- ->where('U8插入类型','<>','关闭')
- ->select();
- if (empty($workOrderList)){
- $this->success('未获取新工单');
- }
- $j = $m = $n =0;
- foreach ($workOrderList as $key=>$value){
- $code = substr($value['成品编号'],0,5);
- $client = \db('物料_存货结构')->where('编号',$code)->value('名称');
- //插入产品资料
- $processData = \db('产品_基本资料')
- ->where('产品编号',$value['成品编号'])
- ->count();
- $detail = \db('物料_存货编码')->where('物料代码',$value['成品编号'])->find();
- if ($processData === 0){
- $product = [
- '客户编号' => $code,
- '客户名称' => $client,
- '产品编号' => $value['成品编号'],
- '产品名称' => $value['成品名称'],
- '计量单位' => $detail['领用单位'],
- '状态' => '',
- 'U8UID' => $detail['U8UID'],
- '产品类别' => $detail['规格'],
- 'Sys_id' => '[272/超级用户]',
- 'Sys_rq' => date('Y-m-d H:i:s',time()),
- 'Mod_rq' => date('Y-m-d H:i:s',time()),
- ];
- $product['UniqID'] = \db('产品_基本资料')->order('UniqID desc')->value('UniqID')+1;
- $productSql = \db('产品_基本资料')->fetchSql(true)->insert($product);
- \db()->query($productSql);
- }
- //插入工单资料
- $data = [
- 'Gd_gdbh' => $value['工单编号'],
- '行号' => $value['行号'],
- 'Gd_客户代号' => $code,
- '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('U8UID',$value['U8_UID'])
- ->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{
- unset($data['Uniqid']);
- $updateSql = \db('工单_基本资料')->where('U8UID',$value['U8_UID'])->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('U8UID',$value['U8_UID'])->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{
- unset($data['UNIQID']);
- $updateSql = \db('工单_bom资料')
- ->where('U8UID',$value['U8_UID'])
- ->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('U8UID',$value['U8_UID'])
- ->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('U8UID',$value['U8_UID'])
- ->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('U8UID',$value['U8_UID'])
- ->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('U8UID',$value['U8_UID'])
- ->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('U8UID',$value['U8_UID'])
- ->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){
- $code = substr($value['物料代码'],0,3);
- if ($code === 'Y10' || $code === 'Y14' || $code === 'Y12'){
- //插入产品资料
- $productData = \db('产品_基本资料')
- ->where('产品编号',$value['物料代码'])
- ->count();
- $clientCode = substr($value['物料代码'],0,5);
- $clientName = \db('物料_存货结构')->where('编号',$clientCode)->value('rtrim(名称)');
- $product = [
- '客户编号' => $clientCode,
- '客户名称' => $clientName,
- '产品编号' => $value['物料代码'],
- '产品名称' => $value['物料名称'],
- '计量单位' => $value['领用单位'],
- '状态' => '',
- 'U8UID' => $value['U8_UID'],
- '产品类别' => $value['规格'],
- 'Sys_id' => '[272/超级用户]',
- 'Sys_rq' => date('Y-m-d H:i:s',time()),
- 'Mod_rq' => date('Y-m-d H:i:s',time()),
- ];
- if ($productData === 0){
- $product['UniqID'] = \db('产品_基本资料')->order('UniqID desc')->value('UniqID')+1;
- $productSql = \db('产品_基本资料')->fetchSql(true)->insert($product);
- }else{
- $productSql = \db('产品_基本资料')->where('产品编号',$value['物料代码'])->fetchSql(true)->update($product);
- }
- $productRes = \db()->query($productSql);
- }
- $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('U8UID',$value['U8_UID'])
- ->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('U8UID',$value['U8_UID'])
- ->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('U8UID',$value['U8_UID'])
- ->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('U8UID',$value['U8_UID'])
- ->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('U8UID',$value['U8_UID'])
- ->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('U8UID',$value['U8_UID'])
- ->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('U8UID',$value['U8_UID'])
- ->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('U8UID',$value['U8_UID'])
- ->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('U8UID',$value['U8_UID'])
- ->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('U8UID',$value['U8_UID'])
- ->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);
- }
- $db5 = \db()->connect(config('database.db5'));
- $where = [
- 'sczl_rq' => ['>=','2024-04-01 00:00:00']
- ];
- $productData = $db5->name('设备_产量计酬')
- ->where($where)
- ->select();
- var_dump($productData);
- //获取机台信息
- $machineData = \db('设备_基本资料')
- ->where('mn_设备编号','<>','')
- ->field('rtrim(设备编号) as 设备编号,rtrim(mn_设备编号) as 美浓设备编号')
- ->select();
- //获取员工资料
- $employeeData = \db('人事_基本资料')
- ->where('mn_员工编号','<>','')
- ->field('rtrim(mn_员工编号) as 美浓员工编号')
- ->select();
- $employee = array_column($employeeData,'美浓员工编号');
- //循环判断机台、员工编号
- $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++){
- if (in_array($data[$key]['sczl_bh'.$i],$employee)){
- $data[$key]['sczl_bh'.$i] = \db('人事_基本资料')
- ->where('mn_员工编号',$data[$key]['sczl_bh'.$i])
- ->value('员工编号');
- }else{
- array_push($name,$value['sczl_bh'.$i]);
- $data[$key]['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('设备_产量计酬')->delete(true);
- $sql = \db('设备_产量计酬')->fetchSql(true)->insertAll($data);
- $res = \db()->query($sql);
- if ($res !== false){
- $this->success('同步成功');
- }else{
- $this->error('同步失败');
- }
- }
- }
|