Decision.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  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()) {
  131. $this->error('请求错误');
  132. }
  133. $param = $this->request->param();
  134. // 检查必需的参数
  135. if (empty($param['mouth'])) {
  136. $this->error('参数错误');
  137. }
  138. // Initializing where conditions
  139. $where = [];
  140. // 添加可选的查询条件
  141. if (!empty($param['machine'])) {
  142. $where['a.sczl_jtbh'] = $param['machine'];
  143. }
  144. if (!empty($param['team'])) {
  145. $where['a.sczl_bzdh'] = ['like', substr($param['team'], 0, 1) . '%'];
  146. }
  147. // 将参数转换成标准日期格式
  148. $mouth = date_create_from_format('Ym', $param['mouth'])->format('Y-m');
  149. $where['a.sczl_rq'] = ['like', $mouth . '%'];
  150. // 分页配置
  151. $page = !empty($param['page']) ? (int)$param['page'] : 1;
  152. $limit = !empty($param['limit']) ? (int)$param['limit'] : 9999; // 默认查询所有
  153. // 查询数据
  154. $list = \db('设备_产量计酬')
  155. ->alias('a')
  156. ->join('工单_印件资料 c', 'a.sczl_gdbh = c.Yj_Gdbh AND a.sczl_yjno = c.yj_Yjno')
  157. ->join('工单_工艺资料 d', 'a.sczl_gdbh = d.Gy0_gdbh AND a.sczl_yjno = d.Gy0_yjno AND a.sczl_gxh = d.Gy0_gxh')
  158. ->field([
  159. 'a.sczl_gdbh' => '工单编号',
  160. 'a.sczl_yjno' => '印件号',
  161. 'a.sczl_gxh' => '工序号',
  162. 'c.yj_yjmc' => '印件名称',
  163. 'CONCAT(d.Gy0_gxmc,"(",d.Add_gxmc,")")' => '工序名称',
  164. 'DATE(a.sczl_rq)' => '工作日期',
  165. 'a.sczl_jtbh' => '机台编号',
  166. 'a.sczl_bzdh' => '班组编号',
  167. 'SUM(a.sczl_cl)' => '产量',
  168. 'a.sczl_ms' => '墨色数',
  169. 'rtrim(d.印刷方式)' => '印刷方式',
  170. 'rtrim(d.版距)' => '版距'
  171. ])
  172. ->where($where)
  173. ->group('a.sczl_gdbh, a.sczl_yjno, a.sczl_gxh, a.sczl_rq, a.sczl_jtbh, a.sczl_bzdh')
  174. ->order('工作日期')
  175. ->page($page, $limit) // 使用 page 和 limit 实现分页
  176. ->select();
  177. // 数据处理
  178. if (!empty($list)) {
  179. foreach ($list as $key => $value) {
  180. $list[$key]['印件名称'] = $value['印件号'] . '-' . $value['印件名称'];
  181. $list[$key]['工序名称'] = $value['工序号'] . '-' . $value['工序名称'];
  182. unset($list[$key]['印件号'], $list[$key]['工序号']);
  183. // 产量计算
  184. if ($value['印刷方式'] === '卷对卷') {
  185. $list[$key]['产量'] = round($value['产量'] / $value['版距'] * 1000);
  186. }
  187. // 墨色数修正
  188. if ($value['墨色数'] === '0.00') {
  189. $list[$key]['墨色数'] = '1.00';
  190. }
  191. }
  192. }
  193. $this->success('成功', $list);
  194. }
  195. /**
  196. * 月度机台运行工时汇总
  197. * @return void
  198. * @throws \think\db\exception\DataNotFoundException
  199. * @throws \think\db\exception\ModelNotFoundException
  200. * @throws \think\exception\DbException
  201. */
  202. public function MachineOperation()
  203. {
  204. if ($this->request->isGet() === false){
  205. $this->error('请求错误');
  206. }
  207. $param = $this->request->param();
  208. if (empty($param['mouth'])){
  209. $this->error('参数错误');
  210. }
  211. $where = [];
  212. if(!empty($param['sist'])){
  213. $where['a.设备编组'] = $param['sist'];
  214. }
  215. //将参数装换成标准日期格式
  216. $mouth = date_create_from_format('Ym', $param['mouth'])->format('Y-m');
  217. $list = \db('设备_基本资料')
  218. ->alias('a')
  219. ->join('设备_产量计酬 b', 'a.设备编号 = b.sczl_jtbh')
  220. ->join('工单_印件资料 c', 'b.sczl_gdbh = c.Yj_Gdbh AND b.sczl_yjno = c.yj_Yjno')
  221. ->join('工单_工艺资料 d', 'b.sczl_gdbh = d.Gy0_gdbh AND b.sczl_yjno = d.Gy0_yjno AND b.sczl_gxh = d.Gy0_gxh')
  222. ->field([
  223. 'a.设备编号' => '设备编号',
  224. 'rtrim(a.设备名称)' => '设备名称',
  225. 'SUM(CASE WHEN rtrim(d.版距) = "卷对卷" THEN b.sczl_cl / NULLIF(d.版距, 0) * 1000 ELSE b.sczl_cl END) AS 产量',
  226. 'SUM(b.sczl_设备运行工时)' => '设备运行工时',
  227. 'SUM(b.sczl_保养工时)' => '保养工时',
  228. 'SUM(b.sczl_打样总工时)' => '打样总工时',
  229. 'SUM(b.sczl_打样工时)' => '打样补产工时',
  230. 'SUM(b.sczl_装版总工时)' => '装版总工时',
  231. 'SUM(b.sczl_装版工时)' => '装板补产工时',
  232. 'SUM(b.sczl_异常停机工时)' => '异常停机工时',
  233. 'rtrim(d.印刷方式)' => '印刷方式',
  234. 'rtrim(d.版距)' => '版距'
  235. ])
  236. ->where($where)
  237. ->where('b.sczl_rq','like', $mouth.'%')
  238. ->group('a.设备编号')
  239. ->order('a.设备编号')
  240. ->select();
  241. $total = \db('设备_基本资料')
  242. ->alias('a')
  243. ->join('设备_产量计酬 b','a.设备编号 = b.sczl_jtbh')
  244. ->field([
  245. 'SUM(b.sczl_设备运行工时)' => '设备运行工时',
  246. 'SUM(b.sczl_保养工时)' => '保养工时',
  247. 'SUM(b.sczl_打样总工时)' => '打样总工时',
  248. 'SUM(b.sczl_打样工时)' => '打样补产工时',
  249. 'SUM(b.sczl_装版总工时)' => '装板总工时',
  250. 'SUM(b.sczl_装版工时)' => '装板补产工时',
  251. 'SUM(b.sczl_异常停机工时)' => '异常停机工时'
  252. ])
  253. ->where($where)
  254. ->where('b.sczl_rq','like', $mouth.'%')
  255. ->find();
  256. $list['total'] = $total;
  257. $this->success('成功',$list);
  258. }
  259. /**
  260. * 设备运行工时机台生产工单数据详情
  261. * @return void
  262. * @throws \think\db\exception\DataNotFoundException
  263. * @throws \think\db\exception\ModelNotFoundException
  264. * @throws \think\exception\DbException
  265. */
  266. public function MachineOperationProductDetail()
  267. {
  268. if (!$this->request->isGet()) {
  269. $this->error('请求错误');
  270. }
  271. $param = $this->request->param();
  272. if (empty($param['mouth'])) {
  273. $this->error('参数错误');
  274. }
  275. // Initialize where conditions
  276. $where = [];
  277. if (!empty($param['machine'])) {
  278. $where['a.sczl_jtbh'] = $param['machine'];
  279. }
  280. // 将参数转换成标准日期格式
  281. $mouth = date_create_from_format('Ym', $param['mouth'])->format('Y-m');
  282. $where['a.sczl_rq'] = ['like', $mouth . '%'];
  283. // 分页配置
  284. $page = !empty($param['page']) ? (int)$param['page'] : 1;
  285. $limit = !empty($param['limit']) ? (int)$param['limit'] : 9999; // 默认查询所有
  286. // 查询数据
  287. $list = \db('设备_产量计酬')
  288. ->alias('a')
  289. ->join('设备_基本资料 b', 'a.sczl_jtbh = b.设备编号')
  290. ->join('工单_印件资料 c', 'a.sczl_gdbh = c.Yj_Gdbh AND a.sczl_yjno = c.yj_Yjno')
  291. ->join('工单_工艺资料 d', 'a.sczl_gdbh = d.Gy0_gdbh AND a.sczl_yjno = d.Gy0_yjno AND a.sczl_gxh = d.Gy0_gxh')
  292. ->field([
  293. 'a.sczl_jtbh' => '设备编号',
  294. 'rtrim(b.设备名称)' => '设备名称',
  295. 'DATE(a.sczl_rq)' => '日期',
  296. 'a.sczl_gdbh' => '工单编号',
  297. 'a.sczl_yjno' => '印件号',
  298. 'a.sczl_gxh' => '工序号',
  299. 'c.yj_yjmc' => '印件名称',
  300. 'CONCAT(d.Gy0_gxmc, "(", d.Add_gxmc, ")")' => '工序名称',
  301. 'SUM(a.sczl_cl)' => '产量',
  302. 'SUM(a.sczl_设备运行工时)' => '设备运行工时',
  303. 'SUM(a.sczl_保养工时)' => '保养工时',
  304. 'SUM(a.sczl_打样总工时)' => '打样总工时',
  305. 'SUM(a.sczl_打样工时)' => '打样补产工时',
  306. 'SUM(a.sczl_装版总工时)' => '装板总工时',
  307. 'SUM(a.sczl_装版工时)' => '装板补产工时',
  308. 'SUM(a.sczl_异常停机工时)' => '异常停机工时',
  309. 'a.sczl_ms' => '墨色数',
  310. 'rtrim(d.印刷方式)' => '印刷方式',
  311. 'rtrim(d.版距)' => '版距'
  312. ])
  313. ->where($where)
  314. ->group('a.sczl_rq, a.sczl_gdbh, a.sczl_gxh, a.sczl_jtbh')
  315. ->order('a.sczl_rq')
  316. ->page($page, $limit) // 使用 page 和 limit 技术实现分页
  317. ->select();
  318. // 数据处理
  319. if (!empty($list)) {
  320. foreach ($list as $key => $value) {
  321. $list[$key]['工序名称'] = $value['印件号'] . '-' . $value['工序号'] . '-' . $value['工序名称'];
  322. // 移除不需要的字段
  323. unset($list[$key]['印件号'], $list[$key]['工序号']);
  324. // 产量计算
  325. if ($value['印刷方式'] === '卷对卷') {
  326. $list[$key]['产量'] = round($value['产量'] / $value['版距'] * 1000);
  327. }
  328. // 墨色数修正
  329. if ($value['墨色数'] === '0.00') {
  330. $list[$key]['墨色数'] = '1.00';
  331. }
  332. }
  333. }
  334. $this->success('成功', $list);
  335. }
  336. /**
  337. * 工序产出率月度统计报表
  338. * @return void
  339. * @throws \think\db\exception\DataNotFoundException
  340. * @throws \think\db\exception\ModelNotFoundException
  341. * @throws \think\exception\DbException
  342. */
  343. public function ProcessOutputRate()
  344. {
  345. if ($this->request->isGet() === false){
  346. $this->error('请求错误');
  347. }
  348. $param = $this->request->param();
  349. if (empty($param)){
  350. $this->error('参数错误');
  351. }
  352. //查询已经进入超节损的月份
  353. $mouth = \db('工单_质量考核汇总')
  354. ->where('sys_ny','like',$param['year'].'%')
  355. ->column('distinct(sys_ny) as mouth');
  356. //创建工序数组
  357. $processType = ['胶印','卷凹','圆烫','圆切','烫金','模切','丝印','喷码','单凹'];
  358. $result = $data = [];
  359. foreach ($mouth as $key=>$value){
  360. foreach ($processType as $item){
  361. //查询进入超节损一年内所有数据
  362. $list = \db('工单_质量考核汇总')
  363. ->alias('a')
  364. ->join('工单_工艺资料 b','a.Gy0_gdbh = b.Gy0_gdbh AND a.印件及工序 = b.Gy0_yjno AND a.工序 = b.Gy0_gxh')
  365. ->join('工单_印件资料 c','a.Gy0_gdbh = c.Yj_Gdbh AND a.印件及工序 = c.yj_Yjno')
  366. ->field('a.sys_ny,(a.计划损耗+sum(a.班组质检废品))/a.印件工序产量 as 废品率')
  367. ->where('b.Gy0_gxmc','like',$item.'%')
  368. ->where('a.sys_ny',$value)
  369. ->group('a.Gy0_gdbh,b.Gy0_yjno,a.工序')
  370. ->select();
  371. $data[$value][$item] = $list;
  372. }
  373. }
  374. $months = [
  375. $param['year'].'01' => '01月',
  376. $param['year'].'02' => '02月',
  377. $param['year'].'03' => '03月',
  378. $param['year'].'04' => '04月',
  379. $param['year'].'05' => '05月',
  380. $param['year'].'06' => '06月',
  381. $param['year'].'07' => '07月',
  382. $param['year'].'08' => '08月',
  383. $param['year'].'09' => '09月',
  384. $param['year'].'10' => '10月',
  385. $param['year'].'11' => '11月',
  386. $param['year'].'12' => '12月'
  387. ];
  388. //汇总数据
  389. foreach ($processType as $index => $process) {
  390. $result[$index] = array(
  391. "工序类型" => $process,
  392. "01月" => "",
  393. "02月" => "",
  394. "03月" => "",
  395. "04月" => "",
  396. "05月" => "",
  397. "06月" => "",
  398. "07月" => "",
  399. "08月" => "",
  400. "09月" => "",
  401. "10月" => "",
  402. "11月" => "",
  403. "12月" => ""
  404. );
  405. // 遍历月份
  406. foreach ($months as $month => $monthName) {
  407. if (isset($data[$month])){
  408. $count = count($data[$month][$process]);
  409. }
  410. $totalRate = 0;
  411. // 检查月份是否存在于数据中
  412. if (isset($data[$month])) {
  413. // 检查工序是否存在于月份数据中
  414. if (isset($data[$month][$process])) {
  415. // 累加废品率
  416. foreach ($data[$month][$process] as $rate) {
  417. $totalRate += floatval(1-$rate["废品率"]);
  418. }
  419. }
  420. }
  421. if ($count > 0){
  422. $rateNumber = $totalRate/$count;
  423. }
  424. // 格式化为百分比字符串,保留两位小数
  425. if ($totalRate > 0) {
  426. $result[$index][$monthName] = sprintf("%.2f%%", $rateNumber * 100);
  427. } else {
  428. $result[$index][$monthName] = ""; // 如果没有数据,则为空字符串
  429. }
  430. }
  431. }
  432. foreach ($result as &$item) {
  433. $total = 0;
  434. $count = 0;
  435. // 遍历月份,计算总和和数量
  436. for ($i = 1; $i <= 12; $i++) {
  437. $month = sprintf("%02d月", $i); // 格式化月份,例如 "01月"
  438. if (isset($item[$month]) && $item[$month] !== "") {
  439. // 移除百分号,并将字符串转换为浮点数
  440. $value = floatval(str_replace("%", "", $item[$month]));
  441. $total += $value;
  442. $count++;
  443. }
  444. }
  445. // 计算平均值
  446. if ($count > 0) {
  447. $average = $total / $count;
  448. // 格式化为百分比字符串,保留两位小数
  449. $item["平均值"] = sprintf("%.2f%%", $average);
  450. } else {
  451. $item["平均值"] = "0.00%"; // 如果没有数据,则为 0.00%
  452. }
  453. }
  454. $this->success('成功',$result);
  455. }
  456. /**
  457. * 获取年分数据
  458. * @return void
  459. */
  460. public function GetYear()
  461. {
  462. if ($this->request->isGet() === false){
  463. $this->error('请求错误');
  464. }
  465. $data = \db('工单_质量考核汇总')
  466. ->group('year')
  467. ->column('YEAR(STR_TO_DATE(sys_ny, "%Y%m")) as year');
  468. $this->success('成功',$data);
  469. }
  470. /**
  471. * 数据透视表
  472. * @return null
  473. * @throws \think\Exception
  474. * @throws \think\db\exception\DataNotFoundException
  475. * @throws \think\db\exception\ModelNotFoundException
  476. * @throws \think\exception\DbException
  477. */
  478. public function PoductData()
  479. {
  480. if (!$this->request->isGet()) {
  481. $this->error('请求错误');
  482. }
  483. $param = $this->request->param();
  484. if (empty($param['year'])) {
  485. $this->error('参数错误');
  486. }
  487. // 定义分类规则及顺序
  488. $processOrder = [
  489. 1 => ['name' => '胶印工序', 'keys' => ['胶印', '上光']],
  490. 2 => ['name' => '凹印工序', 'keys' => ['卷凹']],
  491. 3 => ['name' => '圆烫工序', 'keys' => ['圆烫']],
  492. 4 => ['name' => '圆切工序', 'keys' => ['圆切']],
  493. 5 => ['name' => '烫模工序', 'keys' => ['烫金', '模切', '凹凸']],
  494. 6 => ['name' => '丝印工序', 'keys' => ['丝印']],
  495. 7 => ['name' => '喷码工序', 'keys' => ['喷码']],
  496. 8 => ['name' => '单凹工序', 'keys' => ['单凹']]
  497. ];
  498. // 构建基础查询
  499. $query = \db('工单_质量考核汇总')
  500. ->alias('a')
  501. ->field('
  502. a.sczl_jtbh AS 机台编号,
  503. a.Gy0_gdbh AS 工单编号,
  504. a.印件及工序 AS 工序号,
  505. a.产品名称 AS 印件名称,
  506. a.工序 AS 工序,
  507. a.工序名称,
  508. a.联数,
  509. a.班组产量,
  510. a.班组制程废品,
  511. a.班组质检废品,
  512. a.sczl_bzdh AS 班组编号,
  513. b.印刷方式,
  514. b.版距,
  515. DATE_FORMAT(a.入仓日期, \'%Y%m\') AS 完工年月
  516. ')
  517. ->join('工单_工艺资料 b', 'a.Gy0_gdbh = b.Gy0_gdbh AND a.印件及工序 = b.Gy0_yjno AND a.工序 = b.Gy0_gxh')
  518. ->where('a.sys_ny', 'like', $param['year'] . '%')
  519. ->where('a.工序名称','not like','%机检%')
  520. ->where('a.工序名称','not like','%拆片%');
  521. // 获取总数
  522. $total = clone $query;
  523. $total = $total->count();
  524. // 执行查询
  525. $rawList = isset($param['page'], $param['limit'])
  526. ? $query->page($param['page'])->limit($param['limit'])->select()
  527. : $query->select();
  528. // 处理分类标记
  529. $processedList = [];
  530. foreach ($rawList as $item) {
  531. $matched = false;
  532. // 顺序匹配分类规则
  533. foreach ($processOrder as $typeId => $rule) {
  534. foreach ($rule['keys'] as $keyword) {
  535. if (strpos($item['工序名称'], $keyword) !== false) {
  536. // 添加分类标记
  537. $item['type_id'] = $typeId;
  538. $item['type_name'] = $rule['name'];
  539. $processedList[] = $item;
  540. $matched = true;
  541. break 2; // 跳出两层循环
  542. }
  543. }
  544. }
  545. // 未匹配到分类的数据丢弃
  546. }
  547. // 按分类顺序排序(保持1-8的顺序)
  548. usort($processedList, function($a, $b) {
  549. return $a['type_id'] <=> $b['type_id'];
  550. });
  551. // 返回结构
  552. $data['data'] = $processedList;
  553. $data['total'] = $total; // 原始总数
  554. $data['filtered_total'] = count($processedList); // 实际有效数
  555. return count($processedList) > 0
  556. ? $this->success('成功', $data)
  557. : $this->error('未找到数据');
  558. }
  559. }