Synchronization.php 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use Overtrue\Pinyin;
  6. /**
  7. * 中间表数据同步
  8. */
  9. class Synchronization extends Api
  10. {
  11. protected $noNeedLogin = ['*'];
  12. protected $noNeedRight = ['*'];
  13. /**
  14. * 工单资料数据同步
  15. */
  16. public function WorkOrderData()
  17. {
  18. if ($this->request->isGet() === false){
  19. $this->error('请求错误');
  20. }
  21. $db3 = Db::connect(config('database.db3'));
  22. $workOrderList = $db3->name('U8_06工单资料')
  23. ->where('MES接收时间',null)
  24. ->where('MES接收状态','0')
  25. ->where('U8插入类型','<>','关闭')
  26. ->select();
  27. if (empty($workOrderList)){
  28. $this->success('未获取新工单');
  29. }
  30. $j = $m = $n =0;
  31. foreach ($workOrderList as $key=>$value){
  32. //插入产品资料
  33. $productData = \db('产品_基本资料')
  34. ->where('产品编号',$value['成品编号'])
  35. ->count();
  36. if ($productData === 0){
  37. $clientCode = substr($value['成品编号'],0,5);
  38. $product = [
  39. '客户编号' => $clientCode,
  40. '客户名称' => $value['客户名称'],
  41. '产品编号' => $value['成品编号'],
  42. '产品名称' => $value['成品名称'],
  43. '计量单位' => '万张',
  44. '状态' => '',
  45. 'Mod_rq' => date('Y-m-d H:i:s',time()),
  46. 'UniqID' => \db('产品_基本资料')->order('UniqID desc')->value('UniqID')+1,
  47. ];
  48. if (strpos($value['成品名称'],'小盒') === false){
  49. $product['产品类别'] = '条盒';
  50. }else{
  51. $product['产品类别'] = '小盒';
  52. }
  53. $productSql = \db('产品_基本资料')->fetchSql(true)->insert($product);
  54. $productRes = \db()->query($productSql);
  55. if ($productRes === false){
  56. $n++;
  57. }
  58. }
  59. //插入工单资料
  60. if (preg_match("/[A-Za-z]/",$value['工单编号'])){
  61. $workcode = $value['工单编号'];
  62. }else{
  63. $workcode = 'Y'.$value['工单编号'];
  64. }
  65. $client = \db('产品_基本资料')->where('产品编号',$value['成品编号'])->field('rtrim(客户编号) as 客户编号,rtrim(客户名称) as 客户名称')->find();
  66. $data = [
  67. 'Gd_gdbh' => $workcode,
  68. '行号' => $value['行号'],
  69. 'Gd_客户代号' => $client['客户编号'],
  70. 'Gd_客户名称' => $client['客户名称'],
  71. 'Gd_khdh' => $value['客户编号'],
  72. 'Gd_khmc' => $value['客户名称'],
  73. '客户料号' => $value['客户料号'],
  74. '成品代号' => $value['成品编号'],
  75. '成品名称' => $value['成品名称'],
  76. 'Gd_cpdh' => $value['产品编号'],
  77. 'Gd_cpmc' => $value['产品名称'],
  78. '产品版本号' => $value['版本号'],
  79. '销售订单号' => $value['销售订单号'],
  80. '警语版面' => $value['警语版面'],
  81. '码源数量' => substr(str_replace('.','',$value['投料数量']),0,-2),
  82. 'Gd_desc' => $value['备注'],
  83. '接单日期' => $value['接单日期'],
  84. '开单日期' => $value['开单日期'],
  85. '交货日期' => $value['交货日期'],
  86. '订单数量' => $value['订单数量'],
  87. '实际投料' => $value['投料数量'],
  88. '产品单价' => $value['产品单价'],
  89. '计量单位' => '万张',
  90. '成本考核_胶印' => 1,
  91. '成本考核_凹印' => 1,
  92. '成本考核_丝印' => 1,
  93. '成本考核_模切' => 1,
  94. '成本考核_检验' => 1,
  95. 'gd_statu' => '3-计划中',
  96. 'Sys_id' => '[1012/开单员]',
  97. 'Sys_rq' => date('Y-m-d H:i:s',time()),
  98. 'Mod_rq' => date('Y-m-d H:i:s',time()),
  99. 'U8UID' => $value['U8_UID'],
  100. 'Uniqid' => $value['UniqId']
  101. ];
  102. $workOrderdata = \db('工单_基本资料')
  103. ->where('U8UID',$value['U8_UID'])
  104. ->count();
  105. if ($workOrderdata === 0){
  106. $addSql = \db('工单_基本资料')->fetchSql(true)->insert($data);
  107. $result = \db()->query($addSql);
  108. if ($result === false){
  109. $m++;
  110. }else{
  111. $sqlString = $db3->name('U8_06工单资料')
  112. ->where('UniqId', $value['UniqId'])
  113. ->fetchSql(true)
  114. ->update([
  115. 'MES接收时间' => date('Y-m-d H:i:s', time()),
  116. 'MES接收状态' => '1'
  117. ]);
  118. $db3->execute($sqlString);
  119. }
  120. }else{
  121. unset($data['Uniqid']);
  122. $updateSql = \db('工单_基本资料')->where('U8UID',$value['U8_UID'])->fetchSql(true)->update($data);
  123. $updateRes = \db()->query($updateSql);
  124. if ($updateRes === false){
  125. $j++;
  126. }else{
  127. $sqlString = $db3->name('U8_06工单资料')
  128. ->where('UniqId', $value['UniqId'])
  129. ->fetchSql(true)
  130. ->update([
  131. 'MES接收时间' => date('Y-m-d H:i:s', time()),
  132. 'MES接收状态' => '1'
  133. ]);
  134. $db3->execute($sqlString);
  135. }
  136. }
  137. }
  138. if ($j !== 0 || $m !==0 || $n !== 0){
  139. $this->error('工单资料同步失败');
  140. }else{
  141. $this->success('工单资料同步成功');
  142. }
  143. }
  144. /**
  145. * 工单bom资料同步
  146. */
  147. public function WorkOrderBomData()
  148. {
  149. if ($this->request->isGet() === false){
  150. $this->error('请求错误');
  151. }
  152. $db3 = Db::connect(config('database.db3'));
  153. $BomDataList = $db3->name('U8_09工单bom')
  154. ->where('MES接收时间',null)
  155. ->where('MES接收状态','0')
  156. ->order('U8传递时间 desc')
  157. ->select();
  158. if (empty($BomDataList)){
  159. $this->success('未找到新工单BOM');
  160. }
  161. $j = $m = 0;
  162. foreach ($BomDataList as $key=>$value){
  163. $res = \db('工单_bom资料')->where('U8UID',$value['U8_UID'])->count();
  164. if (preg_match("/[A-Za-z]/",$value['BOM_工单编号'])){
  165. $workcode = $value['BOM_工单编号'];
  166. }else{
  167. $workcode = 'Y'.$value['BOM_工单编号'];
  168. }
  169. $data = [
  170. 'BOM_方案' => '工单评审定案',
  171. 'BOM_工单编号' => $workcode,
  172. 'BOM_版本' => $value['BOM_版本'],
  173. 'BOM_工单行号' => $value['BOM_工单行号'],
  174. 'BOM_行号' => $value['BOM_行号'],
  175. 'BOM_产品编号' => $value['BOM_产品编号'],
  176. 'BOM_物料编码' => $value['BOM_物料编码'],
  177. 'BOM_物料名称' => $value['BOM_物料名称'],
  178. 'BOM_投料单位' => $value['BOM_投料单位'],
  179. 'BOM_投入数' => $value['BOM_投入数'],
  180. 'BOM_产出数' => $value['BOM_产出数'],
  181. 'BOM_产出单位' => $value['BOM_产出单位'],
  182. 'BOM_标准用量' => $value['BOM_标准用量'],
  183. 'BOM_实际用量' => $value['BOM_实际用量'],
  184. 'BOM_计划用量' => $value['BOM_计划用量'],
  185. 'BOM_核算价格' => 0,
  186. 'Bom_领用工序' => '01-01',
  187. 'BOM_备注' => $value['BOM_备注'],
  188. 'Mod_rq' => date('Y-m-d H:i:s',time()),
  189. 'U8UID' => $value['U8_UID'],
  190. 'UNIQID' => $value['UNIQID']
  191. ];
  192. if ($res === 0){
  193. $addSql = \db('工单_bom资料')->fetchSql(true)->insert($data);
  194. $addRes = \db()->query($addSql);
  195. if ($addRes === false){
  196. $m++;
  197. }else{
  198. $sqlString = $db3->name('U8_09工单bom')
  199. ->where('UNIQID', $value['UNIQID'])
  200. ->fetchSql(true)
  201. ->update([
  202. 'MES接收时间' => date('Y-m-d H:i:s', time()),
  203. 'MES接收状态' => '1'
  204. ]);
  205. $db3->execute($sqlString);
  206. }
  207. }else{
  208. unset($data['UNIQID']);
  209. $updateSql = \db('工单_bom资料')
  210. ->where('U8UID',$value['U8_UID'])
  211. ->fetchSql(true)
  212. ->update($data);
  213. $updateRes = \db()->query($updateSql);
  214. if ($updateRes === false){
  215. $j++;
  216. }else{
  217. $sqlString = $db3->name('U8_09工单bom')
  218. ->where('UNIQID', $value['UNIQID'])
  219. ->fetchSql(true)
  220. ->update([
  221. 'MES接收时间' => date('Y-m-d H:i:s', time()),
  222. 'MES接收状态' => '1'
  223. ]);
  224. $db3->execute($sqlString);
  225. }
  226. }
  227. }
  228. if ($j !== 0 || $m !== 0){
  229. $this->error('工单BOM资料同步失败');
  230. }else{
  231. $this->success('工单BOM资料同步成功');
  232. }
  233. }
  234. /**
  235. * 存货结构数据同步
  236. */
  237. public function MaterialRequisitionData()
  238. {
  239. if ($this->request->isGet() === false){
  240. $this->error('请求错误');
  241. }
  242. $db3 = \db()->connect(config('database.db3'));
  243. $MaterialDataList = $db3->name('U8_11存货结构')
  244. ->where('MES接收时间',null)
  245. ->where('MES接收状态','0')
  246. ->select();
  247. if (empty($MaterialDataList)){
  248. $this->success('未找到新的物料存货结构');
  249. }
  250. $i = 0;
  251. foreach ($MaterialDataList as $key=>$value){
  252. $data = [
  253. '编号' => $value['编号'],
  254. '名称' => $value['名称'],
  255. 'Sys_id' => '[272/超级用户]',
  256. 'Sys_rq' => date('Y-m-d H:i:s',time()),
  257. 'Mod_rq' => date('Y-m-d H:i:s',time()),
  258. 'U8UID' => $value['U8_UID'],
  259. 'UniqId' => $value['UniqId']
  260. ];
  261. if ($value['U8插入类型'] === '新增'){
  262. $sql = \db('物料_存货结构')->fetchSql(true)->insert($data);
  263. $res = \db()->query($sql);
  264. if ($res === false){
  265. $i++;
  266. }else{
  267. $sqlString = $db3->name('U8_11存货结构')
  268. ->where('UniqId', $value['UniqId'])
  269. ->fetchSql(true)
  270. ->update([
  271. 'MES接收时间' => date('Y-m-d H:i:s', time()),
  272. 'MES接收状态' => '1'
  273. ]);
  274. $db3->execute($sqlString);
  275. }
  276. }else{
  277. $sql = \db('物料_存货结构')
  278. ->fetchSql(true)
  279. ->where('U8UID',$value['U8_UID'])
  280. ->update($data);
  281. $res = \db()->query($sql);
  282. if ($res === false){
  283. $i++;
  284. }else{
  285. $sqlString = $db3->name('U8_11存货结构')
  286. ->where('UniqId', $value['UniqId'])
  287. ->fetchSql(true)
  288. ->update([
  289. 'MES接收时间' => date('Y-m-d H:i:s', time()),
  290. 'MES接收状态' => '1'
  291. ]);
  292. $db3->execute($sqlString);
  293. }
  294. }
  295. }
  296. if ($i !== 0){
  297. $this->error('存货结构同步失败');
  298. }else{
  299. $this->success('存货结构同步成功');
  300. }
  301. }
  302. /**
  303. * 人事基本资料同步
  304. * @return void
  305. * @throws \think\Exception
  306. * @throws \think\db\exception\BindParamException
  307. * @throws \think\db\exception\DataNotFoundException
  308. * @throws \think\db\exception\ModelNotFoundException
  309. * @throws \think\exception\DbException
  310. * @throws \think\exception\PDOException
  311. */
  312. public function PersonnelData()
  313. {
  314. //拼音类
  315. $pinyin = new Pinyin\Pinyin();
  316. if ($this->request->isGet() === false){
  317. $this->error('请求错误');
  318. }
  319. $db3 = \db()->connect(config('database.db3'));
  320. $PersonnelDataList = $db3->name('U8_02人事资料')
  321. ->where('MES接收时间',null)
  322. ->where('MES接收状态','0')
  323. ->select();
  324. if (empty($PersonnelDataList)){
  325. $this->success('未找到新的人事资料');
  326. }
  327. $i = 0;
  328. foreach ($PersonnelDataList as $key=>$value){
  329. //获取姓名首字母
  330. $pycode = $pinyin->abbr($value['员工姓名']);
  331. $nameCode = strtoupper($pycode);
  332. $data = [
  333. '工卡编号'=>'',
  334. '卡钟设定'=>'',
  335. '打卡设置'=>'',
  336. '员工编号'=>$value['员工编号'],
  337. '员工姓名'=>$value['员工姓名'],
  338. '性别'=>$value['性别'],
  339. '聘用日期'=>$value['聘用日期'],
  340. '转正日期'=>$value['转正日期'],
  341. 'U8离职日期'=>$value['离职日期'],
  342. 'MES离职日期'=>$value['离职日期'],
  343. '扣减司龄'=>0,
  344. '部门编码'=>$value['部门编码'],
  345. '所在部门'=>$value['所在部门'],
  346. '人员类别'=>$value['人员类别'],
  347. '人员性质'=>$value['人员性质'],
  348. '班次类型'=>'',
  349. '标准工时制'=>'',
  350. '职称职务'=>$value['职称职务'],
  351. '薪资级别'=>$value['级别'],
  352. '工资表类别'=>'',
  353. '基本工资'=>'',
  354. '绩效工资1'=>'',
  355. '绩效工资2'=>'',
  356. '技能工资'=>'',
  357. '岗位津贴'=>'',
  358. '竞业补贴'=>'',
  359. '专业技术津贴'=>'',
  360. '技工技师津贴'=>'',
  361. '特殊工种津贴'=>'',
  362. '各类奖项津贴'=>'',
  363. '职危津贴'=>'',
  364. '夜班津贴'=>'',
  365. '全勤津贴'=>'',
  366. '住房津贴'=>'',
  367. '高温津贴'=>'',
  368. '用餐津贴'=>'',
  369. '司龄津贴'=>'',
  370. '联系电话'=>$value['联系电话'],
  371. '合同类型'=>'',
  372. '合同起始日期'=>'1900-01-01 00:00:00',
  373. '合同终止日期'=>'1900-01-01 00:00:00',
  374. '合同备注'=>'',
  375. '出生日期'=>$value['出生日期'],
  376. 'pycode'=>$nameCode,
  377. '籍贯'=>'',
  378. '民族'=>'',
  379. '身份证号'=>$value['身份证号'],
  380. '证件有效日期'=>'1900-01-01 00:00:00',
  381. '发证机关'=>'',
  382. '家庭住址'=>'',
  383. '学历'=>'',
  384. '婚姻状况'=>'',
  385. '社保开始日期'=>'1900-01-01 00:00:00',
  386. '开户银行'=>$value['开户银行'],
  387. '开户账号'=>$value['开户账号'],
  388. '存折办理日期'=>'1900-01-01 00:00:00',
  389. '紧急电话'=>'',
  390. '照片ID'=>'',
  391. '在职状态'=>$value['在职状态'],
  392. 'U8在职'=>$value['在职状态'],
  393. '薪酬核算分组'=>'',
  394. '考勤类型'=>'',
  395. '班组代号'=>'',
  396. 'sys_id'=>'[272/超级用户]',
  397. 'sys_rq'=>date('Y-m-d H:i:s',time()),
  398. 'mod_rq'=>'1900-01-01 00:00:00',
  399. 'U8UID'=>$value['U8_UID'],
  400. 'UniqID'=>$value['UniqId']
  401. ];
  402. $number = \db('人事_基本资料')
  403. ->where('U8UID',$value['U8_UID'])
  404. ->count();
  405. if ($number === 0){
  406. $sql = \db('人事_基本资料')->fetchSql(true)->insert($data);
  407. $res = \db()->query($sql);
  408. if ($res === false){
  409. $i++;
  410. }else{
  411. $sqlString = $db3->name('U8_02人事资料')
  412. ->where('UniqId', $value['UniqId'])
  413. ->fetchSql(true)
  414. ->update([
  415. 'MES接收时间' => date('Y-m-d H:i:s', time()),
  416. 'MES接收状态' => '1'
  417. ]);
  418. $db3->execute($sqlString);
  419. }
  420. }else{
  421. $sql = \db('人事_基本资料')
  422. ->fetchSql(true)
  423. ->where('U8UID',$value['U8_UID'])
  424. ->update($data);
  425. $res = \db()->query($sql);
  426. if ($res === false){
  427. $i++;
  428. }else{
  429. $sqlString = $db3->name('U8_02人事资料')
  430. ->where('UniqId', $value['UniqId'])
  431. ->fetchSql(true)
  432. ->update([
  433. 'MES接收时间' => date('Y-m-d H:i:s', time()),
  434. 'MES接收状态' => '1'
  435. ]);
  436. $db3->execute($sqlString);
  437. }
  438. }
  439. }
  440. if ($i !== 0){
  441. $this->error('人事资料同步失败');
  442. }else{
  443. $this->success('人事资料同步成功');
  444. }
  445. }
  446. /**
  447. * 人事组织结构
  448. * @return void
  449. * @throws \think\Exception
  450. * @throws \think\db\exception\BindParamException
  451. * @throws \think\db\exception\DataNotFoundException
  452. * @throws \think\db\exception\ModelNotFoundException
  453. * @throws \think\exception\DbException
  454. * @throws \think\exception\PDOException
  455. */
  456. public function OrganizationalStructureData()
  457. {
  458. if ($this->request->isGet() === false){
  459. $this->error('请求错误');
  460. }
  461. $db3 = \db()->connect(config('database.db3'));
  462. $OrganizationalDataList = $db3->name('U8_01组织结构')
  463. ->where('MES接收时间',null)
  464. ->where('MES接收状态','0')
  465. ->select();
  466. if (empty($OrganizationalDataList)){
  467. $this->success('未找到新的组织结构');
  468. }
  469. $i = 0;
  470. foreach ($OrganizationalDataList as $key=>$value){
  471. $data = [
  472. '编号'=>$value['编号'],
  473. '名称'=>$value['名称'],
  474. '状态'=>$value['状态'],
  475. 'Sys_id'=>'[272/超级用户]',
  476. 'Sys_rq'=>date('Y-m-d H:i:s',time()),
  477. 'Mod_rq'=>'1900-01-01 00:00:00',
  478. 'U8UID'=>$value['U8_UID'],
  479. 'UNIQID'=>$value['UniqId'],
  480. ];
  481. $number = \db('人事_组织结构')
  482. ->where('U8UID',$value['U8_UID'])
  483. ->count();
  484. if ($number === 0){
  485. $sql = \db('人事_组织结构')->fetchSql(true)->insert($data);
  486. $res = \db()->query($sql);
  487. if ($res === false){
  488. $i++;
  489. }else{
  490. $sqlString = $db3->name('U8_01组织结构')
  491. ->where('UniqId', $value['UniqId'])
  492. ->fetchSql(true)
  493. ->update([
  494. 'MES接收时间' => date('Y-m-d H:i:s', time()),
  495. 'MES接收状态' => '1'
  496. ]);
  497. $db3->execute($sqlString);
  498. }
  499. }else{
  500. $sql = \db('人事_组织结构')
  501. ->fetchSql(true)
  502. ->where('U8UID',$value['U8_UID'])
  503. ->update($data);
  504. $res = \db()->query($sql);
  505. if ($res === false){
  506. $i++;
  507. }else{
  508. $sqlString = $db3->name('U8_01组织结构')
  509. ->where('UniqId', $value['UniqId'])
  510. ->fetchSql(true)
  511. ->update([
  512. 'MES接收时间' => date('Y-m-d H:i:s', time()),
  513. 'MES接收状态' => '1'
  514. ]);
  515. $db3->execute($sqlString);
  516. }
  517. }
  518. }
  519. if ($i !== 0){
  520. $this->error('人事组织结构同步失败');
  521. }else{
  522. $this->success('人事组织结构同步成功');
  523. }
  524. }
  525. /**
  526. * 物料存货编码数据同步
  527. * @return void
  528. * @throws \think\Exception
  529. * @throws \think\db\exception\BindParamException
  530. * @throws \think\db\exception\DataNotFoundException
  531. * @throws \think\db\exception\ModelNotFoundException
  532. * @throws \think\exception\DbException
  533. * @throws \think\exception\PDOException
  534. */
  535. public function InventoryCodeData()
  536. {
  537. if ($this->request->isGet() === false){
  538. $this->error('请求错误');
  539. }
  540. $db3 = \db()->connect(config('database.db3'));
  541. $OrganizationalDataList = $db3->name('U8_04物料编码')
  542. ->where('MES接收时间',null)
  543. ->where('MES接收状态','0')
  544. ->select();
  545. if (empty($OrganizationalDataList)){
  546. $this->success('未找到新的物料编码');
  547. }
  548. $i = 0;
  549. foreach ($OrganizationalDataList as $key=>$value){
  550. $data = [
  551. '物料代码'=>$value['物料代码'],
  552. '物料名称'=>$value['物料名称'],
  553. '规格'=>$value['规格'],
  554. '采购单位'=>$value['采购单位'],
  555. '领用单位'=>$value['领用单位'],
  556. '单位换算率'=>$value['单位换算率'],
  557. '单价'=>$value['单价'],
  558. '币种'=>$value['币种'],
  559. '物料备注'=>$value['物料备注'],
  560. '状态'=>$value['状态'],
  561. 'Sys_id'=>'[272/超级用户]',
  562. 'Sys_rq'=>date('Y-m-d H:i:s',time()),
  563. 'Mod_rq'=>'1900-01-01 00:00:00',
  564. 'U8UID'=>$value['U8_UID'],
  565. 'UniqId'=>$value['UniqId'],
  566. ];
  567. $number = \db('物料_存货编码')
  568. ->where('U8UID',$value['U8_UID'])
  569. ->count();
  570. if ($number === 0){
  571. $sql = \db('物料_存货编码')->fetchSql(true)->insert($data);
  572. $res = \db()->query($sql);
  573. if ($res === false){
  574. $i++;
  575. }else{
  576. $sqlString = $db3->name('U8_04物料编码')
  577. ->where('UniqId', $value['UniqId'])
  578. ->fetchSql(true)
  579. ->update([
  580. 'MES接收时间' => date('Y-m-d H:i:s', time()),
  581. 'MES接收状态' => '1'
  582. ]);
  583. $db3->execute($sqlString);
  584. }
  585. }else{
  586. $sql = \db('物料_存货编码')
  587. ->fetchSql(true)
  588. ->where('U8UID',$value['U8_UID'])
  589. ->update($data);
  590. $res = \db()->query($sql);
  591. if ($res === false){
  592. $i++;
  593. }else{
  594. $sqlString = $db3->name('U8_04物料编码')
  595. ->where('UniqId', $value['UniqId'])
  596. ->fetchSql(true)
  597. ->update([
  598. 'MES接收时间' => date('Y-m-d H:i:s', time()),
  599. 'MES接收状态' => '1'
  600. ]);
  601. $db3->execute($sqlString);
  602. }
  603. }
  604. }
  605. if ($i !== 0){
  606. $this->error('物料编码同步失败');
  607. }else{
  608. $this->success('物料编码同步成功');
  609. }
  610. }
  611. /**
  612. * 客户供应商数据同步
  613. * @return void
  614. * @throws \think\Exception
  615. * @throws \think\db\exception\BindParamException
  616. * @throws \think\db\exception\DataNotFoundException
  617. * @throws \think\db\exception\ModelNotFoundException
  618. * @throws \think\exception\DbException
  619. * @throws \think\exception\PDOException
  620. */
  621. public function CustomerSupplierData()
  622. {
  623. if ($this->request->isGet() === false){
  624. $this->error('请求错误');
  625. }
  626. $db3 = \db()->connect(config('database.db3'));
  627. $OrganizationalDataList = $db3->name('U8_03客户供应商')
  628. ->where('MES接收时间',null)
  629. ->where('MES接收状态','0')
  630. ->select();
  631. if (empty($OrganizationalDataList)){
  632. $this->success('未找到新的客户供应商');
  633. }
  634. $i = 0;
  635. foreach ($OrganizationalDataList as $key=>$value){
  636. $data = [
  637. '类型'=>$value['类型'],
  638. '编号'=>$value['编号'],
  639. '名称'=>$value['名称'],
  640. '简称'=>$value['简称'],
  641. '地址'=>$value['地址'],
  642. '对口部门'=>$value['对口部门'],
  643. '联系人'=>$value['联系人'],
  644. '电话'=>$value['电话'],
  645. '业务员'=>$value['业务员'],
  646. '币种'=>$value['币种'],
  647. 'Sys_id'=>'[272/超级用户]',
  648. 'Sys_rq'=>date('Y-m-d H:i:s',time()),
  649. 'Mod_rq'=>'1900-01-01 00:00:00',
  650. 'U8UID'=>$value['U8_UID'],
  651. 'UniqId'=>$value['UniqId'],
  652. ];
  653. $number = \db('erp_客户供应商')
  654. ->where('U8UID',$value['U8_UID'])
  655. ->count();
  656. if ($number === 0){
  657. $sql = \db('erp_客户供应商')->fetchSql(true)->insert($data);
  658. $res = \db()->query($sql);
  659. if ($res === false){
  660. $i++;
  661. }else{
  662. $sqlString = $db3->name('U8_03客户供应商')
  663. ->where('UniqId', $value['UniqId'])
  664. ->fetchSql(true)
  665. ->update([
  666. 'MES接收时间' => date('Y-m-d H:i:s', time()),
  667. 'MES接收状态' => '1'
  668. ]);
  669. $db3->execute($sqlString);
  670. }
  671. }else{
  672. $sql = \db('erp_客户供应商')
  673. ->fetchSql(true)
  674. ->where('U8UID',$value['U8_UID'])
  675. ->update($data);
  676. $res = \db()->query($sql);
  677. if ($res === false){
  678. $i++;
  679. }else{
  680. $sqlString = $db3->name('U8_03客户供应商')
  681. ->where('UniqId', $value['UniqId'])
  682. ->fetchSql(true)
  683. ->update([
  684. 'MES接收时间' => date('Y-m-d H:i:s', time()),
  685. 'MES接收状态' => '1'
  686. ]);
  687. $db3->execute($sqlString);
  688. }
  689. }
  690. }
  691. if ($i !== 0){
  692. $this->error('客户供应商同步失败');
  693. }else{
  694. $this->success('客户供应商同步成功');
  695. }
  696. }
  697. /**
  698. * 物料领用记录数据同步
  699. * @return void
  700. * @throws \think\Exception
  701. * @throws \think\db\exception\BindParamException
  702. * @throws \think\db\exception\DataNotFoundException
  703. * @throws \think\db\exception\ModelNotFoundException
  704. * @throws \think\exception\DbException
  705. * @throws \think\exception\PDOException
  706. */
  707. public function ReceiptRecordData()
  708. {
  709. if ($this->request->isGet() === false){
  710. $this->error('请求错误');
  711. }
  712. $db3 = \db()->connect(config('database.db3'));
  713. $OrganizationalDataList = $db3->name('U8_07物料领用')
  714. ->where('MES接收时间',null)
  715. ->where('MES接收状态','0')
  716. ->select();
  717. if (empty($OrganizationalDataList)){
  718. $this->success('未找到新的物料领用记录');
  719. }
  720. $i = 0;
  721. foreach ($OrganizationalDataList as $key=>$value){
  722. if (preg_match("/[A-Za-z]/",$value['工单编号'])){
  723. $workcode = $value['工单编号'];
  724. }else{
  725. $workcode = 'Y'.$value['工单编号'];
  726. }
  727. $data = [
  728. 'st_rq'=>$value['日期'],
  729. 'st_jylb'=>$value['交易类别'],
  730. 'st_gdbh'=>$workcode,
  731. '采购单号'=>$value['采购单号'],
  732. '供方批次'=>$value['供方批次'],
  733. 'st_wlbh'=>$value['物料编号'],
  734. 'st_sl'=>$value['领用数量'],
  735. 'st_dw'=>$value['领用单位'],
  736. '领用单价'=>$value['领用单价'],
  737. 'st_desc'=>$value['备注'],
  738. '仓库编号'=>$value['仓库编号'],
  739. 'st_dpt'=>$value['采购单号'],
  740. 'st_jtbh'=>$value['机台编号'],
  741. 'sys_id'=>'[272/超级用户]',
  742. 'sys_rq'=>date('Y-m-d H:i:s',time()),
  743. 'mod_rq'=>'1900-01-01 00:00:00',
  744. 'U8UID'=>$value['U8_UID'],
  745. 'Uniqid'=>$value['UniqId'],
  746. ];
  747. $number = \db('物料_收发记录')
  748. ->where('U8UID',$value['U8_UID'])
  749. ->count();
  750. if ($number === 0){
  751. $sql = \db('物料_收发记录')->fetchSql(true)->insert($data);
  752. $res = \db()->query($sql);
  753. if ($res === false){
  754. $i++;
  755. }else{
  756. $sqlString = $db3->name('U8_07物料领用')
  757. ->where('UniqId', $value['UniqId'])
  758. ->fetchSql(true)
  759. ->update([
  760. 'MES接收时间' => date('Y-m-d H:i:s', time()),
  761. 'MES接收状态' => '1'
  762. ]);
  763. $db3->execute($sqlString);
  764. }
  765. }else{
  766. $sql = \db('物料_收发记录')
  767. ->fetchSql(true)
  768. ->where('U8UID',$value['U8_UID'])
  769. ->update($data);
  770. $res = \db()->query($sql);
  771. if ($res === false){
  772. $i++;
  773. }else{
  774. $sqlString = $db3->name('U8_07物料领用')
  775. ->where('UniqId', $value['UniqId'])
  776. ->fetchSql(true)
  777. ->update([
  778. 'MES接收时间' => date('Y-m-d H:i:s', time()),
  779. 'MES接收状态' => '1'
  780. ]);
  781. $db3->execute($sqlString);
  782. }
  783. }
  784. }
  785. if ($i !== 0){
  786. $this->error('物料领用记录同步失败');
  787. }else{
  788. $this->success('物料领用记录同步成功');
  789. }
  790. }
  791. /**
  792. * 仓库信息数据同步
  793. * @return void
  794. * @throws \think\Exception
  795. * @throws \think\db\exception\BindParamException
  796. * @throws \think\db\exception\DataNotFoundException
  797. * @throws \think\db\exception\ModelNotFoundException
  798. * @throws \think\exception\DbException
  799. * @throws \think\exception\PDOException
  800. */
  801. public function WarehouseInformationData()
  802. {
  803. if ($this->request->isGet() === false){
  804. $this->error('请求错误');
  805. }
  806. $db3 = \db()->connect(config('database.db3'));
  807. $OrganizationalDataList = $db3->name('U8_12仓库信息')
  808. ->where('MES接收时间',null)
  809. ->where('MES接收状态','0')
  810. ->select();
  811. if (empty($OrganizationalDataList)){
  812. $this->success('未找到新的仓库信息');
  813. }
  814. $i = 0;
  815. foreach ($OrganizationalDataList as $key=>$value){
  816. $data = [
  817. '编号'=>$value['编号'],
  818. '名称'=>$value['名称'],
  819. 'Sys_id'=>'[272/超级用户]',
  820. 'Sys_rq'=>date('Y-m-d H:i:s',time()),
  821. 'Mod_rq'=>'1900-01-01 00:00:00',
  822. 'U8UID'=>$value['U8_UID'],
  823. 'UniqId'=>$value['UniqId'],
  824. ];
  825. $number = \db('物料_仓库信息')
  826. ->where('U8UID',$value['U8_UID'])
  827. ->count();
  828. if ($number === 0){
  829. $sql = \db('物料_仓库信息')->fetchSql(true)->insert($data);
  830. $res = \db()->query($sql);
  831. if ($res === false){
  832. $i++;
  833. }else{
  834. $sqlString = $db3->name('U8_12仓库信息')
  835. ->where('UniqId', $value['UniqId'])
  836. ->fetchSql(true)
  837. ->update([
  838. 'MES接收时间' => date('Y-m-d H:i:s', time()),
  839. 'MES接收状态' => '1'
  840. ]);
  841. $db3->execute($sqlString);
  842. }
  843. }else{
  844. $sql = \db('物料_仓库信息')
  845. ->fetchSql(true)
  846. ->where('U8UID',$value['U8_UID'])
  847. ->update($data);
  848. $res = \db()->query($sql);
  849. if ($res === false){
  850. $i++;
  851. }else{
  852. $sqlString = $db3->name('U8_12仓库信息')
  853. ->where('UniqId', $value['UniqId'])
  854. ->fetchSql(true)
  855. ->update([
  856. 'MES接收时间' => date('Y-m-d H:i:s', time()),
  857. 'MES接收状态' => '1'
  858. ]);
  859. $db3->execute($sqlString);
  860. }
  861. }
  862. }
  863. if ($i !== 0){
  864. $this->error('仓库信息同步失败');
  865. }else{
  866. $this->success('仓库信息同步成功');
  867. }
  868. }
  869. /**
  870. * 职位编码数据同步
  871. * @return void
  872. * @throws \think\Exception
  873. * @throws \think\db\exception\BindParamException
  874. * @throws \think\db\exception\DataNotFoundException
  875. * @throws \think\db\exception\ModelNotFoundException
  876. * @throws \think\exception\DbException
  877. * @throws \think\exception\PDOException
  878. */
  879. public function PositionData()
  880. {
  881. if ($this->request->isGet() === false){
  882. $this->error('请求错误');
  883. }
  884. $db3 = \db()->connect(config('database.db3'));
  885. $OrganizationalDataList = $db3->name('U8_13职位编码')
  886. ->where('MES接收时间',null)
  887. ->where('MES接收状态','0')
  888. ->select();
  889. if (empty($OrganizationalDataList)){
  890. $this->success('未找到新的职位编码');
  891. }
  892. $i = 0;
  893. foreach ($OrganizationalDataList as $key=>$value){
  894. $data = [
  895. '职位编码'=>$value['职位编码'],
  896. '职位名称'=>$value['职位名称'],
  897. '定编人数'=>0,
  898. '备注说明'=>'',
  899. 'sys_id'=>'[272/超级用户]',
  900. 'sys_rq'=>date('Y-m-d H:i:s',time()),
  901. 'Mod_rq'=>'1900-01-01 00:00:00',
  902. 'U8UID'=>$value['U8_UID'],
  903. 'UniqID'=>$value['UniqID'],
  904. ];
  905. $number = \db('人事_职位编码')
  906. ->where('U8UID',$value['U8_UID'])
  907. ->count();
  908. if ($number === 0){
  909. $sql = \db('人事_职位编码')->fetchSql(true)->insert($data);
  910. $res = \db()->query($sql);
  911. if ($res === false){
  912. $i++;
  913. }else{
  914. $sqlString = $db3->name('U8_13职位编码')
  915. ->where('UniqID', $value['UniqID'])
  916. ->fetchSql(true)
  917. ->update([
  918. 'MES接收时间' => date('Y-m-d H:i:s', time()),
  919. 'MES接收状态' => '1'
  920. ]);
  921. $db3->execute($sqlString);
  922. }
  923. }else{
  924. $sql = \db('人事_职位编码')
  925. ->fetchSql(true)
  926. ->where('U8UID',$value['U8_UID'])
  927. ->update($data);
  928. $res = \db()->query($sql);
  929. if ($res === false){
  930. $i++;
  931. }else{
  932. $sqlString = $db3->name('U8_13职位编码')
  933. ->where('UniqID', $value['UniqID'])
  934. ->fetchSql(true)
  935. ->update([
  936. 'MES接收时间' => date('Y-m-d H:i:s', time()),
  937. 'MES接收状态' => '1'
  938. ]);
  939. $db3->execute($sqlString);
  940. }
  941. }
  942. }
  943. if ($i !== 0){
  944. $this->error('职位编码同步失败');
  945. }else{
  946. $this->success('职位编码同步成功');
  947. }
  948. }
  949. /**
  950. * 设备产量计酬云中间表数据库同步
  951. * @return void
  952. * @throws \think\db\exception\BindParamException
  953. * @throws \think\db\exception\DataNotFoundException
  954. * @throws \think\db\exception\ModelNotFoundException
  955. * @throws \think\exception\DbException
  956. * @throws \think\exception\PDOException
  957. */
  958. public function ProductionData()
  959. {
  960. if ($this->request->isGet() === false){
  961. $this->error('请求错误');
  962. }
  963. if(is_dir(ROOT_PATH.'public/'.date('Y-m-d',time())) == null)
  964. {
  965. mkdir(ROOT_PATH.'public/'.date('Y-m-d',time()),0777,true);
  966. }
  967. $db5 = \db()->connect(config('database.db5'));
  968. $where = [
  969. 'sczl_rq' => ['>=','2024-04-01 00:00:00']
  970. ];
  971. $productData = $db5->name('设备_产量计酬')
  972. ->where($where)
  973. ->select();
  974. var_dump($productData);
  975. //获取机台信息
  976. $machineData = \db('设备_基本资料')
  977. ->where('mn_设备编号','<>','')
  978. ->field('rtrim(设备编号) as 设备编号,rtrim(mn_设备编号) as 美浓设备编号')
  979. ->select();
  980. //获取员工资料
  981. $employeeData = \db('人事_基本资料')
  982. ->where('mn_员工编号','<>','')
  983. ->field('rtrim(mn_员工编号) as 美浓员工编号')
  984. ->select();
  985. $employee = array_column($employeeData,'美浓员工编号');
  986. //循环判断机台、员工编号
  987. $j = 0;
  988. $data = [];
  989. foreach ($productData as $key=>$value){
  990. //判断机台编号
  991. foreach ($machineData as $v){
  992. if ($value['sczl_jtbh'] === $v['美浓设备编号']){
  993. $productData[$key]['sczl_jtbh'] = $v['设备编号'];
  994. array_push($data,$productData[$key]);
  995. }
  996. }
  997. }
  998. if (empty($data)){
  999. $this->error('未找到新的生产数据');
  1000. }
  1001. foreach ($data as $key=>$value){
  1002. $name = [];
  1003. //判断员工编号,如果不存在写入日志文件
  1004. for($i=1;$i<=10;$i++){
  1005. if (in_array($data[$key]['sczl_bh'.$i],$employee)){
  1006. $data[$key]['sczl_bh'.$i] = \db('人事_基本资料')
  1007. ->where('mn_员工编号',$data[$key]['sczl_bh'.$i])
  1008. ->value('员工编号');
  1009. }else{
  1010. array_push($name,$value['sczl_bh'.$i]);
  1011. $data[$key]['sczl_bh'.$i] = '';
  1012. }
  1013. }
  1014. $name = array_unique($name);
  1015. $filename = ROOT_PATH.'public/'.date('Y-m-d',time()).'/'.$value['sczl_jtbh'].'日志文件.txt';
  1016. $handle = fopen($filename, 'w');
  1017. foreach ($name as $v){
  1018. fwrite($handle, $v);
  1019. }
  1020. fclose($handle);
  1021. //修改工单编号
  1022. if (preg_match("/[A-Za-z]/",$value['sczl_gdbh'])){
  1023. $workcode = $value['sczl_gdbh'];
  1024. }else{
  1025. $workcode = 'Y'.$value['sczl_gdbh'];
  1026. }
  1027. $data[$key]['sczl_gdbh'] = $workcode;
  1028. }
  1029. //插入设备产量计酬数据
  1030. \db('设备_产量计酬')->delete(true);
  1031. $sql = \db('设备_产量计酬')->fetchSql(true)->insertAll($data);
  1032. $res = \db()->query($sql);
  1033. if ($res !== false){
  1034. $this->success('同步成功');
  1035. }else{
  1036. $this->error('同步失败');
  1037. }
  1038. }
  1039. }