Synchronization.php 42 KB

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