PrintingPlate.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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() === false){
  78. $this->error('请求错误');
  79. }
  80. $param = $this->request->param();
  81. if (empty($param)){
  82. $this->error('参数错误');
  83. }
  84. if (isset($param['code']) && !empty($param['code'])){
  85. //截取物料编码,带字母截取前七位,不带字母截取前五位
  86. if (preg_match('/[a-zA-Z]/', $param['code'])) {
  87. $code = substr($param['code'], 0, 7);
  88. } else {
  89. $code = substr($param['code'], 0, 6);
  90. }
  91. $where['a.存货编码'] = ['like', $code . '%'];
  92. }
  93. if (isset($param['search']) && !empty($param['search'])){
  94. $where['b.物料名称'] = ['like', '%' . $param['search'] . '%'];
  95. }
  96. //根据物料编码分类查询
  97. $list = db('产品_印版库')
  98. ->alias('a')
  99. ->join('物料_存货编码 b', 'a.存货编码 = b.物料代码')
  100. ->join('工单_印版领用记录 c', 'a.存货编码 = c.Yb_存货编码 AND a.供方批号 = c.Yb_供方批号', 'left')
  101. ->where($where)
  102. ->group('a.存货编码, a.供方批号')
  103. ->order('报废日期, a.存货编码')
  104. ->field('
  105. rtrim(a.存货编码) as 存货编码,
  106. rtrim(b.物料名称) as 物料名称,
  107. rtrim(a.印版名称) as 印版名称,
  108. rtrim(a.供方批号) as 供方批号,
  109. DATE(a.制造日期) as 制造日期,
  110. CASE
  111. WHEN a.报废日期 = "1900-01-01 00:00:00" THEN NULL
  112. ELSE DATE(a.报废日期)
  113. END as 报废日期,
  114. a.原始印数,
  115. a.考核印数,
  116. a.UniqID,
  117. rtrim(a.Sys_id) as 创建用户,
  118. a.Sys_rq as 创建日期,
  119. a.Mod_rq as 修改时间,
  120. count(c.Yb_印数) as 累计印数
  121. ')
  122. ->select();
  123. if (empty($list)) {
  124. $this->error('失败');
  125. }else{
  126. $this->success('成功', $list);
  127. }
  128. }
  129. /**
  130. * 印版管理印版修改
  131. * @return void
  132. * @throws \think\db\exception\DataNotFoundException
  133. * @throws \think\db\exception\ModelNotFoundException
  134. * @throws \think\exception\DbException
  135. */
  136. public function MaterailDetail()
  137. {
  138. if ($this->request->isGet() === false){
  139. $this->error('请求错误');
  140. }
  141. $param = $this->request->param();
  142. if (empty($param) || !isset($param['UniqID'])){
  143. $this->error('参数错误');
  144. }
  145. $result = db('产品_印版库')
  146. ->alias('a')
  147. ->join('物料_存货编码 b', 'a.存货编码 = b.物料代码')
  148. ->where('a.UniqID', $param['UniqID'])
  149. ->order('报废日期, a.存货编码')
  150. ->field('
  151. rtrim(a.存货编码) as 存货编码,
  152. rtrim(b.物料名称) as 物料名称,
  153. rtrim(a.印版名称) as 印版备注,
  154. rtrim(a.供方批号) as 供方批号,
  155. DATE(a.制造日期) as 制造日期,
  156. CASE
  157. WHEN a.报废日期 = "1900-01-01 00:00:00" THEN NULL
  158. ELSE DATE(a.报废日期)
  159. END as 报废日期,
  160. a.原始印数,
  161. a.考核印数,
  162. a.UniqID
  163. ')
  164. ->find();
  165. if (empty($result)) {
  166. $this->error('未找到数据');
  167. }else{
  168. $this->success('成功', $result);
  169. }
  170. }
  171. /**
  172. * 印版资料新增修改
  173. * @return void
  174. * @throws \think\Exception
  175. * @throws \think\db\exception\BindParamException
  176. * @throws \think\db\exception\DataNotFoundException
  177. * @throws \think\db\exception\ModelNotFoundException
  178. * @throws \think\exception\DbException
  179. * @throws \think\exception\PDOException
  180. */
  181. public function MaterailEdit()
  182. {
  183. if ($this->request->isPost() === false){
  184. $this->error('请求错误');
  185. }
  186. $param = Request::instance()->post();
  187. if (empty($param) || !isset($param['code'])){
  188. $this->error('参数错误');
  189. }
  190. $data = [
  191. '存货编码' => $param['code'],
  192. '供方批号' => $param['batch'],
  193. '印版名称' => $param['desc'],
  194. '制造日期' => $param['Manufactur_date'],
  195. '原始印数' => $param['start_num'],
  196. '考核印数' => $param['Assessment_num'],
  197. '报废日期' => $param['Scrappe_date']?:'1900-01-01 00:00:00',
  198. 'Sys_id' => $param['sys_id']
  199. ];
  200. //查询数据是否存在,存在则修改,不存在则增加
  201. $res = db('产品_印版库')
  202. ->where('存货编码',$param['code'])
  203. ->where('供方批号',$param['batch'])
  204. ->find();
  205. if (empty($res)){
  206. $data['Sys_rq'] = date('Y-m-d H:i:s',time());
  207. $sql = db('产品_印版库')->fetchSql(true)->insert($data);
  208. }else{
  209. $UniqID = $param['UniqID'];
  210. $data['Mod_rq'] = date('Y-m-d H:i:s',time());
  211. $sql = db('产品_印版库')->where('UniqID',$UniqID)->fetchSql(true)->update($data);
  212. }
  213. $result = db()->query($sql);
  214. if ($result === false){
  215. $this->error('修改失败');
  216. }else{
  217. $this->success('修改成功');
  218. }
  219. }
  220. /**
  221. * 印版新增->存货编码获取
  222. * @return void
  223. * @throws \think\db\exception\DataNotFoundException
  224. * @throws \think\db\exception\ModelNotFoundException
  225. * @throws \think\exception\DbException
  226. */
  227. public function getInventoryCode()
  228. {
  229. if (!$this->request->isGet()) {
  230. $this->error('请求错误');
  231. }
  232. $param = $this->request->param();
  233. if (empty($param) || !isset($param['code'])) {
  234. $this->error('参数错误');
  235. }
  236. // 提取前缀
  237. $codeLength = preg_match('/[a-zA-Z]/', $param['code']) ? 5 : 4;
  238. $code = substr($param['code'], 0, $codeLength);
  239. $where['物料代码'] = ['like', $code . '%'];
  240. if (!empty($param['search'])) {
  241. $where['物料名称'] = ['like', '%' . $param['search'] . '%'];
  242. }
  243. // 查询物料存货编码
  244. $list = db('物料_存货编码')
  245. ->where($where)
  246. ->field('rtrim(物料代码) as 物料代码, rtrim(物料名称) as 物料名称, rtrim(规格) as 规格')
  247. ->select();
  248. // 数据处理
  249. $data = [];
  250. foreach ($list as $item) {
  251. // 提取物料代码的前缀
  252. $prefixLength = preg_match('/[a-zA-Z]/', $item['物料代码']) ? [3, 5, 7] : [2, 4, 6];
  253. // 使用普通的数组映射替代箭头函数
  254. $num1 = substr($item['物料代码'], 0, $prefixLength[0]);
  255. $num2 = substr($item['物料代码'], 0, $prefixLength[1]);
  256. $num3 = substr($item['物料代码'], 0, $prefixLength[2]);
  257. // 批量查询物料结构名称
  258. $names = db('物料_存货结构')
  259. ->whereIn('编号', [$num1, $num2, $num3])
  260. ->column('名称', '编号');
  261. // 将数据组织进数组
  262. $name1 = isset($names[$num1]) ? $names[$num1] : '';
  263. $name2 = isset($names[$num2]) ? $names[$num2] : '';
  264. $name3 = isset($names[$num3]) ? $names[$num3] : '';
  265. if (!isset($data["$num1/$name1"][$num2][$num3.'/'.$name3])) {
  266. $data["$num1/$name1"][$num2][$num3.'/'.$name3] = [];
  267. }
  268. $data["$num1/$name1"][$num2][$num3.'/'.$name3][] = "{$item['物料代码']}/{$item['物料名称']}/{$item['规格']}";
  269. }
  270. $this->success('成功', $data);
  271. }
  272. /**
  273. * 印版领用
  274. * @return void
  275. * @throws \think\db\exception\BindParamException
  276. * @throws \think\exception\PDOException
  277. */
  278. public function PrintingPlateReceive()
  279. {
  280. if (!$this->request->isPost()) {
  281. $this->error('请求错误');
  282. }
  283. $param = Request::instance()->post();
  284. if (empty($param) || !isset($param['gdbh'])) {
  285. $this->error('参数错误');
  286. }
  287. $data = [
  288. 'Yb_工单编号' => $param['gdbh'],
  289. 'Yb_印件号' => $param['yjno'],
  290. 'Yb_存货编码' => $param['code'],
  291. 'Yb_供方批号' => $param['batch'],
  292. 'Yb_领用日期' => date('Y-m-d',time()),
  293. 'Yb_领用机台' => $param['machine'],
  294. 'Sys_id' => $param['sys_id'],
  295. 'Sys_rq' => date('Y-m-d H:i:s',time()),
  296. ];
  297. $sql = db('工单_印版领用记录')
  298. ->fetchSql(true)
  299. ->insert($data);
  300. $res = db('')->query($sql);
  301. if ($res === false){
  302. $this->error('领用失败');
  303. }else{
  304. $this->success('领用成功');
  305. }
  306. }
  307. /**
  308. * 印版工单领用
  309. * @return void
  310. * @throws \think\db\exception\DataNotFoundException
  311. * @throws \think\db\exception\ModelNotFoundException
  312. * @throws \think\exception\DbException
  313. */
  314. public function PrintDetailReceive()
  315. {
  316. if (!$this->request->isGet()) {
  317. $this->error('请求错误');
  318. }
  319. $param = $this->request->param();
  320. if (empty($param) || !isset($param['code'])) {
  321. $this->error('参数错误');
  322. }
  323. $list = db('工单_印版领用记录')
  324. ->alias('a')
  325. ->field('a.Yb_工单编号 as 工单编号,a.Yb_印件号 as 印件号,a.Yb_领用日期 as 领用日期,a.Yb_退还日期 as 退还日期,a.Yb_领用机台 as 领用机台,
  326. a.Yb_印数 as 印数,a.Sys_id as 创建用户,a.Sys_rq as 创建时间,a.UniqID,b.成品代号,rtrim(b.成品名称) as 成品名称')
  327. ->join('工单_基本资料 b', 'a.Yb_工单编号 = b.Gd_gdbh')
  328. ->where('a.Yb_存货编码',$param['code'])
  329. ->where('a.Yb_供方批号',$param['batch'])
  330. ->order('a.Yb_领用日期 desc')
  331. ->select();
  332. if (empty($list)){
  333. $this->error('未找到领用记录');
  334. }else{
  335. $this->success('成功', $list);
  336. }
  337. }
  338. /**
  339. * 印版领用记录删除
  340. * @return void
  341. * @throws \think\Exception
  342. * @throws \think\exception\PDOException
  343. */
  344. public function PrintReceiveDelete()
  345. {
  346. if ($this->request->isGet() === false) {
  347. $this->error('请求错误');
  348. }
  349. $param = $this->request->param();
  350. if (empty($param) || !isset($param['id'])) {
  351. $this->error('参数错误');
  352. }
  353. $id = explode(',', $param['id']);
  354. if (empty($id)) {
  355. $this->error('请先选中要删除数据');
  356. }
  357. $res = db('工单_印版领用记录')
  358. ->where('UniqID','in',$id)
  359. ->delete();
  360. if ($res === false){
  361. $this->error('删除失败');
  362. }else{
  363. $this->success('删除成功');
  364. }
  365. }
  366. //印版库管理菜单下方客户产品印版管理
  367. public function PrintDetailTab()
  368. {
  369. if($this->request->isGet() === false){
  370. $this->error('请求错误');
  371. }
  372. $list = db('产品_印版资料')
  373. ->alias('a')
  374. ->field('rtrim(a.YB_Cpdh) as 产品代号,rtrim(b.产品名称) as 产品名称,b.')
  375. ->join('产品_基本资料 b', 'a.YB_Cpdh = b.产品编号')
  376. ->group('a.YB_Cpdh')
  377. ->select();
  378. halt($list);
  379. }
  380. }