PrintingPlate.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  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. if (!$this->request->isGet()) {
  78. $this->error('请求错误');
  79. }
  80. $params = $this->request->param();
  81. if (empty($params)) {
  82. $this->error('参数错误');
  83. }
  84. $page = intval($params['page']);
  85. $limit = intval($params['limit']);
  86. $where = [];
  87. if (!empty($params['code'])) {
  88. $code = preg_match('/[a-zA-Z]/', $params['code'])
  89. ? substr($params['code'], 0, 7)
  90. : substr($params['code'], 0, 6);
  91. $where['a.存货编码'] = ['like', $code . '%'];
  92. }
  93. if (!empty($params['key']) && isset($params['key'])) {
  94. $where['a.报废日期'] = '1900-01-01 00:00:00';
  95. }
  96. if (!empty($params['search'])) {
  97. $where['b.物料名称|c.Yb_工单编号'] = ['like', '%' . $params['search'] . '%'];
  98. }
  99. //总数
  100. $total = db('产品_印版库')
  101. ->alias('a')
  102. ->join('物料_存货编码 b', 'a.存货编码 = b.物料代码')
  103. ->join('工单_印版领用记录 c',
  104. 'a.存货编码 = c.Yb_存货编码 AND a.供方批号 = c.Yb_供方批号',
  105. 'LEFT')
  106. ->where($where)
  107. ->group('a.存货编码, a.供方批号')
  108. ->count();
  109. $list = db('产品_印版库')
  110. ->alias('a')
  111. ->join('物料_存货编码 b', 'a.存货编码 = b.物料代码')
  112. ->join('工单_印版领用记录 c',
  113. 'a.存货编码 = c.Yb_存货编码 AND a.供方批号 = c.Yb_供方批号',
  114. 'LEFT')
  115. ->where($where)
  116. ->group('a.存货编码, a.供方批号')
  117. ->order('报废日期, a.存货编码')
  118. ->field([
  119. 'rtrim(a.存货编码) as 存货编码',
  120. 'rtrim(b.物料名称) as 物料名称',
  121. 'rtrim(a.印版名称) as 印版名称',
  122. 'rtrim(a.供方批号) as 供方批号',
  123. 'DATE(a.制造日期) as 制造日期',
  124. "CASE
  125. WHEN a.报废日期 = '1900-01-01 00:00:00' THEN NULL
  126. ELSE DATE(a.报废日期)
  127. END as 报废日期",
  128. 'a.原始印数',
  129. 'a.考核印数',
  130. 'a.UniqID',
  131. 'c.UniqID as GDUID',
  132. 'rtrim(a.Sys_id) as 创建用户',
  133. 'a.Sys_rq as 创建日期',
  134. 'a.Mod_rq as 修改时间',
  135. 'SUM(c.Yb_印数) as 累计印数',
  136. "MAX(CASE WHEN c.Yb_领用日期 IS NOT NULL AND c.Yb_退还日期 IS NULL THEN c.Yb_工单编号 END) as 工单编号"
  137. ])
  138. ->limit(($page - 1) * $limit, $limit)
  139. ->select();
  140. if (empty($list)) {
  141. $this->error('未找到相关记录');
  142. }
  143. $this->success('查询成功', [
  144. 'data' => $list,
  145. 'total' => $total,
  146. ]);
  147. }
  148. /**
  149. * 印版管理印版修改
  150. * @return void
  151. * @throws \think\db\exception\DataNotFoundException
  152. * @throws \think\db\exception\ModelNotFoundException
  153. * @throws \think\exception\DbException
  154. */
  155. public function MaterailDetail()
  156. {
  157. if ($this->request->isGet() === false){
  158. $this->error('请求错误');
  159. }
  160. $param = $this->request->param();
  161. if (empty($param) || !isset($param['UniqID'])){
  162. $this->error('参数错误');
  163. }
  164. $result = db('产品_印版库')
  165. ->alias('a')
  166. ->join('物料_存货编码 b', 'a.存货编码 = b.物料代码')
  167. ->where('a.UniqID', $param['UniqID'])
  168. ->order('报废日期, a.存货编码')
  169. ->field('
  170. rtrim(a.存货编码) as 存货编码,
  171. rtrim(b.物料名称) as 物料名称,
  172. rtrim(a.印版名称) as 印版备注,
  173. rtrim(a.供方批号) as 供方批号,
  174. DATE(a.制造日期) as 制造日期,
  175. CASE
  176. WHEN a.报废日期 = "1900-01-01 00:00:00" THEN NULL
  177. ELSE DATE(a.报废日期)
  178. END as 报废日期,
  179. a.原始印数,
  180. a.考核印数,
  181. a.UniqID
  182. ')
  183. ->find();
  184. if (empty($result)) {
  185. $this->error('未找到数据');
  186. }else{
  187. $this->success('成功', $result);
  188. }
  189. }
  190. /**
  191. * 印版资料新增修改
  192. * @return void
  193. * @throws \think\Exception
  194. * @throws \think\db\exception\BindParamException
  195. * @throws \think\db\exception\DataNotFoundException
  196. * @throws \think\db\exception\ModelNotFoundException
  197. * @throws \think\exception\DbException
  198. * @throws \think\exception\PDOException
  199. */
  200. public function MaterailEdit()
  201. {
  202. if ($this->request->isPost() === false){
  203. $this->error('请求错误');
  204. }
  205. $param = Request::instance()->post();
  206. if (empty($param) || !isset($param['code'])){
  207. $this->error('参数错误');
  208. }
  209. $data = [
  210. '存货编码' => $param['code'],
  211. '供方批号' => $param['batch'],
  212. '印版名称' => $param['desc'],
  213. '制造日期' => $param['Manufactur_date'],
  214. '原始印数' => $param['start_num'],
  215. '考核印数' => $param['Assessment_num'],
  216. '报废日期' => $param['Scrappe_date']?:'1900-01-01 00:00:00',
  217. 'Sys_id' => $param['sys_id']
  218. ];
  219. //查询数据是否存在,存在则修改,不存在则增加
  220. $res = db('产品_印版库')
  221. ->where('存货编码',$param['code'])
  222. ->where('供方批号',$param['batch'])
  223. ->find();
  224. if (empty($res)){
  225. $data['Sys_rq'] = date('Y-m-d H:i:s',time());
  226. if ($param['number'] !== '' || $param['number'] !== '0'){
  227. if ($param['sist'] === '凹丝印车间'){
  228. $data['供方批号'] = $param['batch'].'-'.$param['number'];
  229. $sql = db('产品_印版库')->fetchSql(true)->insert($data);
  230. }else{
  231. for ($i = 1; $i <= $param['number']; $i++){
  232. if ($i<10){
  233. $number = '0'.$i;
  234. }else{
  235. $number = $i;
  236. }
  237. $data['供方批号'] = $param['batch'].'-'.$number;
  238. $resData[] = $data;
  239. }
  240. $sql = db('产品_印版库')->fetchSql(true)->insertAll($resData);
  241. }
  242. }else{
  243. $sql = db('产品_印版库')->fetchSql(true)->insert($data);
  244. }
  245. }else{
  246. $UniqID = $param['UniqID'];
  247. $data['Mod_rq'] = date('Y-m-d H:i:s',time());
  248. $sql = db('产品_印版库')->where('UniqID',$UniqID)->fetchSql(true)->update($data);
  249. }
  250. $result = db()->query($sql);
  251. if ($result === false){
  252. $this->error('修改失败');
  253. }else{
  254. $this->success('修改成功');
  255. }
  256. }
  257. /**
  258. * 印版新增->存货编码获取
  259. * @return void
  260. * @throws \think\db\exception\DataNotFoundException
  261. * @throws \think\db\exception\ModelNotFoundException
  262. * @throws \think\exception\DbException
  263. */
  264. public function getInventoryCode()
  265. {
  266. if (!$this->request->isGet()) {
  267. $this->error('请求错误');
  268. }
  269. $param = $this->request->param();
  270. if (empty($param) || !isset($param['code'])) {
  271. $this->error('参数错误');
  272. }
  273. // 提取前缀
  274. $codeLength = preg_match('/[a-zA-Z]/', $param['code']) ? 5 : 4;
  275. $code = substr($param['code'], 0, $codeLength);
  276. $where['物料代码'] = ['like', $code . '%'];
  277. if (!empty($param['search'])) {
  278. $where['物料代码'] = $param['search'];
  279. }
  280. // 查询物料存货编码
  281. $list = db('物料_存货编码')
  282. ->where($where)
  283. ->field('rtrim(物料代码) as 物料代码, rtrim(物料名称) as 物料名称, rtrim(规格) as 规格')
  284. ->select();
  285. // 数据处理
  286. $data = [];
  287. foreach ($list as $item) {
  288. // 提取物料代码的前缀
  289. $prefixLength = preg_match('/[a-zA-Z]/', $item['物料代码']) ? [3, 5, 7] : [2, 4, 6];
  290. // 使用普通的数组映射替代箭头函数
  291. $num1 = substr($item['物料代码'], 0, $prefixLength[0]);
  292. $num2 = substr($item['物料代码'], 0, $prefixLength[1]);
  293. $num3 = substr($item['物料代码'], 0, $prefixLength[2]);
  294. // 批量查询物料结构名称
  295. $names = db('物料_存货结构')
  296. ->whereIn('编号', [$num1, $num2, $num3])
  297. ->column('名称', '编号');
  298. // 将数据组织进数组
  299. $name1 = isset($names[$num1]) ? $names[$num1] : '';
  300. $name2 = isset($names[$num2]) ? $names[$num2] : '';
  301. $name3 = isset($names[$num3]) ? $names[$num3] : '';
  302. if (!isset($data["$num1/$name1"][$num2][$num3.'/'.$name3])) {
  303. $data["$num1/$name1"][$num2][$num3.'/'.$name3] = [];
  304. }
  305. $data["$num1/$name1"][$num2][$num3.'/'.$name3][] = "{$item['物料代码']}/{$item['物料名称']}/{$item['规格']}";
  306. }
  307. $this->success('成功', $data);
  308. }
  309. /**
  310. * 印版领用
  311. * @return void
  312. * @throws \think\db\exception\BindParamException
  313. * @throws \think\exception\PDOException
  314. */
  315. public function PrintingPlateReceive()
  316. {
  317. if (!$this->request->isPost()) {
  318. $this->error('请求错误');
  319. }
  320. $param = Request::instance()->post();
  321. if (empty($param)) {
  322. $this->error('参数错误');
  323. }
  324. $data = [];
  325. foreach ($param as $item) {
  326. $data[] = [
  327. 'Yb_工单编号' => $item['gdbh'],
  328. 'Yb_印件号' => $item['yjno'],
  329. 'Yb_存货编码' => $item['code'],
  330. 'Yb_供方批号' => $item['batch'],
  331. 'Yb_领用日期' => date('Y-m-d',time()),
  332. 'Yb_领用机台' => $item['machine'],
  333. 'Sys_id' => $item['sys_id'],
  334. 'Sys_rq' => date('Y-m-d H:i:s',time()),
  335. ];
  336. }
  337. $sql = db('工单_印版领用记录')
  338. ->fetchSql(true)
  339. ->insertAll($data);
  340. $res = db('')->query($sql);
  341. if ($res === false){
  342. $this->error('领用失败');
  343. }else{
  344. $this->success('领用成功');
  345. }
  346. }
  347. /**
  348. * 印版工单领用
  349. * @return void
  350. * @throws \think\db\exception\DataNotFoundException
  351. * @throws \think\db\exception\ModelNotFoundException
  352. * @throws \think\exception\DbException
  353. */
  354. public function PrintDetailReceive()
  355. {
  356. if (!$this->request->isGet()) {
  357. $this->error('请求错误');
  358. }
  359. $param = $this->request->param();
  360. if (empty($param) || !isset($param['code'])) {
  361. $this->error('参数错误');
  362. }
  363. $list = db('工单_印版领用记录')
  364. ->alias('a')
  365. ->field('a.Yb_工单编号 as 工单编号,a.Yb_印件号 as 印件号,a.Yb_领用日期 as 领用日期,a.Yb_退还日期 as 退还日期,a.Yb_领用机台 as 领用机台,
  366. a.Yb_印数 as 印数,a.Sys_id as 创建用户,a.Sys_rq as 创建时间,a.UniqID,b.成品代号,rtrim(b.成品名称) as 成品名称')
  367. ->join('工单_基本资料 b', 'a.Yb_工单编号 = b.Gd_gdbh','left')
  368. ->where('a.Yb_存货编码',$param['code'])
  369. ->where('a.Yb_供方批号',$param['batch'])
  370. ->order('a.UniqID desc')
  371. ->group('a.Yb_工单编号,a.Yb_印件号,a.UniqID')
  372. ->select();
  373. if (empty($list)){
  374. $this->error('未找到领用记录');
  375. }else{
  376. $this->success('成功', $list);
  377. }
  378. }
  379. /**
  380. * 印版领用记录删除
  381. * @return void
  382. * @throws \think\Exception
  383. * @throws \think\exception\PDOException
  384. */
  385. public function PrintReceiveDelete()
  386. {
  387. if ($this->request->isGet() === false) {
  388. $this->error('请求错误');
  389. }
  390. $param = $this->request->param();
  391. if (empty($param) || !isset($param['id'])) {
  392. $this->error('参数错误');
  393. }
  394. $id = explode(',', $param['id']);
  395. if (empty($id)) {
  396. $this->error('请先选中要删除数据');
  397. }
  398. $res = db('工单_印版领用记录')
  399. ->where('UniqID','in',$id)
  400. ->delete();
  401. if ($res === false){
  402. $this->error('删除失败');
  403. }else{
  404. $this->success('删除成功');
  405. }
  406. }
  407. //印版库管理菜单下方客户产品印版管理
  408. public function PrintDetailTab()
  409. {
  410. if($this->request->isGet() === false){
  411. $this->error('请求错误');
  412. }
  413. $list = db('产品_印版资料')
  414. ->alias('a')
  415. ->field('
  416. rtrim(a.YB_Cpdh) as 产品代号,
  417. rtrim(b.产品名称) as 产品名称,
  418. rtrim(b.客户编号) as 客户编号,
  419. rtrim(b.客户名称) as 客户名称,
  420. rtrim(a.存货编码) as 存货编码,
  421. rtrim(c.名称) as 名称
  422. ')
  423. ->join('产品_基本资料 b', 'a.YB_Cpdh = b.产品编号')
  424. ->join('物料_存货结构 c',
  425. "(CASE
  426. WHEN a.存货编码 REGEXP '[A-Za-z]'
  427. THEN LEFT(rtrim(a.存货编码), 5)
  428. ELSE LEFT(rtrim(a.存货编码), 4)
  429. END) = rtrim(c.编号)"
  430. )
  431. ->group('a.YB_Cpdh,名称')
  432. ->order('a.YB_Cpdh,a.存货编码')
  433. ->select();
  434. if (empty($list)){
  435. $this->error('未找到客户数据');
  436. }
  437. foreach ($list as $item) {
  438. $customerKey = $item['客户编号'] . '【' . $item['客户名称'] . '】';
  439. $productKey = $item['产品代号'] . '【' . $item['产品名称'] . '】';
  440. if (!isset($data[$customerKey])) {
  441. $data[$customerKey] = [];
  442. }
  443. if (!isset($data[$customerKey][$productKey])) {
  444. $data[$customerKey][$productKey] = [];
  445. }
  446. if (!in_array($item['名称'], $data[$customerKey][$productKey])) {
  447. $data[$customerKey][$productKey][] = $item['名称'];
  448. }
  449. }
  450. $this->success('成功', $data);
  451. }
  452. //客户印版库右侧列表
  453. public function PrintDetail()
  454. {
  455. if ($this->request->isGet() === false) {
  456. $this->error('请求错误');
  457. }
  458. $param = $this->request->param();
  459. if (empty($param) || !isset($param['code']) || !isset($param['category'])) {
  460. $this->error('请求错误');
  461. }
  462. //获取印版库分类编号
  463. $categoryNumber = db('物料_存货');
  464. $where = [
  465. 'a.YB_Cpdh' => $param['code'],
  466. 'b.YB_Cpdh' => $param['category'],
  467. ];
  468. // $list = db('<UNK>_<UNK>')
  469. }
  470. /**
  471. * 印版删除
  472. * @return void
  473. * @throws \think\Exception
  474. * @throws \think\exception\PDOException
  475. */
  476. public function PrintDetaiDel()
  477. {
  478. if ($this->request->isGet() === false) {
  479. $this->error('请求错误');
  480. }
  481. $param = $this->request->param();
  482. if (empty($param) || !isset($param['UniqID'])) {
  483. $this->error('参数错误');
  484. }
  485. $id = explode(',', $param['UniqID']);
  486. $res = db('产品_印版库')
  487. ->where('UniqID','in',$id)
  488. ->delete();
  489. if ($res === false){
  490. $this->error('删除失败');
  491. }else{
  492. $this->success('删除成功');
  493. }
  494. }
  495. }