PrintingPlate.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. public function MaterailCodeList()
  70. {
  71. if ($this->request->isGet() === false){
  72. $this->error('请求错误');
  73. }
  74. $param = $this->request->param();
  75. if (empty($param) || !isset($param['code'])){
  76. $this->error('参数错误');
  77. }
  78. //截取物料编码,带字母截取前七位,不带字母截取前五位
  79. if (preg_match('/[a-zA-Z]/', $param['code'])) {
  80. $code = substr($param['code'], 0, 7);
  81. } else {
  82. $code = substr($param['code'], 0, 6);
  83. }
  84. //根据物料编码分类查询
  85. }
  86. public function MaterailDetail()
  87. {
  88. if ($this->request->isGet() === false){
  89. $this->error('请求错误');
  90. }
  91. $param = $this->request->param();
  92. if (empty($param) || !isset($param['code'])){
  93. $this->error('参数错误');
  94. }
  95. }
  96. //印版资料修改
  97. public function MaterailEdit()
  98. {
  99. if ($this->request->isPost() === false){
  100. $this->error('请求错误');
  101. }
  102. $param = Request::instance()->post();
  103. if (empty($param) || !isset($param['code'])){
  104. $this->error('参数错误');
  105. }
  106. $data = [
  107. '存货编码' => $param['code'],
  108. '供方批号' => $param['batch'],
  109. '印版名称' => $param['desc'],
  110. '制造日期' => $param['Manufactur_date'],
  111. '原始印数' => $param['start_num'],
  112. '考核印数' => $param['Assessment_num'],
  113. '报废日期' => $param['Scrappe_date']?:'1900-01-01 00:00:00',
  114. 'Sys_id' => $param['sys_id']
  115. ];
  116. //查询数据是否存在,存在则修改,不存在则增加
  117. $res = db('产品_印版库')
  118. ->where('存货编码',$param['code'])
  119. ->where('供方批号',$param['batch'])
  120. ->find();
  121. if (empty($res)){
  122. $data['Sys_rq'] = date('Y-m-d H:i:s',time());
  123. $sql = db('产品_印版库')->fetchSql(true)->insert($data);
  124. }else{
  125. $data['Mod_rq'] = date('Y-m-d H:i:s',time());
  126. $sql = db('产品_印版库')->fetchSql(true)->update($data);
  127. }
  128. $result = db()->query($sql);
  129. if ($result === false){
  130. $this->error('修改失败');
  131. }else{
  132. $this->success('修改成功');
  133. }
  134. }
  135. }