PrintingPlate.php 16 KB

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