Synchronization.php 37 KB

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