Synchronization.php 45 KB

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