success('请求成功'); } /** * 获取工单接单日期的年月列表(左侧菜单栏) * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getWorkOrderDates() { if ($this->request->isGet() === false) { $this->error('请求错误'); } $list = \think\Db::table('工单_基本资料') ->whereNull('Mod_rq') // 排除 Mod_rq 不为 null 的数据 ->where('落货日期', '<>', '') // 排除空值 ->field(\think\Db::raw('DATE_FORMAT(落货日期, "%Y-%m") as 年月')) ->group('年月') ->order('年月', 'desc') // 按年月倒序排列,最新的在前面 ->select(); if (empty($list)) { $this->success('', []); } // 提取年月值组成数组 $data = []; foreach ($list as $item) { $data[] = $item['年月']; } $this->success('成功', $data); } /** * 根据月份获取工单数据(排除已修改记录) * @return void * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function getWorkOrdersByMonth() { if ($this->request->isGet() === false) { $this->error('请求错误'); } $rq = $this->request->get('rq'); if (empty($rq) || !preg_match('/^\d{4}-\d{2}$/', $rq)) { $this->error('参数格式错误,请使用 YYYY-MM 格式'); } // 计算月份起止日期 list($year, $month) = explode('-', $rq); $start = "{$year}-{$month}-01"; $end = date('Y-m-d', strtotime("{$year}-{$month}-01 +1 month")); $list = \think\Db::table('工单_基本资料') ->alias('g') ->join('库存_出入库明细 d', 'g.订单编号 = d.order_id', 'LEFT') ->where('g.落货日期', '>=', $start) ->where('g.落货日期', '<', $end) ->whereNull('g.Mod_rq') ->field([ 'g.Uniqid', 'g.订单编号', 'g.审核 as 核批', 'g.审核日期 as 核批日期', 'g.接单日期 as 下单日期', 'g.落货日期 as 货期', 'g.生产款号 as 款号', 'g.订单数量', 'g.工单入仓数量 as 入库数量', 'g.款式', 'g.客户编号 as 客人编号', // 面料入库时间 - 使用子查询避免重复 \think\Db::raw('(SELECT MIN(rq) FROM 库存_出入库明细 WHERE order_id = g.订单编号 AND name = "入库") as 面料入库时间'), // 裁剪相关 - 使用子查询 \think\Db::raw('(SELECT MIN(sczl_rq) FROM 设备_产量计酬 WHERE 订单编号 = g.订单编号 AND 工序名称 = "裁剪" AND Mod_rq IS NULL) as 开裁日期'), \think\Db::raw('(SELECT SUM(数量) FROM 设备_产量计酬 WHERE 订单编号 = g.订单编号 AND 工序名称 = "裁剪" AND Mod_rq IS NULL) as 实裁数量'), // 车缝相关 - 使用子查询 \think\Db::raw('(SELECT MIN(sczl_rq) FROM 设备_产量计酬 WHERE 订单编号 = g.订单编号 AND 工序名称 = "车缝" AND Mod_rq IS NULL) as 上车位日期'), \think\Db::raw('(SELECT MIN(sczl_rq) FROM 设备_产量计酬 WHERE 订单编号 = g.订单编号 AND 工序名称 = "车缝" AND 尾包 = 1 AND Mod_rq IS NULL) as 车位完成日期'), // 后道相关 - 使用子查询 \think\Db::raw('(SELECT MIN(sczl_rq) FROM 设备_产量计酬 WHERE 订单编号 = g.订单编号 AND 工序名称 = "手工" AND 尾包 = 1 AND Mod_rq IS NULL) as 后道完成日期'), // 包装完成数量 - 使用子查询 \think\Db::raw('(SELECT SUM(数量) FROM 设备_产量计酬 WHERE 订单编号 = g.订单编号 AND 工序名称 = "包装" AND Mod_rq IS NULL) as 已完成数量'), // 生产组别 - 使用子查询 \think\Db::raw('(SELECT GROUP_CONCAT(DISTINCT SUBSTRING(sczl_jtbh, 3, 2) ORDER BY SUBSTRING(sczl_jtbh, 3, 2) SEPARATOR "、") FROM 设备_产量计酬 WHERE 订单编号 = g.订单编号 AND 工序名称 = "车缝" AND Mod_rq IS NULL) as 生产组别'), // 占位字段 \think\Db::raw('NULL as 辅料入库时间'), \think\Db::raw('NULL as 台产'), \think\Db::raw('NULL as 产前样批核'), \think\Db::raw('NULL as 备注'), ]) ->group('g.订单编号') ->select(); if (empty($list)) { $this->success('', []); } // 处理日期字段,去掉时分秒 $dateFields = ['下单日期', '货期', '面料入库时间', '辅料入库时间', '开裁日期', '上车位日期', '车位完成日期', '后道完成日期']; foreach ($list as &$item) { foreach ($dateFields as $field) { if (isset($item[$field]) && !empty($item[$field])) { $item[$field] = date('Y-m-d', strtotime($item[$field])); } } if (empty($item['生产组别'])) { $item['生产组别'] = ''; } // 确保数值字段为整数 $item['实裁数量'] = intval($item['实裁数量'] ?? 0); $item['已完成数量'] = intval($item['已完成数量'] ?? 0); $item['订单数量'] = intval($item['订单数量'] ?? 0); $item['入库数量'] = intval($item['入库数量'] ?? 0); } $this->success('成功', $list); } }