PrintingPlate.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Request;
  5. /**
  6. * 印版库管理
  7. */
  8. class PrintingPlate extends Api
  9. {
  10. protected $noNeedLogin = ['*'];
  11. protected $noNeedRight = ['*'];
  12. /**
  13. * 印版库管理左侧菜单
  14. * @return void
  15. */
  16. public function getTab()
  17. {
  18. if (!$this->request->isGet()) {
  19. $this->error('请求错误');
  20. }
  21. $data = [
  22. 'MN印版' => $this->buildTree('05'),
  23. '翌星印版' => $this->buildTree('Y05')
  24. ];
  25. $this->success('成功', $data);
  26. }
  27. //私有方法,构建数据
  28. private function buildTree($prefix)
  29. {
  30. $list = db('物料_存货结构')
  31. ->where('编号', 'like', $prefix . '%')
  32. ->order('编号', 'asc')
  33. ->select();
  34. $map = [];
  35. $tree = [];
  36. // 创建编号映射表
  37. foreach ($list as $item) {
  38. $map[$item['编号']] = $item['名称'];
  39. }
  40. // 构建树形结构
  41. foreach ($list as $item) {
  42. $code = $item['编号'];
  43. $name = $item['名称'];
  44. $key = "{$code} {$name}";
  45. $depth = strlen($code) - strlen($prefix);
  46. switch ($depth) {
  47. case 0: // 根节点 (05/Y05)
  48. $tree[$key] = [];
  49. break;
  50. case 2: // 二级节点 (0501/Y0501)
  51. $parentCode = substr($code, 0, strlen($prefix));
  52. $parentKey = "{$parentCode} {$map[$parentCode]}";
  53. $tree[$parentKey][$key] = [];
  54. break;
  55. case 4: // 三级节点 (050100/Y050101)
  56. $parentCode = substr($code, 0, strlen($prefix) + 2);
  57. $grandCode = substr($code, 0, strlen($prefix));
  58. $grandKey = "{$grandCode} {$map[$grandCode]}";
  59. $parentKey = "{$parentCode} {$map[$parentCode]}";
  60. if (isset($tree[$grandKey][$parentKey])) {
  61. $tree[$grandKey][$parentKey][] = $key;
  62. }
  63. break;
  64. }
  65. }
  66. return $tree;
  67. }
  68. /**
  69. * 存货编码列表
  70. * @return void
  71. * @throws \think\db\exception\DataNotFoundException
  72. * @throws \think\db\exception\ModelNotFoundException
  73. * @throws \think\exception\DbException
  74. */
  75. // public function MaterailCodeList()
  76. // {
  77. //
  78. // if (!$this->request->isGet()) {
  79. // $this->error('请求错误');
  80. // }
  81. // $params = $this->request->param();
  82. // if (empty($params)) {
  83. // $this->error('参数错误');
  84. // }
  85. //
  86. // $page = intval($params['page']);
  87. // $limit = intval($params['limit']);
  88. // $where = [];
  89. // if (!empty($params['code'])) {
  90. // $code = preg_match('/[a-zA-Z]/', $params['code'])
  91. // ? substr($params['code'], 0, 7)
  92. // : substr($params['code'], 0, 6);
  93. // $where['a.存货编码'] = ['like', $code . '%'];
  94. // }
  95. // if (!empty($params['key']) && isset($params['key'])) {
  96. // $where['a.报废日期'] = '1900-01-01 00:00:00';
  97. // }
  98. // if (!empty($params['search'])) {
  99. // $where['b.物料名称|c.Yb_工单编号'] = ['like', '%' . $params['search'] . '%'];
  100. // $where['c.Yb_退还日期'] = null;
  101. // }
  102. // //总数
  103. // $total = db('产品_印版库')
  104. // ->alias('a')
  105. // ->join('物料_存货编码 b', 'a.存货编码 = b.物料代码')
  106. // ->join('工单_印版领用记录 c',
  107. // 'a.存货编码 = c.Yb_存货编码 AND a.供方批号 = c.Yb_供方批号',
  108. // 'LEFT')
  109. // ->where($where)
  110. // ->group('a.存货编码, a.供方批号')
  111. // ->count();
  112. //
  113. // $list = db('产品_印版库')
  114. // ->alias('a')
  115. // ->join('物料_存货编码 b', 'a.存货编码 = b.物料代码')
  116. // ->join('工单_印版领用记录 c',
  117. // 'a.存货编码 = c.Yb_存货编码 AND a.供方批号 = c.Yb_供方批号',
  118. // 'LEFT')
  119. // ->where($where)
  120. // ->group('a.存货编码, a.供方批号')
  121. // ->order('报废日期, a.存货编码')
  122. // ->field([
  123. // 'rtrim(a.存货编码) as 存货编码',
  124. // 'rtrim(b.物料名称) as 物料名称',
  125. // 'rtrim(a.印版名称) as 印版名称',
  126. // 'rtrim(a.供方批号) as 供方批号',
  127. // 'DATE(a.制造日期) as 制造日期',
  128. // "CASE
  129. // WHEN a.报废日期 = '1900-01-01 00:00:00' THEN NULL
  130. // ELSE DATE(a.报废日期)
  131. // END as 报废日期",
  132. // 'a.原始印数',
  133. // 'a.考核印数',
  134. // 'a.UniqID',
  135. // 'CASE WHEN c.Yb_退还日期 IS NULL THEN c.UniqID ELSE NULL END as GDUID',
  136. // 'rtrim(a.Sys_id) as 创建用户',
  137. // 'a.Sys_rq as 创建日期',
  138. // 'a.Mod_rq as 修改时间',
  139. // 'SUM(c.Yb_印数) as 累计印数',
  140. // "MAX(CASE WHEN c.Yb_领用日期 IS NOT NULL AND c.Yb_退还日期 IS NULL THEN c.Yb_工单编号 END) as 工单编号"
  141. // ])
  142. // ->limit(($page - 1) * $limit, $limit)
  143. // ->select();
  144. // if (empty($list)) {
  145. // $this->error('未找到相关记录');
  146. // }
  147. // $this->success('查询成功', [
  148. // 'data' => $list,
  149. // 'total' => $total,
  150. // ]);
  151. // }
  152. public function MaterailCodeList()
  153. {
  154. if (!$this->request->isGet()) {
  155. $this->error('请求错误');
  156. }
  157. $params = $this->request->param();
  158. if (empty($params)) {
  159. $this->error('参数错误');
  160. }
  161. $page = intval($params['page']);
  162. $limit = intval($params['limit']);
  163. $where = [];
  164. if (!empty($params['code'])) {
  165. $code = preg_match('/[a-zA-Z]/', $params['code'])
  166. ? substr($params['code'], 0, 7)
  167. : substr($params['code'], 0, 6);
  168. $where['a.存货编码'] = ['like', $code . '%'];
  169. }
  170. if (!empty($params['key']) && isset($params['key'])) {
  171. $where['a.报废日期'] = '1900-01-01 00:00:00';
  172. }
  173. if (!empty($params['search'])) {
  174. $where['b.物料名称|c.Yb_工单编号'] = ['like', '%' . $params['search'] . '%'];
  175. $where['c.Yb_退还日期'] = null;
  176. }
  177. // 总数查询
  178. $total = db('产品_印版库')
  179. ->alias('a')
  180. ->join('物料_存货编码 b', 'a.存货编码 = b.物料代码')
  181. ->join('工单_印版领用记录 c',
  182. 'a.存货编码 = c.Yb_存货编码 AND a.供方批号 = c.Yb_供方批号',
  183. 'LEFT')
  184. ->where($where)
  185. ->group('a.存货编码, a.供方批号')
  186. ->count();
  187. // 数据列表查询
  188. $list = db('产品_印版库')
  189. ->alias('a')
  190. ->join('物料_存货编码 b', 'a.存货编码 = b.物料代码')
  191. ->join('工单_印版领用记录 c',
  192. 'a.存货编码 = c.Yb_存货编码 AND a.供方批号 = c.Yb_供方批号',
  193. 'LEFT')
  194. ->where($where)
  195. ->group('a.存货编码, a.供方批号')
  196. ->order('报废日期, a.存货编码')
  197. ->field([
  198. 'rtrim(a.存货编码) as 存货编码',
  199. 'rtrim(b.物料名称) as 物料名称',
  200. 'rtrim(a.印版名称) as 印版名称',
  201. 'rtrim(a.供方批号) as 供方批号',
  202. 'DATE(a.制造日期) as 制造日期',
  203. "CASE
  204. WHEN a.报废日期 = '1900-01-01 00:00:00' THEN NULL
  205. ELSE DATE(a.报废日期)
  206. END as 报废日期",
  207. 'a.原始印数',
  208. 'a.考核印数',
  209. 'a.UniqID',
  210. "MAX(CASE
  211. WHEN c.Yb_退还日期 IS NULL
  212. THEN c.UniqID
  213. ELSE NULL
  214. END) as GDUID",
  215. 'rtrim(a.Sys_id) as 创建用户',
  216. 'a.Sys_rq as 创建日期',
  217. 'a.Mod_rq as 修改时间',
  218. 'SUM(c.Yb_印数) as 累计印数',
  219. "MAX(CASE
  220. WHEN c.Yb_领用日期 IS NOT NULL AND c.Yb_退还日期 IS NULL
  221. THEN c.Yb_工单编号
  222. END) as 工单编号"
  223. ])
  224. ->limit(($page - 1) * $limit, $limit)
  225. ->select();
  226. if (empty($list)) {
  227. $this->error('未找到相关记录');
  228. }
  229. $this->success('查询成功', [
  230. 'data' => $list,
  231. 'total' => $total,
  232. ]);
  233. }
  234. /**
  235. * 印版管理印版修改
  236. * @return void
  237. * @throws \think\db\exception\DataNotFoundException
  238. * @throws \think\db\exception\ModelNotFoundException
  239. * @throws \think\exception\DbException
  240. */
  241. public function MaterailDetail()
  242. {
  243. if ($this->request->isGet() === false){
  244. $this->error('请求错误');
  245. }
  246. $param = $this->request->param();
  247. if (empty($param) || !isset($param['UniqID'])){
  248. $this->error('参数错误');
  249. }
  250. $result = db('产品_印版库')
  251. ->alias('a')
  252. ->join('物料_存货编码 b', 'a.存货编码 = b.物料代码')
  253. ->where('a.UniqID', $param['UniqID'])
  254. ->order('报废日期, a.存货编码')
  255. ->field('
  256. rtrim(a.存货编码) as 存货编码,
  257. rtrim(b.物料名称) as 物料名称,
  258. rtrim(a.印版名称) as 印版备注,
  259. rtrim(a.供方批号) as 供方批号,
  260. DATE(a.制造日期) as 制造日期,
  261. CASE
  262. WHEN a.报废日期 = "1900-01-01 00:00:00" THEN NULL
  263. ELSE DATE(a.报废日期)
  264. END as 报废日期,
  265. a.原始印数,
  266. a.考核印数,
  267. a.UniqID
  268. ')
  269. ->find();
  270. if (empty($result)) {
  271. $this->error('未找到数据');
  272. }else{
  273. $this->success('成功', $result);
  274. }
  275. }
  276. /**
  277. * 印版资料新增修改
  278. * @return void
  279. * @throws \think\Exception
  280. * @throws \think\db\exception\BindParamException
  281. * @throws \think\db\exception\DataNotFoundException
  282. * @throws \think\db\exception\ModelNotFoundException
  283. * @throws \think\exception\DbException
  284. * @throws \think\exception\PDOException
  285. */
  286. public function MaterailEdit()
  287. {
  288. if ($this->request->isPost() === false){
  289. $this->error('请求错误');
  290. }
  291. $param = Request::instance()->post();
  292. if (empty($param) || !isset($param['code'])){
  293. $this->error('参数错误');
  294. }
  295. $data = [
  296. '存货编码' => $param['code'],
  297. '供方批号' => $param['batch'],
  298. '印版名称' => $param['desc'],
  299. '制造日期' => $param['Manufactur_date'],
  300. '原始印数' => $param['start_num'],
  301. '考核印数' => $param['Assessment_num'],
  302. '报废日期' => $param['Scrappe_date']?:'1900-01-01 00:00:00',
  303. 'Sys_id' => $param['sys_id']
  304. ];
  305. //查询数据是否存在,存在则修改,不存在则增加
  306. $res = db('产品_印版库')
  307. ->where('存货编码',$param['code'])
  308. ->where('供方批号',$param['batch'])
  309. ->find();
  310. if (empty($res)){
  311. $data['Sys_rq'] = date('Y-m-d H:i:s',time());
  312. if ($param['number'] !== '' || $param['number'] !== '0'){
  313. if ($param['sist'] === '凹丝印车间'){
  314. $data['供方批号'] = $param['batch'].'-'.$param['number'];
  315. $sql = db('产品_印版库')->fetchSql(true)->insert($data);
  316. }else{
  317. for ($i = 1; $i <= $param['number']; $i++){
  318. if ($i<10){
  319. $number = '0'.$i;
  320. }else{
  321. $number = $i;
  322. }
  323. $data['供方批号'] = $param['batch'].'-'.$number;
  324. $resData[] = $data;
  325. }
  326. $sql = db('产品_印版库')->fetchSql(true)->insertAll($resData);
  327. }
  328. }else{
  329. $sql = db('产品_印版库')->fetchSql(true)->insert($data);
  330. }
  331. }else{
  332. $UniqID = $param['UniqID'];
  333. $data['Mod_rq'] = date('Y-m-d H:i:s',time());
  334. $sql = db('产品_印版库')->where('UniqID',$UniqID)->fetchSql(true)->update($data);
  335. }
  336. $result = db()->query($sql);
  337. if ($result === false){
  338. $this->error('修改失败');
  339. }else{
  340. $this->success('修改成功');
  341. }
  342. }
  343. /**
  344. * 印版新增->存货编码获取
  345. * @return void
  346. * @throws \think\db\exception\DataNotFoundException
  347. * @throws \think\db\exception\ModelNotFoundException
  348. * @throws \think\exception\DbException
  349. */
  350. public function getInventoryCode()
  351. {
  352. if (!$this->request->isGet()) {
  353. $this->error('请求错误');
  354. }
  355. $param = $this->request->param();
  356. if (empty($param) || !isset($param['code'])) {
  357. $this->error('参数错误');
  358. }
  359. // 提取前缀
  360. $codeLength = preg_match('/[a-zA-Z]/', $param['code']) ? 5 : 4;
  361. $code = substr($param['code'], 0, $codeLength);
  362. $where['物料代码'] = ['like', $code . '%'];
  363. if (!empty($param['search'])) {
  364. $where['物料代码'] = $param['search'];
  365. }
  366. // 查询物料存货编码
  367. $list = db('物料_存货编码')
  368. ->where($where)
  369. ->field('rtrim(物料代码) as 物料代码, rtrim(物料名称) as 物料名称, rtrim(规格) as 规格')
  370. ->select();
  371. // 数据处理
  372. $data = [];
  373. foreach ($list as $item) {
  374. // 提取物料代码的前缀
  375. $prefixLength = preg_match('/[a-zA-Z]/', $item['物料代码']) ? [3, 5, 7] : [2, 4, 6];
  376. // 使用普通的数组映射替代箭头函数
  377. $num1 = substr($item['物料代码'], 0, $prefixLength[0]);
  378. $num2 = substr($item['物料代码'], 0, $prefixLength[1]);
  379. $num3 = substr($item['物料代码'], 0, $prefixLength[2]);
  380. // 批量查询物料结构名称
  381. $names = db('物料_存货结构')
  382. ->whereIn('编号', [$num1, $num2, $num3])
  383. ->column('名称', '编号');
  384. // 将数据组织进数组
  385. $name1 = isset($names[$num1]) ? $names[$num1] : '';
  386. $name2 = isset($names[$num2]) ? $names[$num2] : '';
  387. $name3 = isset($names[$num3]) ? $names[$num3] : '';
  388. if (!isset($data["$num1/$name1"][$num2][$num3.'/'.$name3])) {
  389. $data["$num1/$name1"][$num2][$num3.'/'.$name3] = [];
  390. }
  391. $data["$num1/$name1"][$num2][$num3.'/'.$name3][] = "{$item['物料代码']}/{$item['物料名称']}/{$item['规格']}";
  392. }
  393. $this->success('成功', $data);
  394. }
  395. /**
  396. * 印版领用
  397. * @return void
  398. * @throws \think\db\exception\BindParamException
  399. * @throws \think\exception\PDOException
  400. */
  401. public function PrintingPlateReceive()
  402. {
  403. if (!$this->request->isPost()) {
  404. $this->error('请求错误');
  405. }
  406. $param = Request::instance()->post();
  407. if (empty($param)) {
  408. $this->error('参数错误');
  409. }
  410. $data = [];
  411. foreach ($param as $item) {
  412. $data[] = [
  413. 'Yb_工单编号' => $item['gdbh'],
  414. 'Yb_印件号' => $item['yjno'],
  415. 'Yb_存货编码' => $item['code'],
  416. 'Yb_供方批号' => $item['batch'],
  417. 'Yb_领用日期' => date('Y-m-d',time()),
  418. 'Yb_领用机台' => $item['machine'],
  419. 'Sys_id' => $item['sys_id'],
  420. 'Sys_rq' => date('Y-m-d H:i:s',time()),
  421. ];
  422. }
  423. $sql = db('工单_印版领用记录')
  424. ->fetchSql(true)
  425. ->insertAll($data);
  426. $res = db('')->query($sql);
  427. if ($res === false){
  428. $this->error('领用失败');
  429. }else{
  430. $this->success('领用成功');
  431. }
  432. }
  433. /**
  434. * 印版工单领用
  435. * @return void
  436. * @throws \think\db\exception\DataNotFoundException
  437. * @throws \think\db\exception\ModelNotFoundException
  438. * @throws \think\exception\DbException
  439. */
  440. public function PrintDetailReceive()
  441. {
  442. if (!$this->request->isGet()) {
  443. $this->error('请求错误');
  444. }
  445. $param = $this->request->param();
  446. if (empty($param) || !isset($param['code'])) {
  447. $this->error('参数错误');
  448. }
  449. $list = db('工单_印版领用记录')
  450. ->alias('a')
  451. ->field('a.Yb_工单编号 as 工单编号,a.Yb_印件号 as 印件号,a.Yb_领用日期 as 领用日期,a.Yb_退还日期 as 退还日期,a.Yb_领用机台 as 领用机台,
  452. a.Yb_印数 as 印数,a.Sys_id as 创建用户,a.Sys_rq as 创建时间,a.UniqID,b.成品代号,rtrim(b.成品名称) as 成品名称')
  453. ->join('工单_基本资料 b', 'a.Yb_工单编号 = b.Gd_gdbh','left')
  454. ->where('a.Yb_存货编码',$param['code'])
  455. ->where('a.Yb_供方批号',$param['batch'])
  456. ->order('a.UniqID desc')
  457. ->group('a.Yb_工单编号,a.Yb_印件号,a.UniqID')
  458. ->select();
  459. if (empty($list)){
  460. $this->error('未找到领用记录');
  461. }else{
  462. $this->success('成功', $list);
  463. }
  464. }
  465. /**
  466. * 印版领用记录删除
  467. * @return void
  468. * @throws \think\Exception
  469. * @throws \think\exception\PDOException
  470. */
  471. public function PrintReceiveDelete()
  472. {
  473. if ($this->request->isGet() === false) {
  474. $this->error('请求错误');
  475. }
  476. $param = $this->request->param();
  477. if (empty($param) || !isset($param['id'])) {
  478. $this->error('参数错误');
  479. }
  480. $id = explode(',', $param['id']);
  481. if (empty($id)) {
  482. $this->error('请先选中要删除数据');
  483. }
  484. $res = db('工单_印版领用记录')
  485. ->where('UniqID','in',$id)
  486. ->delete();
  487. if ($res === false){
  488. $this->error('删除失败');
  489. }else{
  490. $this->success('删除成功');
  491. }
  492. }
  493. //印版库管理菜单下方客户产品印版管理
  494. public function PrintDetailTab()
  495. {
  496. if($this->request->isGet() === false){
  497. $this->error('请求错误');
  498. }
  499. $list = db('产品_印版资料')
  500. ->alias('a')
  501. ->field('
  502. rtrim(a.YB_Cpdh) as 产品代号,
  503. rtrim(b.产品名称) as 产品名称,
  504. rtrim(b.客户编号) as 客户编号,
  505. rtrim(b.客户名称) as 客户名称,
  506. rtrim(a.存货编码) as 存货编码,
  507. rtrim(c.名称) as 名称
  508. ')
  509. ->join('产品_基本资料 b', 'a.YB_Cpdh = b.产品编号')
  510. ->join('物料_存货结构 c',
  511. "(CASE
  512. WHEN a.存货编码 REGEXP '[A-Za-z]'
  513. THEN LEFT(rtrim(a.存货编码), 5)
  514. ELSE LEFT(rtrim(a.存货编码), 4)
  515. END) = rtrim(c.编号)"
  516. )
  517. ->group('a.YB_Cpdh,名称')
  518. ->order('a.YB_Cpdh,a.存货编码')
  519. ->select();
  520. if (empty($list)){
  521. $this->error('未找到客户数据');
  522. }
  523. foreach ($list as $item) {
  524. $customerKey = $item['客户编号'] . '【' . $item['客户名称'] . '】';
  525. $productKey = $item['产品代号'] . '【' . $item['产品名称'] . '】';
  526. if (!isset($data[$customerKey])) {
  527. $data[$customerKey] = [];
  528. }
  529. if (!isset($data[$customerKey][$productKey])) {
  530. $data[$customerKey][$productKey] = [];
  531. }
  532. if (!in_array($item['名称'], $data[$customerKey][$productKey])) {
  533. $data[$customerKey][$productKey][] = $item['名称'];
  534. }
  535. }
  536. $this->success('成功', $data);
  537. }
  538. //客户印版库右侧列表
  539. public function PrintDetail()
  540. {
  541. if ($this->request->isGet() === false) {
  542. $this->error('请求错误');
  543. }
  544. $param = $this->request->param();
  545. if (empty($param) || !isset($param['code']) || !isset($param['category'])) {
  546. $this->error('请求错误');
  547. }
  548. //获取印版库分类编号
  549. $categoryNumber = db('物料_存货');
  550. $where = [
  551. 'a.YB_Cpdh' => $param['code'],
  552. 'b.YB_Cpdh' => $param['category'],
  553. ];
  554. // $list = db('<UNK>_<UNK>')
  555. }
  556. /**
  557. * 印版删除
  558. * @return void
  559. * @throws \think\Exception
  560. * @throws \think\exception\PDOException
  561. */
  562. public function PrintDetaiDel()
  563. {
  564. if ($this->request->isGet() === false) {
  565. $this->error('请求错误');
  566. }
  567. $param = $this->request->param();
  568. if (empty($param) || !isset($param['UniqID'])) {
  569. $this->error('参数错误');
  570. }
  571. $id = explode(',', $param['UniqID']);
  572. $res = db('产品_印版库')
  573. ->where('UniqID','in',$id)
  574. ->delete();
  575. if ($res === false){
  576. $this->error('删除失败');
  577. }else{
  578. $this->success('删除成功');
  579. }
  580. }
  581. }