Synchronization.php 37 KB

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