Decision.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use think\Request;
  6. /**
  7. * 设备运行跟踪
  8. */
  9. class Decision extends Api
  10. {
  11. protected $noNeedLogin = ['*'];
  12. protected $noNeedRight = ['*'];
  13. //月度产量统计菜单
  14. public function OutputSstatisticsMenu()
  15. {
  16. if ($this->request->isGet() === false){
  17. $this->error('请求错误');
  18. }
  19. $mouth = \db('设备_产量计酬')
  20. ->distinct(true)
  21. ->field('DATE_FORMAT(sczl_rq, "%Y-%m") AS month')
  22. ->order('month desc')
  23. ->select();
  24. $sist = \db('设备_基本资料')
  25. ->whereNotNull('设备编组')
  26. ->group('设备编组')
  27. ->column('rtrim(设备编组) as 设备编组');
  28. $data = [];
  29. foreach ($mouth as $key=>$value) {
  30. $arr = [
  31. 'date'=>date('Ym',strtotime($value['month'])),
  32. 'sbbh'=>$sist,
  33. ];
  34. array_push($data,$arr);
  35. }
  36. $this->success('成功',$data);
  37. }
  38. /**
  39. * 月度产量统计上方机台生产数据
  40. * @return void
  41. * @throws \think\db\exception\DataNotFoundException
  42. * @throws \think\db\exception\ModelNotFoundException
  43. * @throws \think\exception\DbException
  44. */
  45. public function MachineProduction()
  46. {
  47. if ($this->request->isGet() === false){
  48. $this->error('请求错误');
  49. }
  50. $param = $this->request->param();
  51. if (empty($param['mouth'])){
  52. $this->error('参数错误');
  53. }
  54. $where = [];
  55. if(!empty($param['sist'])){
  56. $where['设备编组'] = $param['sist'];
  57. }
  58. //将参数装换成标准日期格式
  59. $mouth = date_create_from_format('Ym', $param['mouth'])->format('Y-m');
  60. $machine = \db('设备_基本资料')
  61. ->where($where)
  62. ->where('sys_sbID','<>','')
  63. ->field('设备编号')
  64. ->order('设备编号')
  65. ->select();
  66. $day = \db('设备_产量计酬')
  67. ->distinct(true)
  68. ->field('DATE_FORMAT(sczl_rq,"%Y-%m-%d") as day')
  69. ->whereRaw("DATE_FORMAT(sczl_rq, '%Y-%m') = '$mouth'")
  70. ->order('day')
  71. ->select();
  72. $day = array_reduce($day, function($carry, $item) {
  73. return array_merge($carry, array_values($item));
  74. }, []);
  75. $data = [];
  76. $data['head'] = $day;
  77. foreach ($machine as $key=>$value){
  78. $data['total'][$key] = \db('设备_产量计酬')
  79. ->field('sczl_jtbh,sczl_bzdh,SUM(sczl_cl) as total_cl,sczl_rq')
  80. ->where('sczl_rq','like',$mouth.'%')
  81. ->where('sczl_jtbh',$value['设备编号'])
  82. ->group('sczl_bzdh')
  83. ->select();
  84. foreach ($data['total'][$key] as $k=>$v){
  85. $day_cl = \db('设备_产量计酬')
  86. ->alias('a')
  87. ->join('工单_印件资料 c','a.sczl_gdbh = c.Yj_Gdbh AND a.sczl_yjno = c.yj_Yjno')
  88. ->join('工单_工艺资料 d','a.sczl_gdbh = d.Gy0_gdbh AND a.sczl_yjno = d.Gy0_yjno AND a.sczl_gxh = d.Gy0_gxh')
  89. ->field([
  90. 'a.sczl_gdbh' => '工单编号',
  91. 'a.sczl_yjno' => '印件号',
  92. 'a.sczl_gxh' => '工序号',
  93. 'c.yj_yjmc' => '印件名称',
  94. 'CONCAT(d.Gy0_gxmc,"(",d.Add_gxmc,")")' => '工序名称',
  95. 'DATE(a.sczl_rq)' => 'day',
  96. 'a.sczl_jtbh' => '机台编号',
  97. 'a.sczl_bzdh' => '班组编号',
  98. 'SUM(a.sczl_cl)' => 'total_cl',
  99. 'a.sczl_ms' => '墨色数',
  100. 'rtrim(d.印刷方式)' => '印刷方式',
  101. 'rtrim(d.版距)' => '版距'
  102. ])
  103. ->where('a.sczl_rq','like',$mouth.'%')
  104. ->where('a.sczl_jtbh', $value['设备编号'])
  105. ->where('a.sczl_bzdh', $v['sczl_bzdh'])
  106. ->group('sczl_bzdh,day')
  107. ->select();
  108. $day_total = [];
  109. foreach ($day_cl as $index=>$item){
  110. if ($item['印刷方式'] === '卷对卷'){
  111. $day_cl[$index]['total_cl'] = round($item['total_cl']/$item['版距']*1000);
  112. }
  113. $day_total[$item['day']] =$day_cl[$index]['total_cl'];
  114. }
  115. $data['total'][$key][$k]['day_total'] = $day_total;
  116. $data['total'][$key][$k]['total_cl'] = array_sum($day_total);
  117. }
  118. }
  119. $this->success('成功',$data);
  120. }
  121. /**
  122. * 机台班次生产工单明细
  123. * @return void
  124. * @throws \think\db\exception\DataNotFoundException
  125. * @throws \think\db\exception\ModelNotFoundException
  126. * @throws \think\exception\DbException
  127. */
  128. public function MachineProductDetail()
  129. {
  130. if ($this->request->isGet() === false){
  131. $this->error('请求错误');
  132. }
  133. $param = $this->request->param();
  134. if (empty($param['mouth'])){
  135. $this->error('参数错误');
  136. }
  137. if (isset($param['machine']) && !empty($param['machine'])){
  138. $where['a.sczl_jtbh'] = $param['machine'];
  139. }
  140. if (isset($param['team']) && !empty($param['team'])){
  141. $where['a.sczl_bzdh'] = ['like',substr($param['team'],0,1).'%'];
  142. }
  143. //将参数装换成标准日期格式
  144. $mouth = date_create_from_format('Ym', $param['mouth'])->format('Y-m');
  145. $where['a.sczl_rq'] = ['like',$mouth.'%'];
  146. // $team = substr($param['team'],0,1);
  147. $list = \db('设备_产量计酬')
  148. ->alias('a')
  149. ->join('工单_印件资料 c','a.sczl_gdbh = c.Yj_Gdbh AND a.sczl_yjno = c.yj_Yjno')
  150. ->join('工单_工艺资料 d','a.sczl_gdbh = d.Gy0_gdbh AND a.sczl_yjno = d.Gy0_yjno AND a.sczl_gxh = d.Gy0_gxh')
  151. ->field([
  152. 'a.sczl_gdbh' => '工单编号',
  153. 'a.sczl_yjno' => '印件号',
  154. 'a.sczl_gxh' => '工序号',
  155. 'c.yj_yjmc' => '印件名称',
  156. 'CONCAT(d.Gy0_gxmc,"(",d.Add_gxmc,")")' => '工序名称',
  157. 'DATE(a.sczl_rq)' => '工作日期',
  158. 'a.sczl_jtbh' => '机台编号',
  159. 'a.sczl_bzdh' => '班组编号',
  160. 'SUM(a.sczl_cl)' => '产量',
  161. 'a.sczl_ms' => '墨色数',
  162. 'rtrim(d.印刷方式)' => '印刷方式',
  163. 'rtrim(d.版距)' => '版距'
  164. ])
  165. ->where($where)
  166. ->group('a.sczl_gdbh,a.sczl_yjno,a.sczl_gxh,a.sczl_rq,a.sczl_jtbh,a.sczl_bzdh')
  167. ->order('工作日期')
  168. ->select();
  169. if (!empty($list)){
  170. foreach ($list as $key=>$value){
  171. $list[$key]['印件名称'] = $value['印件号'].'-'.$value['印件名称'];
  172. $list[$key]['工序名称'] = $value['工序号'].'-'.$value['工序名称'];
  173. unset($list[$key]['印件号'],$list[$key]['工序号']);
  174. if ($value['印刷方式'] === '卷对卷'){
  175. $list[$key]['产量'] = round($value['产量']/$value['版距']*1000);
  176. }
  177. if ($value['墨色数'] === '0.00'){
  178. $list[$key]['墨色数'] = '1.00';
  179. }
  180. }
  181. }
  182. $this->success('成功',$list);
  183. }
  184. /**
  185. * 月度机台运行工时汇总
  186. * @return void
  187. * @throws \think\db\exception\DataNotFoundException
  188. * @throws \think\db\exception\ModelNotFoundException
  189. * @throws \think\exception\DbException
  190. */
  191. public function MachineOperation()
  192. {
  193. if ($this->request->isGet() === false){
  194. $this->error('请求错误');
  195. }
  196. $param = $this->request->param();
  197. if (empty($param['mouth'])){
  198. $this->error('参数错误');
  199. }
  200. $where = [];
  201. if(!empty($param['sist'])){
  202. $where['a.设备编组'] = $param['sist'];
  203. }
  204. //将参数装换成标准日期格式
  205. $mouth = date_create_from_format('Ym', $param['mouth'])->format('Y-m');
  206. $list = \db('设备_基本资料')
  207. ->alias('a')
  208. ->join('设备_产量计酬 b', 'a.设备编号 = b.sczl_jtbh')
  209. ->join('工单_印件资料 c', 'b.sczl_gdbh = c.Yj_Gdbh AND b.sczl_yjno = c.yj_Yjno')
  210. ->join('工单_工艺资料 d', 'b.sczl_gdbh = d.Gy0_gdbh AND b.sczl_yjno = d.Gy0_yjno AND b.sczl_gxh = d.Gy0_gxh')
  211. ->field([
  212. 'a.设备编号' => '设备编号',
  213. 'rtrim(a.设备名称)' => '设备名称',
  214. 'SUM(CASE WHEN rtrim(d.版距) = "卷对卷" THEN b.sczl_cl / NULLIF(d.版距, 0) * 1000 ELSE b.sczl_cl END) AS 产量',
  215. 'SUM(b.sczl_设备运行工时)' => '设备运行工时',
  216. 'SUM(b.sczl_保养工时)' => '保养工时',
  217. 'SUM(b.sczl_打样总工时)' => '打样总工时',
  218. 'SUM(b.sczl_打样工时)' => '打样补产工时',
  219. 'SUM(b.sczl_装版总工时)' => '装版总工时',
  220. 'SUM(b.sczl_装版工时)' => '装板补产工时',
  221. 'SUM(b.sczl_异常停机工时)' => '异常停机工时',
  222. 'rtrim(d.印刷方式)' => '印刷方式',
  223. 'rtrim(d.版距)' => '版距'
  224. ])
  225. ->where($where)
  226. ->where('b.sczl_rq','like', $mouth.'%')
  227. ->group('a.设备编号')
  228. ->order('a.设备编号')
  229. ->select();
  230. $total = \db('设备_基本资料')
  231. ->alias('a')
  232. ->join('设备_产量计酬 b','a.设备编号 = b.sczl_jtbh')
  233. ->field([
  234. 'SUM(b.sczl_设备运行工时)' => '设备运行工时',
  235. 'SUM(b.sczl_保养工时)' => '保养工时',
  236. 'SUM(b.sczl_打样总工时)' => '打样总工时',
  237. 'SUM(b.sczl_打样工时)' => '打样补产工时',
  238. 'SUM(b.sczl_装版总工时)' => '装板总工时',
  239. 'SUM(b.sczl_装版工时)' => '装板补产工时',
  240. 'SUM(b.sczl_异常停机工时)' => '异常停机工时'
  241. ])
  242. ->where($where)
  243. ->whereTime('b.sczl_rq',$mouth)
  244. ->find();
  245. $list['total'] = $total;
  246. $this->success('成功',$list);
  247. }
  248. /**
  249. * 设备运行工时机台生产工单数据详情
  250. * @return void
  251. * @throws \think\db\exception\DataNotFoundException
  252. * @throws \think\db\exception\ModelNotFoundException
  253. * @throws \think\exception\DbException
  254. */
  255. public function MachineOperationProductDetail()
  256. {
  257. if ($this->request->isGet() === false){
  258. $this->error('请求错误');
  259. }
  260. $param = $this->request->param();
  261. if (empty($param['mouth'])){
  262. $this->error('参数错误');
  263. }
  264. if (isset($param['machine']) && !empty($param['machine'])){
  265. $where['a.sczl_jtbh'] = $param['machine'];
  266. }
  267. //将参数装换成标准日期格式
  268. $mouth = date_create_from_format('Ym', $param['mouth'])->format('Y-m');
  269. $where['a.sczl_rq'] = ['like',$mouth.'%'];
  270. $list = \db('设备_产量计酬')
  271. ->alias('a')
  272. ->join('设备_基本资料 b','a.sczl_jtbh = b.设备编号')
  273. ->join('工单_印件资料 c','a.sczl_gdbh = c.Yj_Gdbh AND a.sczl_yjno = c.yj_Yjno')
  274. ->join('工单_工艺资料 d','a.sczl_gdbh = d.Gy0_gdbh AND a.sczl_yjno = d.Gy0_yjno AND a.sczl_gxh = d.Gy0_gxh')
  275. ->field([
  276. 'a.sczl_jtbh' => '设备编号',
  277. 'rtrim(b.设备名称)' => '设备名称',
  278. 'DATE(a.sczl_rq)' => '日期',
  279. 'a.sczl_gdbh' => '工单编号',
  280. 'a.sczl_yjno' => '印件号',
  281. 'a.sczl_gxh' => '工序号',
  282. 'c.yj_yjmc' => '印件名称',
  283. 'CONCAT(d.Gy0_gxmc,"(",d.Add_gxmc,")")' => '工序名称',
  284. 'SUM(a.sczl_cl)' => '产量',
  285. 'SUM(a.sczl_设备运行工时)' => '设备运行工时',
  286. 'SUM(a.sczl_保养工时)' => '保养工时',
  287. 'SUM(a.sczl_打样总工时)' => '打样总工时',
  288. 'SUM(a.sczl_打样工时)' => '打样补产工时',
  289. 'SUM(a.sczl_装版总工时)' => '装板总工时',
  290. 'SUM(a.sczl_装版工时)' => '装板补产工时',
  291. 'SUM(a.sczl_异常停机工时)' => '异常停机工时',
  292. 'a.sczl_ms' => '墨色数',
  293. 'rtrim(d.印刷方式)' => '印刷方式',
  294. 'rtrim(d.版距)' => '版距'
  295. ])
  296. ->where($where)
  297. ->group('a.sczl_rq,a.sczl_gdbh,a.sczl_rq,a.sczl_jtbh')
  298. ->order('a.sczl_rq')
  299. ->select();
  300. if (!empty($list)){
  301. foreach ($list as $key=>$value){
  302. $list[$key]['工序名称'] = $value['印件号'].'-'.$value['工序号'].'-'.$value['工序名称'];
  303. unset($list[$key]['印件号'],$list[$key]['工序号']);
  304. if ($value['印刷方式'] === '卷对卷'){
  305. $list[$key]['产量'] = round($value['产量']/$value['版距']*1000);
  306. }
  307. if ($value['墨色数'] === '0.00'){
  308. $list[$key]['墨色数'] = '1.00';
  309. }
  310. }
  311. }
  312. $this->success('成功',$list);
  313. }
  314. /**
  315. * 工序产出率月度统计报表
  316. * @return void
  317. * @throws \think\db\exception\DataNotFoundException
  318. * @throws \think\db\exception\ModelNotFoundException
  319. * @throws \think\exception\DbException
  320. */
  321. public function ProcessOutputRate()
  322. {
  323. if ($this->request->isGet() === false){
  324. $this->error('请求错误');
  325. }
  326. $param = $this->request->param();
  327. if (empty($param)){
  328. $this->error('参数错误');
  329. }
  330. //查询已经进入超节损的月份
  331. $mouth = \db('工单_质量考核汇总')
  332. ->where('sys_ny','like',$param['year'].'%')
  333. ->column('distinct(sys_ny) as mouth');
  334. //创建工序数组
  335. $processType = ['胶印','卷凹','圆烫','圆切','烫金','模切','丝印','喷码','单凹'];
  336. $result = $data = [];
  337. foreach ($mouth as $key=>$value){
  338. foreach ($processType as $item){
  339. //查询进入超节损一年内所有数据
  340. $list = \db('工单_质量考核汇总')
  341. ->alias('a')
  342. ->join('工单_工艺资料 b','a.Gy0_gdbh = b.Gy0_gdbh AND a.印件及工序 = b.Gy0_yjno AND a.工序 = b.Gy0_gxh')
  343. ->join('工单_印件资料 c','a.Gy0_gdbh = c.Yj_Gdbh AND a.印件及工序 = c.yj_Yjno')
  344. ->field('a.sys_ny,(a.计划损耗+sum(a.班组质检废品))/a.印件工序产量 as 废品率')
  345. ->where('b.Gy0_gxmc','like',$item.'%')
  346. ->where('a.sys_ny',$value)
  347. ->group('a.Gy0_gdbh,b.Gy0_yjno,a.工序')
  348. ->select();
  349. $data[$value][$item] = $list;
  350. }
  351. }
  352. $months = [
  353. $param['year'].'01' => '01月',
  354. $param['year'].'02' => '02月',
  355. $param['year'].'03' => '03月',
  356. $param['year'].'04' => '04月',
  357. $param['year'].'05' => '05月',
  358. $param['year'].'06' => '06月',
  359. $param['year'].'07' => '07月',
  360. $param['year'].'08' => '08月',
  361. $param['year'].'09' => '09月',
  362. $param['year'].'10' => '10月',
  363. $param['year'].'11' => '11月',
  364. $param['year'].'12' => '12月'
  365. ];
  366. //汇总数据
  367. foreach ($processType as $index => $process) {
  368. $result[$index] = array(
  369. "工序类型" => $process,
  370. "01月" => "",
  371. "02月" => "",
  372. "03月" => "",
  373. "04月" => "",
  374. "05月" => "",
  375. "06月" => "",
  376. "07月" => "",
  377. "08月" => "",
  378. "09月" => "",
  379. "10月" => "",
  380. "11月" => "",
  381. "12月" => ""
  382. );
  383. // 遍历月份
  384. foreach ($months as $month => $monthName) {
  385. if (isset($data[$month])){
  386. $count = count($data[$month][$process]);
  387. }
  388. $totalRate = 0;
  389. // 检查月份是否存在于数据中
  390. if (isset($data[$month])) {
  391. // 检查工序是否存在于月份数据中
  392. if (isset($data[$month][$process])) {
  393. // 累加废品率
  394. foreach ($data[$month][$process] as $rate) {
  395. $totalRate += floatval(1-$rate["废品率"]);
  396. }
  397. }
  398. }
  399. if ($count > 0){
  400. $rateNumber = $totalRate/$count;
  401. }
  402. // 格式化为百分比字符串,保留两位小数
  403. if ($totalRate > 0) {
  404. $result[$index][$monthName] = sprintf("%.2f%%", $rateNumber * 100);
  405. } else {
  406. $result[$index][$monthName] = ""; // 如果没有数据,则为空字符串
  407. }
  408. }
  409. }
  410. foreach ($result as &$item) {
  411. $total = 0;
  412. $count = 0;
  413. // 遍历月份,计算总和和数量
  414. for ($i = 1; $i <= 12; $i++) {
  415. $month = sprintf("%02d月", $i); // 格式化月份,例如 "01月"
  416. if (isset($item[$month]) && $item[$month] !== "") {
  417. // 移除百分号,并将字符串转换为浮点数
  418. $value = floatval(str_replace("%", "", $item[$month]));
  419. $total += $value;
  420. $count++;
  421. }
  422. }
  423. // 计算平均值
  424. if ($count > 0) {
  425. $average = $total / $count;
  426. // 格式化为百分比字符串,保留两位小数
  427. $item["平均值"] = sprintf("%.2f%%", $average);
  428. } else {
  429. $item["平均值"] = "0.00%"; // 如果没有数据,则为 0.00%
  430. }
  431. }
  432. $this->success('成功',$result);
  433. }
  434. /**
  435. * 获取年分数据
  436. * @return void
  437. */
  438. public function GetYear()
  439. {
  440. if ($this->request->isGet() === false){
  441. $this->error('请求错误');
  442. }
  443. $data = \db('工单_质量考核汇总')
  444. ->group('year')
  445. ->column('YEAR(STR_TO_DATE(sys_ny, "%Y%m")) as year');
  446. $this->success('成功',$data);
  447. }
  448. /**
  449. * 数据透视表
  450. * @return null
  451. * @throws \think\Exception
  452. * @throws \think\db\exception\DataNotFoundException
  453. * @throws \think\db\exception\ModelNotFoundException
  454. * @throws \think\exception\DbException
  455. */
  456. public function PoductData()
  457. {
  458. if (!$this->request->isGet()) {
  459. $this->error('请求错误');
  460. }
  461. $param = $this->request->param();
  462. if (empty($param['year'])) {
  463. $this->error('参数错误');
  464. }
  465. // 定义分类规则及顺序
  466. $processOrder = [
  467. 1 => ['name' => '胶印工序', 'keys' => ['胶印', '上光']],
  468. 2 => ['name' => '凹印工序', 'keys' => ['卷凹']],
  469. 3 => ['name' => '圆烫工序', 'keys' => ['圆烫']],
  470. 4 => ['name' => '圆切工序', 'keys' => ['圆切']],
  471. 5 => ['name' => '烫模工序', 'keys' => ['烫金', '模切', '凹凸']],
  472. 6 => ['name' => '丝印工序', 'keys' => ['丝印']],
  473. 7 => ['name' => '喷码工序', 'keys' => ['喷码']],
  474. 8 => ['name' => '单凹工序', 'keys' => ['单凹']]
  475. ];
  476. // 构建基础查询
  477. $query = \db('工单_质量考核汇总')
  478. ->alias('a')
  479. ->field('
  480. a.sczl_jtbh AS 机台编号,
  481. a.Gy0_gdbh AS 工单编号,
  482. a.印件及工序 AS 工序号,
  483. a.产品名称 AS 印件名称,
  484. a.工序 AS 工序,
  485. a.工序名称,
  486. a.联数,
  487. a.班组产量,
  488. a.班组制程废品,
  489. a.班组质检废品,
  490. a.sczl_bzdh AS 班组编号,
  491. b.印刷方式,
  492. b.版距,
  493. DATE_FORMAT(a.入仓日期, \'%Y%m\') AS 完工年月
  494. ')
  495. ->join('工单_工艺资料 b', 'a.Gy0_gdbh = b.Gy0_gdbh AND a.印件及工序 = b.Gy0_yjno AND a.工序 = b.Gy0_gxh')
  496. ->where('a.sys_ny', 'like', $param['year'] . '%')
  497. ->where('a.工序名称','not like','%机检%')
  498. ->where('a.工序名称','not like','%拆片%');
  499. // 获取总数
  500. $total = clone $query;
  501. $total = $total->count();
  502. // 执行查询
  503. $rawList = isset($param['page'], $param['limit'])
  504. ? $query->page($param['page'])->limit($param['limit'])->select()
  505. : $query->select();
  506. // 处理分类标记
  507. $processedList = [];
  508. foreach ($rawList as $item) {
  509. $matched = false;
  510. // 顺序匹配分类规则
  511. foreach ($processOrder as $typeId => $rule) {
  512. foreach ($rule['keys'] as $keyword) {
  513. if (strpos($item['工序名称'], $keyword) !== false) {
  514. // 添加分类标记
  515. $item['type_id'] = $typeId;
  516. $item['type_name'] = $rule['name'];
  517. $processedList[] = $item;
  518. $matched = true;
  519. break 2; // 跳出两层循环
  520. }
  521. }
  522. }
  523. // 未匹配到分类的数据丢弃
  524. }
  525. // 按分类顺序排序(保持1-8的顺序)
  526. usort($processedList, function($a, $b) {
  527. return $a['type_id'] <=> $b['type_id'];
  528. });
  529. // 返回结构
  530. $data['data'] = $processedList;
  531. $data['total'] = $total; // 原始总数
  532. $data['filtered_total'] = count($processedList); // 实际有效数
  533. return count($processedList) > 0
  534. ? $this->success('成功', $data)
  535. : $this->error('未找到数据');
  536. }
  537. }