| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Cache;
- use think\Exception;
- use think\Log;
- use \think\Request;
- use \think\Db;
- /**
- * 报表接口
- */
- class OrderSuperLoss extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**
- * 首页-已核查成品编号
- *
- */
- public function index()
- {
- $this->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')
- ->join('设备_产量计酬 c', 'g.订单编号 = c.订单编号', 'LEFT')
- ->where('g.落货日期', '>=', $start)
- ->where('g.落货日期', '<', $end)
- ->whereNull('g.Mod_rq')
- ->whereNull('c.Mod_rq')
- ->field([
- 'g.接单日期 as 下单日期',
- 'g.落货日期 as 货期',
- 'g.生产款号 as 款号',
- 'g.订单数量',
- 'g.工单入仓数量 as 入库数量',
- 'g.款式',
- 'g.客户编号 as 客人编号',
- \think\Db::raw('MIN(CASE WHEN d.name = "入库" THEN d.rq END) as 面料入库时间'),
- \think\Db::raw('MIN(CASE WHEN c.工序名称 = "裁剪" THEN c.sczl_rq END) as 开裁日期'),
- \think\Db::raw('SUM(CASE WHEN c.工序名称 = "裁剪" THEN c.数量 ELSE 0 END) as 实裁数量'),
- \think\Db::raw('MIN(CASE WHEN c.工序名称 = "车缝" THEN c.sczl_rq END) as 上车位日期'),
- \think\Db::raw('MIN(CASE WHEN c.工序名称 = "车缝" AND c.尾包 = 1 THEN c.sczl_rq END) as 车位完成日期'),
- \think\Db::raw('MIN(CASE WHEN c.工序名称 = "手工" AND c.尾包 = 1 THEN c.sczl_rq END) as 后道完成日期'),
- \think\Db::raw('SUM(CASE WHEN c.工序名称 = "包装" THEN c.数量 ELSE 0 END) 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['生产组别'] = '';
- }
- }
- $this->success('成功', $list);
- }
-
- }
|